New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SQL: Introduce NotEquals node to simplify expressions #35234
Conversation
Add NotEquals node in parser to simplify expressions so that <value1> != <value2> is no longer translated internally to NOT(<value1> = <value2>) Closes: elastic#35210 Fixes: elastic#35233
Pinging @elastic/es-search-aggs |
@@ -585,7 +585,11 @@ private static Query translateQuery(BinaryComparison bc) { | |||
name = fa.exactAttribute().name(); | |||
} | |||
} | |||
return new TermQuery(loc, name, value); | |||
Query query= new TermQuery(loc, name, value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting : query=
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - I wonder why though the !=
was not failing before - wasn't the terms query properly wrapped in a negation?
@@ -11,12 +11,6 @@ | |||
import org.elasticsearch.xpack.sql.expression.Literal; | |||
import org.elasticsearch.xpack.sql.expression.function.scalar.Processors; | |||
import org.elasticsearch.xpack.sql.expression.gen.processor.ConstantProcessor; | |||
import org.elasticsearch.xpack.sql.expression.predicate.operator.comparison.BinaryComparisonProcessor; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
? These classes are still used so why are the imports removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's in the same package ;)
@@ -536,16 +537,15 @@ protected QueryTranslation asQuery(BinaryComparison bc, boolean onAggs) { | |||
// | |||
// Agg context means HAVING -> PipelineAggs | |||
// | |||
ScriptTemplate script = bc.asScript(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why it got moved down? Did it fail when used against a FieldAttribute
(which suggest a bug in the pipeline/querytranslator)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was no bug there, I just thought that it's better to called the asScript()
when actually needed and not beforehand. If you have any objection I can revert.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Left just two minor comments.
SELECT languages = 2, NOT languages = 2, languages != 2, NOT languages != 2, languages != null, NOT null != languages | ||
FROM "test_emp" WHERE emp_no IN(10018, 10019, 10020) ORDER BY emp_no ; | ||
|
||
2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these 3 lines accepted by the test class? I'm assuming you added these to show which languages
values you are testing against. If so, why not showing the languages
column as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no this was a leftover, I'll remove them but I will merge #35239 first which fixes and enables existing tests.
@@ -19,6 +19,11 @@ public static Boolean eq(Object l, Object r) { | |||
return i == null ? null : i.intValue() == 0; | |||
} | |||
|
|||
static Boolean neq(Object l, Object r) { | |||
Integer i = compare(l, r); | |||
return i == null? null : i.intValue() != 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return i == null? null : i.intValue() != 0;
just add a whitespace: return i == null ? null : i.intValue() != 0;
. If the PR is held back by this picky comment, you can ignore it and merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no worries, I'll fix, need to merge once the select-csv.spec is fixed anyway.
Backported to |
Backported to |
Add NotEquals node in parser to simplify expressions so that != is
no longer translated internally to NOT( = )
Closes: #35210
Fixes: #35233