[fix](Nereids) remove double sigature of ceil, floor and round (#22134)

we convert input parameters to double for function ceil, floor and round,
because DecimalV2 could not do these operation. Since we intro DecimalV3,
we should convert all parameters to DecimalV3 to get correct result.
For example, when we use double as parameters, we get wrong result:
```sql
select round(341/20000,4),341/20000,round(0.01705,4);
+-------------------------+---------------+-------------------+
| round((341 / 20000), 4) | (341 / 20000) | round(0.01705, 4) |
+-------------------------+---------------+-------------------+
| 0.017                   | 0.01705       | 0.0171            |
+-------------------------+---------------+-------------------+
```
DecimalV3 could get correct result
```sql
select round(341/20000,4),341/20000,round(0.01705,4);
+-------------------------+---------------+-------------------+
| round((341 / 20000), 4) | (341 / 20000) | round(0.01705, 4) |
+-------------------------+---------------+-------------------+
| 0.0171                  | 0.01705       | 0.0171            |
+-------------------------+---------------+-------------------+
```
This commit is contained in:
morrySnow
2023-07-24 16:08:00 +08:00
committed by GitHub
parent d2531db1cf
commit 21deb57a4d
12 changed files with 208 additions and 225 deletions

View File

@ -25,7 +25,6 @@ import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable;
import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression;
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.DecimalV3Type;
import org.apache.doris.nereids.types.DoubleType;
import org.apache.doris.nereids.types.IntegerType;
import com.google.common.base.Preconditions;
@ -40,7 +39,6 @@ public class Ceil extends ScalarFunction
implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullable, ComputePrecisionForRound {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE),
FunctionSignature.ret(DecimalV3Type.WILDCARD).args(DecimalV3Type.WILDCARD),
FunctionSignature.ret(DecimalV3Type.WILDCARD).args(DecimalV3Type.WILDCARD, IntegerType.INSTANCE)
);

View File

@ -25,7 +25,6 @@ import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable;
import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression;
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.DecimalV3Type;
import org.apache.doris.nereids.types.DoubleType;
import org.apache.doris.nereids.types.IntegerType;
import com.google.common.base.Preconditions;
@ -40,7 +39,6 @@ public class Dceil extends ScalarFunction
implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullable, ComputePrecisionForRound {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE),
FunctionSignature.ret(DecimalV3Type.WILDCARD).args(DecimalV3Type.WILDCARD),
FunctionSignature.ret(DecimalV3Type.WILDCARD).args(DecimalV3Type.WILDCARD, IntegerType.INSTANCE)
);

View File

@ -25,7 +25,6 @@ import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable;
import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression;
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.DecimalV3Type;
import org.apache.doris.nereids.types.DoubleType;
import org.apache.doris.nereids.types.IntegerType;
import com.google.common.base.Preconditions;
@ -40,7 +39,6 @@ public class Dfloor extends ScalarFunction
implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullable, ComputePrecisionForRound {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE),
FunctionSignature.ret(DecimalV3Type.WILDCARD).args(DecimalV3Type.WILDCARD),
FunctionSignature.ret(DecimalV3Type.WILDCARD).args(DecimalV3Type.WILDCARD, IntegerType.INSTANCE)
);

View File

@ -24,7 +24,6 @@ import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSi
import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable;
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.DecimalV3Type;
import org.apache.doris.nereids.types.DoubleType;
import org.apache.doris.nereids.types.IntegerType;
import com.google.common.base.Preconditions;
@ -39,8 +38,6 @@ public class Dround extends ScalarFunction
implements ExplicitlyCastableSignature, PropagateNullable, ComputePrecisionForRound {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE),
FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE, IntegerType.INSTANCE),
FunctionSignature.ret(DecimalV3Type.WILDCARD).args(DecimalV3Type.WILDCARD),
FunctionSignature.ret(DecimalV3Type.WILDCARD).args(DecimalV3Type.WILDCARD, IntegerType.INSTANCE)
);

View File

@ -25,7 +25,6 @@ import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable;
import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression;
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.DecimalV3Type;
import org.apache.doris.nereids.types.DoubleType;
import org.apache.doris.nereids.types.IntegerType;
import com.google.common.base.Preconditions;
@ -40,7 +39,6 @@ public class Floor extends ScalarFunction
implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullable, ComputePrecisionForRound {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE),
FunctionSignature.ret(DecimalV3Type.WILDCARD).args(DecimalV3Type.WILDCARD),
FunctionSignature.ret(DecimalV3Type.WILDCARD).args(DecimalV3Type.WILDCARD, IntegerType.INSTANCE)
);

