Tinkerpop 3 M6 Union Step

82 views
Skip to first unread message

Nick DeYoung

unread,
Mar 12, 2015, 12:58:45 PM3/12/15
to gremli...@googlegroups.com
Context 

I'm working on a project where we have a tool that can generate generic germlin traversals from a json representation of the query. 
I'm trying to handle a case where we can 'or' queries together and I'm trying to use the UnionStep to do this. 

However when I have a traversal in the Union Step that has an 'as()' and a 'back()' I get an error: 

g.V().union(g.of().as('IwanttoEmitThese").out("someEdgeLabel").has("someProperty","someValue").back("IwanttoEmitThese"),g.of().has("someProperty2","someValue"))

java.lang.IllegalArgumentException: Side effects do not have a value for provided key: v1
at com.tinkerpop.gremlin.process.Traversal$SideEffects$Exceptions.sideEffectDoesNotExist(Traversal.java:432) ~[gremlin-core-3.0.0.M6.jar:na]
at com.tinkerpop.gremlin.process.util.DefaultTraversalSideEffects.get(DefaultTraversalSideEffects.java:103) ~[gremlin-core-3.0.0.M6.jar:na]
at com.tinkerpop.gremlin.process.Traverser.get(Traverser.java:91) ~[gremlin-core-3.0.0.M6.jar:na]
at com.tinkerpop.gremlin.process.graph.step.map.BackStep.lambda$new$33(BackStep.java:21) ~[gremlin-core-3.0.0.M6.jar:na]
at com.tinkerpop.gremlin.process.graph.step.map.BackStep$$Lambda$74/2115737255.apply(Unknown Source) ~[na:na]
at com.tinkerpop.gremlin.process.graph.step.map.MapStep.processNextStart(MapStep.java:27) ~[gremlin-core-3.0.0.M6.jar:na]
at com.tinkerpop.gremlin.process.util.AbstractStep.hasNext(AbstractStep.java:105) ~[gremlin-core-3.0.0.M6.jar:na]
at com.tinkerpop.gremlin.process.util.DefaultTraversal.hasNext(DefaultTraversal.java:77) ~[gremlin-core-3.0.0.M6.jar:na]
at com.tinkerpop.gremlin.process.graph.step.branch.UnionStep.processNextStart(UnionStep.java:30) ~[gremlin-core-3.0.0.M6.jar:na]
at com.tinkerpop.gremlin.process.util.AbstractStep.hasNext(AbstractStep.java:105) ~[gremlin-core-3.0.0.M6.jar:na]
at com.tinkerpop.gremlin.process.util.ExpandableStepIterator.next(ExpandableStepIterator.java:33) ~[gremlin-core-3.0.0.M6.jar:na]
at com.tinkerpop.gremlin.process.graph.step.map.MapStep.processNextStart(MapStep.java:24) ~[gremlin-core-3.0.0.M6.jar:na]
at com.tinkerpop.gremlin.process.util.AbstractStep.next(AbstractStep.java:89) ~[gremlin-core-3.0.0.M6.jar:na]
at com.tinkerpop.gremlin.process.util.AbstractStep.next(AbstractStep.java:15) ~[gremlin-core-3.0.0.M6.jar:na]
at com.tinkerpop.gremlin.process.Traversal.fill(Traversal.java:181) ~[gremlin-core-3.0.0.M6.jar:na]
at com.tinkerpop.gremlin.process.Traversal.toList(Traversal.java:157) ~[gremlin-core-3.0.0.M6.jar:na] 

The Google for "Side effects do not have a value for provided key" 

gave me some results, but this seemed the most pertinent: 


Not super helpful to me not sure how to use __ in java on M6 (question 1) i guess if there is an example of this

so I fired up the gremlin console to try do accomplish this in the console: 

Here's what I tried to do in console: 

g = TinkerGraph.open()
marko = g.addVertex(label,"instance","name","marko")
markoSmell = g.addVertex(label,"instance","smellProperty","smelly")
markoSmellAttachment = g.addVertex(label,"instance","name","SmellyPicture")
marko.addEdge("smell",markoSmell)
markoSmell.addEdge("attachment",markoSmellAttachment)

nick = g.addVertex(label,"instance","name","nick")
nickSmell = g.addVertex(label,"instance","smellProperty","sweet")
nick.addEdge("smell",nickSmell)



g.V()
g.E()
g.V().outE("smell")
g.V().out("smell").has("smellProperty","smelly")
g.V().out("smell").outE("attachment")

// anything that has a smell with the smellProperty == 'smelly' or 
// anything that has a smell with the an attachment with the name == 'SmellyPicture'

g.V().out("smell").as("a").union(g.of().has("smellProperty","smelly",g.of().as("b").out("attachment").has("name","SmellyPicture").back("b").back("a")


Here's the console output, see at the end that the console just fails and stops working after executing the traversal with the union 

:( anyone have thoughts?


thanks

// ndy

         \,,,/

         (o o)

-----oOOo-(3)-oOOo-----

plugin activated: tinkerpop.server

plugin activated: tinkerpop.utilities

plugin activated: tinkerpop.tinkergraph

gremlin> g = TinkerGraph.open()

==>tinkergraph[vertices:0 edges:0]

gremlin> marko = g.addVertex(label,"instance","name","marko")

==>v[0]

gremlin> markoSmell = g.addVertex(label,"instance","smellProperty","smelly")

==>v[2]

gremlin> markoSmellAttachment = g.addVertex(label,"instance","name","SmellyPicture")

==>v[4]

gremlin> marko.addEdge("smell",markoSmell)

==>e[6][0-smell->2]

gremlin> markoSmell.addEdge("attachment",markoSmellAttachment)

==>e[7][2-attachment->4]

gremlin> nick = g.addVertex(label,"instance","name","nick")

==>v[8]

gremlin> nickSmell = g.addVertex(label,"instance","smellProperty","sweet")

==>v[10]

gremlin> nick.addEdge("smell",nickSmell)

==>e[12][8-smell->10]

gremlin> g.V()

==>v[0]

==>v[2]

==>v[4]

==>v[8]

==>v[10]

gremlin> g.E()

==>e[6][0-smell->2]

==>e[7][2-attachment->4]

==>e[12][8-smell->10]

gremlin> g.V().outE("smell")

==>e[6][0-smell->2]

==>e[12][8-smell->10]

gremlin> g.V().out("smell").has("smellProperty","smelly")

==>v[2]

gremlin> g.V().out("smell").outE("attachment")

==>e[7][2-attachment->4]

gremlin> g.V().out("smell").as("a").union(g.of().has("smellProperty","smelly",g.of().as("b").out("attachment").has("name","SmellyPicture").back("b").back("a")

gremlin> g

groovysh_parse: 3: expecting ')', found 'g' @ line 3, column 1.

   g

   ^


1 error

Display stack trace? [yN] gn

gremlin> g.V()

groovysh_parse: 3: expecting ')', found 'g' @ line 3, column 1.

   g.V()

   ^


1 error

Display stack trace? [yN] n

gremlin> g

groovysh_parse: 3: expecting ')', found 'g' @ line 3, column 1.

   g

   ^


1 error

Display stack trace? [yN] y

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:

groovysh_parse: 3: expecting ')', found 'g' @ line 3, column 1.

   g

   ^


1 error


at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:309)

at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:106)

at org.codehaus.groovy.control.ErrorCollector.addFatalError(ErrorCollector.java:148)

at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:119)

at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:131)

at org.codehaus.groovy.control.SourceUnit.addError(SourceUnit.java:359)

at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:142)

at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:108)

at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:236)

