Skip to content

Commit 0194c58

Browse files
committed
SQL: Add BinaryMathProcessor to named writeables list (#30127)
BinaryMathProcessor was missing from the list of register named writeables causing deserialization errors Fix #30014
1 parent 45d273a commit 0194c58

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/Processors.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.elasticsearch.xpack.sql.expression.function.scalar.arithmetic.BinaryArithmeticProcessor;
1111
import org.elasticsearch.xpack.sql.expression.function.scalar.arithmetic.UnaryArithmeticProcessor;
1212
import org.elasticsearch.xpack.sql.expression.function.scalar.datetime.DateTimeProcessor;
13+
import org.elasticsearch.xpack.sql.expression.function.scalar.math.BinaryMathProcessor;
1314
import org.elasticsearch.xpack.sql.expression.function.scalar.math.MathProcessor;
1415
import org.elasticsearch.xpack.sql.expression.function.scalar.processor.runtime.BucketExtractorProcessor;
1516
import org.elasticsearch.xpack.sql.expression.function.scalar.processor.runtime.ChainingProcessor;
@@ -40,6 +41,7 @@ public static List<NamedWriteableRegistry.Entry> getNamedWriteables() {
4041
// arithmetic
4142
entries.add(new Entry(Processor.class, BinaryArithmeticProcessor.NAME, BinaryArithmeticProcessor::new));
4243
entries.add(new Entry(Processor.class, UnaryArithmeticProcessor.NAME, UnaryArithmeticProcessor::new));
44+
entries.add(new Entry(Processor.class, BinaryMathProcessor.NAME, BinaryMathProcessor::new));
4345
// datetime
4446
entries.add(new Entry(Processor.class, DateTimeProcessor.NAME, DateTimeProcessor::new));
4547
// math
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
package org.elasticsearch.xpack.sql.expression.function.scalar.math;
7+
8+
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
9+
import org.elasticsearch.common.io.stream.Writeable.Reader;
10+
import org.elasticsearch.test.AbstractWireSerializingTestCase;
11+
import org.elasticsearch.xpack.sql.expression.Literal;
12+
import org.elasticsearch.xpack.sql.expression.function.scalar.Processors;
13+
import org.elasticsearch.xpack.sql.expression.function.scalar.processor.runtime.ConstantProcessor;
14+
import org.elasticsearch.xpack.sql.expression.function.scalar.processor.runtime.Processor;
15+
16+
import static org.elasticsearch.xpack.sql.tree.Location.EMPTY;
17+
18+
public class BinaryMathProcessorTests extends AbstractWireSerializingTestCase<BinaryMathProcessor> {
19+
public static BinaryMathProcessor randomProcessor() {
20+
return new BinaryMathProcessor(
21+
new ConstantProcessor(randomLong()),
22+
new ConstantProcessor(randomLong()),
23+
randomFrom(BinaryMathProcessor.BinaryMathOperation.values()));
24+
}
25+
26+
@Override
27+
protected BinaryMathProcessor createTestInstance() {
28+
return randomProcessor();
29+
}
30+
31+
@Override
32+
protected Reader<BinaryMathProcessor> instanceReader() {
33+
return BinaryMathProcessor::new;
34+
}
35+
36+
@Override
37+
protected NamedWriteableRegistry getNamedWriteableRegistry() {
38+
return new NamedWriteableRegistry(Processors.getNamedWriteables());
39+
}
40+
41+
public void testAtan2() {
42+
Processor ba = new ATan2(EMPTY, l(1), l(1)).makeProcessorDefinition().asProcessor();
43+
assertEquals(0.7853981633974483d, ba.process(null));
44+
}
45+
46+
public void testPower() {
47+
Processor ba = new Power(EMPTY, l(2), l(2)).makeProcessorDefinition().asProcessor();
48+
assertEquals(4d, ba.process(null));
49+
}
50+
51+
public void testHandleNull() {
52+
assertNull(new ATan2(EMPTY, l(null), l(3)).makeProcessorDefinition().asProcessor().process(null));
53+
assertNull(new Power(EMPTY, l(null), l(null)).makeProcessorDefinition().asProcessor().process(null));
54+
}
55+
56+
private static Literal l(Object value) {
57+
return Literal.of(EMPTY, value);
58+
}
59+
}

0 commit comments

Comments
 (0)