Gremlin查询最后一个值的groupcount [英] Gremlin query for groupcount of last value
问题描述
我有一个带有两套顶点的泰坦图,一套用于UserID,另一套用于Products.购买产品时,UserID和产品顶点之间的边缘包含日期".我正在寻找一个gremlin查询,该查询可以按上次购买的产品给我一组用户ID
I have a titan graph with two sets of vertices, one for UserID and another for Products. The edges between the UserID and Product vertices contain the "Dates" when products were purchased. I am looking for a gremlin query that can give me a groupcount of userids by the last product purchased
例如,如果有如下数据
UserID,Date,Product
A,2016-01-01,'Razor'
A,2016-01-02,'Toothpaste'
B,2016-02-01,'Toothpaste'
B,2016-02-02,'Razor'
C,2016-01-04,'Toothpaste'
我正在寻找类似下面的输出
I am looking for an output like below
Product, Count
'Toothpaste',2
'Razor',1
非常感谢您的帮助.
推荐答案
以下查询可在OLTP和OLAP中使用,并且不会触及过多的顶点:
The following query works in OLTP and OLAP and doesn't touch more vertices than necessary:
g.V().hasLabel("User").
local(outE("purchased").order().by("date", decr).limit(1)).inV().
groupCount().by("name")
此外,当您在date
上创建顶点中心索引时,Titan可以完美地优化此查询.
Furthermore this query can be perfectly optimized by Titan, when you create a vertex centric index on date
.
这篇关于Gremlin查询最后一个值的groupcount的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!