Skip to content

Commit 645730a

Browse files
committed
Remove constant evaluator in favor of building a literal.
1 parent f804232 commit 645730a

File tree

2 files changed

+10
-106
lines changed
  • x-pack/plugin/esql/src/main

2 files changed

+10
-106
lines changed

x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/string/SpaceConstantEvaluator.java

Lines changed: 0 additions & 89 deletions
This file was deleted.

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

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.elasticsearch.compute.operator.BreakingBytesRefBuilder;
1717
import org.elasticsearch.compute.operator.EvalOperator.ExpressionEvaluator;
1818
import org.elasticsearch.xpack.esql.core.expression.Expression;
19+
import org.elasticsearch.xpack.esql.core.expression.Literal;
1920
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
2021
import org.elasticsearch.xpack.esql.core.tree.Source;
2122
import org.elasticsearch.xpack.esql.core.type.DataType;
@@ -32,6 +33,7 @@
3233
import static org.elasticsearch.common.unit.ByteSizeUnit.MB;
3334
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.DEFAULT;
3435
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isType;
36+
import static org.elasticsearch.xpack.esql.core.type.DataType.KEYWORD;
3537

3638
public class Space extends UnaryScalarFunction {
3739
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(Expression.class, "Space", Space::new);
@@ -70,7 +72,7 @@ public String getWriteableName() {
7072

7173
@Override
7274
public DataType dataType() {
73-
return DataType.KEYWORD;
75+
return KEYWORD;
7476
}
7577

7678
@Override
@@ -87,15 +89,15 @@ public boolean foldable() {
8789
return number.foldable();
8890
}
8991

90-
@Evaluator(extraName = "Constant")
91-
static BytesRef processConstant(@Fixed(includeInToString = false, build = true) BreakingBytesRefBuilder scratch, @Fixed int number) {
92-
return processInner(scratch, number);
93-
}
94-
9592
@Evaluator(warnExceptions = { IllegalArgumentException.class })
9693
static BytesRef process(@Fixed(includeInToString = false, build = true) BreakingBytesRefBuilder scratch, int number) {
9794
checkNumber(number);
98-
return processInner(scratch, number);
95+
scratch.grow(number);
96+
scratch.clear();
97+
for (int i = 0; i < number; ++i) {
98+
scratch.append((byte) ' ');
99+
}
100+
return scratch.bytesRefView();
99101
}
100102

101103
static void checkNumber(int number) {
@@ -107,15 +109,6 @@ static void checkNumber(int number) {
107109
}
108110
}
109111

110-
static BytesRef processInner(BreakingBytesRefBuilder scratch, int number) {
111-
scratch.grow(number);
112-
scratch.clear();
113-
for (int i = 0; i < number; ++i) {
114-
scratch.append((byte) ' ');
115-
}
116-
return scratch.bytesRefView();
117-
}
118-
119112
@Override
120113
public Expression replaceChildren(List<Expression> newChildren) {
121114
return new Space(source(), newChildren.get(0));
@@ -131,7 +124,7 @@ public ExpressionEvaluator.Factory toEvaluator(Function<Expression, ExpressionEv
131124
if (number.foldable()) {
132125
int num = (int) number.fold();
133126
checkNumber(num);
134-
return new SpaceConstantEvaluator.Factory(source(), context -> new BreakingBytesRefBuilder(context.breaker(), "space"), num);
127+
return toEvaluator.apply(new Literal(source(), " ".repeat(num), KEYWORD));
135128
}
136129

137130
ExpressionEvaluator.Factory numberExpr = toEvaluator.apply(number);

0 commit comments

Comments
 (0)