This is an automated email from the ASF dual-hosted git repository. panxiaolei pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new 7dcde4d529 [bug](decimal) Use max value as result if overflow (#23602) 7dcde4d529 is described below commit 7dcde4d5299b8c1693fe7e7663a04e9b623b4414 Author: Gabriel <gabrielleeb...@gmail.com> AuthorDate: Tue Aug 29 13:26:25 2023 +0800 [bug](decimal) Use max value as result if overflow (#23602) * [bug](decimal) Use max value as result if overflow * update --- be/src/vec/data_types/data_type_decimal.h | 5 --- be/src/vec/functions/function_binary_arithmetic.h | 4 +- .../decimalv3/test_decimalv3_overflow.out | 7 +++ .../decimalv3/test_decimalv3_overflow.groovy | 50 ++++++++++++++++++++++ 4 files changed, 59 insertions(+), 7 deletions(-) diff --git a/be/src/vec/data_types/data_type_decimal.h b/be/src/vec/data_types/data_type_decimal.h index bc2ac4ab68..275f356ff7 100644 --- a/be/src/vec/data_types/data_type_decimal.h +++ b/be/src/vec/data_types/data_type_decimal.h @@ -89,11 +89,6 @@ constexpr size_t max_decimal_precision<Decimal128I>() { return 38; } -template <typename T> -constexpr typename T::NativeType max_decimal_value() { - return 0; -} - DataTypePtr create_decimal(UInt64 precision, UInt64 scale, bool use_v2); inline UInt32 least_decimal_precision_for(TypeIndex int_type) { diff --git a/be/src/vec/functions/function_binary_arithmetic.h b/be/src/vec/functions/function_binary_arithmetic.h index 0b92898302..1725ef30a2 100644 --- a/be/src/vec/functions/function_binary_arithmetic.h +++ b/be/src/vec/functions/function_binary_arithmetic.h @@ -459,7 +459,7 @@ private: NativeResultType res; // TODO handle overflow gracefully if (Op::template apply<NativeResultType>(a, b, res)) { - res = max_decimal_value<ResultType>(); + res = type_limit<ResultType>::max(); } return res; } else { @@ -499,7 +499,7 @@ private: // TODO handle overflow gracefully if (overflow) { LOG(WARNING) << "Decimal math overflow"; - res = max_decimal_value<ResultType>(); + res = type_limit<ResultType>::max(); } } else { res = apply(a, b); diff --git a/regression-test/data/datatype_p0/decimalv3/test_decimalv3_overflow.out b/regression-test/data/datatype_p0/decimalv3/test_decimalv3_overflow.out new file mode 100644 index 0000000000..9ffc65665a --- /dev/null +++ b/regression-test/data/datatype_p0/decimalv3/test_decimalv3_overflow.out @@ -0,0 +1,7 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !sql -- +9999999999999999999999999999.9999999999 + +-- !sql -- +\N + diff --git a/regression-test/suites/datatype_p0/decimalv3/test_decimalv3_overflow.groovy b/regression-test/suites/datatype_p0/decimalv3/test_decimalv3_overflow.groovy new file mode 100644 index 0000000000..bb4b4ba42d --- /dev/null +++ b/regression-test/suites/datatype_p0/decimalv3/test_decimalv3_overflow.groovy @@ -0,0 +1,50 @@ +// 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_decimalv3_overflow") { + def tblName1 = "test_decimalv3_overflow1" + sql "drop table if exists ${tblName1}" + sql """ CREATE TABLE ${tblName1} ( + `data_time` date NOT NULL COMMENT "", + `c1` decimal(22, 4) NULL COMMENT "" + ) ENGINE=OLAP + UNIQUE KEY(`data_time`) + DISTRIBUTED BY HASH(`data_time`) BUCKETS 10 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); """ + sql "insert into ${tblName1} values('2022-08-01', 104665062791137173.7169)" + + def tblName2 = "test_decimalv3_overflow2" + sql "drop table if exists ${tblName2}" + sql """ CREATE TABLE ${tblName2} ( + `data_time` date NOT NULL COMMENT "", + `c2` decimal(20, 2) NULL COMMENT "", + ) ENGINE=OLAP + UNIQUE KEY(`data_time`) + DISTRIBUTED BY HASH(`data_time`) BUCKETS 10 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); """ + sql "insert into ${tblName2} values('2022-08-01', 705091149953414452.46)" + + qt_sql """ select c2 / 10000 * c1 from ${tblName1}, ${tblName2}; """ + + sql """ set check_overflow_for_decimal=true; """ + + qt_sql """ select c2 / 10000 * c1 from ${tblName1}, ${tblName2}; """ +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org