Are TinkerGraph IDs now strings?

1.057 прегледа
Пређи на прву непрочитану поруку

Kelvin Lawrence

непрочитано,
23. 4. 2015. 10:34:1123.4.15.
– gremli...@googlegroups.com
Quick question and I apologize in advance if it has been asked before (I did do a search and did not find it).

I have been doing some tire kicking on the Tinkerpop 3 download (M7 is the current level I think).

It appears that when using TinkerGraph now, that IDs are strings.

Is this correct and if so I am curious why this change was made as I believe they were integers before and are still long integers in Titan.

So on Tinkerpop 2 I would use

    g.v(47)   or i=47; g.v(i) to get to the node with ID 47

But, on Tinkerpop 3 (TinkerGraph) is have to use

    g.V('47') or g.V(i.toString())


Am I missing something?

This makes writing prototype code on TinkerGraph and then moving it to, say, Titan a pain as one uses strings and the other uses integers.


Sorry for the beginner level question but I am curious?


Sidenote: As I play with Tinkerpop 3 I am keeping a log of the differences I see and I plan to contibute those as some sort of getting started post once TP 3 is fully stable.

Keep up the good work guys!

Stephen Mallette

непрочитано,
23. 4. 2015. 11:09:3323.4.15.
– gremli...@googlegroups.com
At M7, there was nothing that i can remember that internally coerced ids to strings that I can think of.  That's the easy answer for M7.  As of the latest and what we expect for GA, the answer is a bit more complicated.  As you can see, this works as it did in TP2:

gremlin> graph = TinkerGraph.open()
==>tinkergraph[vertices:0 edges:0]
gremlin> graph.addVertex(id,47)
==>v[47]
gremlin> g = graph.traversal()
==>graphtraversalsource[tinkergraph[vertices:1 edges:0], standard]
gremlin> g.V(47)
==>v[47]
gremlin> graph.addVertex(id,48l)
==>v[48]
gremlin> g.V(48)
gremlin> g.V(48l)
==>v[48]
gremlin> g.V("48")
gremlin> g.V("47")
gremlin> 

Note that the last couple tries to get it as a String doesn't return anything.  So types are intact internally.  As of the lastest work, you can configure TinkerGraph with an IdManager:

gremlin> conf = new BaseConfiguration()
==>org.apache.commons.configuration.BaseConfiguration@79f227a9
gremlin> conf.setProperty("gremlin.tinkergraph.vertexIdManager","LONG")
==>null
gremlin> graph = TinkerGraph.open(conf)
==>tinkergraph[vertices:0 edges:0]
gremlin> graph.addVertex(id,47)
==>v[47]
gremlin> graph.addVertex(id,48l)
==>v[48]
gremlin> graph.addVertex(id,"49")
==>v[49]

In the above example the IdManager for vertices is configured with the LongIdManager which basically forces all IDs to Long:

gremlin> g.V().id().map{it.get()getClass()}
==>class java.lang.Long
==>class java.lang.Long
==>class java.lang.Long

which is helpful in some cases because if TinkerGraph knows the types it can do this:

gremlin> g = graph.traversal()
==>graphtraversalsource[tinkergraph[vertices:3 edges:0], standard]
gremlin> g.V("47")
==>v[47]
gremlin> g.V(47)
==>v[47]
gremlin> g.V(48)
==>v[48]
gremlin> g.V(49)
==>v[49]
gremlin> g.V(49l)
==>v[49]

Note that usage of IdManager allows TinkerGraph to be compliant with the test suite in allowing g.V(v.id().toString()) to work properly.

With respect to:

> This makes writing prototype code on TinkerGraph and then moving it to, say, Titan a pain as one uses strings and the other uses integers.

You may yet have a pain in this area, as Titan (and most other Graph implementations) does not support id assignment.

Sidenote: As I play with Tinkerpop 3 I am keeping a log of the differences I see and I plan to contibute those as some sort of getting started post once TP 3 is fully stable.

cool - thanks!


--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/4d7a859c-7c94-4a72-84ba-6f1d2b83831a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kelvin Lawrence

