This is an automated email from the ASF dual-hosted git repository. xuyang 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 bcb2ba19743 [branch-2.0](decimalv2) fix decimal overflow while with decimalv2 (#36519) bcb2ba19743 is described below commit bcb2ba197435407ead8704c011d0538d0e2c5821 Author: camby <camby...@tencent.com> AuthorDate: Thu Jun 20 10:33:15 2024 +0800 [branch-2.0](decimalv2) fix decimal overflow while with decimalv2 (#36519) ## Proposed changes fix issue https://github.com/apache/doris/issues/36493 <!--Describe your changes.--> --- .../java/org/apache/doris/catalog/ScalarType.java | 6 ++- .../decimalv3/test_compatible_for_decimalv2.out | 11 ++++++ .../decimalv3/test_compatible_for_decimalv2.groovy | 46 ++++++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java b/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java index f9a57670d68..b4a81068b3f 100644 --- a/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java +++ b/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java @@ -1116,7 +1116,11 @@ public class ScalarType extends Type { if ((t1.isDecimalV3() && t2.isDecimalV2()) || (t2.isDecimalV3() && t1.isDecimalV2())) { int scale = Math.max(t1.scale, t2.scale); int integerPart = Math.max(t1.precision - t1.scale, t2.precision - t2.scale); - return ScalarType.createDecimalV3Type(integerPart + scale, scale); + if (scale + integerPart > MAX_DECIMAL128_PRECISION) { + return Type.DOUBLE; + } else { + return ScalarType.createDecimalV3Type(integerPart + scale, scale); + } } if (t1.isDecimalV2() || t2.isDecimalV2()) { diff --git a/regression-test/data/datatype_p0/decimalv3/test_compatible_for_decimalv2.out b/regression-test/data/datatype_p0/decimalv3/test_compatible_for_decimalv2.out new file mode 100644 index 00000000000..8c8fbe76f76 --- /dev/null +++ b/regression-test/data/datatype_p0/decimalv3/test_compatible_for_decimalv2.out @@ -0,0 +1,11 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !sql1 -- + +-- !sql2 -- +1 + +-- !sql3 -- + +-- !sql4 -- +1 + diff --git a/regression-test/suites/datatype_p0/decimalv3/test_compatible_for_decimalv2.groovy b/regression-test/suites/datatype_p0/decimalv3/test_compatible_for_decimalv2.groovy new file mode 100644 index 00000000000..ff53312aa31 --- /dev/null +++ b/regression-test/suites/datatype_p0/decimalv3/test_compatible_for_decimalv2.groovy @@ -0,0 +1,46 @@ +// 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_compatible_for_decimalv2", "nonConcurrent") { + // create table with decimalv2 type + sql """ admin set frontend config ("disable_decimalv2"="false"); """ + sql """ admin set frontend config ("enable_decimal_conversion"="false"); """ + sql "drop table if exists uniq_a" + sql """ create table uniq_a(k1 int, v1 decimal(15,4)) unique key(k1) DISTRIBUTED by hash(k1) buckets 1 properties("replication_num"="1"); """ + + // create table with decimalv3 type + sql """ admin set frontend config ("disable_decimalv2"="true"); """ + sql """ admin set frontend config ("enable_decimal_conversion"="true"); """ + sql "drop table if exists uniq_b" + sql """ create table uniq_b(k1 int, v1 decimal(27,8)) unique key(k1) DISTRIBUTED by hash(k1) buckets 1 properties("replication_num"="1"); """ + + sql "insert into uniq_a values(1, '1.2345');" + sql "insert into uniq_b values(1, '1.2345');" + sql "sync" + + // using having + sum + sql 'set enable_nereids_planner=false' + qt_sql1 "select uniq_a.k1 from uniq_a left join uniq_b on uniq_a.k1 = uniq_b.k1 group by uniq_a.k1 having sum(uniq_b.v1) <> sum(uniq_a.v1);" + qt_sql2 "select uniq_a.k1 from uniq_a left join uniq_b on uniq_a.k1 = uniq_b.k1 group by uniq_a.k1 having sum(uniq_b.v1) = sum(uniq_a.v1);" + + sql 'set enable_nereids_planner=true' + qt_sql3 "select uniq_a.k1 from uniq_a left join uniq_b on uniq_a.k1 = uniq_b.k1 group by uniq_a.k1 having sum(uniq_b.v1) <> sum(uniq_a.v1);" + qt_sql4 "select uniq_a.k1 from uniq_a left join uniq_b on uniq_a.k1 = uniq_b.k1 group by uniq_a.k1 having sum(uniq_b.v1) = sum(uniq_a.v1);" + + sql "drop table if exists uniq_a" + sql "drop table if exists uniq_b" +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org