Skip to content

Commit 62ee45c

Browse files
Refactor Div arithmetic function to accept data type explicitly (elastic#97832)
1 parent 067f5d3 commit 62ee45c

File tree

2 files changed

+14
-4
lines changed
  • x-pack/plugin
    • eql/src/main/java/org/elasticsearch/xpack/eql/expression/function
    • ql/src/main/java/org/elasticsearch/xpack/ql/expression/predicate/operator/arithmetic

2 files changed

+14
-4
lines changed

x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/expression/function/EqlFunctionRegistry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private FunctionDefinition[][] functions() {
6868
// Arithmetic
6969
new FunctionDefinition[] {
7070
def(Add.class, Add::new, "add"),
71-
def(Div.class, Div::new, "divide"),
71+
def(Div.class, (BinaryBuilder<Div>) Div::new, "divide"),
7272
def(Mod.class, Mod::new, "modulo"),
7373
def(Mul.class, Mul::new, "multiply"),
7474
def(ToNumber.class, ToNumber::new, "number"),

x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/expression/predicate/operator/arithmetic/Div.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,33 @@
1717
*/
1818
public class Div extends ArithmeticOperation implements BinaryComparisonInversible {
1919

20+
private DataType dataType;
21+
2022
public Div(Source source, Expression left, Expression right) {
23+
this(source, left, right, null);
24+
}
25+
26+
public Div(Source source, Expression left, Expression right, DataType dataType) {
2127
super(source, left, right, DefaultBinaryArithmeticOperation.DIV);
28+
this.dataType = dataType;
2229
}
2330

2431
@Override
2532
protected NodeInfo<Div> info() {
26-
return NodeInfo.create(this, Div::new, left(), right());
33+
return NodeInfo.create(this, Div::new, left(), right(), dataType);
2734
}
2835

2936
@Override
3037
protected Div replaceChildren(Expression newLeft, Expression newRight) {
31-
return new Div(source(), newLeft, newRight);
38+
return new Div(source(), newLeft, newRight, dataType);
3239
}
3340

3441
@Override
3542
public DataType dataType() {
36-
return DataTypeConverter.commonType(left().dataType(), right().dataType());
43+
if (dataType == null) {
44+
dataType = DataTypeConverter.commonType(left().dataType(), right().dataType());
45+
}
46+
return dataType;
3747
}
3848

3949
@Override

0 commit comments

Comments
 (0)