Gremlin查询以在ResultSet中返回多个结果

时间:2018-11-08 07:53:11

标签: gremlin tinkerpop

可能是我对gremlin查询的理解是错误的:)。我正在尝试从Java客户端执行查询,查询是:g.V()。hasLabel('MYLABEL')。 具有与标签匹配的多个(例如20个)顶点,并且ResultSet仅有一个 Result,其中包括所有二十个顶点的数据。我想拥有20个结果的ResultSet。我需要用什么方式重新安排查询。请提出建议。

  • 更多细节:

从控制台。

[从gremlin控制台运行的查询结果] [1]

gremlin> client.submit(“ g.V()。hasLabel('PERSON')”)

==>结果{object = v [11] class = org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex} ==>结果{object = v [13] class = org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex} ==>结果{object = v [15] class = org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex}

从Java客户端 查询-> g.V()。hasLabel('PERSON')

结果->结果{object = {@ type = g:List,@value = [{@ type = g:Vertex,@ value = {id = {@ type = g: Int64,@ value = 11},标签= PERSON,属性= {AGE = [{@ type = g:VertexProperty,@ value = {id = {@ type = g:Int64,@ value = 12},值= {@ type = g:Int32,@ value = 11},label = AGE}}]}}},{@ type = g:Vertex,@ value = {id = {@ type = g:Int64,@ value = 13}, label = PERSON,属性= {AGE = [{@ type = g:VertexProperty,@ value = {id = {@ type = g:Int64,@ value = 14},value = {@ type = g:Int32,@value = 12},label = AGE}}]}}},{@ type = g:Vertex,@ value = {id = {@ type = g:Int64,@ value = 15},label = PERSON,属性= {AGE = [{{@ type = g:VertexProperty,@ value = {id = {@ type = g:Int64,@ value = 16},value = {@ type = g:Int32,@ value = 13},label = AGE} }]}}}]} class = java.util.LinkedHashMap}

1 个答案:

答案 0 :(得分:2)

只需像使用fold()一样-您可以在这里看到我的示例:

gremlin> cluster = Cluster.open()
==>localhost/127.0.0.1:8182
gremlin> client = cluster.connect()
==>org.apache.tinkerpop.gremlin.driver.Client$ClusteredClient@51efb731
gremlin> r = client.submit("g.V().hasLabel('person')").all().get()
==>result{object=v[1] class=org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex}
==>result{object=v[2] class=org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex}
==>result{object=v[4] class=org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex}
==>result{object=v[6] class=org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex}
gremlin> r = client.submit("g.V().hasLabel('person').fold()").all().get()
==>result{object=[v[1], v[2], v[4], v[6]] class=java.util.ArrayList}

请注意,在此示例中,fold()的缺点是不会将结果流回客户端。您将在服务器的内存中构建整个列表,然后将其序列化为单个有效负载。如果该列表足够大并且您生成了足够多的此类列表,则可能会遇到内存/ GC问题。