问题描述
我正在调用JanusGraph远程,默认情况下它将返回ReferenceVertex.为了同样检索属性,我使用了valueMap(),它适用于简单的查询.
I am calling JanusGraph remote, which returns ReferenceVertex by default. In order to retrieve properties as well, I use valueMap(), which works well for simple queries.
但是,在我的用例中,我需要建立一个联接,该联接基于ReferenceVertex可以很好地工作,如下所示:
However, in my use case I need to build a join, which works well based on ReferenceVertex as follows:
// select t1.table2_ID, t2.table2_ID from table1 as t1 inner join table2 as t2 on t1.table2_ID = t2.table2_ID
GraphTraversal<?, ?> t1 = __.start().as("table1").out("relatesTo").hasLabel("table2").as("table2");
GraphTraversal<?, ?> t2 = g.V().hasLabel("table1").match(t1).select("table1", "table2");
List<?> l = t2.toList();
将valueMap添加到遍历中以检索属性时,它将失败.我想包括以下特定属性:
When adding valueMap to the traversal to retrieve the properties it fails. I want to include specific properties as follows:
// select t1.column1, t2.column2 from table1 as t1 inner join table2 as t2 on p.table2_ID = c.table2_ID
GraphTraversal<?, ?> t1 = __.start().as("table1").out("relatesTo").hasLabel("table2").valueMap(true, "column2").as("table2");
GraphTraversal<?, ?> t2 = g.V().hasLabel("table1").valueMap(true, "column1").match(t1).select("table1", "table2");
List<?> l = t2.toList();
-> java.util.HashMap无法转换为org.apache.tinkerpop.gremlin.structure.Element
我是否建立了错误的遍历,或者这是Tinkerpop中的限制/错误?
Did I build the wrong traversal, or is this a limitation / bug in Tinkerpop?
谢谢
推荐答案
您可以调制select()
以将valueMap()
应用于返回的每一列.这是使用TinkerPop附带的现代玩具图的示例:
You can just modulate the select()
to apply valueMap()
to each column you return. Here's an example using the modern toy graph that ships with TinkerPop:
gremlin> g.V().as('a').out().as('b').select('a','b').by(valueMap())
==>[a:[name:[marko],age:[29]],b:[name:[lop],lang:[java]]]
==>[a:[name:[marko],age:[29]],b:[name:[vadas],age:[27]]]
==>[a:[name:[marko],age:[29]],b:[name:[josh],age:[32]]]
==>[a:[name:[josh],age:[32]],b:[name:[ripple],lang:[java]]]
==>[a:[name:[josh],age:[32]],b:[name:[lop],lang:[java]]]
==>[a:[name:[peter],age:[35]],b:[name:[lop],lang:[java]]]
因此,在您的情况下,您只需这样做:
so in your case you would just do:
GraphTraversal<?, ?> t1 = __.start().as("table1").out("relatesTo").hasLabel("table2").as("table2");
GraphTraversal<?, ?> t2 = g.V().hasLabel("table1").match(t1).select("table1", "table2").by(__.valueMap());
List<?> l = t2.toList();
也就是说,除非您出于这个问题的目的将代码缩写了一下,否则我不确定在这种情况下是否需要match()
.似乎您可以将其简化为:
That said, unless you've abbreviated your code a bit for purpose of this question, I'm not sure I see the need for match()
in this case. Seems like you could just simplify that to just:
List<?> l = g.V().hasLabel("table1").
out("relatesTo").hasLabel("table2").as("table2").
select("table1", "table2").
by(__.valueMap()).toList();
这篇关于将valueMap与match()一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!