at org.codehaus.groovy.tools.shell.RigidParser.parse(Parser.groovy:157)

at org.codehaus.groovy.tools.shell.Parser.parse(Parser.groovy:73)

at org.codehaus.groovy.tools.shell.Groovysh.execute(Groovysh.groovy:172)

at org.codehaus.groovy.tools.shell.Shell.leftShift(Shell.groovy:119)

at org.codehaus.groovy.tools.shell.ShellRunner.work(ShellRunner.groovy:94)

at org.codehaus.groovy.tools.shell.InteractiveShellRunner.super$2$work(InteractiveShellRunner.groovy)

at sun.reflect.GeneratedMethodAccessor33.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:483)

at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)

at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1208)

at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:130)

at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuper0(ScriptBytecodeAdapter.java:150)

at org.codehaus.groovy.tools.shell.InteractiveShellRunner.work(InteractiveShellRunner.groovy:123)

at org.codehaus.groovy.tools.shell.ShellRunner.run(ShellRunner.groovy:58)

at org.codehaus.groovy.tools.shell.InteractiveShellRunner.super$2$run(InteractiveShellRunner.groovy)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:483)

at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)

at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1208)

at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:130)

at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuper0(ScriptBytecodeAdapter.java:150)

at org.codehaus.groovy.tools.shell.InteractiveShellRunner.run(InteractiveShellRunner.groovy:82)

