Merged query using logical operator AND returns false results


Flash
 
Edited

Dear developers, I re-corrected the syntax and ran new experiments, still triggered the bugs.

### Expected behavior:
We construct the following scenario: we randomly generate two queries Q1, Q2, and merge these two queries using MATCH operator into a new query Q3. See reference at https://stackoverflow.com/questions/48067834/gremlin-intersection-operation. Based on the calculation. The Q3 query result set should be the intersection of result sets from Q1 and Q2.
We generate graph schema and data based on random strings and values. Here is one of our examples that triggered the bug.

1. `g.V().bothE('el1').outV()` returns `[8400]`.
2. `g.V().and(__.outE('el2'))` returns `[16592, 4120, 4136, 4168, 4304]`.
3. `g.V().match(__.as('a').bothE('el1').outV(),__.as('a').filter(and(__.outE('el2')))).select('a')` returns `[16592, 4120, 4168, 4304]`.

We calculate the intersection result set of Q1 and Q2, which is `[]` an empty set.
The intersection result set doesn't equal to Q3 result set.

### Actual behavior:
The intersection result set should equal to Q3 result set. We did trigger some cases conform to this requirement, but still there're some cases that violate this constraint.

### Steps to reproduce:
- Create data
```
Vertex:
g.addV('vl1').property('vp3','true').property(T.id,4168)
g.addV('vl2').property('vp0','-1270611045').property(T.id,4296)
g.addV('vl1').property('vp3','true').property(T.id,4304)
g.addV('vl0').property('vp2',''nw)0Y'').property(T.id,8400)
g.addV('vl2').property('vp0','-1270611045').property('vp2',''~kK4?'').property(T.id,4264)
g.addV('vl1').property('vp3','false').property(T.id,4120)
g.addV('vl1').property('vp3','false').property(T.id,4136)
g.addV('vl2').property('vp2',''qrΛO|'').property(T.id,12496)
g.addV('vl2').property('vp2',''qrΛO|'').property(T.id,4312)
g.addV('vl1').property('vp3','false').property(T.id,16592)

Edge:
g.V(4120).as('4120').V(4168).as('4168').addE('el2').from('4120').to('4168')
g.V(4120).as('4120').V(4136).as('4136').addE('el0').from('4120').to('4136')
g.V(4120).as('4120').V(16592).as('16592').addE('el0').from('4120').to('16592')
g.V(16592).as('16592').V(4168).as('4168').addE('el2').from('16592').to('4168')
g.V(4136).as('4136').V(4120).as('4120').addE('el2').from('4136').to('4120')
g.V(4168).as('4168').V(8400).as('8400').addE('el1').from('4168').to('8400')
g.V(4120).as('4120').V(8400).as('8400').addE('el1').from('4120').to('8400')
g.V(4136).as('4136').V(4168).as('4168').addE('el0').from('4136').to('4168')
g.V(4304).as('4304').V(4120).as('4120').addE('el2').from('4304').to('4120')
g.V(4304).as('4304').V(4136).as('4136').addE('el2').from('4304').to('4136')
g.V(16592).as('16592').V(8400).as('8400').addE('el1').from('16592').to('8400')
g.V(4168).as('4168').V(4120).as('4120').addE('el2').from('4168').to('4120')
g.V(4136).as('4136').V(4304).as('4304').addE('el2').from('4136').to('4304')
g.V(4304).as('4304').V(8400).as('8400').addE('el1').from('4304').to('8400')
g.V(4120).as('4120').V(4168).as('4168').addE('el0').from('4120').to('4168')
g.V(4168).as('4168').V(16592).as('16592').addE('el2').from('4168').to('16592')
g.V(16592).as('16592').V(4120).as('4120').addE('el2').from('16592').to('4120')
g.V(4136).as('4136').V(16592).as('16592').addE('el2').from('4136').to('16592')
g.V(4304).as('4304').V(16592).as('16592').addE('el0').from('4304').to('16592')
g.V(4168).as('4168').V(4120).as('4120').addE('el0').from('4168').to('4120')
```


Flash
 

Hi, give me some time, I'll further check this. Thanks great a lot!


hadoopmarc@...
 

I cannot reproduce the issue you encountered.

```
gremlin> g.V().order().by(desc).order().by(asc).dedup().fold()
==>[v[4128],v[4232],v[4288],v[4304],v[4336],v[8328],v[8384],v[12424],v[12480],v[16576]]
gremlin> g.V().or(__.both('el1')).in('el1').order().by(asc).dedup().fold()
==>[v[4288],v[4336],v[12480],v[16576]]
gremlin> g.V().and(order().by(desc).order().by(asc),or(__.both('el1')).in('el1'))
==>v[8384]
==>v[4128]
==>v[4232]
```
I used the inmemory backend of janusgraph-0.6.2 with graph.set-vertex-id=true in the gremlin console.

