[FEAT MERGE]4_2_sql_feature
Co-authored-by: yinyj17 <yinyijun92@gmail.com> Co-authored-by: xianyu-w <707512433@qq.com> Co-authored-by: jingtaoye35 <1255153887@qq.com>
This commit is contained in:
@ -13,6 +13,7 @@
|
||||
#define USING_LOG_PREFIX SQL_ENG
|
||||
#include "ob_expr_sqrt.h"
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
#include "share/object/ob_obj_cast.h"
|
||||
#include "objit/common/ob_item_type.h"
|
||||
//#include "sql/engine/expr/ob_expr_promotion_util.h"
|
||||
@ -78,6 +79,31 @@ int calc_sqrt_expr_mysql(const ObExpr &expr, ObEvalCtx &ctx,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int calc_sqrt_expr_mysql_in_batch(const ObExpr &expr,
|
||||
ObEvalCtx &ctx,
|
||||
const ObBitVector &skip,
|
||||
const int64_t batch_size)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(expr.args_[0]->eval_batch(ctx, skip, batch_size))) {
|
||||
LOG_WARN("vectorized evaluate failed", K(ret), K(expr));
|
||||
} else {
|
||||
ObBitVector &eval_flag = expr.get_evaluated_flags(ctx);
|
||||
ObDatumVector arg_datums = expr.args_[0]->locate_expr_datumvector(ctx);
|
||||
ObDatum *res_datums = expr.locate_batch_datums(ctx);
|
||||
for (int64_t i = 0; i < batch_size; ++i) {
|
||||
if (!eval_flag.contain(i) && !skip.contain(i)) {
|
||||
if (arg_datums.at(i)->is_null() || arg_datums.at(i)->get_double() < 0) {
|
||||
res_datums[i].set_null();
|
||||
} else {
|
||||
res_datums[i].set_double(std::sqrt(arg_datums.at(i)->get_double()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int calc_sqrt_expr_oracle_double(const ObExpr &expr, ObEvalCtx &ctx,
|
||||
ObDatum &res_datum)
|
||||
{
|
||||
@ -111,6 +137,72 @@ int calc_sqrt_expr_oracle_double(const ObExpr &expr, ObEvalCtx &ctx,
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int calc_sqrt_expr_oracle_double_in_batch_impl(const ObExpr &expr,
|
||||
ObEvalCtx &ctx,
|
||||
const ObBitVector &skip,
|
||||
const int64_t batch_size)
|
||||
{
|
||||
ObBitVector &eval_flag = expr.get_evaluated_flags(ctx);
|
||||
ObDatumVector arg_datums = expr.args_[0]->locate_expr_datumvector(ctx);
|
||||
ObDatum *res_datums = expr.locate_batch_datums(ctx);
|
||||
int ret = OB_SUCCESS;
|
||||
if (std::is_same<T, float>::value) {
|
||||
for (int64_t i = 0; i < batch_size && OB_SUCC(ret); ++i) {
|
||||
if (!eval_flag.contain(i) && !skip.contain(i)) {
|
||||
ObDatum *arg = arg_datums.at(i);
|
||||
if (arg->is_null()) {
|
||||
res_datums[i].set_null();
|
||||
} else if (arg->get_float() < 0) {
|
||||
res_datums[i].set_float(NAN);
|
||||
} else {
|
||||
res_datums[i].set_float(std::sqrt(arg->get_float()));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (std::is_same<T, double>::value) {
|
||||
for (int64_t i = 0; i < batch_size && OB_SUCC(ret); ++i) {
|
||||
if (!eval_flag.contain(i) && !skip.contain(i)) {
|
||||
ObDatum *arg = arg_datums.at(i);
|
||||
if (arg->is_null()) {
|
||||
res_datums[i].set_null();
|
||||
} else if (arg->get_double() < 0) {
|
||||
res_datums[i].set_double(NAN);
|
||||
} else {
|
||||
res_datums[i].set_double(std::sqrt(arg->get_double()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int calc_sqrt_expr_oracle_double_in_batch(const ObExpr &expr,
|
||||
ObEvalCtx &ctx,
|
||||
const ObBitVector &skip,
|
||||
const int64_t batch_size)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(expr.args_[0]->eval_batch(ctx, skip, batch_size))) {
|
||||
LOG_WARN("vectorized evaluate failed", K(ret), K(expr));
|
||||
} else {
|
||||
ObObjType arg_type = expr.args_[0]->datum_meta_.type_;
|
||||
switch (arg_type) {
|
||||
case ObDoubleType:
|
||||
ret = calc_sqrt_expr_oracle_double_in_batch_impl<double>(expr, ctx, skip, batch_size);
|
||||
break;
|
||||
case ObFloatType:
|
||||
ret = calc_sqrt_expr_oracle_double_in_batch_impl<float>(expr, ctx, skip, batch_size);
|
||||
break;
|
||||
default:
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("unexpected arg type", K(ret), K(arg_type));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int calc_sqrt_expr_oracle_number(const ObExpr &expr, ObEvalCtx &ctx,
|
||||
ObDatum &res_datum)
|
||||
{
|
||||
@ -133,6 +225,41 @@ int calc_sqrt_expr_oracle_number(const ObExpr &expr, ObEvalCtx &ctx,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int calc_sqrt_expr_oracle_number_in_batch(const ObExpr &expr,
|
||||
ObEvalCtx &ctx,
|
||||
const ObBitVector &skip,
|
||||
const int64_t batch_size)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(expr.args_[0]->eval_batch(ctx, skip, batch_size))) {
|
||||
LOG_WARN("vectorized evaluate failed", K(ret), K(expr));
|
||||
} else {
|
||||
ObBitVector &eval_flag = expr.get_evaluated_flags(ctx);
|
||||
ObDatumVector arg_datums = expr.args_[0]->locate_expr_datumvector(ctx);
|
||||
ObDatum *res_datums = expr.locate_batch_datums(ctx);
|
||||
number::ObNumber res_nmb;
|
||||
number::ObNumber arg_nmb;
|
||||
char temp_buf_alloc[number::ObNumber::MAX_CALC_BYTE_LEN];
|
||||
ObDataBuffer temp_allocator(temp_buf_alloc, number::ObNumber::MAX_CALC_BYTE_LEN);
|
||||
for (int64_t i = 0; i < batch_size && OB_SUCC(ret); ++i) {
|
||||
if (!eval_flag.contain(i) && !skip.contain(i)) {
|
||||
if (arg_datums.at(i)->is_null()) {
|
||||
res_datums[i].set_null();
|
||||
} else {
|
||||
arg_nmb = arg_datums.at(i)->get_number();
|
||||
if (OB_FAIL(arg_nmb.sqrt(res_nmb, temp_allocator))) {
|
||||
LOG_WARN("calc sqrt failed", K(ret), K(arg_nmb), K(res_nmb));
|
||||
} else {
|
||||
res_datums[i].set_number(res_nmb);
|
||||
}
|
||||
temp_allocator.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprSqrt::cg_expr(ObExprCGCtx &expr_cg_ctx, const ObRawExpr &raw_expr,
|
||||
ObExpr &rt_expr) const
|
||||
{
|
||||
@ -147,8 +274,10 @@ int ObExprSqrt::cg_expr(ObExprCGCtx &expr_cg_ctx, const ObRawExpr &raw_expr,
|
||||
if (lib::is_oracle_mode()) {
|
||||
if (ObDoubleType == arg_res_type || ObFloatType == arg_res_type) {
|
||||
rt_expr.eval_func_ = calc_sqrt_expr_oracle_double;
|
||||
rt_expr.eval_batch_func_ = calc_sqrt_expr_oracle_double_in_batch;
|
||||
} else if (ObNumberType == arg_res_type) {
|
||||
rt_expr.eval_func_ = calc_sqrt_expr_oracle_number;
|
||||
rt_expr.eval_batch_func_ = calc_sqrt_expr_oracle_number_in_batch;
|
||||
} else {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("arg type must be double or number in oracle mode", K(ret),
|
||||
@ -157,6 +286,7 @@ int ObExprSqrt::cg_expr(ObExprCGCtx &expr_cg_ctx, const ObRawExpr &raw_expr,
|
||||
} else {
|
||||
if (ObDoubleType == arg_res_type) {
|
||||
rt_expr.eval_func_ = calc_sqrt_expr_mysql;
|
||||
rt_expr.eval_batch_func_ = calc_sqrt_expr_mysql_in_batch;
|
||||
} else {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("arg_res_type must be double in mysql mode", K(ret), K(arg_res_type));
|
||||
|
||||
Reference in New Issue
Block a user