This is an automated email from the ASF dual-hosted git repository. morningman pushed a commit to branch dev-1.0.0 in repository https://gitbox.apache.org/repos/asf/incubator-doris.git
commit c6d2ac6b6ffc72f4c7e98b3ea516ae08347a13d5 Author: dataroaring <[email protected]> AuthorDate: Mon Mar 28 12:41:00 2022 +0800 [fix] fix core dump when avg on not null decimal in empty table (#8681) --- .../aggregate_functions/aggregate_function_avg.h | 6 +++-- regression-test/suites/empty_table/ddl/empty.sql | 7 +++++ regression-test/suites/empty_table/load.groovy | 31 ++++++++++++++++++++++ .../suites/empty_table/sql/avg_decimal.sql | 1 + 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/be/src/vec/aggregate_functions/aggregate_function_avg.h b/be/src/vec/aggregate_functions/aggregate_function_avg.h index 7b40f95..4aeb7fe 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_avg.h +++ b/be/src/vec/aggregate_functions/aggregate_function_avg.h @@ -40,8 +40,10 @@ struct AggregateFunctionAvgData { if constexpr (std::numeric_limits<ResultT>::is_iec559) return static_cast<ResultT>(sum) / count; /// allow division by zero - if (!count) - throw Exception("AggregateFunctionAvg with zero values", TStatusCode::VEC_LOGIC_ERROR); + if (!count) { + // null is handled in AggregationNode::_get_without_key_result + return static_cast<ResultT>(sum); + } return static_cast<ResultT>(sum) / count; } diff --git a/regression-test/suites/empty_table/ddl/empty.sql b/regression-test/suites/empty_table/ddl/empty.sql new file mode 100644 index 0000000..c3d423d --- /dev/null +++ b/regression-test/suites/empty_table/ddl/empty.sql @@ -0,0 +1,7 @@ +CREATE TABLE `empty` ( + `c1` INT, + `c2` String, + `c3` Decimal(15, 2) NOT NULL +) +DISTRIBUTED BY HASH(`c1`) BUCKETS 1 +PROPERTIES("replication_num" = "1"); diff --git a/regression-test/suites/empty_table/load.groovy b/regression-test/suites/empty_table/load.groovy new file mode 100644 index 0000000..a8a554e --- /dev/null +++ b/regression-test/suites/empty_table/load.groovy @@ -0,0 +1,31 @@ + +// 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. + +// The cases is copied from https://github.com/trinodb/trino/tree/master +// /testing/trino-product-tests/src/main/resources/sql-tests/testcases +// and modified by Doris. + +def tables=["empty"] + +for (String table in tables) { + sql """ DROP TABLE IF EXISTS $table """ +} + +for (String table in tables) { + sql new File("""${context.file.parent}/ddl/${table}.sql""").text +} diff --git a/regression-test/suites/empty_table/sql/avg_decimal.sql b/regression-test/suites/empty_table/sql/avg_decimal.sql new file mode 100644 index 0000000..d9cdcd2 --- /dev/null +++ b/regression-test/suites/empty_table/sql/avg_decimal.sql @@ -0,0 +1 @@ +SELECT avg(c3) from empty --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
