Update Eclipselink grammar to support = & != for null comparison.

Eclipselink transforms = & and != in queries into IS and IS NOT.

Closes #3314
Original pull request: #3316
This commit is contained in:
Christoph Strobl
2024-01-15 12:39:20 +01:00
committed by Mark Paluch
parent fbf831c8c1
commit a3dd07fa38
3 changed files with 21 additions and 5 deletions

View File

@@ -362,7 +362,7 @@ like_expression
;
null_comparison_expression
: (single_valued_path_expression | input_parameter | nullif_expression) IS (NOT)? NULL
: (single_valued_path_expression | input_parameter | nullif_expression) ((IS (NOT)?) | (op=(EQUAL | NOT_EQUAL))) NULL
;
empty_collection_comparison_expression

View File

@@ -1315,10 +1315,13 @@ class EqlQueryRenderer extends EqlBaseVisitor<List<JpaQueryParsingToken>> {
tokens.addAll(visit(ctx.nullif_expression()));
}
tokens.add(new JpaQueryParsingToken(ctx.IS()));
if (ctx.NOT() != null) {
tokens.add(new JpaQueryParsingToken(ctx.NOT()));
if (ctx.op != null) {
tokens.add(new JpaQueryParsingToken(ctx.op.getText()));
} else {
tokens.add(new JpaQueryParsingToken(ctx.IS()));
if (ctx.NOT() != null) {
tokens.add(new JpaQueryParsingToken(ctx.NOT()));
}
}
tokens.add(new JpaQueryParsingToken(ctx.NULL()));

View File

@@ -401,4 +401,17 @@ class EqlComplianceTests {
assertQuery("SELECT b FROM Bundle b WHERE coalesce(b.deleted, false) AND b.latestImport = true");
assertQuery("SELECT b FROM Bundle b WHERE NOT coalesce(b.deleted, false) AND b.latestImport = true");
}
@Test // GH-3314
void isNullAndIsNotNull() {
assertQuery("SELECT e FROM Employee e WHERE (e.active = null OR e.active = true)");
assertQuery("SELECT e FROM Employee e WHERE (e.active = NULL OR e.active = true)");
assertQuery("SELECT e FROM Employee e WHERE (e.active IS null OR e.active = true)");
assertQuery("SELECT e FROM Employee e WHERE (e.active IS NULL OR e.active = true)");
assertQuery("SELECT e FROM Employee e WHERE (e.active != null OR e.active = true)");
assertQuery("SELECT e FROM Employee e WHERE (e.active != NULL OR e.active = true)");
assertQuery("SELECT e FROM Employee e WHERE (e.active IS NOT null OR e.active = true)");
assertQuery("SELECT e FROM Employee e WHERE (e.active IS NOT NULL OR e.active = true)");
}
}