|
|
@@ -18,6 +18,7 @@ import org.elasticsearch.xpack.esql.expression.function.EsqlFunctionRegistry;
|
|
|
import org.elasticsearch.xpack.esql.expression.function.UnsupportedAttribute;
|
|
|
import org.elasticsearch.xpack.esql.expression.function.scalar.EsqlScalarFunction;
|
|
|
import org.elasticsearch.xpack.esql.expression.predicate.operator.arithmetic.EsqlArithmeticOperation;
|
|
|
+import org.elasticsearch.xpack.esql.expression.predicate.operator.comparison.In;
|
|
|
import org.elasticsearch.xpack.esql.plan.logical.Aggregate;
|
|
|
import org.elasticsearch.xpack.esql.plan.logical.Drop;
|
|
|
import org.elasticsearch.xpack.esql.plan.logical.Enrich;
|
|
|
@@ -96,6 +97,7 @@ import static org.elasticsearch.xpack.core.enrich.EnrichPolicy.GEO_MATCH_TYPE;
|
|
|
import static org.elasticsearch.xpack.esql.stats.FeatureMetric.LIMIT;
|
|
|
import static org.elasticsearch.xpack.esql.type.EsqlDataTypes.GEO_POINT;
|
|
|
import static org.elasticsearch.xpack.esql.type.EsqlDataTypes.GEO_SHAPE;
|
|
|
+import static org.elasticsearch.xpack.ql.type.DataTypes.BOOLEAN;
|
|
|
import static org.elasticsearch.xpack.ql.type.DataTypes.DATETIME;
|
|
|
import static org.elasticsearch.xpack.ql.type.DataTypes.DOUBLE;
|
|
|
import static org.elasticsearch.xpack.ql.type.DataTypes.FLOAT;
|
|
|
@@ -105,6 +107,7 @@ import static org.elasticsearch.xpack.ql.type.DataTypes.KEYWORD;
|
|
|
import static org.elasticsearch.xpack.ql.type.DataTypes.LONG;
|
|
|
import static org.elasticsearch.xpack.ql.type.DataTypes.NESTED;
|
|
|
import static org.elasticsearch.xpack.ql.type.DataTypes.TEXT;
|
|
|
+import static org.elasticsearch.xpack.ql.type.DataTypes.VERSION;
|
|
|
|
|
|
public class Analyzer extends ParameterizedRuleExecutor<LogicalPlan, AnalyzerContext> {
|
|
|
// marker list of attributes for plans that do not have any concrete fields to return, but have other computed columns to return
|
|
|
@@ -802,6 +805,9 @@ public class Analyzer extends ParameterizedRuleExecutor<LogicalPlan, AnalyzerCon
|
|
|
if (f instanceof EsqlArithmeticOperation || f instanceof BinaryComparison) {
|
|
|
return processBinaryOperator((BinaryOperator) f);
|
|
|
}
|
|
|
+ if (f instanceof In in) {
|
|
|
+ return processIn(in);
|
|
|
+ }
|
|
|
return f;
|
|
|
}
|
|
|
|
|
|
@@ -846,14 +852,14 @@ public class Analyzer extends ParameterizedRuleExecutor<LogicalPlan, AnalyzerCon
|
|
|
|
|
|
if (left.dataType() == KEYWORD
|
|
|
&& left.foldable()
|
|
|
- && (right.dataType().isNumeric() || right.dataType() == DATETIME)
|
|
|
+ && (supportsImplicitCasting(right.dataType()))
|
|
|
&& ((left instanceof EsqlScalarFunction) == false)) {
|
|
|
targetDataType = right.dataType();
|
|
|
from = left;
|
|
|
}
|
|
|
if (right.dataType() == KEYWORD
|
|
|
&& right.foldable()
|
|
|
- && (left.dataType().isNumeric() || left.dataType() == DATETIME)
|
|
|
+ && (supportsImplicitCasting(left.dataType()))
|
|
|
&& ((right instanceof EsqlScalarFunction) == false)) {
|
|
|
targetDataType = left.dataType();
|
|
|
from = right;
|
|
|
@@ -867,6 +873,33 @@ public class Analyzer extends ParameterizedRuleExecutor<LogicalPlan, AnalyzerCon
|
|
|
return childrenChanged ? o.replaceChildren(newChildren) : o;
|
|
|
}
|
|
|
|
|
|
+ private static Expression processIn(In in) {
|
|
|
+ Expression left = in.value();
|
|
|
+ List<Expression> right = in.list();
|
|
|
+
|
|
|
+ if (left.resolved() == false || supportsImplicitCasting(left.dataType()) == false) {
|
|
|
+ return in;
|
|
|
+ }
|
|
|
+ List<Expression> newChildren = new ArrayList<>(right.size() + 1);
|
|
|
+ boolean childrenChanged = false;
|
|
|
+
|
|
|
+ for (Expression value : right) {
|
|
|
+ if (value.dataType() == KEYWORD && value.foldable()) {
|
|
|
+ Expression e = castStringLiteral(value, left.dataType());
|
|
|
+ newChildren.add(e);
|
|
|
+ childrenChanged = true;
|
|
|
+ } else {
|
|
|
+ newChildren.add(value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ newChildren.add(left);
|
|
|
+ return childrenChanged ? in.replaceChildren(newChildren) : in;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static boolean supportsImplicitCasting(DataType type) {
|
|
|
+ return type == DATETIME || type == IP || type == VERSION || type == BOOLEAN;
|
|
|
+ }
|
|
|
+
|
|
|
public static Expression castStringLiteral(Expression from, DataType target) {
|
|
|
assert from.foldable();
|
|
|
try {
|