непрочитано,
23. 4. 2015. 11:30:1023.4.15.
– gremli...@googlegroups.com
Thanks so much for the fast and detailed reply Stephen. Extremely useful. So much to learn so little time :-)

Cheers
Kelvin

Kelvin Lawrence

непрочитано,
4. 6. 2015. 18:44:474.6.15.
– gremli...@googlegroups.com
One more question on this if I may Stephen.

The example you gave works when done step by step as you showed, however when I load my graph using the graphML loader the IDs are still strings once loaded even with the base configuration in place.

Is there another step I need when loading from an XML file?




Stephen Mallette

непрочитано,
5. 6. 2015. 06:18:125.6.15.
– gremli...@googlegroups.com
Seems to work ok for me:

gremlin> conf = new BaseConfiguration()
==>org.apache.commons.configuration.BaseConfiguration@1922e6d
gremlin> conf.setProperty('gremlin.tinkergraph.vertexIdManager','LONG')
==>null
gremlin> conf.setProperty('gremlin.graph','org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph')
==>null
gremlin> graph = TinkerGraph.open(conf)
==>tinkergraph[vertices:0 edges:0]
gremlin> graph.io(graphml()).readGraph('data/tinkerpop-modern.xml')
==>null
gremlin> graph.vertices().next().id()
==>1
gremlin> graph.vertices().next().id().class
==>class java.lang.Long

Note that I did the above on the latest SNAPSHOT (don't know if there is a problem in an old version or not).


--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.

Kelvin Lawrence

непрочитано,
5. 6. 2015. 09:32:565.6.15.
– gremli...@googlegroups.com
Hi Stephen, thanks for checking it out.

I see two differences between our tests.
1. I am using the latest public packaged code so back on M8 (I'll try on SNAPSHOT)
2. I have a slightly different call to the XML loading code:
--- graph.io().readGraphML('data/routedata.graphml') 

You are using readGraph and I am using readGraphML   (not sure if that is relevant but it's the only difference I see in our code)

Kelvin Lawrence

непрочитано,
5. 6. 2015. 12:40:385.6.15.
– gremli...@googlegroups.com
Update - it works on M9 using your version of the XML load step!!

Thanks !!

Kelvin Lawrence

непрочитано,
10. 6. 2015. 13:25:4410.6.15.
– gremli...@googlegroups.com
I am still missing something here it seems.

If I code this, id is treated as a string (not what I want)

gremlin> g.V().has(id,lt(10))
==>v[1]

So I ended up trying this and it works as expected.

gremlin> g.V().as('x').id.is(lt(10)).select('x')
==>v[1]
==>v[2]
==>v[3]
==>v[4]
==>v[5]
==>v[6]
==>v[7]
==>v[8]
==>v[9]

I'm sure I am still missing something here but these little subtleties are driving me up the wall!

Cheers
Kelvin

Marko Rodriguez

непрочитано,
10. 6. 2015. 14:14:0810.6.15.
– gremli...@googlegroups.com
Ha.

Here is the thing. Given the complexity of id uniqueness with Long vs. Integer vs. Short and Double vs. Float and Character vs. String, we decided that an IDs toString() representation is its symbol of uniqueness. Thus, has(id..) converts the id to String. You can do this to get to the IDs as numbers:

g.V.where(id().is(lt(10)))

HTH,
Marko.

Kelvin Lawrence

непрочитано,
10. 6. 2015. 14:20:4210.6.15.
– gremli...@googlegroups.com
Thanks Marko, so I was almost there! I had tried a few versions of where but not that one!!

Marko Rodriguez

непрочитано,
10. 6. 2015. 14:32:3310.6.15.
– gremli...@googlegroups.com
Great. Can you make a ticket demonstrating your problem? I think I know an easy way to make it work --- maybe.

Thanks,
Marko.

Kelvin Lawrence

непрочитано,
10. 6. 2015. 14:36:4710.6.15.
– gremli...@googlegroups.com
Sure thing, will do that. Might take me a couple of hours but next break I get will do it.

Kelvin

Kelvin Lawrence

непрочитано,
10. 6. 2015. 14:59:5810.6.15.
– gremli...@googlegroups.com
Ticket created.
Одговори свима
Одговори аутору
Проследи
0 нових порука