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]]
I am getting the expected type of output i.e. Map<VertexId, List<VertexId>>
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);
[{77467688={1531850904=1, 4742561976=1, 1009049792=1, 1010020408=1, 1053356264=1}, 73363640={2060075072=1, 3698942184=1, 6776295608=1, 7030726848=1, 35401920=1}}]
See answer given here https://stackoverflow.com/a/43284707/5025129
iterate()
get zero resultnext()
get one resulttoList()
get many resultsYou should call on
toList()
rather thannext()
.This is also a good read on result iteration http://tinkerpop.apache.org/docs/current/tutorials/the-gremlin-console/#result-iteration
EDIT: 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 theBulkSet.toString()
vsArrayList.toString()
.TinkerPop 3.0.x
TinkerPop 3.1.x
You could build the
titan11
branch which uses TinkerPop 3.1.1 or you could try JanusGraph.