Is there a way to store filtered edges before computing features

Viewed 26

For a given vertex, I want to compute multiple aggregate features, which are indistinct from one another, which I might do as follows.

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())

The obvious issue with this query is that I'm computing __.bothE().has('trxn_dt', lt(999999999999)) every time I want to create a new aggregate feature (i.e. P1, P2, P3). This becomes clear when I try to compute this set of features for a vertex with a high number of edges.

Is there a way to store the filtered set of edges, and then select it for later use? Something like this pseudo query:

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())

This question goes back to a previous question I asked (here), but I'm seeking a more generic approach, and I'm struggling to adapt it to a generic set of features.

1 Answers

You're suggesting you "hold()" the results and while Gremlin has aggregate() and store() for such things, if you need a List, just fold() your results and then project() that single List as you need to:

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())

In this way you don't need side-effects or path-tracking.

Related