From 8d15201820b6e3171e83f7cae4636e9593f47ca1 Mon Sep 17 00:00:00 2001 From: Patrick16262 <1626295293@qq.com> Date: Wed, 12 Jun 2024 01:03:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E8=81=9A=E5=90=88?= =?UTF-8?q?=E5=87=BD=E6=95=B0bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/observer/net/communicator.h | 4 ++++ src/observer/sql/expr/function.cpp | 16 +++++++++++++--- .../sql/operator/group_physical_operator.cpp | 8 ++++---- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/observer/net/communicator.h b/src/observer/net/communicator.h index 4379194..1605c26 100644 --- a/src/observer/net/communicator.h +++ b/src/observer/net/communicator.h @@ -14,6 +14,7 @@ See the Mulan PSL v2 for more details. */ #pragma once +#include #include #include @@ -23,6 +24,8 @@ struct ConnectionContext; class SessionEvent; class Session; class BufferedWriter; +class Communicator; + /** * @defgroup Communicator @@ -42,6 +45,7 @@ class BufferedWriter; class Communicator { public: + virtual ~Communicator(); /** diff --git a/src/observer/sql/expr/function.cpp b/src/observer/sql/expr/function.cpp index 043d148..4ec9fbd 100644 --- a/src/observer/sql/expr/function.cpp +++ b/src/observer/sql/expr/function.cpp @@ -107,8 +107,17 @@ RC RoundFunction::check_params() const float RoundFunction::do_round(float num, int precision) const { - float factor = pow(10, precision); - return round(num * factor) / factor; + float factor = pow(10, precision); + float upperred_num = num * factor; + + int fractional_part = static_cast(upperred_num); + float truncated_half = upperred_num - fractional_part - 0.5; + + if ((truncated_half > 1e-5) || (truncated_half < 1e-5 && truncated_half > -1e-5 && fractional_part % 2 == 1)) { + fractional_part += 1; + } + + return (float)fractional_part / factor; } RC DateFormatFunction::function_body(std::vector params, Value &result) const @@ -147,7 +156,8 @@ RC DateFormatFunction::function_body(std::vector params, Value &result) c return RC::SUCCESS; } -RC DateFormatFunction::check_params() const { +RC DateFormatFunction::check_params() const +{ if (FunctionExpression::param_exprs_.size() != 2) { LOG_WARN("Invalid number of parameters for date_format function, expected 2, got %zu", FunctionExpression::param_exprs_.size()); return RC::INVALID_ARGUMENT; diff --git a/src/observer/sql/operator/group_physical_operator.cpp b/src/observer/sql/operator/group_physical_operator.cpp index cc1269c..4c0fa6f 100644 --- a/src/observer/sql/operator/group_physical_operator.cpp +++ b/src/observer/sql/operator/group_physical_operator.cpp @@ -76,12 +76,12 @@ RC GroupPhysicalOperator::open(Trx *trx) RC GroupPhysicalOperator::next() { - if (current_tuple_index_ >= (int)tuples_.size()) { + if (current_tuple_index_ + 1 < (int)tuples_.size()) { + current_tuple_index_ += 1; + return RC::SUCCESS; + } else { return RC::RECORD_EOF; } - - current_tuple_index_++; - return RC::SUCCESS; } RC GroupPhysicalOperator::close()