View File

@ -24,7 +24,6 @@ import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSi
import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable;
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.DecimalV3Type;
import org.apache.doris.nereids.types.DoubleType;
import org.apache.doris.nereids.types.IntegerType;
import com.google.common.base.Preconditions;
@ -39,8 +38,6 @@ public class Round extends ScalarFunction
implements ExplicitlyCastableSignature, PropagateNullable, ComputePrecisionForRound {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE),
FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE, IntegerType.INSTANCE),
FunctionSignature.ret(DecimalV3Type.WILDCARD).args(DecimalV3Type.WILDCARD),
FunctionSignature.ret(DecimalV3Type.WILDCARD).args(DecimalV3Type.WILDCARD, IntegerType.INSTANCE)
);

View File

@ -24,7 +24,6 @@ import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSi
import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable;
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.DecimalV3Type;
import org.apache.doris.nereids.types.DoubleType;
import org.apache.doris.nereids.types.IntegerType;
import com.google.common.base.Preconditions;
@ -39,8 +38,6 @@ public class RoundBankers extends ScalarFunction
implements ExplicitlyCastableSignature, PropagateNullable, ComputePrecisionForRound {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE),
FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE, IntegerType.INSTANCE),
FunctionSignature.ret(DecimalV3Type.WILDCARD).args(DecimalV3Type.WILDCARD),
FunctionSignature.ret(DecimalV3Type.WILDCARD).args(DecimalV3Type.WILDCARD, IntegerType.INSTANCE)
);

View File

@ -25,7 +25,6 @@ import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable;
import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression;
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.DecimalV3Type;
import org.apache.doris.nereids.types.DoubleType;
import org.apache.doris.nereids.types.IntegerType;
import com.google.common.base.Preconditions;
@ -40,7 +39,6 @@ public class Truncate extends ScalarFunction
implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullable, ComputePrecisionForRound {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE, IntegerType.INSTANCE),
FunctionSignature.ret(DecimalV3Type.WILDCARD).args(DecimalV3Type.WILDCARD, IntegerType.INSTANCE)
);

View File

@ -34,6 +34,7 @@ import org.apache.doris.nereids.trees.expressions.literal.TinyIntLiteral;
import org.apache.doris.nereids.trees.expressions.literal.VarcharLiteral;
import org.apache.doris.nereids.types.DateTimeV2Type;
import org.apache.doris.nereids.types.DateV2Type;
import org.apache.doris.nereids.types.DecimalV3Type;
import org.apache.doris.nereids.types.DoubleType;
import org.apache.doris.nereids.types.IntegerType;
import org.apache.doris.nereids.util.PlanChecker;
@ -145,7 +146,7 @@ public class UdfTest extends TestWithFeService implements PlanPatternMatchSuppor
new VarcharLiteral("day")),
new Cast(new Add(
new Multiply(
new Floor(new Divide(
new Floor(new Cast(new Divide(
new Cast(
new Hour(new Cast(new VarcharLiteral("2023-05-20 12:23:45"), DateTimeV2Type.SYSTEM_DEFAULT)),
DoubleType.INSTANCE
@ -153,11 +154,11 @@ public class UdfTest extends TestWithFeService implements PlanPatternMatchSuppor
new Divide(
new Cast(new TinyIntLiteral(((byte) 24)), DoubleType.INSTANCE),
new Cast(new IntegerLiteral(((byte) 3)), DoubleType.INSTANCE)
))
)), DecimalV3Type.createDecimalV3Type(30, 15))
),
new Cast(new TinyIntLiteral(((byte) 1)), DoubleType.INSTANCE)
new Cast(new TinyIntLiteral(((byte) 1)), DecimalV3Type.createDecimalV3Type(3, 0))
),
new Cast(new TinyIntLiteral(((byte) 1)), DoubleType.INSTANCE)
new Cast(new TinyIntLiteral(((byte) 1)), DecimalV3Type.createDecimalV3Type(33, 0))
), IntegerType.INSTANCE)
),
new VarcharLiteral("%Y%m%d:%H")

View File

