假设我有这个图表:
+--own--> [made=Renault] --------------is-------------+
[name=Joan] v
+--own--> [made=Citroen] --is--> [type=Gas] [type=Diesel]
+--own--> [made=Peugeot] --is--> [type=Gas] ^
[name=Jacky] --own--> [made=Opel] ------------is-----------+
现在我想生成每个人拥有的类型燃料的列表。
| Person | Type |
+--------+--------+
| Joan | Gas |
| Joan | Diesel |
| Jacky | Diesel |
在 SQL 中,我可能会在类型和名称上使用 ORDER BY,但我不明白在 Gremlin 中如何对它们进行分组?
最佳答案
table pipe做这个。我为您的模型加载了一个名为“_stp_type”的索引属性,其中包含 Joan 和 Jacky 的值“Person”。我还为它们提供了一个“Name”属性。
g.idx('entities')[['_stp_type':'Person']].Name.as('Owner').back(1).out('Owns').Type.as('Type').table().cap().next().unique()
返回:
[
[
Jacky,
Diesel
],
[
Joan,
Diesel
],
[
Joan,
Gas
]
]
需要独特的方法(在表类上)来防止 Joan 为每辆汽油动力车辆拥有单独的条目。
关于java - Java 中的 Gremlin group By,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24087414/