at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:215)

at com.tinkerpop.gremlin.console.Console.<init>(Console.groovy:95)

at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:636)

at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:215)

at com.tinkerpop.gremlin.console.Console.main(Console.groovy:248)

gremlin> 

Nick DeYoung

unread,
Mar 12, 2015, 1:04:41 PM3/12/15
to gremli...@googlegroups.com
g.V().out("smell").as("a").union(g.of().has("smellProperty","smelly"),g.of().as("b").out("attachment").has("name","SmellyPicture")).back("b").back("a")

gives: 

gremlin> g.V().out("smell").as("a").union(g.of().has("smellProperty","smelly"),g.of().as("b").out("attachment").has("name","SmellyPicture")).back("b").back("a")

java.lang.IllegalStateException

Display stack trace? [yN] y

java.lang.IllegalStateException

at com.tinkerpop.gremlin.structure.Graph.of(Graph.java:149)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:483)

at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSite.invoke(PojoMetaMethodSite.java:189)

at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)

at groovysh_evaluate.run(groovysh_evaluate:3)

at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:215)

at org.codehaus.groovy.tools.shell.Interpreter.evaluate(Interpreter.groovy:69)

at org.codehaus.groovy.tools.shell.Groovysh.execute(Groovysh.groovy:185)

at org.codehaus.groovy.tools.shell.Shell.leftShift(Shell.groovy:119)

at org.codehaus.groovy.tools.shell.ShellRunner.work(ShellRunner.groovy:94)

at org.codehaus.groovy.tools.shell.InteractiveShellRunner.super$2$work(InteractiveShellRunner.groovy)

at sun.reflect.GeneratedMethodAccessor32.invoke(Unknown Source)

Caused by: java.lang.NullPointerException

at com.tinkerpop.gremlin.structure.Graph.of(Graph.java:147)

... 42 more

Nick DeYoung

unread,
Mar 12, 2015, 4:52:34 PM3/12/15
to gremli...@googlegroups.com
so my problem was I was not using 3.0.0.M6 gremlin console, 
once I git checkout tags/3.0.0.M6 and mvn clean install -DfeelingLucky and run /bin/gremlin.sh I get this: 


just lin in my Java. 


         \,,,/

         (o o)

-----oOOo-(3)-oOOo-----

gremlin> :plugin list

==>tinkerpop.server

==>tinkerpop.gephi

==>tinkerpop.utilities

==>tinkerpop.sugar

==>tinkerpop.tinkergraph

gremlin> :plugin use tinkerpop.tinkergraph

==>tinkerpop.tinkergraph activated

gremlin> :plugin use tinkerpop.utilities

==>tinkerpop.utilities activated

gremlin> g = TinkerGraph.open()

==>tinkergraph[vertices:0 edges:0]

gremlin> g.addVertex(label,"instance","name","marko")

==>v[0]

gremlin> g.V().union(g.of().as('a').has("name","marko").back('a'))

Side effects do not have a value for provided key: a

Display stack trace? [yN] y

java.lang.IllegalArgumentException: Side effects do not have a value for provided key: a

at com.tinkerpop.gremlin.process.Traversal$SideEffects$Exceptions.sideEffectDoesNotExist(Traversal.java:432)

at com.tinkerpop.gremlin.process.util.DefaultTraversalSideEffects.get(DefaultTraversalSideEffects.java:103)

at com.tinkerpop.gremlin.process.Traverser.get(Traverser.java:91)

at com.tinkerpop.gremlin.process.graph.step.map.BackStep.lambda$new$370(BackStep.java:21)

at com.tinkerpop.gremlin.process.graph.step.map.BackStep$$Lambda$22/1968298538.apply(Unknown Source)

at com.tinkerpop.gremlin.process.graph.step.map.MapStep.processNextStart(MapStep.java:27)

at com.tinkerpop.gremlin.process.util.AbstractStep.hasNext(AbstractStep.java:105)

