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

@ -17,14 +17,20 @@
#include "sql/engine/expr/ob_expr_promotion_util.h"
#include "sql/session/ob_sql_session_info.h"
#include "sql/engine/expr/ob_expr_result_type_util.h"
#include "sql/engine/expr/ob_expr_is.h"
#include <math.h>
namespace oceanbase {
namespace oceanbase
{
using namespace common;
namespace sql {
namespace sql
{
int ObExprNvlUtil::calc_result_type(ObExprResType& type,
int ObExprNvlUtil::calc_result_type(ObExprResType &type,
ObExprResType& type1, ObExprResType& type2, ObExprTypeCtx& type_ctx)
ObExprResType &type1,
ObExprResType &type2,
ObExprTypeCtx &type_ctx)
{
UNUSED(type_ctx);
int ret = OB_SUCCESS;
@ -36,7 +42,7 @@ int ObExprNvlUtil::calc_result_type(ObExprResType& type,
if (OB_SUCC(ret) && ob_is_string_type(type.get_type())) {
ObCollationLevel res_cs_level = CS_LEVEL_INVALID;
ObCollationType res_cs_type = CS_TYPE_INVALID;
if (share::is_oracle_mode()) {
if (lib::is_oracle_mode()) {
res_cs_level = CS_LEVEL_IMPLICIT;
if (type1.is_string_type()) {
res_cs_type = type1.get_collation_type();
@ -44,12 +50,9 @@ int ObExprNvlUtil::calc_result_type(ObExprResType& type,
res_cs_type = type_ctx.get_session()->get_dtc_params().nls_collation_;
}
} else {
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("aggregate collation failed", K(ret), K(type1), K(type2));
}
}
@ -64,20 +67,21 @@ int ObExprNvlUtil::calc_result_type(ObExprResType& type,
if (OB_SUCC(ret)) {
type.set_length(MAX(type1.get_length(), type2.get_length()));
// flag. if both type1 and type2 are NULL, type is null
if (type1.has_result_flag(OB_MYSQL_NOT_NULL_FLAG) || type2.has_result_flag(OB_MYSQL_NOT_NULL_FLAG)) {
type.set_result_flag(OB_MYSQL_NOT_NULL_FLAG);
if (type1.has_result_flag(NOT_NULL_FLAG) || type2.has_result_flag(NOT_NULL_FLAG)) {
type.set_result_flag(NOT_NULL_FLAG);
}
}
return ret;
}
ObExprNvl::ObExprNvl(ObIAllocator& alloc) : ObFuncExprOperator(alloc, T_FUN_SYS_NVL, N_NVL, 2, NOT_ROW_DIMENSION)
ObExprNvl::ObExprNvl(ObIAllocator &alloc)
: ObFuncExprOperator(alloc, T_FUN_SYS_NVL, N_NVL, 2, NOT_ROW_DIMENSION)
{}
ObExprNvl::~ObExprNvl()
{}
void set_calc_type(const ObExprResType& in_type, ObExprResType& out_type)
void set_calc_type(const ObExprResType &in_type, ObExprResType &out_type)
{
out_type.set_calc_meta(in_type.get_obj_meta());
out_type.set_calc_accuracy(in_type.get_accuracy());
@ -85,8 +89,10 @@ void set_calc_type(const ObExprResType& in_type, ObExprResType& out_type)
out_type.set_calc_collation_level(in_type.get_collation_level());
}
int ObExprNvl::calc_result_type2(
ObExprResType& type, ObExprResType& type1, ObExprResType& type2, ObExprTypeCtx& type_ctx) const
int ObExprNvl::calc_result_type2(ObExprResType &type,
ObExprResType &type1,
ObExprResType &type2,
ObExprTypeCtx &type_ctx) const
{
int ret = OB_SUCCESS;
if (OB_FAIL(ObExprNvlUtil::calc_result_type(type, type1, type2, type_ctx))) {
@ -105,16 +111,19 @@ int ObExprNvl::calc_result_type2(
} else {
type.set_scale(-1);
}
// For the mixed type of int and uint64, the type needs to be promoted to decimal
if (share::is_mysql_mode() && (ObUInt64Type == type1.get_type() || ObUInt64Type == type2.get_type()) &&
ObIntType == type.get_type()) {
type.set_length(MAX(type1.get_length(), type2.get_length()));
//对于 int 和uint64的混合类型,需要提升类型至decimal
if (lib::is_mysql_mode()
&& (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());
}
// enumset.
const bool type1_is_enumset = ob_is_enumset_tc(type1.get_type());
const bool type2_is_enumset = ob_is_enumset_tc(type2.get_type());
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 failed", K(ret));
@ -127,19 +136,19 @@ int ObExprNvl::calc_result_type2(
if (type1_is_enumset) {
type1.set_calc_type(calc_type);
type1.set_calc_collation_type(ObCharset::get_system_collation());
} else if (session->use_static_typing_engine()) {
} else {
set_calc_type(type, type1);
}
if (type2_is_enumset) {
type2.set_calc_type(calc_type);
} else if (session->use_static_typing_engine()) {
} else {
set_calc_type(type, type2);
}
} else if (session->use_static_typing_engine()) {
} else {
set_calc_type(type, type1);
set_calc_type(type, type2);
}
} else if (session->use_static_typing_engine()) {
} else {
set_calc_type(type, type1);
set_calc_type(type, type2);
}
@ -147,78 +156,54 @@ int ObExprNvl::calc_result_type2(
return ret;
}
int ObExprNvl::calc_result2(ObObj& result, const ObObj& obj1, const ObObj& obj2, ObExprCtx& expr_ctx) const
{
int ret = OB_SUCCESS;
const ObObj* p_res = NULL;
if (OB_ISNULL(expr_ctx.calc_buf_) || OB_ISNULL(expr_ctx.my_session_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("invalid argument. allocator or session is NULL", K(ret), K(expr_ctx.calc_buf_), K(expr_ctx.my_session_));
} else {
p_res = obj1.is_null() ? &obj2 : &obj1;
//We cannot expect the framework to help us convert types
//to ensure that they are consistent with the deduced results in old engine
//convert collations to avoid unexpected compares like gbk = utf8
bool need_cast = !p_res->is_null()
&& (p_res->get_type() != get_result_type().get_type()
|| p_res->get_collation_type() != get_result_type().get_collation_type());
// no necessary to check p_res is NULL or not
if (need_cast) {
EXPR_DEFINE_CAST_CTX(expr_ctx, CM_NONE);
cast_ctx.dest_collation_ = get_result_type().get_collation_type();
if (OB_FAIL(ObObjCaster::to_type(get_result_type().get_type(), cast_ctx, *p_res, result))) {
LOG_WARN("cast failed", K(ret), K(get_result_type().get_type()), K(*p_res));
}
} else {
result = *p_res;
}
}
return ret;
}
ObExprOracleNvl::ObExprOracleNvl(ObIAllocator& alloc)
: ObFuncExprOperator(alloc, T_FUN_SYS_NVL, N_NVL, 2, NOT_ROW_DIMENSION)
ObExprOracleNvl::ObExprOracleNvl(ObIAllocator &alloc)
: ObFuncExprOperator(alloc, T_FUN_SYS_NVL, N_NVL, 2, NOT_ROW_DIMENSION)
{}
ObExprOracleNvl::~ObExprOracleNvl()
{}
int ObExprOracleNvl::calc_result_type2(
ObExprResType& type, ObExprResType& type1, ObExprResType& type2, ObExprTypeCtx& type_ctx) const
int ObExprOracleNvl::calc_result_type2(ObExprResType &type,
ObExprResType &type1,
ObExprResType &type2,
ObExprTypeCtx &type_ctx) const
{
return calc_nvl_oralce_result_type(type, type1, type2, type_ctx);
}
int ObExprOracleNvl::calc_nvl_oralce_result_type(
ObExprResType& type, ObExprResType& type1, ObExprResType& type2, ObExprTypeCtx& type_ctx)
int ObExprOracleNvl::calc_nvl_oralce_result_type(ObExprResType &type,
ObExprResType &type1,
ObExprResType &type2,
ObExprTypeCtx &type_ctx)
{
/*
create table t1 (col_num1 decimal(10, 2), col_num2 decimal(10, 8),
col_str1 varchar(20 char), col_str2 varchar2(60 byte),
col_tz timestamp(3) with time zone,
col_ltz timestamp(6) with local time zone);
create view tmp as
select nvl(col_str1, col_num1) s1_n1,
nvl(col_str1, col_num2) s1_n2,
nvl(col_str2, col_num1) s2_n1,
nvl(col_str2, col_num2) s2_n2,
nvl(col_str1, col_str2) s1_s2,
nvl(col_tz, col_ltz) tz_ltz,
nvl(NULL, col_ltz) null_ltz
from t1;
desc tmp;
/*
create table t1 (col_num1 decimal(10, 2), col_num2 decimal(10, 8),
col_str1 varchar(20 char), col_str2 varchar2(60 byte),
col_tz timestamp(3) with time zone,
col_ltz timestamp(6) with local time zone);
create view tmp as
select nvl(col_str1, col_num1) s1_n1,
nvl(col_str1, col_num2) s1_n2,
nvl(col_str2, col_num1) s2_n1,
nvl(col_str2, col_num2) s2_n2,
nvl(col_str1, col_str2) s1_s2,
nvl(col_tz, col_ltz) tz_ltz,
nvl(NULL, col_ltz) null_ltz
from t1;
desc tmp;
SQL> desc tmp;
Name Null? Type
--------------- -------- ----------------------------
S1_N1 VARCHAR2(40 CHAR)
S1_N2 VARCHAR2(40 CHAR)
S2_N1 VARCHAR2(60)
S2_N2 VARCHAR2(60)
S1_S2 VARCHAR2(80)
TZ_LTZ TIMESTAMP(3) WITH TIME ZONE
NULL_LTZ TIMESTAMP(6) WITH LOCAL TIME ZONE
*/
SQL> desc tmp;
Name Null? Type
--------------- -------- ----------------------------
S1_N1 VARCHAR2(40 CHAR)
S1_N2 VARCHAR2(40 CHAR)
S2_N1 VARCHAR2(60)
S2_N2 VARCHAR2(60)
S1_S2 VARCHAR2(80)
TZ_LTZ TIMESTAMP(3) WITH TIME ZONE
NULL_LTZ TIMESTAMP(6) WITH LOCAL TIME ZONE
*/
int ret = OB_SUCCESS;
if (OB_FAIL(ObExprNvlUtil::calc_result_type(type, type1, type2, type_ctx))) {
LOG_WARN("calc_result_type2 failed", K(ret), K(type1), K(type2));
@ -227,7 +212,9 @@ int ObExprOracleNvl::calc_nvl_oralce_result_type(
// unknow precision and scale
type.set_precision(PRECISION_UNKNOWN_YET);
type.set_scale(ORA_NUMBER_SCALE_UNKNOWN_YET);
} else if (type.is_otimestamp_type() || type.is_interval_ym() || type.is_interval_ds()) {
} else if (type.is_otimestamp_type()
|| type.is_interval_ym()
|| type.is_interval_ds()) {
/*
* for otimestamp:
* if type is otimestamp, it must be one of these situations:
@ -240,46 +227,36 @@ int ObExprOracleNvl::calc_nvl_oralce_result_type(
*
* the same case for interval type class
*/
ObExprResType& res_type = !type1.is_null() ? type1 : type2;
ObExprResType &res_type = !type1.is_null() ? type1 : type2;
type.set_type(res_type.get_type());
type.set_accuracy(res_type.get_accuracy());
type2.set_calc_accuracy(res_type.get_accuracy());
} else if (type.is_varchar()) {
ObLengthSemantics length_semantics = type1.get_length_semantics();
if (type2.is_number()) {
/*
* when type is varchar and type2 is number, type length is determined by type1 length
* and the DEFAULT length of ObNumberType (which is 40 in oracle), not type2 length.
* see the sql results above:
* the length value of col_num1 and col_num2 are both 11, but s1_n1 length is 40,
* which is max(col_str1 length, ObNumberType DEFAULT length).
* s1_n2 / s2_n1 / s2_n2 are similar.
*/
ObLength default_number_length = 40;
type.set_length(MAX(type1.get_length(), default_number_length));
} else if (type2.is_string_type()) {
/*
* when type1 and type2 have different length semantics, type semantics should be byte,
* and the length is of type1 length and type2 length in byte.
* we need not adjust the length in other condition.
*/
if (type1.is_null()) {
length_semantics = type2.get_length_semantics();
} else if (type1.get_length_semantics() != type2.get_length_semantics()) {
ObLength length1_byte = 0;
ObLength length2_byte = 0;
if (OB_FAIL(type1.get_length_for_meta_in_bytes(length1_byte)) ||
OB_FAIL(type2.get_length_for_meta_in_bytes(length2_byte))) {
LOG_WARN("get length in bytes failed", K(ret), K(type1), K(type2));
} else {
length_semantics = LS_BYTE;
type.set_length(MAX(length1_byte, length2_byte));
}
}
} else if (type.is_character_type()) {
ObSEArray<ObExprResType*, 2, ObNullAllocator> params;
// the result type and collation is only determined by type1 unless type1 is const NULL.
if (!type1.is_null()) {
OZ (params.push_back(&type1));
OZ (aggregate_string_type_and_charset_oracle(*type_ctx.get_session(), params, type,
PREFER_VAR_LEN_CHAR));
OZ (params.push_back(&type2));
} else {
OZ (params.push_back(&type2));
OZ (aggregate_string_type_and_charset_oracle(*type_ctx.get_session(), params, type,
PREFER_VAR_LEN_CHAR));
OZ (params.push_back(&type1));
}
type.set_length_semantics(length_semantics);
// the result length semantics is determined by all params
OZ (aggregate_length_semantics_oracle(*type_ctx.get_session(), params, type));
OZ (deduce_string_param_calc_type_and_charset(*type_ctx.get_session(), type, params));
OX (type.set_length(MAX(type1.get_calc_length(), type2.get_calc_length())));
} else if (lib::is_oracle_mode() && type.is_ext()) {
CK (type1.get_udt_id() == type2.get_udt_id());
OX (type.set_udt_id(type1.get_udt_id()));
} else if (type.is_temporal_type()) {
type.set_scale(0);
}
/*
* https://aone.alibaba-inc.com/issue/18763797
* select nvl(0, 'hello') from dual;
* the sql above will return error: ORA-01722: invalid number.
* we must execute necessary cast operation before we determine which obj should be returned,
@ -291,57 +268,55 @@ int ObExprOracleNvl::calc_nvl_oralce_result_type(
return ret;
}
int ObExprOracleNvl::calc_result2(ObObj& result, const ObObj& obj1, const ObObj& obj2, ObExprCtx& expr_ctx) const
{
UNUSED(expr_ctx);
result = obj1.is_null() ? obj2 : obj1;
return OB_SUCCESS;
}
ObExprNaNvl::ObExprNaNvl(ObIAllocator& alloc)
: ObFuncExprOperator(alloc, T_FUN_SYS_NANVL, T_NANVL, 2, NOT_ROW_DIMENSION)
ObExprNaNvl::ObExprNaNvl(ObIAllocator &alloc)
: ObFuncExprOperator(alloc, T_FUN_SYS_NANVL, T_NANVL, 2, NOT_ROW_DIMENSION)
{}
ObExprNaNvl::~ObExprNaNvl()
{}
int ObExprNaNvl::calc_result_type2(
ObExprResType& type, ObExprResType& type1, ObExprResType& type2, ObExprTypeCtx& type_ctx) const
int ObExprNaNvl::calc_result_type2(ObExprResType &type,
ObExprResType &type1,
ObExprResType &type2,
ObExprTypeCtx &type_ctx) const
{
int ret = OB_SUCCESS;
UNUSED(type_ctx);
ObObjType result_type = ObMaxType;
if (OB_FAIL(ObExprResultTypeUtil::get_nanvl_result_type(result_type, type1.get_type(), type2.get_type()))) {
LOG_WARN("fail to get_round_result_type", K(ret), K(type1), K(type2));
} else {
type.set_type(result_type);
int ret = OB_SUCCESS;
if (ob_is_lob_tc(type1.get_type()) || ob_is_oracle_datetime_tc(type1.get_type())
|| ob_is_rowid_tc(type1.get_type())) {
ret = OB_ERR_INVALID_TYPE_FOR_OP;
LOG_USER_ERROR(OB_ERR_INVALID_TYPE_FOR_OP, "NUMBER",
ob_obj_type_str(type1.get_type()));
LOG_WARN("invalid type of parameter", K(ret), K(type1));
} else if (ob_is_lob_tc(type2.get_type()) || ob_is_oracle_datetime_tc(type2.get_type())
|| ob_is_rowid_tc(type2.get_type())) {
ret = OB_ERR_INVALID_TYPE_FOR_OP;
LOG_USER_ERROR(OB_ERR_INVALID_TYPE_FOR_OP, "NUMBER",
ob_obj_type_str(type2.get_type()));
LOG_WARN("invalid type of parameter", K(ret), K(type2));
}
if (OB_SUCC(ret)) {
type.set_type(ObNumberType);
type.set_scale(ORA_NUMBER_SCALE_UNKNOWN_YET);
type.set_precision(PRECISION_UNKNOWN_YET);
type1.set_calc_type(result_type);
type1.set_calc_type(result_type);
if (ob_is_double_type(type1.get_type()) || ob_is_double_type(type2.get_type())) {
type.set_type(ObDoubleType);
} else if (ob_is_float_type(type1.get_type()) || ob_is_float_type(type2.get_type())) {
type.set_type(ObFloatType);
}
type1.set_calc_type(type.get_type());
type2.set_calc_type(type.get_type());
}
return ret;
}
int ObExprNaNvl::calc_result2(ObObj& result, const ObObj& obj1, const ObObj& obj2, ObExprCtx& expr_ctx) const
{
// TODO::
int ret = OB_SUCCESS;
UNUSED(expr_ctx);
if (obj1.is_null() || obj2.is_null()) {
result.set_null();
} else {
result = obj1;
}
return OB_SUCCESS;
}
int ObExprNvlUtil::calc_nvl_expr(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& res_datum)
int ObExprNvlUtil::calc_nvl_expr(const ObExpr &expr, ObEvalCtx &ctx,
ObDatum &res_datum)
{
int ret = OB_SUCCESS;
// nvl(arg0, arg1)
ObDatum* arg0 = NULL;
ObDatum* arg1 = NULL;
ObDatum *arg0 = NULL;
ObDatum *arg1 = NULL;
if (OB_FAIL(expr.eval_param_value(ctx, arg0, arg1))) {
LOG_WARN("eval args failed", K(ret));
@ -353,13 +328,46 @@ int ObExprNvlUtil::calc_nvl_expr(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& re
return ret;
}
int ObExprNvlUtil::calc_nvl_expr2(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& res_datum)
int ObExprNvlUtil::calc_nvl_expr_batch(const ObExpr &expr,
ObEvalCtx &ctx,
const ObBitVector &skip,
const int64_t batch_size) {
LOG_DEBUG("eval nvl batch mode", K(batch_size));
int ret = OB_SUCCESS;
ObDatum* results = expr.locate_batch_datums(ctx);
ObBitVector &eval_flags = expr.get_evaluated_flags(ctx);
ObDatumVector args0;
ObDatumVector args1;
if (OB_FAIL(expr.eval_batch_param_value(ctx, skip, batch_size, args0,
args1))) {
LOG_WARN("eval batch args failed", K(ret));
} else {
for (int64_t i = 0; OB_SUCC(ret) && i < batch_size; ++i) {
if (skip.at(i) || eval_flags.at(i)) {
continue;
}
eval_flags.set(i);
ObDatum *arg0 = args0.at(i);
ObDatum *arg1 = args1.at(i);
if (!(arg0->is_null())) {
results[i].set_datum(*arg0);
} else {
results[i].set_datum(*arg1);
}
}
}
return ret;
}
int ObExprNvlUtil::calc_nvl_expr2(const ObExpr &expr, ObEvalCtx &ctx,
ObDatum &res_datum)
{
int ret = OB_SUCCESS;
// nvl(arg0, arg1, arg2)
ObDatum* arg0 = NULL;
ObDatum* arg1 = NULL;
ObDatum* arg2 = NULL;
ObDatum *arg0 = NULL;
ObDatum *arg1 = NULL;
ObDatum *arg2 = NULL;
if (OB_FAIL(expr.eval_param_value(ctx, arg0, arg1, arg2))) {
LOG_WARN("eval args failed", K(ret));
@ -371,31 +379,144 @@ int ObExprNvlUtil::calc_nvl_expr2(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& r
return ret;
}
int ObExprNvl::cg_expr(ObExprCGCtx& expr_cg_ctx, const ObRawExpr& raw_expr, ObExpr& rt_expr) const
int ObExprNvl::cg_expr(ObExprCGCtx &expr_cg_ctx, const ObRawExpr &raw_expr,
ObExpr &rt_expr) const
{
int ret = OB_SUCCESS;
UNUSED(expr_cg_ctx);
UNUSED(raw_expr);
rt_expr.eval_func_ = ObExprNvlUtil::calc_nvl_expr;
rt_expr.eval_batch_func_ = ObExprNvlUtil::calc_nvl_expr_batch;
return ret;
}
int ObExprOracleNvl::cg_expr(ObExprCGCtx& expr_cg_ctx, const ObRawExpr& raw_expr, ObExpr& rt_expr) const
int ObExprOracleNvl::cg_expr(ObExprCGCtx &expr_cg_ctx, const ObRawExpr &raw_expr,
ObExpr &rt_expr) const
{
int ret = OB_SUCCESS;
UNUSED(expr_cg_ctx);
UNUSED(raw_expr);
rt_expr.eval_func_ = ObExprNvlUtil::calc_nvl_expr;
rt_expr.eval_batch_func_ = ObExprNvlUtil::calc_nvl_expr_batch;
return ret;
}
int ObExprNaNvl::cg_expr(ObExprCGCtx& expr_cg_ctx, const ObRawExpr& raw_expr, ObExpr& rt_expr) const
int ObExprNaNvl::cg_expr(ObExprCGCtx &expr_cg_ctx, const ObRawExpr &raw_expr,
ObExpr &rt_expr) const
{
int ret = OB_SUCCESS;
UNUSED(expr_cg_ctx);
UNUSED(raw_expr);
rt_expr.eval_func_ = ObExprNvlUtil::calc_nvl_expr;
UNUSED(expr_cg_ctx);
if (rt_expr.arg_cnt_ != 2 || OB_ISNULL(rt_expr.args_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("count of children is not 2 or children is null", K(ret), K(rt_expr.arg_cnt_),
K(rt_expr.args_));
} else if (OB_ISNULL(rt_expr.args_[0]) || OB_ISNULL(rt_expr.args_[1])) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("child is null", K(ret), K(rt_expr.args_[0]), K(rt_expr.args_[1]));
} else {
rt_expr.eval_func_ = eval_nanvl;
rt_expr.eval_batch_func_ = eval_nanvl_batch;
}
return ret;
}
} // namespace sql
} // namespace oceanbase
// nanvl computational abstraction.
int ObExprNaNvl::eval_nanvl_util(const ObExpr &expr, ObDatum &expr_datum, ObDatum *param1, ObDatum *param2, bool &ret_bool)
{
int ret = OB_SUCCESS;
if (param1->is_null() || param2->is_null()) {
expr_datum.set_null();
} else if (expr.args_[0]->datum_meta_.type_ != ObFloatType
&& expr.args_[0]->datum_meta_.type_ != ObDoubleType) {
expr_datum.set_datum(*param1);
} else {
if (OB_FAIL(ObExprIs::is_infinite_nan(expr.args_[0]->datum_meta_.type_, param1,
ret_bool, ObExprIs::Ieee754::NAN_VALUE))) {
LOG_WARN("calc_is_infinite unexpect error", K(ret));
} else {
if (ret_bool) {
expr_datum.set_datum(*param2);
} else {
expr_datum.set_datum(*param1);
}
}
}
return ret;
}
int ObExprNaNvl::eval_nanvl(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &expr_datum)
{
int ret = OB_SUCCESS;
ObDatum *param1 = NULL;
ObDatum *param2 = NULL;
bool ret_bool = false;
if (OB_FAIL(expr.args_[0]->eval(ctx, param1))) {
LOG_WARN("eval first param failed", K(ret));
} else if (param1->is_null()) {
expr_datum.set_null();
} else if (OB_FAIL(expr.args_[1]->eval(ctx, param2))) {
LOG_WARN("eval second param failed", K(ret));
} else if (param1->is_null() || param2->is_null()) {
expr_datum.set_null();
} else {
if (OB_FAIL(eval_nanvl_util(expr, expr_datum, param1, param2, ret_bool))){
LOG_WARN("eval_nanvl unexpect error", K(ret));
} else {
// do nothing
}
}
return ret;
}
int ObExprNaNvl::eval_nanvl_batch(const ObExpr &expr,
ObEvalCtx &ctx,
const ObBitVector &skip,
const int64_t batch_size) {
LOG_DEBUG("eval nanvl batch mode", K(batch_size));
int ret = OB_SUCCESS;
ObDatum* results = expr.locate_batch_datums(ctx);
ObBitVector &eval_flags = expr.get_evaluated_flags(ctx);
if (OB_FAIL(expr.args_[0]->eval_batch(ctx, skip, batch_size))) {
LOG_WARN("eval args_[0] failed", K(ret));
} else {
ObBitVector &my_skip = expr.get_pvt_skip(ctx);
my_skip.deep_copy(skip, batch_size);
for (int64_t i = 0; OB_SUCC(ret) && i < batch_size; ++i) {
if (my_skip.at(i) || eval_flags.at(i)) {
continue;
}
ObDatum *param1 = NULL;
param1 = &expr.args_[0]->locate_expr_datum(ctx, i);
if (param1->is_null()) {
results[i].set_null();
eval_flags.set(i);
my_skip.set(i);
}
}
if (OB_FAIL(expr.args_[1]->eval_batch(ctx, my_skip, batch_size))) {
LOG_WARN("eval args_[1] failed", K(ret));
} else {
for (int64_t i = 0; OB_SUCC(ret) && i < batch_size; ++i) {
if (my_skip.at(i) || eval_flags.at(i)) {
continue;
}
ObDatum *param1 = NULL;
ObDatum *param2 = NULL;
bool ret_bool = false;
param1 = &expr.args_[0]->locate_expr_datum(ctx, i);
param2 = &expr.args_[1]->locate_expr_datum(ctx, i);
eval_flags.set(i);
if (OB_FAIL(eval_nanvl_util(expr, results[i], param1, param2, ret_bool))){
LOG_WARN("eval_nanvl unexpect error", K(ret));
} else {
// do nothing
}
}
}
}
return ret;
}
}//namespace sql
}//namespace oceanbase