Titan gremlin控制台和Java为group().by()查询返回不同的结果 [英] Titan gremlin console and java returns different result for group().by() query

查看:163
本文介绍了Titan gremlin控制台和Java为group().by()查询返回不同的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用cassandra 2.1支持的Titan 1.0.0 . 7作为后端存储.尝试在gremlin控制台和java程序上执行相同的查询时,我得到两种不同格式的输出2.我正在使用titan-1.0.0-hadoop1提供的gremlin控制台,对于Java我正在使用TinkerPop Gremlin 3.0.1孵化.

I am using Titan 1.0.0 supported by cassandra 2.1.7 as backend storage. While trying to execute the same query on gremlin console and java program, I am getting 2 the output in two different formats. I am using the gremlin console provided by titan-1.0.0-hadoop1 and for java I am using TinkerPop Gremlin 3.0.1-incubating.

Gremlin Console:

gremlin> g.V().has('msid',within(-2128958273, 2147477890)).as('in').local(outE('hie_child').has('hostid_e',within(153,83)).order().by('hrank',incr).limit(5)).group().by(outV().id()).by(inV().id().fold())

==> [77467688:[1531850904,4742561976,1009049792,1010020408,1053356264],73363640:[2060075072,3698942184,6776295608,7030726848, 35401920]]

==>[77467688:[1531850904, 4742561976, 1009049792, 1010020408, 1053356264], 73363640:[2060075072, 3698942184, 6776295608, 7030726848, 35401920]]

我正在获得预期的输出类型,即Map<VertexId, List<VertexId>>

I am getting the expected type of output i.e. Map<VertexId, List<VertexId>>

但是在Java程序中执行相同的查询时,我却得到了Map<VertexId, BulkSet>. BulkSet包含一个计数器,该计数器指示将特定条目添加到结果集中的次数.有人可以告诉我是否有办法在Java中获得与gremlin控制台类似的结果.

But while executing the same query in java program, I am getting Map<VertexId, BulkSet>. The BulkSet includes a counter indicating the number of times a particular entry is added in the result set. Can someone please tell me if there is a way to get the similar result in java as gremlin console.

Java:

List<Map<Object, Object>> list = g.V().has("msid", P.within(-2128958273,2147477890)).as("in").local(__.outE("hie_child").has("hostid_e", P.within(153,83)).order().by("hrank", Order.incr).limit(5)).group().by(__.outV().id()).by(__.inV().id().fold()).fold().next();

System.out.println(list);

[{774774688 = {1531850904 = 1,4742561976 = 1,1009049792 = 1,1010020408 = 1, 1053356264 = 1},73363640 = {2060075072 = 1、3698942184 = 1、6772295608 = 1, 7030726848 = 1,35401920 = 1}}]

[{77467688={1531850904=1, 4742561976=1, 1009049792=1, 1010020408=1, 1053356264=1}, 73363640={2060075072=1, 3698942184=1, 6776295608=1, 7030726848=1, 35401920=1}}]

推荐答案

请参见此处给出的答案 https://stackoverflow.com/a /43284707/5025129

See answer given here https://stackoverflow.com/a/43284707/5025129

  • iterate()得出零结果
  • next()得到一个结果
  • toList()获得很多结果
  • iterate() get zero result
  • next() get one result
  • toList() get many results

您应该调用toList()而不是next().

这也是对结果迭代 http://tinkerpop.apache.org/docs/current/tutorials/the-gremlin-console/#result-iteration

TinkerPop 3.0.x中似乎与此有关,并且可以在Gremlin Console中重现,但在TinkerPop 3.1.x中已修复.实际上,您应该能够使用BulkSet就好了,因为它仅包含值.您看到的是BulkSet.toString()ArrayList.toString()的区别.

There appears to be a bug in TinkerPop 3.0.x related to this, and it is reproducible in the Gremlin Console, but it is fixed in TinkerPop 3.1.x. Actually, you should be able to use the BulkSet just fine as it only contains values. What you're seeing is the difference in the BulkSet.toString() vs ArrayList.toString().

TinkerPop 3.0.x

TinkerPop 3.0.x

gremlin> graph = TinkerFactory.createModern()
==>tinkergraph[vertices:6 edges:6]
gremlin> g = graph.traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin>  l = g.V(1).local( outE('knows') ).group().by( __.outV().id() ).by( __.inV().id().fold() ).fold().next()
==>[1:[2, 4]]
gremlin> l[0].getClass()
==>class org.apache.tinkerpop.gremlin.process.traversal.step.map.GroupStep$GroupMap
gremlin> l[0].values().iterator().next().getClass()
==>class org.apache.tinkerpop.gremlin.process.traversal.step.util.BulkSet
gremlin> bs = l[0].values().iterator().next()
==>2
==>4
gremlin> bs[0].getClass()
==>class java.lang.Integer
gremlin> bs[1].getClass()
==>class java.lang.Integer
gremlin> bs.toString()
==>{2=1, 4=1}

TinkerPop 3.1.x

TinkerPop 3.1.x

gremlin> graph = TinkerFactory.createModern()
==>tinkergraph[vertices:6 edges:6]
gremlin> g = graph.traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin>  l = g.V(1).local( outE('knows') ).group().by( __.outV().id() ).by( __.inV().id().fold() ).fold().next()
==>[1:[2, 4]]
gremlin> l[0].getClass()
==>class java.util.HashMap
gremlin>  l[0].values().iterator().next().getClass()
==>class java.util.ArrayList
gremlin> bs = l[0].values().iterator().next()
==>2
==>4
gremlin> bs[0].getClass()
==>class java.lang.Integer
gremlin> bs[1].getClass()
==>class java.lang.Integer
gremlin> bs.toString()
==>[2, 4]

您可以构建titan11分支使用TinkerPop 3.1.1,或者您可以尝试 JanusGraph .

这篇关于Titan gremlin控制台和Java为group().by()查询返回不同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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