gremlin-bin
gremlin-bin copied to clipboard
Tinkerpop3 doc example fails
The following examples all fail or return a different output :
-
[x] 1) Error
g.V().values('age').fold(0) {a,b -> a + b}
Solution : The typeChecker has no way of inferring what types a and b are,
double
?int
? So we need to manually define them :g.V().values('age').fold(0) {Integer a, Integer b -> a + b}
-
[ ] 2) Error. Once this is fixed I expect that it will not do anything just like
tree()
in 7) this will not serialize properly.g.V().hasLabel('person').outE().identity().inV().count().is(gt(5)).explain()
Solution: For some reason the TypeChecker is not liking the fact that gt(5) has an
Int
rather than aLong
:g.V().hasLabel('person').outE().identity().inV().count().is(gt(5L)).explain()
-
[x] 3) Error. This fails because
System
is not available due to sandboxing. Might not fix this.g.V().sideEffect{println "first: ${it}"}.sideEffect{println "second: ${it}"}.iterate()
-
[ ] 4) Wrong output.
rand = new Random(); g.withSack {rand.nextFloat()}.V().sack()
Returns :
==>Script10$_run_closure1@449cbd0b ==>Script10$_run_closure1@449cbd0b ==>Script10$_run_closure1@449cbd0b ==>Script10$_run_closure1@449cbd0b ==>Script10$_run_closure1@449cbd0b ==>Script10$_run_closure1@449cbd0b
But should be :
==>0.4141646 ==>0.585294 ==>0.0681594 ==>0.9641305 ==>0.7095289 ==>0.33176965
-
[ ] 5) Error
g.withSack {[:]}{it.clone()}.V().out().out(). sack {m,v -> m[v.value('name')] = v.value('lang'); m}.sack()
Partial fix :
g.withSack {[:]}{it.clone()}.V().out().out(). sack {Map m, Vertex v -> m[v.value('name')] = v.value('lang'); m}.sack()
Still throws error :
Could not complete query: startup failed: Script10.groovy: 1: [Static type checking] - Cannot find matching method org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource#withSack(groovy.lang.Closure, groovy.lang.Closure). Please check if the declared type is right and if the method exists. @ line 1, column 1. g.withSack {[:]}{it.clone()}.V().out().out().sack {Map m,Vertex v -> m[v.value('name')] = v.value('lang'); m}.sack() ^ 1 error (Error 597)
-
[ ] 6) Error
g.V(1).repeat(local( bothE().sample(1).by('weight').otherV() )).times(5).path()
Solution :
g.V(1).repeat((GraphTravseral)local( bothE().sample(1).by('weight').otherV() )).times(5).path()
-
[ ] 7) Nothing happens. This is due to the fact tat
tree()
doesn't serialize properly inGraphSON
. (see https://issues.apache.org/jira/browse/TINKERPOP-732 )tree = g.V().out().out().tree().next()
-
[ ] 8) Error
g.V(1).out().fold().inject('gremlin',[1.23,2.34]).unfold()
-
[ ] 9) Error
inject(1,[2,3,[4,5,[6]]]).repeat(unfold()).until(count(local).is(1)).unfold()
Solution :
inject(1,[2,3,[4,5,[6]]]).repeat((GraphTraversal)unfold()).until(count(local).is(1)).unfold()
-
[ ] 10) Error
g.V().out().out().path() .by {it.value('name')} .by {it.value('name')} .by {g.V(it).in('created').values('name').fold().next()}
Partial fix :
g.V().out().out().path() .by {Vertex it -> it.value('name')} .by {Vertex it -> it.value('name')} .by {g.V(it).in('created').values('name').fold().next()}
Still fails with :
Could not complete query: startup failed: Script39.groovy: 1: [Static type checking] - Reference to method is ambiguous. Cannot choose between [org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal <S, E> org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal <S extends java.lang.Object, E extends java.lang.Object>#by(org.apache.tinkerpop.gremlin.process.traversal.Order), org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal <S, E> org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal <S extends java.lang.Object, E extends java.lang.Object>#by(java.util.Comparator <E>), org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal <S, E> org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal <S extends java.lang.Object, E extends java.lang.Object>#by(java.util.function.Function <V, java.lang.Object>)] @ line 1, column 1. g.V().out().out().path().by {Vertex it -> it.value('name')}. by {Vertex it -> it.value('name')}. by {g.V(it).in('created').values('name').fold().next()} ^ 1 error (Error 597)
-
[x] 11) Can't work because it's a
ConsoleMutationListener
gremlin> graph = TinkerFactory.createModern() ==>tinkergraph[vertices:6 edges:6] gremlin> l = new ConsoleMutationListener(graph) ==>MutationListener[tinkergraph[vertices:6 edges:6]] gremlin> strategy = EventStrategy.build().addListener(l).create() ==>EventStrategy gremlin> g = GraphTraversalSource.build().with(strategy).create(graph) ==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard] gremlin> g.addV('name','stephen') Vertex [v[12]] added to graph [tinkergraph[vertices:7 edges:6]] ==>v[12] gremlin> g.E().drop() Edge [e[7][1-knows->2]] removed from graph [tinkergraph[vertices:7 edges:6]] Edge [e[8][1-knows->4]] removed from graph [tinkergraph[vertices:7 edges:5]] Edge [e[9][1-created->3]] removed from graph [tinkergraph[vertices:7 edges:4]] Edge [e[10][4-created->5]] removed from graph [tinkergraph[vertices:7 edges:3]] Edge [e[11][4-created->3]] removed from graph [tinkergraph[vertices:7 edges:2]] Edge [e[12][6-created->3]] removed from graph [tinkergraph[vertices:7 edges:1]]
-
[ ] 12) Error
gremlin> graph = TinkerFactory.createModern() ==>tinkergraph[vertices:6 edges:6] gremlin> strategy = SubgraphStrategy.build().edgeCriterion(hasId(8,9,10)).create() ==>SubgraphStrategy gremlin> g = GraphTraversalSource.build().with(strategy).create(graph) ==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard] gremlin> g.V() // shows all vertices as no filter for vertices was specified ==>v[1] ==>v[2] ==>v[3] ==>v[4] ==>v[5] ==>v[6] gremlin> g.E() // shows only the edges defined in the edgeCriterion ==>e[8][1-knows->4] ==>e[9][1-created->3] ==>e[10][4-created->5]