You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2022/12/24 09:09:54 UTC

[doris] 02/15: [Bug](decimalv3) Fix wrong precision of DECIMALV3 (#15302)

This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 609f8e9882e7b17e9b0e129ae7b4a0fd9224aeef
Author: Gabriel <ga...@gmail.com>
AuthorDate: Fri Dec 23 14:11:08 2022 +0800

    [Bug](decimalv3) Fix wrong precision of DECIMALV3 (#15302)
    
    * [Bug](decimalv3) Fix wrong precision of DECIMALV3
    
    * update
---
 .../java/org/apache/doris/catalog/ScalarType.java  | 10 +++--
 .../decimalv3/test_arithmetic_expressions.out      | 19 +++++++++
 .../decimalv3/test_arithmetic_expressions.groovy   | 49 ++++++++++++++++++++++
 3 files changed, 75 insertions(+), 3 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/ScalarType.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/ScalarType.java
index e97471f73d..3cd713b507 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/ScalarType.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/ScalarType.java
@@ -1022,9 +1022,13 @@ public class ScalarType extends Type {
         }
 
         if (t1.isDecimalV3() && t2.isDecimalV3()) {
-            return ScalarType.createDecimalV3Type(Math.max(t1.decimalPrecision() - t1.decimalScale(),
-                            t2.decimalPrecision() - t2.decimalScale()) + Math.max(t1.decimalScale(),
-                            t2.decimalScale()), Math.max(t1.decimalScale(), t2.decimalScale()));
+            ScalarType finalType = ScalarType.createDecimalV3Type(Math.max(t1.decimalPrecision() - t1.decimalScale(),
+                    t2.decimalPrecision() - t2.decimalScale()) + Math.max(t1.decimalScale(),
+                    t2.decimalScale()), Math.max(t1.decimalScale(), t2.decimalScale()));
+            if (finalType.getPrecision() > MAX_PRECISION) {
+                finalType = ScalarType.createDecimalV3Type(MAX_PRECISION, finalType.getScalarScale());
+            }
+            return finalType;
         }
 
         PrimitiveType smallerType =
diff --git a/regression-test/data/datatype_p0/decimalv3/test_arithmetic_expressions.out b/regression-test/data/datatype_p0/decimalv3/test_arithmetic_expressions.out
new file mode 100644
index 0000000000..a8d9df8d8d
--- /dev/null
+++ b/regression-test/data/datatype_p0/decimalv3/test_arithmetic_expressions.out
@@ -0,0 +1,19 @@
+-- This file is automatically generated. You should know what you did if you want to edit this
+-- !select_all --
+1.100000000000000000	1.200000000000000000	1.300000000000000000
+1.200000000000000000	1.200000000000000000	1.300000000000000000
+1.500000000000000000	1.200000000000000000	1.300000000000000000
+
+-- !select --
+1.320000000000000000000000000000000000
+1.440000000000000000000000000000000000
+1.800000000000000000000000000000000000
+
+-- !select --
+1.300000000000000000000000000000000000
+1.300000000000000000000000000000000000
+1.300000000000000000000000000000000000
+1.320000000000000000000000000000000000
+1.440000000000000000000000000000000000
+1.800000000000000000000000000000000000
+
diff --git a/regression-test/suites/datatype_p0/decimalv3/test_arithmetic_expressions.groovy b/regression-test/suites/datatype_p0/decimalv3/test_arithmetic_expressions.groovy
new file mode 100644
index 0000000000..44cd313fa0
--- /dev/null
+++ b/regression-test/suites/datatype_p0/decimalv3/test_arithmetic_expressions.groovy
@@ -0,0 +1,49 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("test_arithmetic_expressions") {
+
+    def table1 = "test_arithmetic_expressions"
+
+    sql "drop table if exists ${table1}"
+
+    sql """
+    CREATE TABLE IF NOT EXISTS `${table1}` (
+      `k1` decimalv3(38, 18) NULL COMMENT "",
+      `k2` decimalv3(38, 18) NULL COMMENT "",
+      `k3` decimalv3(38, 18) NULL COMMENT ""
+    ) ENGINE=OLAP
+    COMMENT "OLAP"
+    DISTRIBUTED BY HASH(`k1`, `k2`, `k3`) BUCKETS 8
+    PROPERTIES (
+    "replication_allocation" = "tag.location.default: 1",
+    "in_memory" = "false",
+    "storage_format" = "V2"
+    )
+    """
+
+    sql """insert into ${table1} values(1.1,1.2,1.3),
+            (1.2,1.2,1.3),
+            (1.5,1.2,1.3)
+    """
+    qt_select_all "select * from ${table1} order by k1"
+
+    qt_select "select k1 * k2 from ${table1} order by k1"
+    qt_select "select * from (select k1 * k2 from ${table1} union all select k3 from ${table1}) a order by 1"
+
+    sql "drop table if exists ${table1}"
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org