patch 4.0
This commit is contained in:
@ -17,47 +17,65 @@
|
||||
#include "sql/engine/expr/ob_expr_equal.h"
|
||||
#include "sql/engine/expr/ob_expr_oracle_nullif.h"
|
||||
#include "sql/session/ob_sql_session_info.h"
|
||||
#include "sql/engine/ob_exec_context.h"
|
||||
|
||||
namespace oceanbase {
|
||||
using namespace oceanbase::common;
|
||||
namespace sql {
|
||||
|
||||
ObExprOracleNullif::ObExprOracleNullif(ObIAllocator& alloc) : ObExprNullif(alloc)
|
||||
{}
|
||||
ObExprOracleNullif::ObExprOracleNullif(ObIAllocator &alloc)
|
||||
: ObExprNullif(alloc) {}
|
||||
|
||||
int ObExprOracleNullif::calc_result_typeN(
|
||||
ObExprResType& type, ObExprResType* types, int64_t param_num, ObExprTypeCtx& type_ctx) const
|
||||
int ObExprOracleNullif::calc_result_type2(ObExprResType &type,
|
||||
ObExprResType &type1,
|
||||
ObExprResType &type2,
|
||||
ObExprTypeCtx &type_ctx) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
const ObSQLSessionInfo* session = type_ctx.get_session();
|
||||
CK(OB_NOT_NULL(session));
|
||||
CK(2 == param_num);
|
||||
if (OB_SUCC(ret)) {
|
||||
ObExprResType& type1 = types[0];
|
||||
ObExprResType& type2 = types[1];
|
||||
ObSQLSessionInfo *session = const_cast<ObSQLSessionInfo *>(type_ctx.get_session());
|
||||
ObExecContext *exec_ctx = nullptr;
|
||||
if (OB_ISNULL(session)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("session is NULL", K(ret));
|
||||
} else {
|
||||
//Oracle 不支持lob类型的 nullif比较
|
||||
exec_ctx = session->get_cur_exec_ctx();
|
||||
if (type1.is_null() || type1.is_lob()) {
|
||||
ret = OB_ERR_INVALID_TYPE_FOR_OP;
|
||||
LOG_USER_ERROR(OB_ERR_INVALID_TYPE_FOR_OP, "-", ob_obj_type_str(type2.get_type()));
|
||||
LOG_WARN("invalid type of parameter", K(ret), K(type1));
|
||||
if (OB_NOT_NULL(exec_ctx) && exec_ctx->is_ps_prepare_stage()) {
|
||||
type.set_null();
|
||||
} else {
|
||||
if (is_called_in_sql()) {
|
||||
ret = OB_ERR_INVALID_TYPE_FOR_OP;
|
||||
LOG_USER_ERROR(OB_ERR_INVALID_TYPE_FOR_OP, "-",
|
||||
ob_obj_type_str(type2.get_type()));
|
||||
LOG_WARN("invalid type of parameter", K(ret), K(type1));
|
||||
} else {
|
||||
ret = OB_ERR_FIRST_PARAM_MUST_NOT_NULL;
|
||||
LOG_USER_ERROR(OB_ERR_FIRST_PARAM_MUST_NOT_NULL);
|
||||
}
|
||||
}
|
||||
} else if (is_same_type(type1, type2)) {
|
||||
if (is_numberic_type(type1.get_oracle_type(), type2.get_oracle_type())) {
|
||||
calc_numberic_type(type, type1, type2);
|
||||
} else if (ob_is_raw(type1.get_type())) {
|
||||
type.set_raw();
|
||||
type.set_length(type1.get_length());
|
||||
} else {
|
||||
ObExprResType cmp_type;
|
||||
if (OB_FAIL(calc_cmp_type2(cmp_type, type1, type2, type_ctx.get_coll_type()))) {
|
||||
if (OB_FAIL(calc_cmp_type2(cmp_type, type1, type2,
|
||||
type_ctx.get_coll_type()))) {
|
||||
LOG_WARN("failed to calc cmp type", K(ret), K(type1), K(type2));
|
||||
} else {
|
||||
type.set_type(type1.get_type());
|
||||
type.set_accuracy(type1.get_accuracy());
|
||||
if (ob_is_string_type(type.get_type())) {
|
||||
const ObSQLSessionInfo* session = type_ctx.get_session();
|
||||
const ObSQLSessionInfo *session = type_ctx.get_session();
|
||||
ObSEArray<ObExprResType*, 2, ObNullAllocator> params;
|
||||
CK(OB_NOT_NULL(session));
|
||||
OZ(params.push_back(&type1));
|
||||
OZ(params.push_back(&type2));
|
||||
OZ(aggregate_string_type_and_charset_oracle(*session, params, type));
|
||||
OX(type.set_length_semantics(type1.get_length_semantics()))
|
||||
OZ(deduce_string_param_calc_type_and_charset(*session, type, params));
|
||||
if (OB_SUCC(ret)) {
|
||||
// deduce length
|
||||
@ -89,33 +107,42 @@ int ObExprOracleNullif::calc_result_typeN(
|
||||
}
|
||||
} else {
|
||||
ret = OB_ERR_INVALID_TYPE_FOR_OP;
|
||||
LOG_USER_ERROR(
|
||||
OB_ERR_INVALID_TYPE_FOR_OP, ob_obj_type_str(type1.get_type()), ob_obj_type_str(type2.get_type()));
|
||||
LOG_USER_ERROR(OB_ERR_INVALID_TYPE_FOR_OP,
|
||||
ob_obj_type_str(type1.get_type()),
|
||||
ob_obj_type_str(type2.get_type()));
|
||||
LOG_WARN("diff type of parameters", K(ret), K(type1), K(type2));
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret) && session->use_static_typing_engine()) {
|
||||
if (OB_SUCC(ret)) {
|
||||
type1.set_calc_meta(type.get_obj_meta());
|
||||
type2.set_calc_meta(type.get_obj_meta());
|
||||
if (type.is_string_type()) {
|
||||
type1.set_calc_length_semantics(type.get_length_semantics());
|
||||
type2.set_calc_length_semantics(type.get_length_semantics());
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool ObExprOracleNullif::is_same_type(const ObExprResType& type1, const ObExprResType& type2) const
|
||||
bool ObExprOracleNullif::is_same_type(const ObExprResType &type1,
|
||||
const ObExprResType &type2) const
|
||||
{
|
||||
bool ret = false;
|
||||
ObObjOType oracleType1 = type1.get_oracle_type();
|
||||
ObObjOType oracleType2 = type2.get_oracle_type();
|
||||
if (oracleType1 == oracleType2 || is_numberic_type(oracleType1, oracleType2) ||
|
||||
is_string_type(oracleType1, oracleType2) || is_time_type(oracleType1, oracleType2)) {
|
||||
if (oracleType1 == oracleType2 ||
|
||||
is_numberic_type(oracleType1, oracleType2) ||
|
||||
is_string_type(oracleType1, oracleType2) ||
|
||||
is_time_type(oracleType1, oracleType2)) {
|
||||
ret = true;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool ObExprOracleNullif::is_numberic_type(const ObObjOType& otype1, const ObObjOType& otype2) const
|
||||
bool ObExprOracleNullif::is_numberic_type(const ObObjOType &otype1,
|
||||
const ObObjOType &otype2) const
|
||||
{
|
||||
bool ret = false;
|
||||
if ((otype1 >= ObOSmallIntType && otype1 <= ObONumberType) &&
|
||||
@ -125,12 +152,16 @@ bool ObExprOracleNullif::is_numberic_type(const ObObjOType& otype1, const ObObjO
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ObExprOracleNullif::calc_numberic_type(ObExprResType& type, ObExprResType& type1, ObExprResType& type2) const
|
||||
void ObExprOracleNullif::calc_numberic_type(ObExprResType &type,
|
||||
ObExprResType &type1,
|
||||
ObExprResType &type2) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObObjOType oracleType1 = type1.get_oracle_type();
|
||||
ObObjOType oracleType2 = type2.get_oracle_type();
|
||||
// 初始result type为 oracle number类型
|
||||
ObObjOType result = ObONumberType;
|
||||
// 如果oracleType1的类型是binary float/double,result的类型就需要变为binary float/double
|
||||
if (oracleType1 == ObOBinFloatType || oracleType1 == ObOBinDoubleType) {
|
||||
result = oracleType1;
|
||||
}
|
||||
@ -139,6 +170,7 @@ void ObExprOracleNullif::calc_numberic_type(ObExprResType& type, ObExprResType&
|
||||
if (result == ObONumberType) {
|
||||
result = oracleType2;
|
||||
} else {
|
||||
// result为binary float/double;oracleType2为binary float/double
|
||||
result = (result > oracleType2) ? result : oracleType2;
|
||||
}
|
||||
}
|
||||
@ -147,11 +179,15 @@ void ObExprOracleNullif::calc_numberic_type(ObExprResType& type, ObExprResType&
|
||||
type.set_precision(PRECISION_UNKNOWN_YET);
|
||||
type.set_scale(ORA_NUMBER_SCALE_UNKNOWN_YET);
|
||||
} else if (result == ObOBinFloatType) {
|
||||
// binary float类型
|
||||
type.set_float();
|
||||
// float下p,s不生效,
|
||||
type.set_precision(PRECISION_UNKNOWN_YET);
|
||||
type.set_scale(ORA_NUMBER_SCALE_UNKNOWN_YET);
|
||||
} else {
|
||||
} else{
|
||||
// binary double 类型
|
||||
type.set_double();
|
||||
// float下p,s不生效,
|
||||
type.set_precision(PRECISION_UNKNOWN_YET);
|
||||
type.set_scale(ORA_NUMBER_SCALE_UNKNOWN_YET);
|
||||
}
|
||||
@ -161,44 +197,53 @@ void ObExprOracleNullif::calc_numberic_type(ObExprResType& type, ObExprResType&
|
||||
}
|
||||
}
|
||||
|
||||
bool ObExprOracleNullif::is_string_type(const ObObjOType& otype1, const ObObjOType& otype2) const
|
||||
bool ObExprOracleNullif::is_string_type(const ObObjOType &otype1,
|
||||
const ObObjOType &otype2) const
|
||||
{
|
||||
bool ret = false;
|
||||
if (((otype1 >= ObOCharType && otype1 <= ObOVarcharType) && (otype2 >= ObOCharType && otype2 <= ObOVarcharType)) ||
|
||||
//Oracle 模式 NVarchar2和NChar可以进行比较
|
||||
if (((otype1 >= ObOCharType && otype1 <= ObOVarcharType) &&
|
||||
(otype2 >= ObOCharType && otype2 <= ObOVarcharType)) ||
|
||||
((otype1 >= ObONVarchar2Type && otype1 <= ObONCharType) &&
|
||||
(otype2 >= ObONVarchar2Type && otype2 <= ObONCharType))) {
|
||||
(otype2 >= ObONVarchar2Type && otype2 <= ObONCharType))) {
|
||||
ret = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool ObExprOracleNullif::is_time_type(const ObObjOType& otype1, const ObObjOType& otype2) const
|
||||
bool ObExprOracleNullif::is_time_type(const ObObjOType &otype1,
|
||||
const ObObjOType &otype2) const
|
||||
{
|
||||
bool ret = false;
|
||||
if ((otype1 >= ObODateType && otype1 <= ObOTimestampType) && (otype2 >= ObODateType && otype2 <= ObOTimestampType)) {
|
||||
if ((otype1 >= ObODateType && otype1 <= ObOTimestampType) &&
|
||||
(otype2 >= ObODateType && otype2 <= ObOTimestampType)) {
|
||||
ret = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprOracleNullif::cg_expr(ObExprCGCtx& expr_cg_ctx, const ObRawExpr& raw_expr, ObExpr& rt_expr) const
|
||||
int ObExprOracleNullif::cg_expr(ObExprCGCtx &expr_cg_ctx, const ObRawExpr &raw_expr,
|
||||
ObExpr &rt_expr) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
UNUSED(raw_expr);
|
||||
CK(2 == rt_expr.arg_cnt_);
|
||||
|
||||
OV(OB_NOT_NULL(
|
||||
rt_expr.inner_functions_ = reinterpret_cast<void**>(expr_cg_ctx.allocator_->alloc(sizeof(DatumCmpFunc) * 1))),
|
||||
OB_ALLOCATE_MEMORY_FAILED);
|
||||
OV(OB_NOT_NULL(rt_expr.inner_functions_ = reinterpret_cast<void**>(
|
||||
expr_cg_ctx.allocator_->alloc(sizeof(DatumCmpFunc) * 1))),
|
||||
OB_ALLOCATE_MEMORY_FAILED);
|
||||
|
||||
if (OB_SUCC(ret)) {
|
||||
DatumCmpFunc cmp_func = NULL;
|
||||
const ObDatumMeta& left_meta = rt_expr.args_[0]->datum_meta_;
|
||||
const ObDatumMeta& right_meta = rt_expr.args_[1]->datum_meta_;
|
||||
const ObDatumMeta &left_meta = rt_expr.args_[0]->datum_meta_;
|
||||
const ObDatumMeta &right_meta = rt_expr.args_[1]->datum_meta_;
|
||||
const ObCollationType cmp_cs_type = left_meta.cs_type_;
|
||||
CK(left_meta.cs_type_ == right_meta.cs_type_);
|
||||
CK(OB_NOT_NULL(cmp_func = ObExprCmpFuncsHelper::get_datum_expr_cmp_func(
|
||||
left_meta.type_, right_meta.type_, lib::is_oracle_mode(), cmp_cs_type)));
|
||||
left_meta.type_,
|
||||
right_meta.type_,
|
||||
lib::is_oracle_mode(),
|
||||
cmp_cs_type)));
|
||||
OX(rt_expr.inner_func_cnt_ = 1);
|
||||
OX(rt_expr.inner_functions_[0] = reinterpret_cast<void*>(cmp_func));
|
||||
OX(rt_expr.eval_func_ = first_param_can_be_null_ ? eval_nullif : eval_nullif_not_null);
|
||||
@ -206,11 +251,11 @@ int ObExprOracleNullif::cg_expr(ObExprCGCtx& expr_cg_ctx, const ObRawExpr& raw_e
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprOracleNullif::eval_nullif(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& res)
|
||||
int ObExprOracleNullif::eval_nullif(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &res)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObDatum* l = NULL;
|
||||
ObDatum* r = NULL;
|
||||
ObDatum *l = NULL;
|
||||
ObDatum *r = NULL;
|
||||
if (OB_FAIL(expr.eval_param_value(ctx, l, r))) {
|
||||
LOG_WARN("eval param failed", K(ret));
|
||||
} else if (l->is_null()) {
|
||||
@ -229,17 +274,18 @@ int ObExprOracleNullif::eval_nullif(const ObExpr& expr, ObEvalCtx& ctx, ObDatum&
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprOracleNullif::eval_nullif_not_null(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& res)
|
||||
int ObExprOracleNullif::eval_nullif_not_null(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &res)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObDatum* l = NULL;
|
||||
ObDatum* r = NULL;
|
||||
ObDatum *l = NULL;
|
||||
ObDatum *r = NULL;
|
||||
if (OB_FAIL(expr.eval_param_value(ctx, l, r))) {
|
||||
LOG_WARN("eval param failed", K(ret));
|
||||
} else if (l->is_null()) {
|
||||
ObObjType type2 = expr.args_[1]->obj_meta_.get_type();
|
||||
ret = OB_ERR_INVALID_TYPE_FOR_OP;
|
||||
LOG_USER_ERROR(OB_ERR_INVALID_TYPE_FOR_OP, "-", ob_obj_type_str(type2));
|
||||
LOG_USER_ERROR(OB_ERR_INVALID_TYPE_FOR_OP, "-",
|
||||
ob_obj_type_str(type2));
|
||||
} else if (r->is_null()) {
|
||||
// left is not null, right is null, not equal
|
||||
res.set_datum(*l);
|
||||
|
||||
Reference in New Issue
Block a user