You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by st...@apache.org on 2024/06/17 02:52:06 UTC
(doris) branch branch-2.0 updated: [fix](nereids)change the decimal's precision and scale for cast(xx as decimal) (#36315)
This is an automated email from the ASF dual-hosted git repository.
starocean999 pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.0 by this push:
new 4c85fab1701 [fix](nereids)change the decimal's precision and scale for cast(xx as decimal) (#36315)
4c85fab1701 is described below
commit 4c85fab1701c0dc417b959f8ee63a423d8a49e56
Author: starocean999 <40...@users.noreply.github.com>
AuthorDate: Mon Jun 17 10:52:00 2024 +0800
[fix](nereids)change the decimal's precision and scale for cast(xx as decimal) (#36315)
pick from master https://github.com/apache/doris/pull/36316
---
.../expressions/functions/executable/ExecutableFunctions.java | 2 +-
.../trees/expressions/functions/executable/NumericArithmetic.java | 8 ++++----
.../src/main/java/org/apache/doris/nereids/types/DataType.java | 2 +-
.../nereids/rules/expression/rules/SimplifyCastRuleTest.java | 8 ++++----
regression-test/data/nereids_p0/datatype/test_cast.out | 2 +-
5 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/ExecutableFunctions.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/ExecutableFunctions.java
index abed55a1ff4..91a7e5ab353 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/ExecutableFunctions.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/ExecutableFunctions.java
@@ -76,7 +76,7 @@ public class ExecutableFunctions {
return new DoubleLiteral(Math.abs(literal.getValue()));
}
- @ExecFunction(name = "abs", argTypes = {"DECIMAL"}, returnType = "DECIMAL")
+ @ExecFunction(name = "abs", argTypes = {"DECIMALV2"}, returnType = "DECIMALV2")
public static Expression abs(DecimalLiteral literal) {
return new DecimalLiteral(literal.getValue().abs());
}
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/NumericArithmetic.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/NumericArithmetic.java
index f0fb57c76d5..7016c456ebc 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/NumericArithmetic.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/NumericArithmetic.java
@@ -197,7 +197,7 @@ public class NumericArithmetic {
return new DoubleLiteral(result);
}
- @ExecFunction(name = "add", argTypes = {"DECIMAL", "DECIMAL"}, returnType = "DECIMAL")
+ @ExecFunction(name = "add", argTypes = {"DECIMALV2", "DECIMALV2"}, returnType = "DECIMALV2")
public static Expression addDecimalDecimal(DecimalLiteral first, DecimalLiteral second) {
BigDecimal result = first.getValue().add(second.getValue());
return new DecimalLiteral(result);
@@ -368,7 +368,7 @@ public class NumericArithmetic {
return new DoubleLiteral(result);
}
- @ExecFunction(name = "subtract", argTypes = {"DECIMAL", "DECIMAL"}, returnType = "DECIMAL")
+ @ExecFunction(name = "subtract", argTypes = {"DECIMALV2", "DECIMALV2"}, returnType = "DECIMALV2")
public static Expression subtractDecimalDecimal(DecimalLiteral first, DecimalLiteral second) {
BigDecimal result = first.getValue().subtract(second.getValue());
return new DecimalLiteral(result);
@@ -539,7 +539,7 @@ public class NumericArithmetic {
return new DoubleLiteral(result);
}
- @ExecFunction(name = "multiply", argTypes = {"DECIMAL", "DECIMAL"}, returnType = "DECIMAL")
+ @ExecFunction(name = "multiply", argTypes = {"DECIMALV2", "DECIMALV2"}, returnType = "DECIMALV2")
public static Expression multiplyDecimalDecimal(DecimalLiteral first, DecimalLiteral second) {
BigDecimal result = first.getValue().multiply(second.getValue());
return new DecimalLiteral(result);
@@ -570,7 +570,7 @@ public class NumericArithmetic {
return new DoubleLiteral(result);
}
- @ExecFunction(name = "divide", argTypes = {"DECIMAL", "DECIMAL"}, returnType = "DECIMAL")
+ @ExecFunction(name = "divide", argTypes = {"DECIMALV2", "DECIMALV2"}, returnType = "DECIMALV2")
public static Expression divideDecimal(DecimalLiteral first, DecimalLiteral second) {
if (first.getValue().compareTo(BigDecimal.ZERO) == 0) {
return new NullLiteral(first.getDataType());
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DataType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DataType.java
index 9a1e58502b1..ba5d2b70eba 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DataType.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DataType.java
@@ -135,7 +135,7 @@ public abstract class DataType implements AbstractDataType {
if (Config.enable_decimal_conversion && tryConvert) {
switch (types.size()) {
case 1:
- return DecimalV3Type.CATALOG_DEFAULT;
+ return DecimalV3Type.createDecimalV3Type(38, 9);
case 2:
return DecimalV3Type
.createDecimalV3Type(Integer.parseInt(types.get(1)));
diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/rules/SimplifyCastRuleTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/rules/SimplifyCastRuleTest.java
index 8c07b3e972c..658775cedad 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/rules/SimplifyCastRuleTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/rules/SimplifyCastRuleTest.java
@@ -38,10 +38,10 @@ class SimplifyCastRuleTest extends ExpressionRewriteTestHelper {
StringType.INSTANCE);
assertRewriteAfterSimplify("CAST('1' AS VARCHAR)", "'1'",
VarcharType.createVarcharType(-1));
- assertRewriteAfterSimplify("CAST(1 AS DECIMAL)", "1",
- DecimalV3Type.createDecimalV3Type(9, 0));
- assertRewriteAfterSimplify("CAST(1000 AS DECIMAL)", "1000",
- DecimalV3Type.createDecimalV3Type(9, 0));
+ assertRewriteAfterSimplify("CAST(1 AS DECIMAL)", "1.000000000",
+ DecimalV3Type.createDecimalV3Type(38, 9));
+ assertRewriteAfterSimplify("CAST(1000 AS DECIMAL)", "1000.000000000",
+ DecimalV3Type.createDecimalV3Type(38, 9));
assertRewriteAfterSimplify("CAST(1 AS DECIMALV3)", "1",
DecimalV3Type.createDecimalV3Type(9, 0));
assertRewriteAfterSimplify("CAST(1000 AS DECIMALV3)", "1000",
diff --git a/regression-test/data/nereids_p0/datatype/test_cast.out b/regression-test/data/nereids_p0/datatype/test_cast.out
index 2e8095935a3..1b6de583d04 100644
--- a/regression-test/data/nereids_p0/datatype/test_cast.out
+++ b/regression-test/data/nereids_p0/datatype/test_cast.out
@@ -1,4 +1,4 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !select --
-2.21
+2.310000000
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org