Search code examples
gremlintinkerpopjanusgraphtinkerpop3gremlin-server

Multiple properties of unknown number gremlin query


I am trying to add multiple properties to a gremlin vertex. Every time i have different number of properties and different properties as well so I need to make the query dynamic based on a Map to create or update the properties. I found this gremlin python - add multiple but an unknown number of properties to a vertex and tried to do the same with the difference that i instantiate a jansugraph but i get an error. Any ideas will be more than welcome.

The below are written in gremlin console directly, then i will translate it to java code.

graph =JanusGraphFactory.open("conf/test.properties")
g = graph.traversal()
test = [["testKey":"testValue"]]
g.inject(test).unfold().as("test")
 .V(20704).as("v").sideEffect(select("test"))
 .unfold().as("kv").select("v")
.property(select("kv").by(Column.keys),select("kv").by(Column.values)).iterate()

and the error i get is

The provided object does not have accessible keys: class org.janusgraph.graphdb.vertices.CacheVertex
Type ':help' or ':h' for help.
Display stack trace? [yN]y
java.lang.IllegalArgumentException: The provided object does not have accessible keys: class org.janusgraph.graphdb.vertices.CacheVertex

Any ideas what i am doing wrong, i cannot find what to use for keys and values regarding Janus


Solution

  • The main part of the query needs to be inside the sideEffect step. So something like...

    g.inject(test).unfold().as("test").
      V(20704).as("v").
      sideEffect(select("test").
         unfold().as("kv").
         select("v").
         property(select("kv").by(Column.keys),
                  select("kv").by(Column.values))).
      iterate()