Skip to content

Commit cddf15a

Browse files
bugfixes, add support for IN and CIDRMatch
1 parent 588a388 commit cddf15a

File tree

4 files changed

+19
-4
lines changed
  • x-pack/plugin

4 files changed

+19
-4
lines changed

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/Foldables.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,18 @@ public static Object valueOf(FoldContext ctx, Expression e) {
1616
}
1717
throw new QlIllegalArgumentException("Cannot determine value for {}", e);
1818
}
19+
20+
public static Object literalValueOf(Expression e) {
21+
if (e instanceof Literal literal) {
22+
return literal.value();
23+
}
24+
throw new QlIllegalArgumentException("Expected literal, but got {}", e);
25+
}
26+
27+
public static Object extractLiteralOrReturnSelf(Expression e) {
28+
if (e instanceof Literal literal) {
29+
return literal.value();
30+
}
31+
return e;
32+
}
1933
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/ip/CIDRMatch.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.elasticsearch.xpack.esql.capabilities.TranslationAware;
1919
import org.elasticsearch.xpack.esql.core.expression.Expression;
2020
import org.elasticsearch.xpack.esql.core.expression.Expressions;
21+
import org.elasticsearch.xpack.esql.core.expression.Foldables;
2122
import org.elasticsearch.xpack.esql.core.querydsl.query.Query;
2223
import org.elasticsearch.xpack.esql.core.querydsl.query.TermsQuery;
2324
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
@@ -188,7 +189,7 @@ public Query asQuery(LucenePushdownPredicates pushdownPredicates, TranslatorHand
188189
Check.isTrue(Expressions.foldable(matches), "Expected foldable matches, but got [{}]", matches);
189190

190191
String targetFieldName = handler.nameOf(fa.exactAttribute());
191-
Set<Object> set = new LinkedHashSet<>(matches);
192+
Set<Object> set = new LinkedHashSet<>(matches.stream().map(Foldables::extractLiteralOrReturnSelf).toList());
192193

193194
return new TermsQuery(source(), targetFieldName, set);
194195
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/multivalue/MvSort.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public boolean foldable() {
150150

151151
@Override
152152
public Object fold(FoldContext ctx) {
153-
if (order instanceof Literal == false) {
153+
if (order != null && order instanceof Literal == false) {
154154
// if we are here, we know that order is foldable, so we can safely fold it
155155
Literal newOrder = Literal.of(ctx, order);
156156
List<Expression> newChildren = new ArrayList<>();

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/predicate/operator/comparison/In.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
import java.util.Set;
5353

5454
import static org.elasticsearch.common.logging.LoggerMessageFormat.format;
55-
import static org.elasticsearch.xpack.esql.core.expression.Foldables.valueOf;
55+
import static org.elasticsearch.xpack.esql.core.expression.Foldables.literalValueOf;
5656
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.DEFAULT;
5757
import static org.elasticsearch.xpack.esql.core.type.DataType.BOOLEAN;
5858
import static org.elasticsearch.xpack.esql.core.type.DataType.DATETIME;
@@ -491,7 +491,7 @@ private Query translate(LucenePushdownPredicates pushdownPredicates, TranslatorH
491491
queries.add(query);
492492
}
493493
} else {
494-
terms.add(valueOf(FoldContext.small() /* TODO remove me */, rhs));
494+
terms.add(literalValueOf(rhs));
495495
}
496496
}
497497
}

0 commit comments

Comments
 (0)