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 df4da754476 [fix](nereids)use CATALOG_DEFAULT as default decimal precision and scale in cast xx as decimal expr (#31471) df4da754476 is described below commit df4da75447670ceffe23a4c138c65fdb89062c36 Author: starocean999 <40539150+starocean...@users.noreply.github.com> AuthorDate: Wed Feb 28 10:04:08 2024 +0800 [fix](nereids)use CATALOG_DEFAULT as default decimal precision and scale in cast xx as decimal expr (#31471) --- .../src/main/java/org/apache/doris/nereids/types/DataType.java | 8 ++++---- .../main/java/org/apache/doris/nereids/types/DecimalV3Type.java | 2 ++ .../nereids/rules/expression/rules/SimplifyCastRuleTest.java | 8 ++++---- regression-test/data/nereids_p0/datatype/test_cast.out | 4 ++++ regression-test/suites/nereids_p0/datatype/test_cast.groovy | 2 ++ 5 files changed, 16 insertions(+), 8 deletions(-) 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 ffe3c738a2d..9a1e58502b1 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.SYSTEM_DEFAULT; + return DecimalV3Type.CATALOG_DEFAULT; case 2: return DecimalV3Type .createDecimalV3Type(Integer.parseInt(types.get(1))); @@ -148,7 +148,7 @@ public abstract class DataType implements AbstractDataType { } else { switch (types.size()) { case 1: - return DecimalV2Type.SYSTEM_DEFAULT; + return DecimalV2Type.CATALOG_DEFAULT; case 2: return DecimalV2Type.createDecimalV2Type(Integer.parseInt(types.get(1)), 0); @@ -162,7 +162,7 @@ public abstract class DataType implements AbstractDataType { case "decimalv2": switch (types.size()) { case 1: - return DecimalV2Type.SYSTEM_DEFAULT; + return DecimalV2Type.CATALOG_DEFAULT; case 2: return DecimalV2Type.createDecimalV2Type(Integer.parseInt(types.get(1)), 0); case 3: @@ -174,7 +174,7 @@ public abstract class DataType implements AbstractDataType { case "decimalv3": switch (types.size()) { case 1: - return DecimalV3Type.SYSTEM_DEFAULT; + return DecimalV3Type.CATALOG_DEFAULT; case 2: return DecimalV3Type.createDecimalV3Type(Integer.parseInt(types.get(1))); case 3: diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DecimalV3Type.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DecimalV3Type.java index b0fdd205800..80e9adbb906 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DecimalV3Type.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DecimalV3Type.java @@ -42,6 +42,8 @@ public class DecimalV3Type extends FractionalType { public static final DecimalV3Type WILDCARD = new DecimalV3Type(-1, -1); public static final DecimalV3Type SYSTEM_DEFAULT = new DecimalV3Type(MAX_DECIMAL128_PRECISION, DEFAULT_SCALE); + public static final DecimalV3Type CATALOG_DEFAULT = new DecimalV3Type(MAX_DECIMAL32_PRECISION, DEFAULT_SCALE); + private static final DecimalV3Type BOOLEAN_DECIMAL = new DecimalV3Type(1, 0); private static final DecimalV3Type TINYINT_DECIMAL = new DecimalV3Type(3, 0); private static final DecimalV3Type SMALLINT_DECIMAL = new DecimalV3Type(5, 0); 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 f691a5cfdc2..8c07b3e972c 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 @@ -39,13 +39,13 @@ class SimplifyCastRuleTest extends ExpressionRewriteTestHelper { assertRewriteAfterSimplify("CAST('1' AS VARCHAR)", "'1'", VarcharType.createVarcharType(-1)); assertRewriteAfterSimplify("CAST(1 AS DECIMAL)", "1", - DecimalV3Type.createDecimalV3Type(38, 0)); + DecimalV3Type.createDecimalV3Type(9, 0)); assertRewriteAfterSimplify("CAST(1000 AS DECIMAL)", "1000", - DecimalV3Type.createDecimalV3Type(38, 0)); + DecimalV3Type.createDecimalV3Type(9, 0)); assertRewriteAfterSimplify("CAST(1 AS DECIMALV3)", "1", - DecimalV3Type.createDecimalV3Type(38, 0)); + DecimalV3Type.createDecimalV3Type(9, 0)); assertRewriteAfterSimplify("CAST(1000 AS DECIMALV3)", "1000", - DecimalV3Type.createDecimalV3Type(38, 0)); + DecimalV3Type.createDecimalV3Type(9, 0)); } private void assertRewriteAfterSimplify(String expr, String expected, DataType expectedType) { diff --git a/regression-test/data/nereids_p0/datatype/test_cast.out b/regression-test/data/nereids_p0/datatype/test_cast.out new file mode 100644 index 00000000000..2e8095935a3 --- /dev/null +++ b/regression-test/data/nereids_p0/datatype/test_cast.out @@ -0,0 +1,4 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !select -- +2.21 + diff --git a/regression-test/suites/nereids_p0/datatype/test_cast.groovy b/regression-test/suites/nereids_p0/datatype/test_cast.groovy index 29691297efc..29a32557703 100644 --- a/regression-test/suites/nereids_p0/datatype/test_cast.groovy +++ b/regression-test/suites/nereids_p0/datatype/test_cast.groovy @@ -94,4 +94,6 @@ suite("test_cast") { sql "select cast(true as date);" result([[null]]) } + + qt_select """select 1.1*1.1 + cast(1.1 as decimal);""" } \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org