Skip to content

Commit a376466

Browse files
committed
Use in the superclass rather than adding .
1 parent 645730a commit a376466

File tree

2 files changed

+7
-18
lines changed
  • x-pack/plugin/esql/src

2 files changed

+7
-18
lines changed

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

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ public class Space extends UnaryScalarFunction {
4040

4141
static final long MAX_LENGTH = MB.toBytes(1);
4242

43-
private final Expression number;
44-
4543
@FunctionInfo(
4644
returnType = "keyword",
4745
description = "Returns a string of `number` spaces.",
@@ -52,7 +50,6 @@ public Space(
5250
@Param(name = "number", type = { "integer" }, description = "Number of spaces in result.") Expression number
5351
) {
5452
super(source, number);
55-
this.number = number;
5653
}
5754

5855
private Space(StreamInput in) throws IOException {
@@ -62,7 +59,7 @@ private Space(StreamInput in) throws IOException {
6259
@Override
6360
public void writeTo(StreamOutput out) throws IOException {
6461
source().writeTo(out);
65-
out.writeNamedWriteable(number);
62+
out.writeNamedWriteable(field);
6663
}
6764

6865
@Override
@@ -81,12 +78,7 @@ protected TypeResolution resolveType() {
8178
return new TypeResolution("Unresolved children");
8279
}
8380

84-
return isType(number, dt -> dt == DataType.INTEGER, sourceText(), DEFAULT, "integer");
85-
}
86-
87-
@Override
88-
public boolean foldable() {
89-
return number.foldable();
81+
return isType(field, dt -> dt == DataType.INTEGER, sourceText(), DEFAULT, "integer");
9082
}
9183

9284
@Evaluator(warnExceptions = { IllegalArgumentException.class })
@@ -116,22 +108,19 @@ public Expression replaceChildren(List<Expression> newChildren) {
116108

117109
@Override
118110
protected NodeInfo<? extends Expression> info() {
119-
return NodeInfo.create(this, Space::new, number);
111+
return NodeInfo.create(this, Space::new, field);
120112
}
121113

122114
@Override
123115
public ExpressionEvaluator.Factory toEvaluator(Function<Expression, ExpressionEvaluator.Factory> toEvaluator) {
124-
if (number.foldable()) {
125-
int num = (int) number.fold();
116+
if (field.foldable()) {
117+
int num = (int) field.fold();
126118
checkNumber(num);
127119
return toEvaluator.apply(new Literal(source(), " ".repeat(num), KEYWORD));
128120
}
129121

130-
ExpressionEvaluator.Factory numberExpr = toEvaluator.apply(number);
122+
ExpressionEvaluator.Factory numberExpr = toEvaluator.apply(field);
131123
return new SpaceEvaluator.Factory(source(), context -> new BreakingBytesRefBuilder(context.breaker(), "space"), numberExpr);
132124
}
133125

134-
Expression number() {
135-
return number;
136-
}
137126
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ protected Space createTestInstance() {
2424
@Override
2525
protected Space mutateInstance(Space instance) throws IOException {
2626
Source source = instance.source();
27-
Expression number = instance.number();
27+
Expression number = instance.field();
2828
number = randomValueOtherThan(number, AbstractExpressionSerializationTests::randomChild);
2929
return new Space(source, number);
3030
}

0 commit comments

Comments
 (0)