at com.tinkerpop.gremlin.process.util.DefaultTraversal.hasNext(DefaultTraversal.java:77)

at com.tinkerpop.gremlin.process.graph.step.branch.UnionStep.processNextStart(UnionStep.java:30)

at com.tinkerpop.gremlin.process.util.AbstractStep.hasNext(AbstractStep.java:105)

at com.tinkerpop.gremlin.process.util.DefaultTraversal.hasNext(DefaultTraversal.java:77)

at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:215)

at com.tinkerpop.gremlin.console.Console$_closure3.doCall(Console.groovy:155)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:483)

at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)

at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324)

at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:278)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1016)

at org.codehaus.groovy.tools.shell.Groovysh.setLastResult(Groovysh.groovy:370)

at org.codehaus.groovy.tools.shell.Groovysh.this$3$setLastResult(Groovysh.groovy)

at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:215)

at org.codehaus.groovy.tools.shell.Groovysh.execute(Groovysh.groovy:159)

at org.codehaus.groovy.tools.shell.Shell.leftShift(Shell.groovy:121)

at org.codehaus.groovy.tools.shell.ShellRunner.work(ShellRunner.groovy:93)

at org.codehaus.groovy.tools.shell.InteractiveShellRunner.super$2$work(InteractiveShellRunner.groovy)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:483)

at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)

at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1207)

at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:130)

at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuper0(ScriptBytecodeAdapter.java:150)

at org.codehaus.groovy.tools.shell.InteractiveShellRunner.work(InteractiveShellRunner.groovy:123)

at org.codehaus.groovy.tools.shell.ShellRunner.run(ShellRunner.groovy:57)

at org.codehaus.groovy.tools.shell.InteractiveShellRunner.super$2$run(InteractiveShellRunner.groovy)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:483)

at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)

at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1207)

at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:130)

at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuper0(ScriptBytecodeAdapter.java:150)

at org.codehaus.groovy.tools.shell.InteractiveShellRunner.run(InteractiveShellRunner.groovy:83)

at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:215)

at com.tinkerpop.gremlin.console.Console.<init>(Console.groovy:99)

at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:636)

at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:215)

at com.tinkerpop.gremlin.console.Console.main(Console.groovy:252)

gremlin> 



Daniel Kuppitz

unread,
Mar 12, 2015, 5:34:54 PM3/12/15
to gremli...@googlegroups.com
Hey Nick,

you don't need .back(), you can/should do this instead:

g.V().union(g.of().has("name","marko"), ...)

Cheers,
Daniel


--
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/8f749c7b-6c4c-43dd-a532-122390c1366f%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Nick DeYoung

unread,
Mar 12, 2015, 5:49:21 PM3/12/15
to gremli...@googlegroups.com
Daniel, 

the example was to show the error. 

For example, 

// keep anything that has an edge 
// or keep anything that has a name marko
g.V().union(g.of().as('retainThis').out().back('retainThis'), g.of().has('name') 

what I'm trying to acomplish with union is 

I want union to take anonymous traversals. If an anonymous traversal contains an .as(),.back() I'm hosed. 
I'm sure this is fixed in M7 or further, but Titan 0.9M1 is on TP3M6 .. 



For more options, visit https://groups.google.com/d/optout.



--
// ndy 

Nick DeYoung

unread,
Mar 12, 2015, 5:55:03 PM3/12/15
to gremli...@googlegroups.com
for more of a concrete example

this JSON

// anything that has a smell with the smellProperty == 'sick' or 
// anything that has a smell with the an attachment with the name == 'SmellyPicture'
{
"smell": {
"or": {
"smellProperty":"sick",
"attachment": {
"name":"SmellyPicture"
}
}
}
}

needs to become this traversal

g.V.as("a").out("smell").union(g.of().has("smellProperty","sick"),g.of().as("b").out("attachment").has("name","SmellyPicture").back("b")).back("a")

but that traversal kabooms
--
// ndy 

Daniel Kuppitz

unread,
Mar 12, 2015, 6:38:38 PM3/12/15
to gremli...@googlegroups.com
In the current version you can do .has(traversal), but that wasn't possible in M6. As a workaround you can do:

g.V().union(g.of().filter { it.get().out().hasNext() }, g.of().has('name'))

In newer versions simply do:

g.V().union(has(out()), has('name'))

Cheers,
Daniel


Reply all
Reply to author
Forward
0 new messages