patch 4.0
This commit is contained in:
@ -20,14 +20,22 @@
|
||||
using namespace oceanbase::sql;
|
||||
using namespace oceanbase::common;
|
||||
|
||||
namespace oceanbase {
|
||||
namespace sql {}
|
||||
} // namespace oceanbase
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace sql
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
ObExprNot::ObExprNot(ObIAllocator& alloc) : ObLogicalExprOperator(alloc, T_OP_NOT, N_NOT, 1, NOT_ROW_DIMENSION)
|
||||
{}
|
||||
|
||||
int ObExprNot::calc_result_type1(ObExprResType& type, ObExprResType& type1, ObExprTypeCtx& type_ctx) const
|
||||
ObExprNot::ObExprNot(ObIAllocator &alloc)
|
||||
: ObLogicalExprOperator(alloc, T_OP_NOT, N_NOT, 1, NOT_ROW_DIMENSION)
|
||||
{
|
||||
}
|
||||
|
||||
int ObExprNot::calc_result_type1(ObExprResType &type,
|
||||
ObExprResType &type1,
|
||||
ObExprTypeCtx &type_ctx) const
|
||||
{
|
||||
UNUSED(type_ctx);
|
||||
int ret = OB_SUCCESS;
|
||||
@ -39,7 +47,7 @@ int ObExprNot::calc_result_type1(ObExprResType& type, ObExprResType& type1, ObEx
|
||||
ObExprOperator::calc_result_flag1(type, type1);
|
||||
type.set_scale(DEFAULT_SCALE_FOR_INTEGER);
|
||||
type.set_precision(DEFAULT_PRECISION_FOR_BOOL);
|
||||
// keep enumset as enumset
|
||||
//keep enumset as enumset
|
||||
}
|
||||
} else {
|
||||
ret = OB_ERR_INVALID_TYPE_FOR_OP;
|
||||
@ -47,46 +55,38 @@ int ObExprNot::calc_result_type1(ObExprResType& type, ObExprResType& type1, ObEx
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprNot::calc_result1(ObObj& result, const ObObj& obj, ObExprCtx& expr_ctx) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (obj.is_null()) {
|
||||
result.set_null();
|
||||
} else {
|
||||
bool bool_v1 = false;
|
||||
|
||||
EXPR_SET_CAST_CTX_MODE(expr_ctx);
|
||||
if (OB_FAIL(ObLogicalExprOperator::is_true(obj, expr_ctx.cast_mode_ | CM_NO_RANGE_CHECK, bool_v1))) {
|
||||
LOG_WARN("fail to evaluate obj", K(obj), K(ret));
|
||||
} else {
|
||||
result.set_int(static_cast<int64_t>(!bool_v1));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprNot::cg_expr(ObExprCGCtx& expr_cg_ctx, const ObRawExpr& raw_expr, ObExpr& rt_expr) const
|
||||
int ObExprNot::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);
|
||||
if (OB_UNLIKELY(rt_expr.type_ != T_OP_NOT) || OB_UNLIKELY(rt_expr.arg_cnt_ != 1)) {
|
||||
if (OB_UNLIKELY(rt_expr.type_ != T_OP_NOT)
|
||||
|| OB_UNLIKELY(rt_expr.arg_cnt_ != 1)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret));
|
||||
} else {
|
||||
rt_expr.eval_func_ = &eval_not;
|
||||
rt_expr.eval_batch_func_ = &eval_not_batch;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprNot::eval_not(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& expr_datum)
|
||||
int ObExprNot::eval_not(const ObExpr &expr,
|
||||
ObEvalCtx &ctx,
|
||||
ObDatum &expr_datum)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_ISNULL(expr.args_) || OB_UNLIKELY(expr.arg_cnt_ != 1) || OB_ISNULL(expr.args_[0])) {
|
||||
if (OB_ISNULL(expr.args_)
|
||||
|| OB_UNLIKELY(expr.arg_cnt_ != 1)
|
||||
|| OB_ISNULL(expr.args_[0])) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret));
|
||||
} else {
|
||||
ObDatum* param = NULL;
|
||||
// not 表示的参数被加了一个bool表达式,所以逻辑走到这里
|
||||
// 参数的值一定是一个int(0或者1)
|
||||
ObDatum *param = NULL;
|
||||
if (OB_FAIL(expr.args_[0]->eval(ctx, param))) {
|
||||
LOG_WARN("failed to eval", K(ret));
|
||||
} else if (param->is_null()) {
|
||||
@ -98,3 +98,37 @@ int ObExprNot::eval_not(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& expr_datum)
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprNot::eval_not_batch(const ObExpr &expr,
|
||||
ObEvalCtx &ctx,
|
||||
const ObBitVector &skip,
|
||||
const int64_t batch_size)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_ISNULL(expr.args_)
|
||||
|| OB_UNLIKELY(expr.arg_cnt_ != 1)
|
||||
|| OB_ISNULL(expr.args_[0])) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret));
|
||||
} else {
|
||||
ObBitVector &eval_flags = expr.get_evaluated_flags(ctx);
|
||||
if (OB_FAIL(expr.args_[0]->eval_batch(ctx, skip, batch_size))) {
|
||||
LOG_WARN("failed to eval", K(ret));
|
||||
} else {
|
||||
ObDatum *results = expr.locate_batch_datums(ctx);
|
||||
for (int64_t i = 0; i < batch_size; ++i) {
|
||||
if (skip.at(i) || eval_flags.at(i)) {
|
||||
continue;
|
||||
}
|
||||
ObDatum &datum = expr.args_[0]->locate_expr_datum(ctx, i);
|
||||
eval_flags.set(i);
|
||||
if (datum.is_null()) {
|
||||
results[i].set_null();
|
||||
} else {
|
||||
results[i].set_int(0 == datum.get_int());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user