2
votes

I have two properties on my Edges that I want to filter on: a and b. I want to filter these properties using the following list:

lst = [['0102', '2017-01-01'], ['4920', '2018-07-01'], ..., ['2198', '2018-04-01']]

... and using the following logic:

('a1' AND 'b1') OR ('a2' AND 'b2') OR ... OR ('an' AND 'bn')

For filtering the Edges on a single one of the value pairs in lst I could:

g.E().and(has('a', '0102'), has('b', '2017-01-01'))

For filtering on all of them, I could:

s.E().or(and(has('a', '0102'), has('b', '2017-01-01')), 
         and(has('a', '4920'), has('b', '2018-07-01')),
         ...
         and(has('a', '2198'), has('b', '2018-04-01')))

The approach works, but requires manually inputing the filter parameters. It will therefore break as soon as the contents of variable lst changes.

Is there a way to, given the format of variable lst, computationally solve this problem by passing lst into the query?

1

1 Answers

2
votes

This will work:

g.E().as('e').
  filter(constant(lst).unfold().as('t').
         where('e', eq('t')).
           by('a').
           by(limit(local, 1)).
         where('e', eq('t')).
           by('b').
           by(tail(local, 1)))

However, note, that it will be a full scan over all edges, and that performance will further decrease with increasing size of lst.

If your edges are globally indexed (I don't remember if that's even possible in JG), you'd probably see better/faster results if you execute N queries in parallel (where N is the number of entries in lst).