【问题标题】:How to iterate gremlinepipeline of titan db to get the vertex & it's properties in Java API如何迭代titan db的gremlinepipeline以获取顶点及其在Java API中的属性
【发布时间】:2015-03-06 12:26:46
【问题描述】:

这是我正在使用的示例代码,但我不知道如何使用此 Pipeline 对象来获取顶点及其属性。

GremlinPipeline pipeline = new GremlinPipeline(vert)
  .out("LIVES_IN_CITY").in("LIVES_IN_CITY")
  .filter(new PipeFunction<Vertex,Boolean>() {
            public Boolean compute(Vertex v){
                  return v.getProperty("name").equals(city);     
  }}).back(2).out("LIVES_IN_CITY");

【问题讨论】:

  • 我并没有真正按照您的要求进行操作。你能改一下你的问题吗?您是否在问如何从示例代码中显示的管道中获取“结果”?
  • vert 是员工节点,它是起始节点,LIVES_IN_CITY 是员工节点到城市节点的边。我想知道谁是住在同一个城市的其他员工。 gremline 查询可能是: g.V.('id',1234).out('LIVES_IN_CITY').inE.outV 要获得上述结果,我正在使用 gremlinepipeline java api,但我无法正确迭代并获得结果。请建议我如何实现上述结果。

标签: titan tinkerpop tinkerpop-blueprint


【解决方案1】:

Gremlin Pipeline 只是一个 Iterator - 所以就这样对待它。在低级别,使用while 循环迭代检查hasNext() 以查看管道中是否有更多项目要提取并使用next 弹出Iterator 中的下一个项目。

Pipeline 也有 toList()fill() 方法可以在更高的抽象级别上工作。可以看到APIhere

【讨论】:

  • 我尝试迭代但得到类转换异常:java.lang.ClassCastException: com.thinkaurelius.titan.graphdb.vertices.CacheVertex 无法转换为 com.tinkerpop.blueprints.Edge
  • 您是否正在执行与您的问题相同的管道代码?鉴于该代码块,我没有看到您是如何获得该异常的。
  • 对于上面的代码块,我得到了 - com.tinkerpop.pipes.util.FastNoSuchElementException。我对下面提到的上述代码进行了一些更改,并得到了我在第一条评论中提到的 ClassCastException。 GremlinPipeline pipe1 = new GremlinPipeline(vert).out("LIVES_IN_CITY").as("x").inV().filter(new PipeFunction() { public Boolean compute(Vertex v){ System.out .println("pass ho rha hai"); return v.getProperty("name").equals("HOUSTON"); } }).back(2).out("LIVES_IN_CITY");
  • 如果您有FastNoSuchElementException,则管道中没有数据,这可能意味着您的遍历中有错误或测试数据不完整。至于ClassCastException,您正在从out('LIVES_IN_CITY') 步骤执行inV。由于out 返回Vertex,您可以尝试在其上执行inV,因为这是Edge 的一个步骤。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-09-28
  • 2017-09-26
  • 2016-05-26
  • 1970-01-01
  • 2016-08-05
  • 2015-07-05
  • 1970-01-01
相关资源
最近更新 更多