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

@ -19,46 +19,58 @@
using namespace oceanbase::common;
using namespace oceanbase::sql;
namespace oceanbase {
namespace sql {
ObExprCoalesce::ObExprCoalesce(ObIAllocator& alloc)
namespace oceanbase
{
namespace sql
{
ObExprCoalesce::ObExprCoalesce(ObIAllocator &alloc)
: ObExprOperator(alloc, T_FUN_SYS_COALESCE, N_COALESCE, MORE_THAN_ZERO, NOT_ROW_DIMENSION)
{}
{
}
ObExprCoalesce::~ObExprCoalesce()
{}
{
}
int ObExprCoalesce::calc_result_typeN(
ObExprResType& type, ObExprResType* types, int64_t param_num, ObExprTypeCtx& type_ctx) const
int ObExprCoalesce::calc_result_typeN(ObExprResType &type,
ObExprResType *types,
int64_t param_num,
ObExprTypeCtx &type_ctx) const
{
int ret = OB_SUCCESS;
const ObLengthSemantics default_length_semantics =
(OB_NOT_NULL(type_ctx.get_session()) ? type_ctx.get_session()->get_actual_nls_length_semantics() : LS_BYTE);
const ObLengthSemantics default_length_semantics = (OB_NOT_NULL(type_ctx.get_session()) ? type_ctx.get_session()->get_actual_nls_length_semantics() : LS_BYTE);
if (OB_ISNULL(types)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("null types", K(ret));
} else if (OB_UNLIKELY(param_num < 1 || (lib::is_oracle_mode() && param_num <= 1))) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("no enough param", K(ret), K(param_num));
} else if (OB_FAIL(aggregate_result_type_for_case(type,
types,
param_num,
type_ctx.get_coll_type(),
lib::is_oracle_mode(),
default_length_semantics,
type_ctx.get_session(),
true,
true))) {
} else if (OB_FAIL(aggregate_result_type_for_case(
type,
types,
param_num,
type_ctx.get_coll_type(),
lib::is_oracle_mode(),
default_length_semantics,
type_ctx.get_session(),
true,
true,
is_called_in_sql_))) {
LOG_WARN("failed to agg resul type", K(ret));
} else {
const ObSQLSessionInfo* session = dynamic_cast<const ObSQLSessionInfo*>(type_ctx.get_session());
const ObSQLSessionInfo *session =
dynamic_cast<const ObSQLSessionInfo*>(type_ctx.get_session());
if (OB_ISNULL(session)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("cast basic session to sql session info failed", K(ret));
} else {
ObExprOperator::calc_result_flagN(type, types, param_num);
ObObjType calc_type = enumset_calc_types_[OBJ_TYPE_TO_CLASS[type.get_type()]];
bool is_expr_integer_type = (ob_is_int_tc(type.get_type()) || ob_is_uint_tc(type.get_type()));
bool is_expr_integer_type = (ob_is_int_tc(type.get_type()) ||
ob_is_uint_tc(type.get_type()));
bool all_null_type = true;
for (int64_t i = 0; OB_SUCC(ret) && i < param_num; ++i) {
all_null_type = (types[i].get_type() != ObNullType) ? false : all_null_type;
if (ob_is_enumset_tc(types[i].get_type())) {
if (OB_UNLIKELY(ObMaxType == calc_type)) {
ret = OB_ERR_UNEXPECTED;
@ -66,13 +78,14 @@ int ObExprCoalesce::calc_result_typeN(
} else {
types[i].set_calc_type(calc_type);
}
} else if (session->use_static_typing_engine()) {
bool is_arg_integer_type = (ob_is_int_tc(types[i].get_type()) || ob_is_uint_tc(types[i].get_type()));
if ((is_arg_integer_type && is_expr_integer_type) || ObNullType == types[i].get_type()) {
// When the parameter is int/uint tc, the calc type cannot be set to the type of the result
} else {
bool is_arg_integer_type = (ob_is_int_tc(types[i].get_type()) ||
ob_is_uint_tc(types[i].get_type()));
if ((is_arg_integer_type && is_expr_integer_type) ||
ObNullType == types[i].get_type()) {
// 参数是int/uint tc时不能将calc type设置为结果的类型
// eg: select coalesce(null, col_tinyint, col_mediumint) from t1;
// Due to the processing of null by merge type,
// the result type will change when the type is deduced multiple times
// 由于merge type对于null的处理,会多次类型推导时,结果类型发生变化
types[i].set_calc_meta(types[i].get_obj_meta());
types[i].set_calc_accuracy(types[i].get_accuracy());
} else {
@ -81,69 +94,25 @@ int ObExprCoalesce::calc_result_typeN(
}
}
}
}
}
return ret;
}
int ObExprCoalesce::calc_resultN(ObObj& result, const ObObj* objs_stack, int64_t param_num, ObExprCtx& expr_ctx) const
{
int ret = OB_SUCCESS;
if (OB_ISNULL(expr_ctx.calc_buf_)) {
LOG_WARN("null calc_buf_", K(expr_ctx.calc_buf_));
ret = OB_NOT_INIT;
} else {
EXPR_DEFINE_CAST_CTX(expr_ctx, CM_NONE);
ret = calc(result, objs_stack, param_num, result_type_, cast_ctx);
}
return ret;
}
int ObExprCoalesce::calc(ObObj& result, const ObObj* objs_stack, int64_t param_num, const ObExprResType& expected_type,
common::ObCastCtx& cast_ctx)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(objs_stack) || param_num < 1) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid arguments for coalesce", K(objs_stack), K(param_num));
} else if (OB_UNLIKELY(expected_type.is_invalid())) {
LOG_WARN("invalid expect type", K(expected_type));
ret = OB_INVALID_ARGUMENT;
} else {
int64_t result_idx = 0;
for (int64_t i = 0; OB_SUCC(ret) && i < param_num; i++) {
if (ObNullType != objs_stack[i].get_type()) {
result_idx = i;
break;
}
}
if (OB_SUCC(ret)) {
const ObObj* res_point = NULL;
const ObObj& obj_tmp = objs_stack[result_idx];
cast_ctx.dest_collation_ = expected_type.get_collation_type();
EXPR_CAST_OBJ_V2(expected_type.get_type(), obj_tmp, res_point);
if (OB_FAIL(ret) || OB_ISNULL(res_point)) {
LOG_WARN("fail cast obj", K(expected_type.get_type()), K(ret));
} else {
result = *res_point;
if (!result.is_null() && ob_is_string_type(expected_type.get_type())) {
result.set_collation(expected_type);
}
if (!is_called_in_sql() && all_null_type) {
ret = OB_ERR_COALESCE_AT_LEAST_ONE_NOT_NULL;
LOG_USER_ERROR(OB_ERR_COALESCE_AT_LEAST_ONE_NOT_NULL);
}
}
}
return ret;
}
int calc_coalesce_expr(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& res_datum)
int calc_coalesce_expr(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &res_datum)
{
int ret = OB_SUCCESS;
res_datum.set_null();
for (int64_t i = 0; OB_SUCC(ret) && i < expr.arg_cnt_; ++i) {
ObDatum* child_res = NULL;
ObDatum *child_res = NULL;
if (OB_FAIL(expr.args_[i]->eval(ctx, child_res))) {
LOG_WARN("eval arg failed", K(ret), K(i));
} else if (!(child_res->is_null())) {
// TODO: @shaoge coalesce的结果可以不用预分配内存,直接使用某个子节点的结果
res_datum.set_datum(*child_res);
break;
}
@ -151,7 +120,8 @@ int calc_coalesce_expr(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& res_datum)
return ret;
}
int ObExprCoalesce::cg_expr(ObExprCGCtx& expr_cg_ctx, const ObRawExpr& raw_expr, ObExpr& rt_expr) const
int ObExprCoalesce::cg_expr(ObExprCGCtx &expr_cg_ctx, const ObRawExpr &raw_expr,
ObExpr &rt_expr) const
{
int ret = OB_SUCCESS;
UNUSED(expr_cg_ctx);
@ -160,5 +130,5 @@ int ObExprCoalesce::cg_expr(ObExprCGCtx& expr_cg_ctx, const ObRawExpr& raw_expr,
return ret;
}
} // namespace sql
} // namespace oceanbase
}
}