Skip to content

Commit a8f1698

Browse files
committed
Restore replaceChildren(), fix condition on serialization, and improve some code
1 parent 2f48a59 commit a8f1698

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public final BinaryScalarFunction replaceChildren(List<Expression> newChildren)
4646
Expression newLeft = newChildren.get(0);
4747
Expression newRight = newChildren.get(1);
4848

49-
return replaceChildren(newLeft, newRight);
49+
return left.equals(newLeft) && right.equals(newRight) ? this : replaceChildren(newLeft, newRight);
5050
}
5151

5252
protected abstract BinaryScalarFunction replaceChildren(Expression newLeft, Expression newRight);

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/AbstractFunctionTestCase.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ protected final Expression buildDeepCopyOfFieldExpression(TestCaseSupplier.TestC
538538
}
539539

540540
private Expression randomSerializeDeserialize(Expression expression) {
541-
if (false && randomBoolean()) {
541+
if (randomBoolean()) {
542542
return expression;
543543
}
544544

@@ -561,8 +561,14 @@ protected Expression serializeDeserializeExpression(Expression expression) {
561561
in -> in.readNamedWriteable(Expression.class),
562562
testCase.getConfiguration() // The configuration query should be == to the source text of the function for this to work
563563
);
564-
// Fields use synthetic sources, which can't be serialized. So we use the originals instead.
565-
return newExpression.replaceChildrenSameSize(expression.children());
564+
565+
// Fields use synthetic sources, which can't be serialized. So we replace with the originals instead.
566+
var dummyChildren = newExpression.children()
567+
.stream()
568+
.<Expression>map(c -> new Literal(Source.EMPTY, "anything that won't match any test case", c.dataType()))
569+
.toList();
570+
// We first replace them with other unrelated expressions to force a replace, as some replaceChildren() will check for equality
571+
return newExpression.replaceChildrenSameSize(dummyChildren).replaceChildrenSameSize(expression.children());
566572
}
567573

568574
protected final Expression buildLiteralExpression(TestCaseSupplier.TestCase testCase) {

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,10 @@ public void testSerializationWithConfiguration() {
3535

3636
assertSerialization(expr, config);
3737

38-
Configuration differentConfig;
39-
do {
40-
differentConfig = randomConfiguration();
41-
} while (config.equals(differentConfig));
38+
Configuration differentConfig = randomValueOtherThan(config, AbstractConfigurationFunctionTestCase::randomConfiguration);
4239

4340
Expression differentExpr = buildWithConfiguration(testCase.getSource(), testCase.getDataAsFields(), differentConfig);
44-
assertFalse(expr.equals(differentExpr));
41+
assertNotEquals(expr, differentExpr);
4542
}
4643

4744
private static Configuration randomConfiguration() {

0 commit comments

Comments
 (0)