Skip to content

Commit 588a388

Browse files
Remove folding from AggregateFunction and CIDRMatch
1 parent 140af7e commit 588a388

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/AggregateFunction.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.elasticsearch.xpack.esql.capabilities.PostAnalysisPlanVerificationAware;
1313
import org.elasticsearch.xpack.esql.common.Failures;
1414
import org.elasticsearch.xpack.esql.core.expression.Expression;
15-
import org.elasticsearch.xpack.esql.core.expression.FoldContext;
1615
import org.elasticsearch.xpack.esql.core.expression.Literal;
1716
import org.elasticsearch.xpack.esql.core.expression.TypeResolutions;
1817
import org.elasticsearch.xpack.esql.core.expression.function.Function;
@@ -95,7 +94,7 @@ public List<? extends Expression> parameters() {
9594

9695
public boolean hasFilter() {
9796
return filter != null
98-
&& (filter.foldable() == false || Boolean.TRUE.equals(filter.fold(FoldContext.small() /* TODO remove me */)) == false);
97+
&& (filter.foldable() == false || (filter instanceof Literal literal && Boolean.TRUE.equals(literal.value()) == false));
9998
}
10099

101100
public Expression filter() {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
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.FoldContext;
2221
import org.elasticsearch.xpack.esql.core.querydsl.query.Query;
2322
import org.elasticsearch.xpack.esql.core.querydsl.query.TermsQuery;
2423
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
@@ -189,7 +188,7 @@ public Query asQuery(LucenePushdownPredicates pushdownPredicates, TranslatorHand
189188
Check.isTrue(Expressions.foldable(matches), "Expected foldable matches, but got [{}]", matches);
190189

191190
String targetFieldName = handler.nameOf(fa.exactAttribute());
192-
Set<Object> set = new LinkedHashSet<>(Expressions.fold(FoldContext.small() /* TODO remove me */, matches));
191+
Set<Object> set = new LinkedHashSet<>(matches);
193192

194193
return new TermsQuery(source(), targetFieldName, set);
195194
}

x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/230_folding.yml

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,20 @@ setup:
2424
dims: 3
2525
index: true
2626
similarity: l2_norm
27+
ip:
28+
type: ip
2729

2830
- do:
2931
bulk:
3032
index: employees
3133
refresh: true
3234
body:
3335
- { "index": { } }
34-
- { "hire_date": "2020-01-01", "salary_change": 100.5, "salary": 50000, "salary_change_long": 100, "name": "Alice Smith", "image_vector": [ 0.1, 0.2, 0.3 ] }
36+
- { "hire_date": "2020-01-01", "salary_change": 100.5, "salary": 50000, "salary_change_long": 100, "name": "Alice Smith", "image_vector": [ 0.1, 0.2, 0.3 ], "ip": "192.168.1.1" }
3537
- { "index": { } }
36-
- { "hire_date": "2021-01-01", "salary_change": 200.5, "salary": 60000, "salary_change_long": 200, "name": "Bob Johnson", "image_vector": [ 0.4, 0.5, 0.6 ] }
38+
- { "hire_date": "2021-01-01", "salary_change": 200.5, "salary": 60000, "salary_change_long": 200, "name": "Bob Johnson", "image_vector": [ 0.4, 0.5, 0.6 ], "ip": "192.168.1.2" }
3739
- { "index": { } }
38-
- { "hire_date": "2019-01-01", "salary_change": 50.5, "salary": 40000, "salary_change_long": 50, "name": "Charlie Smith", "image_vector": [ 0.7, 0.8, 0.9 ] }
40+
- { "hire_date": "2019-01-01", "salary_change": 50.5, "salary": 40000, "salary_change_long": 50, "name": "Charlie Smith", "image_vector": [ 0.7, 0.8, 0.9 ], "ip": "10.168.1.2" }
3941

4042
---
4143
TOP function with constant folding:
@@ -654,3 +656,25 @@ MV_SORT with invalid non-foldable order:
654656
| EVAL sa = mv_sort(a, CONCAT(str, "DESC")) | LIMIT 1
655657
- match: { error.type: "illegal_argument_exception" }
656658
- contains: { error.reason: "Invalid order value in [mv_sort(a, CONCAT(str, \"DESC\"))], expected one of [ASC, DESC] but got [REVERSEDESC]" }
659+
660+
---
661+
CIDR_MATCH with multiple CIDRs:
662+
- do:
663+
esql.query:
664+
body:
665+
query: |
666+
ROW ip1 = "127.0.0.3"
667+
| WHERE CIDR_MATCH(TO_IP(ip1), CONCAT("127", ".0.0.2/32"), "127.0.0.3/32") | LIMIT 5
668+
- match: { columns.0.name: "ip1" }
669+
- match: { values.0.0: "127.0.0.3" }
670+
671+
---
672+
CIDR_MATCH with non-foldable CIDRs:
673+
- do:
674+
esql.query:
675+
body:
676+
query: |
677+
FROM employees
678+
| WHERE CIDR_MATCH(ip, CONCAT(TO_STRING(ip), "/8"), "127.0.0.3/32") | LIMIT 5
679+
- length: { values: 3 }
680+

0 commit comments

Comments
 (0)