Skip to content

Commit 06adad8

Browse files
nokiaMSgithubgxll
authored andcommitted
[fix][runtime] Convert float to double for relation ops.
1 parent 3196f5c commit 06adad8

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

coding/src/test/java/io/dingodb/expr/coding/TestRelOpCoder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class TestRelOpCoder {
4343
.filter("$[2] > 50")
4444
.build(),
4545
Types.tuple("INT", "STRING", "FLOAT"),
46-
"7134021442480000930400"
46+
"713402f054154049000000000000930500"
4747
),
4848
arguments(
4949
RelOpStringBuilder.builder(RelConfig.DEFAULT)
@@ -58,7 +58,7 @@ public class TestRelOpCoder {
5858
.project("$[0]", "$[1]", "$[2] / 10")
5959
.build(),
6060
Types.tuple("INT", "STRING", "FLOAT"),
61-
"7134021442480000930400723100370134021441200000860400"
61+
"713402f054154049000000000000930500723100370134021441200000860400"
6262
),
6363
arguments(
6464
RelOpStringBuilder.builder(RelConfig.DEFAULT)

runtime/src/main/java/io/dingodb/expr/runtime/op/BinaryOp.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package io.dingodb.expr.runtime.op;
1818

19+
import io.dingodb.expr.common.type.DecimalType;
20+
import io.dingodb.expr.common.type.DoubleType;
1921
import io.dingodb.expr.common.type.FloatType;
2022
import io.dingodb.expr.common.type.IntType;
2123
import io.dingodb.expr.common.type.Type;
@@ -27,6 +29,12 @@
2729
import io.dingodb.expr.runtime.expr.BinaryOpExpr;
2830
import io.dingodb.expr.runtime.expr.Expr;
2931
import io.dingodb.expr.runtime.expr.Val;
32+
import io.dingodb.expr.runtime.op.relational.EqOpFactory;
33+
import io.dingodb.expr.runtime.op.relational.GeOpFactory;
34+
import io.dingodb.expr.runtime.op.relational.GtOpFactory;
35+
import io.dingodb.expr.runtime.op.relational.LeOpFactory;
36+
import io.dingodb.expr.runtime.op.relational.LtOpFactory;
37+
import io.dingodb.expr.runtime.op.relational.NeOpFactory;
3038
import org.checkerframework.checker.nullness.qual.NonNull;
3139
import org.checkerframework.checker.nullness.qual.Nullable;
3240

@@ -76,13 +84,29 @@ public OpKey bestKeyOf(@NonNull Type @NonNull [] types) {
7684
&& (op.getOpType() == OpType.ADD || op.getOpType() == OpType.SUB
7785
|| op.getOpType() == OpType.MUL || op.getOpType() == OpType.DIV)) {
7886
needCast = true;
87+
} else if ( op != null && (op.getOpType() == OpType.GE || op.getOpType() == OpType.GT
88+
|| op.getOpType() == OpType.LE || op.getOpType() == OpType.GT
89+
|| op.getOpType() == OpType.EQ || op.getOpType() == OpType.NE)) {
90+
if (operand0.getType() instanceof FloatType || operand1.getType() instanceof FloatType) {
91+
needCast = true;
92+
} else if (operand0.getType() instanceof DoubleType || operand1.getType() instanceof DoubleType) {
93+
needCast = true;
94+
}
7995
}
8096

8197
if (op != null && !needCast) {
8298
result = op.createExpr(operand0, operand1);
8399
} else {
84-
Type[] types;
85-
if (op != null && type0 instanceof IntType && type1 instanceof IntType
100+
Type[] types = new Type[]{type0, type1};
101+
if ( this instanceof LtOpFactory || this instanceof LeOpFactory
102+
|| this instanceof GeOpFactory || this instanceof GtOpFactory
103+
|| this instanceof EqOpFactory || this instanceof NeOpFactory) {
104+
if (type0 instanceof FloatType || type1 instanceof FloatType) {
105+
types = new Type[]{Types.DOUBLE, Types.DOUBLE};
106+
} else if (type0 instanceof DoubleType || type1 instanceof DoubleType) {
107+
types = new Type[]{Types.DOUBLE, Types.DOUBLE};
108+
}
109+
} else if (op != null && type0 instanceof IntType && type1 instanceof IntType
86110
&& (op.getOpType() == OpType.ADD || op.getOpType() == OpType.SUB || op.getOpType() == OpType.MUL)) {
87111
types = new Type[]{Types.LONG, Types.LONG};
88112
} else if (op != null && type0 instanceof FloatType && type1 instanceof FloatType

0 commit comments

Comments
 (0)