Skip to content

Commit 408c8fd

Browse files
Remove partiallyFoldable code as it is not needed
1 parent 15dfed3 commit 408c8fd

File tree

3 files changed

+1
-40
lines changed
  • x-pack/plugin

3 files changed

+1
-40
lines changed

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,6 @@ public boolean foldable() {
8585
return false;
8686
}
8787

88-
/**
89-
* Whether the expression can be evaluated partially, for example we might be able to fold and expression in an argument of the function but not remove the function completely
90-
*/
91-
public boolean partiallyFoldable() {
92-
return false;
93-
}
94-
9588
/**
9689
* Evaluate this expression statically to a constant. It is an error to call
9790
* this if {@link #foldable} returns false.
@@ -102,10 +95,6 @@ public Object fold(FoldContext ctx) {
10295
throw new QlIllegalArgumentException("Should not fold expression");
10396
}
10497

105-
public Expression partiallyFold(FoldContext ctx) {
106-
throw new QlIllegalArgumentException("Should not fold expression");
107-
}
108-
10998
public abstract Nullability nullable();
11099

111100
// the references/inputs/leaves of the expression tree

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/vector/Knn.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.elasticsearch.xpack.esql.common.Failures;
1919
import org.elasticsearch.xpack.esql.core.InvalidArgumentException;
2020
import org.elasticsearch.xpack.esql.core.expression.Expression;
21-
import org.elasticsearch.xpack.esql.core.expression.FoldContext;
2221
import org.elasticsearch.xpack.esql.core.expression.Literal;
2322
import org.elasticsearch.xpack.esql.core.expression.MapExpression;
2423
import org.elasticsearch.xpack.esql.core.expression.TypeResolutions;
@@ -248,28 +247,6 @@ private Map<String, Object> knnQueryOptions() throws InvalidArgumentException {
248247
return matchOptions;
249248
}
250249

251-
@Override
252-
public boolean partiallyFoldable() {
253-
return true;
254-
}
255-
256-
@Override
257-
public Expression partiallyFold(FoldContext ctx) {
258-
if (k instanceof Literal) {
259-
// already folded, return self
260-
return this;
261-
}
262-
Object foldedK = k.fold(ctx);
263-
if (foldedK instanceof Number == false) {
264-
throw new EsqlIllegalArgumentException(format(null, "K value must be a constant integer in [{}], found [{}]", source(), k()));
265-
}
266-
List<Expression> newChildren = new ArrayList<>(this.children());
267-
newChildren.set(2, new Literal(source(), foldedK, INTEGER));
268-
Expression replaced = this.replaceChildren(newChildren);
269-
log.error("Partially folded knn function [{}] with k value [{}]", replaced, foldedK);
270-
return replaced;
271-
}
272-
273250
@Override
274251
public List<Number> queryAsObject() {
275252
// we need to check that we got a list and every element in the list is a number

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/rules/logical/ConstantFolding.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ public ConstantFolding() {
1919

2020
@Override
2121
public Expression rule(Expression e, LogicalOptimizerContext ctx) {
22-
if (e.foldable()) {
23-
return Literal.of(ctx.foldCtx(), e);
24-
} else if (e.partiallyFoldable()) {
25-
return e.partiallyFold(ctx.foldCtx());
26-
}
27-
return e;
22+
return e.foldable() ? Literal.of(ctx.foldCtx(), e) : e;
2823
}
2924
}

0 commit comments

Comments
 (0)