This is an automated email from the ASF dual-hosted git repository. yiguolei pushed a commit to branch branch-2.1 in repository https://gitbox.apache.org/repos/asf/doris.git
commit 2d398dfe1fa030670f2a51449e39bb5285b21248 Author: starocean999 <[email protected]> AuthorDate: Tue Mar 26 20:04:04 2024 +0800 [fix](planner)the decimal type of's precision and scale setope ration codn is wrong (#32787) --- .../main/java/org/apache/doris/analysis/Analyzer.java | 18 ++++++++++++++++++ .../suites/nereids_p0/datatype/test_cast.groovy | 5 +++++ 2 files changed, 23 insertions(+) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java index 01d090f6c55..195e6e6e0b3 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java @@ -2327,6 +2327,9 @@ public class Analyzer { lastCompatibleExpr, exprLists.get(j).get(i)); lastCompatibleExpr = exprLists.get(j).get(i); } + if (compatibleType.isDecimalV3()) { + compatibleType = adjustDecimalV3PrecisionAndScale((ScalarType) compatibleType); + } // Now that we've found a compatible type, add implicit casts if necessary. for (int j = 0; j < exprLists.size(); ++j) { if (!exprLists.get(j).get(i).getType().equals(compatibleType)) { @@ -2337,6 +2340,21 @@ public class Analyzer { } } + private ScalarType adjustDecimalV3PrecisionAndScale(ScalarType decimalV3Type) { + ScalarType resultType = decimalV3Type; + int oldPrecision = decimalV3Type.getPrecision(); + int oldScale = decimalV3Type.getDecimalDigits(); + int integerPart = oldPrecision - oldScale; + int maxPrecision = + SessionVariable.getEnableDecimal256() ? ScalarType.MAX_DECIMAL256_PRECISION + : ScalarType.MAX_DECIMAL128_PRECISION; + if (oldPrecision > maxPrecision) { + int newScale = maxPrecision - integerPart; + resultType = ScalarType.createDecimalType(maxPrecision, newScale < 0 ? 0 : newScale); + } + return resultType; + } + public long getConnectId() { return globalState.context.getConnectionId(); } diff --git a/regression-test/suites/nereids_p0/datatype/test_cast.groovy b/regression-test/suites/nereids_p0/datatype/test_cast.groovy index 30530a26daf..b6f96d86288 100644 --- a/regression-test/suites/nereids_p0/datatype/test_cast.groovy +++ b/regression-test/suites/nereids_p0/datatype/test_cast.groovy @@ -113,4 +113,9 @@ suite("test_cast") { sql """select k0 from table_decimal38_4 union all select k0 from table_decimal27_9;""" contains """AS DECIMALV3(38, 4)""" } + sql """set enable_nereids_planner=false;""" + explain { + sql """select k0 from table_decimal38_4 union all select k0 from table_decimal27_9;""" + contains """AS DECIMALV3(38, 4)""" + } } \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