@ -2234,32 +2234,32 @@ Monday
-- !sql_dceil_Double --
\N
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
2.0
2.0
1
1
1
1
1
1
1
1
1
1
2
2
-- !sql_dceil_Double_notnull --
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
2.0
2.0
1
1
1
1
1
1
1
1
1
1
2
2
-- !sql_dceil_DecimalV3S1 --
\N
@ -2495,32 +2495,32 @@ Monday
-- !sql_dfloor_Double --
\N
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
1.0
1.0
1.0
0
0
0
0
0
0
0
0
0
1
1
1
-- !sql_dfloor_Double_notnull --
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
1.0
1.0
1.0
0
0
0
0
0
0
0
0
0
1
1
1
-- !sql_dfloor_DecimalV3S1 --
\N
@ -2761,12 +2761,12 @@ Monday
-0.5228787452803376
-0.3979400086720376
-0.3010299956639812
-0.22184874961635637
-0.2218487496163564
-0.1549019599857432
-0.09691001300805639
-0.045757490560675115
0.0
0.04139268515822507
0.04139268515822508
0.07918124604762482
-- !sql_dlog10_Double_notnull --
@ -2775,12 +2775,12 @@ Monday
-0.5228787452803376
-0.3979400086720376
-0.3010299956639812
-0.22184874961635637
-0.2218487496163564
-0.1549019599857432
-0.09691001300805639
-0.045757490560675115
0.0
0.04139268515822507
0.04139268515822508
0.07918124604762482
-- !sql_domain_String --
@ -2872,61 +2872,61 @@ Monday
-- !sql_dround_Double --
\N
0.0
0.0
0.0
0.0
0.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
0
0
0
0
1
1
1
1
1
1
1
1
-- !sql_dround_Double_notnull --
0.0
0.0
0.0
0.0
0.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
0
0
0
0
1
1
1
1
1
1
1
1
-- !sql_dround_Double_Integer --
\N
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0
1.1
1.2
0.10
0.20
0.30
0.40
0.50
0.60
0.70
0.80
0.90
1.00
1.10
1.20
-- !sql_dround_Double_Integer_notnull --
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0
1.1
1.2
0.10
0.20
0.30
0.40
0.50
0.60
0.70
0.80
0.90
1.00
1.10
1.20
-- !sql_dround_DecimalV3S1 --
\N

View File

@ -436,61 +436,61 @@ string3
-- !sql_round_Double --
\N
0.0
0.0
0.0
0.0
0.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
0
0
0
0
1
1
1
1
1
1
1
1
-- !sql_round_Double_notnull --
0.0
0.0
0.0
0.0
0.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
0
0
0
0
1
1
1
1
1
1
1
1
-- !sql_round_Double_Integer --
\N
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0
1.1
1.2
0.10
0.20
0.30
0.40
0.50
0.60
0.70
0.80
0.90
1.00
1.10
1.20
-- !sql_round_Double_Integer_notnull --
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0
1.1
1.2
0.10
0.20
0.30
0.40
0.50
0.60
0.70
0.80
0.90
1.00
1.10
1.20
-- !sql_round_DecimalV3S1 --
\N
@ -668,61 +668,61 @@ string3
-- !sql_round_bankers_Double --
\N
0.0
0.0
0.0
0.0
0.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
0
0
0
0
0
1
1
1
1
1
1
1
-- !sql_round_bankers_Double_notnull --
0.0
0.0
0.0
0.0
0.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
0
0
0
0
0
1
1
1
1
1
1
1
-- !sql_round_bankers_Double_Integer --
\N
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0
1.1
1.2
0.10
0.20
0.30
0.40
0.50
0.60
0.70
0.80
0.90
1.00
1.10
1.20
-- !sql_round_bankers_Double_Integer_notnull --
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0
1.1
1.2
0.10
0.20
0.30
0.40
0.50
0.60
0.70
0.80
0.90
1.00
1.10
1.20
-- !sql_round_bankers_DecimalV3S1 --
\N

View File

@ -12,9 +12,9 @@
10.12
-- !truncate --
1.0 1989.0 1001.0 123.1 0.1 6.3
2.0 1986.0 1001.0 1243.5 20.2 789.2
3.0 1989.0 1002.0 24453.3 78945.0 3654.0
1 1989 1001 123.1 0.1 6.3
2 1986 1001 1243.5 20.2 789.2
3 1989 1002 24453.3 78945.0 3653.9
-- !select --
16 16 16
@ -99,10 +99,10 @@
247.14 469.36 691.58
-- !query --
200 500 700
200.0 500.0 700.0
-- !query --
0 0 0
0.0 0.0 0.0
-- !query --
247.136 469.358 691.579
@ -114,4 +114,5 @@
200.000 500.000 700.000
-- !query --
0.000 0.000 0.000
0.000 0.000 0.000