Fix default function bug
This commit is contained in:
@ -12,6 +12,7 @@
|
||||
|
||||
#include "sql/engine/expr/ob_expr_fun_default.h"
|
||||
#include "sql/engine/expr/ob_expr_column_conv.h"
|
||||
#include "sql/resolver/expr/ob_raw_expr_util.h"
|
||||
using namespace oceanbase::common;
|
||||
|
||||
namespace oceanbase
|
||||
@ -20,7 +21,7 @@ namespace sql
|
||||
{
|
||||
|
||||
ObExprFunDefault::ObExprFunDefault(ObIAllocator &alloc)
|
||||
: ObFuncExprOperator(alloc, T_FUN_SYS_DEFAULT, N_DEFAULT, 5, NOT_VALID_FOR_GENERATED_COL, NOT_ROW_DIMENSION)
|
||||
: ObFuncExprOperator(alloc, T_FUN_SYS_DEFAULT, N_DEFAULT, 5, VALID_FOR_GENERATED_COL, NOT_ROW_DIMENSION)
|
||||
{
|
||||
disable_operand_auto_cast();
|
||||
}
|
||||
@ -35,7 +36,6 @@ int ObExprFunDefault::calc_result_typeN(ObExprResType &type,
|
||||
common::ObExprTypeCtx &type_ctx) const
|
||||
{
|
||||
//no need to set calc type of types
|
||||
UNUSED(type_ctx);
|
||||
|
||||
int ret = OB_SUCCESS;
|
||||
//objs[0] type
|
||||
@ -44,8 +44,16 @@ int ObExprFunDefault::calc_result_typeN(ObExprResType &type,
|
||||
//objs[3] nullable_expr
|
||||
//objs[4] default_value
|
||||
//objs[5] column_info
|
||||
|
||||
if (param_num != ObExprColumnConv::PARAMS_COUNT_WITH_COLUMN_INFO
|
||||
const ObRawExpr *raw_expr = type_ctx.get_raw_expr();
|
||||
if (OB_ISNULL(raw_expr) || OB_ISNULL(raw_expr->get_param_expr(0))) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
SQL_ENG_LOG(WARN,"unexpected null", K(ret));
|
||||
} else if (raw_expr->get_param_expr(0)->is_column_ref_expr()) {
|
||||
type.set_type(types[0].get_type());
|
||||
type.set_collation_type(types[0].get_collation_type());
|
||||
type.set_collation_level(CS_LEVEL_IMPLICIT);
|
||||
type.set_accuracy(types[0].get_accuracy());
|
||||
} else if (param_num != ObExprColumnConv::PARAMS_COUNT_WITH_COLUMN_INFO
|
||||
&& param_num != ObExprColumnConv::PARAMS_COUNT_WITHOUT_COLUMN_INFO) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
SQL_ENG_LOG(WARN, "invalid argument, param_num should be 5 or 6", K(param_num));
|
||||
@ -77,6 +85,9 @@ int ObExprFunDefault::calc_default_expr(const ObExpr &expr, ObEvalCtx &ctx,
|
||||
} else if (OB_FAIL(expr.args_[3]->eval(ctx, nullable)) ||
|
||||
OB_FAIL(expr.args_[4]->eval(ctx, def))) {
|
||||
SQL_ENG_LOG(WARN, "eval arg failed", K(ret));
|
||||
} else if (nullable->is_null()) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
SQL_ENG_LOG(WARN, "nullable param should be bool type", K(ret));
|
||||
} else if (def->is_null()) {
|
||||
if (!lib::is_oracle_mode() && !nullable->get_bool()) {
|
||||
ret = OB_ERR_NO_DEFAULT_FOR_FIELD;
|
||||
|
||||
Reference in New Issue
Block a user