Skip to content

Commit

Permalink
修复了聚合函数bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick16262 committed Jun 11, 2024
1 parent 7bbd4b8 commit 8d15201
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/observer/net/communicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the Mulan PSL v2 for more details. */

#pragma once

#include <csignal>
#include <string>
#include <memory>

Expand All @@ -23,6 +24,8 @@ struct ConnectionContext;
class SessionEvent;
class Session;
class BufferedWriter;
class Communicator;


/**
* @defgroup Communicator
Expand All @@ -42,6 +45,7 @@ class BufferedWriter;
class Communicator
{
public:

virtual ~Communicator();

/**
Expand Down
16 changes: 13 additions & 3 deletions src/observer/sql/expr/function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(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<Value> params, Value &result) const
Expand Down Expand Up @@ -147,7 +156,8 @@ RC DateFormatFunction::function_body(std::vector<Value> 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;
Expand Down
8 changes: 4 additions & 4 deletions src/observer/sql/operator/group_physical_operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 8d15201

Please sign in to comment.