patch 4.0

This commit is contained in:
wangzelin.wzl
2022-10-24 10:34:53 +08:00
parent 4ad6e00ec3
commit 93a1074b0c
10533 changed files with 2588271 additions and 2299373 deletions

View File

@ -10,52 +10,40 @@
* See the Mulan PubL v2 for more details.
*/
#define USING_LOG_PREFIX SQL_ENG
#define USING_LOG_PREFIX SQL_ENG
#include "sql/engine/expr/ob_expr_date_diff.h"
#include "lib/timezone/ob_time_convert.h"
#include "lib/ob_name_def.h"
namespace oceanbase {
using namespace common;
namespace sql {
ObExprDateDiff::ObExprDateDiff(ObIAllocator& alloc)
: ObFuncExprOperator(alloc, T_FUN_SYS_DATE_DIFF, N_DATE_DIFF, 2, NOT_ROW_DIMENSION)
{}
ObExprDateDiff::~ObExprDateDiff()
{}
int ObExprDateDiff::calc_result2(ObObj& result, const ObObj& left, const ObObj& right, ObExprCtx& expr_ctx) const
namespace oceanbase
{
using namespace common;
namespace sql
{
ObExprDateDiff::ObExprDateDiff(ObIAllocator &alloc)
: ObFuncExprOperator(alloc, T_FUN_SYS_DATE_DIFF, N_DATE_DIFF, 2, NOT_ROW_DIMENSION)
{
int ret = OB_SUCCESS;
if (OB_UNLIKELY(left.is_null() || right.is_null())) {
result.set_null();
} else {
TYPE_CHECK(left, ObDateType);
TYPE_CHECK(right, ObDateType);
int64_t date_left = left.get_date();
int64_t date_right = right.get_date();
if (OB_UNLIKELY(ObTimeConverter::ZERO_DATE == date_left || ObTimeConverter::ZERO_DATE == date_right)) {
result.set_null();
} else {
result.set_int(date_left - date_right);
}
}
UNUSED(expr_ctx);
return ret;
}
ObExprMonthsBetween::ObExprMonthsBetween(ObIAllocator& alloc)
ObExprDateDiff::~ObExprDateDiff()
{
}
ObExprMonthsBetween::ObExprMonthsBetween(ObIAllocator &alloc)
: ObFuncExprOperator(alloc, T_FUN_SYS_MONTHS_BETWEEN, N_MONTHS_BETWEEN, 2, NOT_ROW_DIMENSION)
{}
{
}
ObExprMonthsBetween::~ObExprMonthsBetween()
{}
{
}
int ObExprMonthsBetween::calc_result_type2(
ObExprResType& type, ObExprResType& type1, ObExprResType& type2, ObExprTypeCtx& type_ctx) const
int ObExprMonthsBetween::calc_result_type2(ObExprResType &type,
ObExprResType &type1,
ObExprResType &type2,
ObExprTypeCtx &type_ctx) const
{
int ret = OB_SUCCESS;
UNUSED(type_ctx);
@ -67,50 +55,9 @@ int ObExprMonthsBetween::calc_result_type2(
return ret;
}
int ObExprMonthsBetween::calc_result2(ObObj& result, const ObObj& obj1, const ObObj& obj2, ObExprCtx& expr_ctx) const
{
int ret = OB_SUCCESS;
const int64_t DAYS_PER_MONTH_BASE = 31;
int64_t date_value1 = 0;
int64_t date_value2 = 0;
int64_t rest_utc_diff = 0;
int64_t months_diff = 0;
number::ObNumber res_num;
number::ObNumber res_int;
number::ObNumber res_frac;
number::ObNumber res_numerator;
number::ObNumber res_denominator;
if (OB_ISNULL(expr_ctx.calc_buf_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("allocator is null", K(ret));
} else if (obj1.is_null_oracle() || obj2.is_null_oracle()) {
result.set_null();
} else if (OB_FAIL(obj1.get_datetime(date_value1))) {
LOG_WARN("fail to get datetime", K(ret));
} else if (OB_FAIL(obj2.get_datetime(date_value2))) {
LOG_WARN("fail to get datetime", K(ret));
} else if (OB_FAIL(ObTimeConverter::calc_days_and_months_between_dates(
date_value1, date_value2, months_diff, rest_utc_diff))) {
LOG_WARN("fail to calc diff of days", K(ret));
} else if (OB_FAIL(res_int.from(months_diff, *expr_ctx.calc_buf_))) {
LOG_WARN("fail to from integer", K(ret));
} else if (OB_FAIL(res_numerator.from(rest_utc_diff, *expr_ctx.calc_buf_))) {
LOG_WARN("fail to from integer", K(ret));
} else if (OB_FAIL(res_denominator.from(DAYS_PER_MONTH_BASE * USECS_PER_DAY, *expr_ctx.calc_buf_))) {
LOG_WARN("fail to from integer", K(ret));
} else if (OB_FAIL(res_numerator.div(res_denominator, res_frac, *expr_ctx.calc_buf_))) {
LOG_WARN("fail to div", K(ret));
} else if (OB_FAIL(res_int.add(res_frac, res_num, *expr_ctx.calc_buf_))) {
LOG_WARN("fail to add", K(ret));
} else {
result.set_number(res_num);
}
return ret;
}
int ObExprDateDiff::cg_expr(ObExprCGCtx& op_cg_ctx, const ObRawExpr& raw_expr, ObExpr& rt_expr) const
int ObExprDateDiff::cg_expr(ObExprCGCtx &op_cg_ctx,
const ObRawExpr &raw_expr,
ObExpr &rt_expr) const
{
int ret = OB_SUCCESS;
UNUSED(op_cg_ctx);
@ -120,14 +67,15 @@ int ObExprDateDiff::cg_expr(ObExprCGCtx& op_cg_ctx, const ObRawExpr& raw_expr, O
return ret;
}
int ObExprDateDiff::eval_date_diff(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& res_datum)
int ObExprDateDiff::eval_date_diff(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &res_datum)
{
int ret = OB_SUCCESS;
ObDatum* left = NULL;
ObDatum* right = NULL;
ObDatum *left = NULL;
ObDatum *right = NULL;
int64_t date_left = 0;
int64_t date_right = 0;
if (OB_FAIL(expr.args_[0]->eval(ctx, left)) || OB_FAIL(expr.args_[1]->eval(ctx, right))) {
if (OB_FAIL(expr.args_[0]->eval(ctx, left))
|| OB_FAIL(expr.args_[1]->eval(ctx, right))) {
LOG_WARN("fail to eval conv", K(ret), K(expr));
} else if (left->is_null() || right->is_null()) {
res_datum.set_null();
@ -135,7 +83,8 @@ int ObExprDateDiff::eval_date_diff(const ObExpr& expr, ObEvalCtx& ctx, ObDatum&
// do nothing
} else if (FALSE_IT(date_right = right->get_date())) {
// do nothing
} else if (OB_UNLIKELY(ObTimeConverter::ZERO_DATE == date_left || ObTimeConverter::ZERO_DATE == date_right)) {
} else if (OB_UNLIKELY(ObTimeConverter::ZERO_DATE == date_left ||
ObTimeConverter::ZERO_DATE == date_right)) {
res_datum.set_null();
} else {
res_datum.set_int(date_left - date_right);
@ -144,7 +93,9 @@ int ObExprDateDiff::eval_date_diff(const ObExpr& expr, ObEvalCtx& ctx, ObDatum&
return ret;
}
int ObExprMonthsBetween::cg_expr(ObExprCGCtx& op_cg_ctx, const ObRawExpr& raw_expr, ObExpr& rt_expr) const
int ObExprMonthsBetween::cg_expr(ObExprCGCtx &op_cg_ctx,
const ObRawExpr &raw_expr,
ObExpr &rt_expr) const
{
int ret = OB_SUCCESS;
UNUSED(op_cg_ctx);
@ -154,11 +105,13 @@ int ObExprMonthsBetween::cg_expr(ObExprCGCtx& op_cg_ctx, const ObRawExpr& raw_ex
return ret;
}
int ObExprMonthsBetween::eval_months_between(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& res_datum)
int ObExprMonthsBetween::eval_months_between(const ObExpr &expr,
ObEvalCtx &ctx,
ObDatum &res_datum)
{
int ret = OB_SUCCESS;
ObDatum* left = NULL;
ObDatum* right = NULL;
ObDatum *left = NULL;
ObDatum *right = NULL;
const int64_t DAYS_PER_MONTH_BASE = 31;
int64_t date_value1 = 0;
int64_t date_value2 = 0;
@ -169,8 +122,10 @@ int ObExprMonthsBetween::eval_months_between(const ObExpr& expr, ObEvalCtx& ctx,
number::ObNumber res_frac;
number::ObNumber res_numerator;
number::ObNumber res_denominator;
common::ObArenaAllocator& tmp_allocator = ctx.get_reset_tmp_alloc();
if (OB_FAIL(expr.args_[0]->eval(ctx, left)) || OB_FAIL(expr.args_[1]->eval(ctx, right))) {
ObEvalCtx::TempAllocGuard alloc_guard(ctx);
common::ObArenaAllocator &tmp_allocator = alloc_guard.get_allocator();
if (OB_FAIL(expr.args_[0]->eval(ctx, left))
|| OB_FAIL(expr.args_[1]->eval(ctx, right))) {
LOG_WARN("fail to eval conv", K(ret), K(expr));
} else if (left->is_null() || right->is_null()) {
res_datum.set_null();
@ -178,8 +133,10 @@ int ObExprMonthsBetween::eval_months_between(const ObExpr& expr, ObEvalCtx& ctx,
// do nothing
} else if (FALSE_IT(date_value2 = right->get_datetime())) {
// do nothing
} else if (OB_FAIL(ObTimeConverter::calc_days_and_months_between_dates(
date_value1, date_value2, months_diff, rest_utc_diff))) {
} else if (OB_FAIL(ObTimeConverter::calc_days_and_months_between_dates(date_value1,
date_value2,
months_diff,
rest_utc_diff))) {
LOG_WARN("fail to calc diff of days", K(ret));
} else if (OB_FAIL(res_int.from(months_diff, tmp_allocator))) {
LOG_WARN("fail to from integer", K(ret));
@ -198,5 +155,5 @@ int ObExprMonthsBetween::eval_months_between(const ObExpr& expr, ObEvalCtx& ctx,
return ret;
}
} // namespace sql
} // namespace oceanbase
} //namespace sql
} //namespace oceanbase