pietermartin / sqlg

TinkerPop graph over sql
MIT License
243 stars 51 forks source link

Traversal with nested or steps creates invalid SQL #398

Closed ktschmidt closed 3 years ago

ktschmidt commented 3 years ago

In a scenario where a vertex has a start/end attribute specifying a range where end is optional is missing means it is open ended, I want to do a traversal with a new range asking if it overlaps. Here are a few sample vertices:

g.addV('V').property('start', 0).property('end', 10).next(); g.addV('V').property('start', 1).next();

I have the following traversal to specify the new range (-1 to 0 in this example). which works fine with TinkerGraph:

g.V().hasLabel('V').or( .has('start', P.lte(-1)).or( .hasNot('end'), .has('end', P.gte(-1)) ), .has('start', P.lte(0)).or( .hasNot('end'), .has('end', P.gte(0)) ) );

Doing the same with Sqlg results in this error:

org.postgresql.util.PSQLException: ERROR: syntax error at or near "(" Position: 175

The SQL from TRACE logging is:

SELECT "public"."V_V"."ID" AS "alias1", "public"."V_V"."start" AS "alias2", "public"."V_V"."end" AS "alias3" FROM "public"."V_V" WHERE (("public"."V_V"."start" <= ?) ( (("public"."V_V"."end" IS NULL) OR ("public"."V_V"."end" >= ?) ) ) OR ("public"."V_V"."start" <= ?) ( (("public"."V_V"."end" IS NULL) OR ("public"."V_V"."end" >= ?) ) ) )

Which is indeed not valid.

I suspect the issue is the nested or steps? I have not seen this until trying to use this traversal.

pietermartin commented 3 years ago

I am having a look at this one now. Seems the nested AndOrHasContainer code is not right

pietermartin commented 3 years ago

This fix is done on the 2020 branch.