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

@ -14,38 +14,42 @@
#define SRC_SQL_ENGINE_EXPR_OB_EXPR_WEEK_OF_FUNC_H_
#include "sql/engine/expr/ob_expr_operator.h"
namespace oceanbase {
namespace sql {
namespace oceanbase
{
namespace sql
{
// WEEKOFYEAR(date)
// Returns the calendar week of the date
// --as a number in the range from 1 to 53.
// WEEKOFYEAR() is a compatibility function
// WEEKOFYEAR() is a compatibility function
// --that is equivalent to WEEK(date,3).
class ObExprWeekOfYear : public ObFuncExprOperator {
public:
ObExprWeekOfYear();
explicit ObExprWeekOfYear(common::ObIAllocator& alloc);
virtual ~ObExprWeekOfYear();
virtual int calc_result_type1(
ObExprResType& type, ObExprResType& date, common::ObExprTypeCtx& type_ctx) const override;
virtual int calc_result1(
common::ObObj& result, const common::ObObj& date, common::ObExprCtx& expr_ctx) const override;
virtual int cg_expr(ObExprCGCtx& op_cg_ctx, const ObRawExpr& raw_expr, ObExpr& rt_expr) const override;
static int calc_weekofyear(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& expr_datum);
virtual int calc_result_type1(ObExprResType& type,
ObExprResType& date,
common::ObExprTypeCtx& type_ctx) const override;
virtual int cg_expr(ObExprCGCtx &op_cg_ctx,
const ObRawExpr &raw_expr,
ObExpr &rt_expr) const override;
static int calc_weekofyear(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &expr_datum);
private:
DISALLOW_COPY_AND_ASSIGN(ObExprWeekOfYear);
};
inline int ObExprWeekOfYear::calc_result_type1(
ObExprResType& type, ObExprResType& date, common::ObExprTypeCtx& type_ctx) const
inline int ObExprWeekOfYear::calc_result_type1(ObExprResType& type,
ObExprResType& date, common::ObExprTypeCtx& type_ctx) const
{
UNUSED(type_ctx);
UNUSED(date);
type.set_int();
type.set_scale(common::DEFAULT_SCALE_FOR_INTEGER);
type.set_precision(common::ObAccuracy ::DDL_DEFAULT_ACCURACY[common::ObIntType].precision_);
type.set_precision(common::ObAccuracy
::DDL_DEFAULT_ACCURACY[common::ObIntType].precision_);
if (ob_is_enumset_tc(date.get_type())) {
date.set_calc_type(common::ObVarcharType);
}
@ -54,30 +58,32 @@ inline int ObExprWeekOfYear::calc_result_type1(
// WEEKDAY(date)
// Returns the weekday index for date
// --(0 = Monday, 1 = Tuesday, ... 6 = Sunday).
// --(0 = Monday, 1 = Tuesday, 6 = Sunday).
class ObExprWeekDay : public ObFuncExprOperator {
public:
ObExprWeekDay();
explicit ObExprWeekDay(common::ObIAllocator& alloc);
virtual ~ObExprWeekDay();
virtual int calc_result_type1(
ObExprResType& type, ObExprResType& date, common::ObExprTypeCtx& type_ctx) const override;
virtual int calc_result1(
common::ObObj& result, const common::ObObj& date, common::ObExprCtx& expr_ctx) const override;
virtual int cg_expr(ObExprCGCtx& op_cg_ctx, const ObRawExpr& raw_expr, ObExpr& rt_expr) const override;
static int calc_weekday(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& expr_datum);
virtual int calc_result_type1(ObExprResType& type,
ObExprResType& date,
common::ObExprTypeCtx& type_ctx) const override;
virtual int cg_expr(ObExprCGCtx &op_cg_ctx,
const ObRawExpr &raw_expr,
ObExpr &rt_expr) const override;
static int calc_weekday(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &expr_datum);
private:
DISALLOW_COPY_AND_ASSIGN(ObExprWeekDay);
};
inline int ObExprWeekDay::calc_result_type1(
ObExprResType& type, ObExprResType& date, common::ObExprTypeCtx& type_ctx) const
inline int ObExprWeekDay::calc_result_type1(ObExprResType& type,
ObExprResType& date, common::ObExprTypeCtx& type_ctx) const
{
UNUSED(type_ctx);
UNUSED(date);
type.set_int();
type.set_scale(common::DEFAULT_SCALE_FOR_INTEGER);
type.set_precision(common::ObAccuracy ::DDL_DEFAULT_ACCURACY[common::ObIntType].precision_);
type.set_precision(common::ObAccuracy
::DDL_DEFAULT_ACCURACY[common::ObIntType].precision_);
if (ob_is_enumset_tc(date.get_type())) {
date.set_calc_type(common::ObVarcharType);
}
@ -93,37 +99,42 @@ public:
ObExprYearWeek();
explicit ObExprYearWeek(common::ObIAllocator& alloc);
virtual ~ObExprYearWeek();
virtual int calc_result_typeN(
ObExprResType& type, ObExprResType* types, int64_t param_num, common::ObExprTypeCtx& type_ctx) const override;
virtual int calc_resultN(common::ObObj& result, const common::ObObj* objs_stack, int64_t param_num,
common::ObExprCtx& expr_ctx) const override;
virtual int cg_expr(ObExprCGCtx& op_cg_ctx, const ObRawExpr& raw_expr, ObExpr& rt_expr) const override;
static int calc_yearweek(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& expr_datum);
virtual int calc_result_typeN(ObExprResType& type,
ObExprResType* types,
int64_t param_num,
common::ObExprTypeCtx& type_ctx)
const override;
virtual int cg_expr(ObExprCGCtx &op_cg_ctx,
const ObRawExpr &raw_expr,
ObExpr &rt_expr) const override;
static int calc_yearweek(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &expr_datum);
private:
DISALLOW_COPY_AND_ASSIGN(ObExprYearWeek);
};
// WEEK(date), WEEK(date, mode) returns the week number for date. The two-argument form of WEEK() enables you to specify
// whether the week starts on Sunday or Monday and whether the return value should be in the range from 0 to 53 or
// from 1 to 53 e.g., SELECT WEEK('2008-02-20',1); --> 8
//WEEK(date), WEEK(date, mode) returns the week number for date. The two-argument form of WEEK() enables you to specify whether
//the week starts on Sunday or Monday and whether the return value should be in the range from 0 to 53 or from 1 to 53
//e.g., SELECT WEEK('2008-02-20',1); --> 8
// SELECT WEEK('2008-02-20'); SELECT WEEK('2008-02-20', 0); --> 7
class ObExprWeek : public ObFuncExprOperator {
public:
ObExprWeek();
explicit ObExprWeek(common::ObIAllocator& alloc);
virtual ~ObExprWeek();
virtual int calc_result_typeN(
ObExprResType& type, ObExprResType* types, int64_t params_count, common::ObExprTypeCtx& type_ctx) const override;
virtual int calc_resultN(common::ObObj& result, const common::ObObj* params, int64_t params_count,
common::ObExprCtx& expr_ctx) const override;
virtual int cg_expr(ObExprCGCtx& op_cg_ctx, const ObRawExpr& raw_expr, ObExpr& rt_expr) const override;
static int calc_week(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& expr_datum);
virtual int calc_result_typeN(ObExprResType& type,
ObExprResType* types,
int64_t params_count,
common::ObExprTypeCtx& type_ctx) const override;
virtual int cg_expr(ObExprCGCtx &op_cg_ctx,
const ObRawExpr &raw_expr,
ObExpr &rt_expr) const override;
static int calc_week(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &expr_datum);
private:
DISALLOW_COPY_AND_ASSIGN(ObExprWeek);
};
} // namespace sql
} // namespace oceanbase
}
}
#endif