Best wishes,    Marc


Flash
 

We discovered a bug that Merged query using logical operator AND returns false results.

- JanusGraph Version: 0.6.2
- Operating system: macOS 13.2.1
- API/Driver: Java

### Expected behavior:
We construct the following scenario: we randomly generate two queries Q1, Q2, and merge these two queries using AND logical operator into a new query Q3. Based on the AND calculation. The Q3 query result set should be the intersection of result sets from Q1 and Q2.
We generate graph schema and data based on random strings and values. Here is one of our examples that triggered the bug.
1) `g.V().order().by(desc).order().by(asc)` returns `[12424, 12480, 16576, 4128, 4232, 4288, 4304, 4336, 8328, 8384]`
2) `g.V().or(__.both('el1')).in('el1')` returns `[4128, 4128, 4128, 4128, 4232, 4232, 4232, 4232, 8384, 8384, 8384, 8384]`
3) `g.V().and(order().by(desc).order().by(asc),or(__.both('el1')).in('el1'))` returns `[12480, 16576, 4288, 4336]`.

We calculate the intersection result set of Q1 and Q2, which is `[4128, 4232, 8384]`.
The intersection result set doesn't equal to Q3 result set.

### Actual behavior:
The intersection result set should equal to Q3 result set. We did trigger some cases conform to this requirement, but still there're some cases that violate this constraint.

### Steps to reproduce:
We create a graph with 10 nodes and 20 edges. We try to make it clear to reproduce the bugs, **hope** to not cause much inconvenience to your reviewing, but we believe the problem does exist.
Following the following graph data generation query, we can reproduce the bugs:
- Create data
```
Vertex:
g.addV('vl0').property('vp0','5263792278886439895').property(T.id,4232)
g.addV('vl1').property('vp2','false').property(T.id,8328)
g.addV('vl2').property('vp0','-6455748616510069092').property('vp2','false').property('vp4','1933940092').property(T.id,4288)
g.addV('vl0').property('vp0','-1604438442701646404').property(T.id,8384)
g.addV('vl0').property('vp0','-6174796112110854467').property(T.id,4128)
g.addV('vl2').property('vp4','1933940092').property(T.id,12480)
g.addV('vl2').property('vp1','false').property('vp0','1448864523379914203').property('vp3','1733085808').property('vp2','true').property('vp4','-1845679587').property(T.id,4336)
g.addV('vl1').property('vp3','28263247').property('vp2','false').property('vp5','true').property(T.id,12424)
g.addV('vl1').property('vp2','true').property(T.id,4304)
g.addV('vl2').property('vp2','false').property(T.id,16576)

Edge:
g.V(4232).as('4232').V(4304).as('4304').addE('el0').from('4232').to('4304')
g.V(4288).as('4288').V(4232).as('4232').addE('el1').from('4288').to('4232')
g.V(4232).as('4232').V(12424).as('12424').addE('el0').from('4232').to('12424')
g.V(16576).as('16576').V(8384).as('8384').addE('el1').from('16576').to('8384')
g.V(4288).as('4288').V(8384).as('8384').addE('el1').from('4288').to('8384')
g.V(16576).as('16576').V(4232).as('4232').addE('el1').from('16576').to('4232')
g.V(4128).as('4128').V(12424).as('12424').addE('el0').from('4128').to('12424')
g.V(4232).as('4232').V(8328).as('8328').addE('el0').from('4232').to('8328')
g.V(8384).as('8384').V(12424).as('12424').addE('el0').from('8384').to('12424')
g.V(16576).as('16576').V(4128).as('4128').addE('el1').from('16576').to('4128')
g.V(8384).as('8384').V(8328).as('8328').addE('el0').from('8384').to('8328')
g.V(4336).as('4336').V(4128).as('4128').addE('el1').from('4336').to('4128')
g.V(12480).as('12480').V(8384).as('8384').addE('el1').from('12480').to('8384')
g.V(12480).as('12480').V(4128).as('4128').addE('el1').from('12480').to('4128')
g.V(4336).as('4336').V(4232).as('4232').addE('el1').from('4336').to('4232')
g.V(4288).as('4288').V(4128).as('4128').addE('el1').from('4288').to('4128')
g.V(4336).as('4336').V(8384).as('8384').addE('el1').from('4336').to('8384')
g.V(12480).as('12480').V(4232).as('4232').addE('el1').from('12480').to('4232')
g.V(4128).as('4128').V(4304).as('4304').addE('el0').from('4128').to('4304')
g.V(4128).as('4128').V(8328).as('8328').addE('el0').from('4128').to('8328')
```