diff --git a/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/expression/predicate/operator/comparison/Equals.java b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/expression/predicate/operator/comparison/Equals.java index 45210c114b80d..31687233216ce 100644 --- a/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/expression/predicate/operator/comparison/Equals.java +++ b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/expression/predicate/operator/comparison/Equals.java @@ -7,8 +7,10 @@ package org.elasticsearch.xpack.ql.expression.predicate.operator.comparison; import org.elasticsearch.xpack.ql.expression.Expression; +import org.elasticsearch.xpack.ql.expression.TypedAttribute; import org.elasticsearch.xpack.ql.expression.predicate.Negatable; import org.elasticsearch.xpack.ql.expression.predicate.operator.comparison.BinaryComparisonProcessor.BinaryComparisonOperation; +import org.elasticsearch.xpack.ql.planner.ExpressionTranslator; import org.elasticsearch.xpack.ql.querydsl.query.Query; import org.elasticsearch.xpack.ql.querydsl.query.RangeQuery; import org.elasticsearch.xpack.ql.querydsl.query.TermQuery; @@ -59,6 +61,9 @@ protected boolean isCommutative() { @Override public Query getQuery(String name, Object value, String format, boolean isDateLiteralComparison, ZoneId zoneId) { + if (left() instanceof TypedAttribute typedLeft) { + name = ExpressionTranslator.pushableAttributeName(typedLeft); + } if (isDateLiteralComparison) { // dates equality uses a range query because it's the one that has a "format" parameter return new RangeQuery(source(), name, value, true, value, true, format, zoneId); diff --git a/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/expression/predicate/operator/comparison/NotEquals.java b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/expression/predicate/operator/comparison/NotEquals.java index 8b2f557e8b923..62b28025be59c 100644 --- a/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/expression/predicate/operator/comparison/NotEquals.java +++ b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/expression/predicate/operator/comparison/NotEquals.java @@ -7,8 +7,10 @@ package org.elasticsearch.xpack.ql.expression.predicate.operator.comparison; import org.elasticsearch.xpack.ql.expression.Expression; +import org.elasticsearch.xpack.ql.expression.TypedAttribute; import org.elasticsearch.xpack.ql.expression.predicate.Negatable; import org.elasticsearch.xpack.ql.expression.predicate.operator.comparison.BinaryComparisonProcessor.BinaryComparisonOperation; +import org.elasticsearch.xpack.ql.planner.ExpressionTranslator; import org.elasticsearch.xpack.ql.querydsl.query.NotQuery; import org.elasticsearch.xpack.ql.querydsl.query.Query; import org.elasticsearch.xpack.ql.querydsl.query.RangeQuery; @@ -56,7 +58,9 @@ protected boolean isCommutative() { @Override public Query getQuery(String name, Object value, String format, boolean isDateLiteralComparison, ZoneId zoneId) { - Query query; + if (left() instanceof TypedAttribute typedLeft) { + name = ExpressionTranslator.pushableAttributeName(typedLeft); + } if (isDateLiteralComparison) { // dates equality uses a range query because it's the one that has a "format" parameter return new NotQuery(source(), new RangeQuery(source(), name, value, true, value, true, format, zoneId)); diff --git a/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/expression/predicate/operator/comparison/NullEquals.java b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/expression/predicate/operator/comparison/NullEquals.java index 3a9efb404d7ff..75eba452944db 100644 --- a/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/expression/predicate/operator/comparison/NullEquals.java +++ b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/expression/predicate/operator/comparison/NullEquals.java @@ -8,7 +8,9 @@ import org.elasticsearch.xpack.ql.expression.Expression; import org.elasticsearch.xpack.ql.expression.Nullability; +import org.elasticsearch.xpack.ql.expression.TypedAttribute; import org.elasticsearch.xpack.ql.expression.predicate.operator.comparison.BinaryComparisonProcessor.BinaryComparisonOperation; +import org.elasticsearch.xpack.ql.planner.ExpressionTranslator; import org.elasticsearch.xpack.ql.querydsl.query.Query; import org.elasticsearch.xpack.ql.querydsl.query.RangeQuery; import org.elasticsearch.xpack.ql.querydsl.query.TermQuery; @@ -58,6 +60,9 @@ protected boolean isCommutative() { @Override public Query getQuery(String name, Object value, String format, boolean isDateLiteralComparison, ZoneId zoneId) { + if (left() instanceof TypedAttribute typedLeft) { + name = ExpressionTranslator.pushableAttributeName(typedLeft); + } if (isDateLiteralComparison) { // dates equality uses a range query because it's the one that has a "format" parameter return new RangeQuery(source(), name, value, true, value, true, format, zoneId); diff --git a/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/planner/ExpressionTranslators.java b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/planner/ExpressionTranslators.java index eba835df3a863..38a536e3b3d41 100644 --- a/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/planner/ExpressionTranslators.java +++ b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/planner/ExpressionTranslators.java @@ -30,8 +30,6 @@ import org.elasticsearch.xpack.ql.expression.predicate.operator.comparison.BinaryComparison; import org.elasticsearch.xpack.ql.expression.predicate.operator.comparison.Equals; import org.elasticsearch.xpack.ql.expression.predicate.operator.comparison.In; -import org.elasticsearch.xpack.ql.expression.predicate.operator.comparison.NotEquals; -import org.elasticsearch.xpack.ql.expression.predicate.operator.comparison.NullEquals; import org.elasticsearch.xpack.ql.expression.predicate.regex.Like; import org.elasticsearch.xpack.ql.expression.predicate.regex.RLike; import org.elasticsearch.xpack.ql.expression.predicate.regex.RegexMatch; @@ -280,7 +278,6 @@ public static Query doTranslate(BinaryComparison bc, TranslatorHandler handler) static Query translate(BinaryComparison bc, TranslatorHandler handler) { TypedAttribute attribute = checkIsPushableAttribute(bc.left()); - Source source = bc.source(); String name = handler.nameOf(attribute); Object value = valueOf(bc.right()); String format = null; @@ -320,14 +317,8 @@ static Query translate(BinaryComparison bc, TranslatorHandler handler) { if (DataTypes.isDateTime(attribute.dataType())) { zoneId = bc.zoneId(); } - if (bc instanceof Equals || bc instanceof NullEquals || bc instanceof NotEquals) { - name = pushableAttributeName(attribute); - } return bc.getQuery(name, value, format, isDateLiteralComparison, zoneId); - - // throw new QlIllegalArgumentException("Don't know how to translate binary comparison [{}] in [{}]", bc.right().nodeString(), - // bc); } }