This is an automated email from the ASF dual-hosted git repository. yiguolei 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 101737023c [Bug](round) fix wrong scale for round-like function (#18507) 101737023c is described below commit 101737023c9260414268280b1a935ba6b945766a Author: Gabriel <gabrielleeb...@gmail.com> AuthorDate: Tue Apr 11 09:36:59 2023 +0800 [Bug](round) fix wrong scale for round-like function (#18507) --- be/src/pipeline/exec/meta_scan_operator.cpp | 37 +++++++++++++++++ be/src/pipeline/exec/meta_scan_operator.h | 46 ++++++++++++++++++++++ .../apache/doris/analysis/FunctionCallExpr.java | 2 +- .../sql_functions/math_functions/test_round.out | 19 ++++++++- .../sql_functions/math_functions/test_round.groovy | 8 +++- 5 files changed, 108 insertions(+), 4 deletions(-) diff --git a/be/src/pipeline/exec/meta_scan_operator.cpp b/be/src/pipeline/exec/meta_scan_operator.cpp new file mode 100644 index 0000000000..30e8daf53d --- /dev/null +++ b/be/src/pipeline/exec/meta_scan_operator.cpp @@ -0,0 +1,37 @@ +// 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. + +#include "meta_scan_operator.h" + +#include "vec/exec/scan/vmeta_scan_node.h" + +namespace doris::pipeline { + +OPERATOR_CODE_GENERATOR(MetaScanOperator, SourceOperator) + +Status MetaScanOperator::open(RuntimeState* state) { + SCOPED_TIMER(_runtime_profile->total_time_counter()); + return _node->open(state); +} + +Status MetaScanOperator::close(RuntimeState* state) { + RETURN_IF_ERROR(SourceOperator::close(state)); + _node->close(state); + return Status::OK(); +} + +} // namespace doris::pipeline diff --git a/be/src/pipeline/exec/meta_scan_operator.h b/be/src/pipeline/exec/meta_scan_operator.h new file mode 100644 index 0000000000..f1f6194628 --- /dev/null +++ b/be/src/pipeline/exec/meta_scan_operator.h @@ -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. + +#pragma once + +#include "operator.h" + +namespace doris::vectorized { +class VMetaScanNode; +} // namespace doris::vectorized + +namespace doris::pipeline { + +class MetaScanOperatorBuilder : public OperatorBuilder<vectorized::VMetaScanNode> { +public: + MetaScanOperatorBuilder(int32_t id, ExecNode* exec_node); + bool is_source() const override { return true; } + OperatorPtr build_operator() override; +}; + +class MetaScanOperator : public SourceOperator<MetaScanOperatorBuilder> { +public: + MetaScanOperator(OperatorBuilderBase* operator_builder, ExecNode* scan_node); + + bool can_read() override { return true; } + + Status open(RuntimeState* state) override; + + Status close(RuntimeState* state) override; +}; + +} // namespace doris::pipeline \ No newline at end of file diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java index bac630a45a..0dbbe6f62a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java @@ -125,7 +125,7 @@ public class FunctionCallExpr extends Expr { } int scaleArg = (int) (((IntLiteral) children.get(1)).getValue()); return ScalarType.createDecimalV3Type(children.get(0).getType().getPrecision(), - Math.max(scaleArg, 0)); + Math.min(Math.max(scaleArg, 0), ((ScalarType) children.get(0).getType()).decimalScale())); } else { return returnType; } diff --git a/regression-test/data/query_p0/sql_functions/math_functions/test_round.out b/regression-test/data/query_p0/sql_functions/math_functions/test_round.out index 1b7e8645db..9cbc25841f 100644 --- a/regression-test/data/query_p0/sql_functions/math_functions/test_round.out +++ b/regression-test/data/query_p0/sql_functions/math_functions/test_round.out @@ -1,12 +1,12 @@ -- This file is automatically generated. You should know what you did if you want to edit this -- !select -- -10.0 +10 -- !select -- 10.12 -- !select -- -10.0 +10 -- !select -- 10.12 @@ -58,6 +58,21 @@ -- !select -- 20 20 20 +-- !select -- +16.025 16.02500 16.02500 + +-- !select -- +16.025 16.02500 16.02500 + +-- !select -- +16.025 16.02500 16.02500 + +-- !select -- +16.025 16.02500 16.02500 + +-- !select -- +16.025 16.02500 16.02500 + -- !nereids_round_arg1 -- 10.0 diff --git a/regression-test/suites/query_p0/sql_functions/math_functions/test_round.groovy b/regression-test/suites/query_p0/sql_functions/math_functions/test_round.groovy index 005f0c7172..115e8a5b1d 100644 --- a/regression-test/suites/query_p0/sql_functions/math_functions/test_round.groovy +++ b/regression-test/suites/query_p0/sql_functions/math_functions/test_round.groovy @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -suite("test_round") { + suite("test_round") { qt_select "SELECT round(10.12345)" qt_select "SELECT round(10.12345, 2)" qt_select "SELECT round_bankers(10.12345)" @@ -51,6 +51,12 @@ suite("test_round") { qt_select """ SELECT truncate(col1, -1), truncate(col2, -1), truncate(col3, -1) FROM `${tableName}`; """ qt_select """ SELECT round_bankers(col1, -1), round_bankers(col2, -1), round_bankers(col3, -1) FROM `${tableName}`; """ + qt_select """ SELECT round(col1, 7), round(col2, 7), round(col3, 7) FROM `${tableName}`; """ + qt_select """ SELECT floor(col1, 7), floor(col2, 7), floor(col3, 7) FROM `${tableName}`; """ + qt_select """ SELECT ceil(col1, 7), ceil(col2, 7), ceil(col3, 7) FROM `${tableName}`; """ + qt_select """ SELECT truncate(col1, 7), truncate(col2, 7), truncate(col3, 7) FROM `${tableName}`; """ + qt_select """ SELECT round_bankers(col1, 7), round_bankers(col2, 7), round_bankers(col3, 7) FROM `${tableName}`; """ + sql """ DROP TABLE IF EXISTS `${tableName}` """ sql "SET enable_nereids_planner=true" --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org