g.inject(list).unfold().as("a").addV("person").choose(__select("a").select("name"), __.property("name", __.select("a").select("name")))
--
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/63f362e6-1c04-45a8-a157-bff03ae280d7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Why not generate a single giant query string by iterating through all 100 of your objects and appending to a string and building up like this:String generateQuery(){StringBuilder query;query.append(g);for (person p : persons) {query.append(".addV('person')");if (p.name != null) {query.append(".property('name'," + p.name + ")";}//... And so on}return query.toString();}g.addV('person').property('name','bob')...
On Sat, May 11, 2019 at 12:55 AM Huimin Yang <hya...@ncsu.edu> wrote:
i'm trying to create hundreds of vertices with different properties, for example there's a Java class named 'person', with class attributes: 'name', 'age', 'sex'. i want to create 100 vertex with label 'person' and each of them has different properties ('name', 'age', 'sex'). some of the property could be null, eg: person John only has two properties: name: 'John', age: '20'--I tried using ObjectMapper to Map the 100 'person' instances as Objects, and put these objects in a list and use inject:
g.inject(list).unfold().as("a").addV("person").choose(__select("a").select("name"), __.property("name", __.select("a").select("name")))
it actually works but the choose step is quite expensive in our case so it's better to avoid it.I'm thinking is there a better solution to create large size of vertices with different properties? Or is there a way without using inject and i could handle the null properties in Java?
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 gremli...@googlegroups.com.
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/4cb2ab90-5963-4651-9dbc-015746e20bcd%40googlegroups.com.
gremlin> g = TinkerGraph.open().traversal()==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]gremlin>gremlin> data = [["name": "Huimin Yang"],["name": "Daniel Kuppitz", "age": 37]]==>[name:Huimin Yang]==>[name:Daniel Kuppitz,age:37]gremlin>gremlin> g.inject(data).unfold().as("m").addV("person").as("v").select("m").unfold().as("kv").select("v").property(select("kv").by(keys), select("kv").by(values)).iterate()gremlin>gremlin> g.V().valueMap()==>[name:[Huimin Yang]]==>[name:[Daniel Kuppitz],age:[37]]
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/1a7761bb-2475-41d2-943a-63bd05016aa6%40googlegroups.com.
Is it possible to convert this query to upsert form like this https://stackoverflow.com/a/49758568
HasContainer accept only String key, therefore cant use dynamic keys
process = { g, persons ->data = persons.collectEntries {[it.name, it]}g.V().has("person", "name", within(data.keySet())).as("v").constant(data).select(select("v").by("name")).store("x").by(select("name")).unfold().filter(select(keys).is(neq("name"))).as("kv").
select("v").property(select("kv").by(keys), select("kv").by(values)).
count(). /* simplest way to reduce everything to a single traverser without wasting memory and CPU resources */constant(data.values()).unfold().filter(select("name").where(without("x"))).as("props").
addV("person").as("v").
select("props").unfold().as("kv").
select("v").property(select("kv").by(keys), select("kv").by(values)).iterate()}
gremlin> g = TinkerGraph.open().traversal()==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]gremlin> data = [["name": "Huimin Yang"],
["name": "Daniel Kuppitz", "age": 36]]; []gremlin> process(g, data)
gremlin> g.V().valueMap()==>[name:[Huimin Yang]]
Iteration #2==>[name:[Daniel Kuppitz],age:[36]]
gremlin> data = [["name": "Huimin Yang"],
["name": "Daniel Kuppitz", "age": 37],["name": "Pavel Ershov"]]; []gremlin> process(g, data)
gremlin> g.V().valueMap()==>[name:[Huimin Yang]]==>[name:[Daniel Kuppitz],age:[37]]
==>[name:[Pavel Ershov]]
--
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/2c99238b-11c1-4ccd-89cc-f7d01f4c56b8%40googlegroups.com.