对于给定的顶点,我想计算多个聚合特征,彼此之间不清楚,可以按照以下步骤进行。
g.V(81968)
.project('P1', 'P2', 'P3')
.by(__.bothE().has('dt_int', lt(999999999999)).values('orig_amt').mean())
.by(__.bothE().has('dt_int', lt(999999999999)).values('currency').dedup().count())
.by(__.bothE().has('dt_int', lt(999999999999)).values('weight').mean())
此查询的明显问题是,每当我要创建新的聚合功能(即__.bothE().has('trxn_dt', lt(999999999999))
,P1
,P2
)时,我都会计算P3
。当我尝试为具有大量边的顶点计算这组特征时,这一点变得很清楚。
是否有一种方法可以存储过滤后的边缘集,然后选择它以备后用?类似于此伪查询:
g.V(81968)
.hold(__.bothE().has('dt_int', lt(999999999999))).as('edges')
.project('P1', 'P2', 'P3')
.by(select('edges').values('orig_amt').mean())
.by(select('edges').values('currency').dedup().count())
.by(select('edges').values('weight').mean())
[这个问题可以追溯到我问的上一个问题(here),但是我正在寻求一种更通用的方法,并且我正在努力使其适应一组通用功能。
[您建议您将结果“保留()”,而Gremlin具有此类的aggregate()
和store()
,如果您需要List
,则只需fold()
您的结果,然后是project()
该单List
根据需要:
g.V(81968).bothE().has('dt_int', lt(999999999999)).
fold().
project('P1', 'P2', 'P3').
by(unfold().values('orig_amt').mean()).
by(unfold().values('currency').dedup().count()).
by(unfold().values('weight').mean())
以这种方式,您不需要副作用或路径跟踪。