Gremlin在存储GremlinGroovyPipeline时调用.count() [英] Gremlin when storing a GremlinGroovyPipeline and calling .count() on it

查看:174
本文介绍了Gremlin在存储GremlinGroovyPipeline时调用.count()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这符合预期:

  gremlin> root.out.outE.has('size',4).count()
==> 3
gremlin> result = root.out.outE.has('size',4).count()
==> 3
gremlin>结果
==> 3
gremlin> root.out.outE.has('count',4).getClass()
==> class com.tinkerpop.gremlin.groovy.GremlinGroovyPipeline
GremlinGroovyPipeline 存入一个变量时,我不能 count()
> gremlin> result = root.out.outE.has('size',4)
==> e [359:200:36028797018964014] [200-sizes-> 40]
==> e [669:404:36028797018964014] [404-sizes-> 400]
==> e [855:516:36028797018964014] [516-sizes-> 524]
gremlin> result.count()
==> 0
gremlin> result.getClass()
==> class com.tinkerpop.gremlin.groovy.GremlinGroovyPipeline



<这对我来说很奇怪。看起来,一旦变量被赋值,结果就没有了。



我在BDB上使用Titan。

解决方案

管道是一个迭代器,所以一旦管道耗尽,它就是空的。 Gremlin控制台会自动迭代管道,因此即使已将管道存储到变量中,它也会耗尽列表。



为了清晰起见,请考虑此示例

  gremlin> g = TinkerGraphFactory.createTinkerGraph()
==> tinkergraph [vertices:6 edges:6]
gremlin> pipeline = g.v(1).out
==> v [2]
==> v [4]
==> v [3]
gremlin> pipeline.next()
com.tinkerpop.pipes.util.FastNoSuchElementException
显示堆栈跟踪? [yN] n
gremlin> pipeline.count()
==> 0

请注意,管道,就像你的例子一样。所以......如果你想将未迭代的管道存储到一个变量中供以后评估,你需要阻止控制台自动迭代它:

 的gremlin> pipeline = g.v(1).out; null 
==> null
gremlin> pipeline.count()
==> 3

当然,一旦迭代它....它是空的:

  gremlin> pipeline.count()
==> 0

你必须初始化那个管道再次:

  gremlin> pipeline = g.v(1).out; null 
==> null
gremlin> pipeline.next()
==> v [2]
gremlin> pipeline.next()
==> v [4]
gremlin> pipeline.next()
==> v [3]
gremlin> pipeline.next()
com.tinkerpop.pipes.util.FastNoSuchElementException
显示堆栈跟踪? [yN] n
gremlin> pipeline.count()
==> 0

所以你可以做的最好的事情如果你想继续使用结果,就像你在回应自己的过程中迭代到列表一样。

  gremlin> ; l = []; gv(1).out.fill(l)
==> v [2]
==> v [4]
==> v [ 3]
gremlin> l.size()
==> 3


This works as expected:

gremlin> root.out.outE.has('size', 4).count()
==>3
gremlin> result = root.out.outE.has('size', 4).count()
==>3
gremlin> result
==>3
gremlin> root.out.outE.has('count', 4).getClass()         
==>class com.tinkerpop.gremlin.groovy.GremlinGroovyPipeline

When I store the GremlinGroovyPipeline into a variable, I can't count() it anymore:

gremlin> result = root.out.outE.has('size', 4)        
==>e[359:200:36028797018964014][200-sizes->40]
==>e[669:404:36028797018964014][404-sizes->400]
==>e[855:516:36028797018964014][516-sizes->524]
gremlin> result.count()
==>0
gremlin> result.getClass()
==>class com.tinkerpop.gremlin.groovy.GremlinGroovyPipeline

This is quite strange to me. It appears that once the variable is assigned, the results are gone.

I'm using Titan on BDB.

解决方案

The pipeline is an iterator, so once the pipeline is exhausted it's "empty". The Gremlin Console automatically iterates the pipeline for you so it effectively exhausts the list even though you've stored the pipeline into a variable.

Consider this example for clarity

gremlin> g = TinkerGraphFactory.createTinkerGraph()
==>tinkergraph[vertices:6 edges:6]
gremlin> pipeline=g.v(1).out
==>v[2]
==>v[4]
==>v[3]
gremlin> pipeline.next()
com.tinkerpop.pipes.util.FastNoSuchElementException
Display stack trace? [yN] n
gremlin> pipeline.count()
==>0

Note that there is nothing left in the pipeline, just as in your example. So...if you want to "store" the non-iterated pipeline in a variable for later evaluation you need to prevent the console from auto-iterating it:

gremlin> pipeline=g.v(1).out;null
==>null
gremlin> pipeline.count()        
==>3

Of course, once you iterate it....it's empty:

gremlin> pipeline.count()
==>0

and you have to initialize that pipeline again:

gremlin> pipeline=g.v(1).out;null
==>null
gremlin> pipeline.next()         
==>v[2]
gremlin> pipeline.next()
==>v[4]
gremlin> pipeline.next()
==>v[3]
gremlin> pipeline.next()
com.tinkerpop.pipes.util.FastNoSuchElementException
Display stack trace? [yN] n
gremlin> pipeline.count()        
==>0

So the best thing you can do if you want to continue to work with the results is to iterate to a list as you did in your response to yourself.

gremlin> l=[];g.v(1).out.fill(l)    
==>v[2]
==>v[4]
==>v[3]
gremlin> l.size()
==>3

这篇关于Gremlin在存储GremlinGroovyPipeline时调用.count()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