patch 4.0
This commit is contained in:
@ -19,22 +19,28 @@
|
||||
#include "sql/engine/expr/ob_expr_promotion_util.h"
|
||||
#include "sql/session/ob_sql_session_info.h"
|
||||
|
||||
namespace oceanbase {
|
||||
using namespace oceanbase::common;
|
||||
namespace sql {
|
||||
|
||||
ObExprIfNull::ObExprIfNull(ObIAllocator& alloc)
|
||||
: ObFuncExprOperator(alloc, T_FUN_SYS_IFNULL, N_IFNULL, 2, NOT_ROW_DIMENSION)
|
||||
{}
|
||||
namespace oceanbase
|
||||
{
|
||||
using namespace oceanbase::common;
|
||||
namespace sql
|
||||
{
|
||||
|
||||
ObExprIfNull::ObExprIfNull(ObIAllocator &alloc) : ObFuncExprOperator(alloc, T_FUN_SYS_IFNULL, N_IFNULL, 2, NOT_ROW_DIMENSION)
|
||||
{
|
||||
}
|
||||
|
||||
ObExprIfNull::~ObExprIfNull()
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
int ObExprIfNull::calc_result_type2(
|
||||
ObExprResType& type, ObExprResType& type1, ObExprResType& type2, ObExprTypeCtx& type_ctx) const
|
||||
int ObExprIfNull::calc_result_type2(ObExprResType &type,
|
||||
ObExprResType &type1,
|
||||
ObExprResType &type2,
|
||||
ObExprTypeCtx &type_ctx) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
const ObSQLSessionInfo* session = type_ctx.get_session();
|
||||
const ObSQLSessionInfo *session = type_ctx.get_session();
|
||||
if (OB_ISNULL(session)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("session is NULL", K(ret));
|
||||
@ -43,12 +49,9 @@ int ObExprIfNull::calc_result_type2(
|
||||
} else if (ob_is_string_type(type.get_type()) || ob_is_json_tc(type.get_type())) {
|
||||
ObCollationLevel res_cs_level = CS_LEVEL_INVALID;
|
||||
ObCollationType res_cs_type = CS_TYPE_INVALID;
|
||||
if (OB_FAIL(ObCharset::aggregate_collation(type1.get_collation_level(),
|
||||
type1.get_collation_type(),
|
||||
type2.get_collation_level(),
|
||||
type2.get_collation_type(),
|
||||
res_cs_level,
|
||||
res_cs_type))) {
|
||||
if (OB_FAIL(ObCharset::aggregate_collation(type1.get_collation_level(), type1.get_collation_type(),
|
||||
type2.get_collation_level(), type2.get_collation_type(),
|
||||
res_cs_level, res_cs_type))) {
|
||||
LOG_WARN("failed to calc collation", K(ret));
|
||||
} else {
|
||||
type.set_collation_level(res_cs_level);
|
||||
@ -62,8 +65,9 @@ int ObExprIfNull::calc_result_type2(
|
||||
} else {
|
||||
type.set_accuracy(type2.get_accuracy());
|
||||
}
|
||||
// For the mixed type of int and uint64, the type needs to be promoted to decimal
|
||||
if ((ObUInt64Type == type1.get_type() || ObUInt64Type == type2.get_type()) && ObIntType == type.get_type()) {
|
||||
//对于 int 和uint64的混合类型,需要提升类型至decimal
|
||||
if ((ObUInt64Type == type1.get_type() || ObUInt64Type == type2.get_type())
|
||||
&& ObIntType == type.get_type()) {
|
||||
type.set_type(ObNumberType);
|
||||
type.set_accuracy(ObAccuracy::DDL_DEFAULT_ACCURACY[ObIntType].get_accuracy());
|
||||
}
|
||||
@ -77,49 +81,22 @@ int ObExprIfNull::calc_result_type2(
|
||||
type.set_scale(-1);
|
||||
}
|
||||
type.set_length(MAX(type1.get_length(), type2.get_length()));
|
||||
if (session->use_static_typing_engine()) {
|
||||
type1.set_calc_meta(type.get_obj_meta());
|
||||
type1.set_calc_accuracy(type.get_accuracy());
|
||||
type2.set_calc_meta(type.get_obj_meta());
|
||||
type2.set_calc_accuracy(type.get_accuracy());
|
||||
} else {
|
||||
if (ob_is_enumset_tc(type1.get_type())) {
|
||||
type1.set_calc_type(type.get_type());
|
||||
}
|
||||
if (ob_is_enumset_tc(type2.get_type())) {
|
||||
type2.set_calc_type(type.get_type());
|
||||
}
|
||||
}
|
||||
type1.set_calc_meta(type.get_obj_meta());
|
||||
type1.set_calc_accuracy(type.get_accuracy());
|
||||
type2.set_calc_meta(type.get_obj_meta());
|
||||
type2.set_calc_accuracy(type.get_accuracy());
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprIfNull::calc_result2(ObObj& result, const ObObj& obj1, const ObObj& obj2, ObExprCtx& expr_ctx) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
const ObObj* p_result = NULL;
|
||||
ObObjType res_type = get_result_type().get_type();
|
||||
const ObObj* p_target = obj1.is_null() ? &obj2 : &obj1;
|
||||
ObObj casted_obj;
|
||||
EXPR_DEFINE_CAST_CTX(expr_ctx, CM_NONE);
|
||||
if (OB_FAIL(ObObjCaster::to_type(res_type, cast_ctx, *p_target, casted_obj, p_result))) {
|
||||
LOG_WARN("failed to cast object", K(ret), K(*p_target), K(res_type));
|
||||
} else if (NULL != p_result) {
|
||||
result = *p_result;
|
||||
} else {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("failed to cast object", K(ret), K(*p_target), K(res_type));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprIfNull::calc_ifnull_expr(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& res_datum)
|
||||
int ObExprIfNull::calc_ifnull_expr(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &res_datum)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
// ifnull(arg0, arg1);
|
||||
ObDatum* arg0 = NULL;
|
||||
ObDatum* arg1 = NULL;
|
||||
ObDatum *arg0 = NULL;
|
||||
ObDatum *arg1 = NULL;
|
||||
// MySQL ifnull是短路的
|
||||
if (OB_FAIL(expr.args_[0]->eval(ctx, arg0))) {
|
||||
LOG_WARN("eval arg0 failed", K(ret));
|
||||
} else if (!arg0->is_null()) {
|
||||
@ -132,7 +109,8 @@ int ObExprIfNull::calc_ifnull_expr(const ObExpr& expr, ObEvalCtx& ctx, ObDatum&
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprIfNull::cg_expr(ObExprCGCtx& expr_cg_ctx, const ObRawExpr& raw_expr, ObExpr& rt_expr) const
|
||||
int ObExprIfNull::cg_expr(ObExprCGCtx &expr_cg_ctx, const ObRawExpr &raw_expr,
|
||||
ObExpr &rt_expr) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
UNUSED(expr_cg_ctx);
|
||||
@ -140,5 +118,5 @@ int ObExprIfNull::cg_expr(ObExprCGCtx& expr_cg_ctx, const ObRawExpr& raw_expr, O
|
||||
rt_expr.eval_func_ = calc_ifnull_expr;
|
||||
return ret;
|
||||
}
|
||||
} // namespace sql
|
||||
} // namespace oceanbase
|
||||
} // namespace sql
|
||||
} // namespace oceanbase
|
||||
|
||||
Reference in New Issue
Block a user