patch 4.0
This commit is contained in:
@ -17,308 +17,48 @@
|
||||
|
||||
using namespace oceanbase::common;
|
||||
|
||||
namespace oceanbase {
|
||||
namespace sql {
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace sql
|
||||
{
|
||||
|
||||
const uint8_t ObExprBitCount::char_to_num_bits[256] = {
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
2,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
3,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
3,
|
||||
2,
|
||||
3,
|
||||
3,
|
||||
4,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
3,
|
||||
2,
|
||||
3,
|
||||
3,
|
||||
4,
|
||||
2,
|
||||
3,
|
||||
3,
|
||||
4,
|
||||
3,
|
||||
4,
|
||||
4,
|
||||
5,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
3,
|
||||
2,
|
||||
3,
|
||||
3,
|
||||
4,
|
||||
2,
|
||||
3,
|
||||
3,
|
||||
4,
|
||||
3,
|
||||
4,
|
||||
4,
|
||||
5,
|
||||
2,
|
||||
3,
|
||||
3,
|
||||
4,
|
||||
3,
|
||||
4,
|
||||
4,
|
||||
5,
|
||||
3,
|
||||
4,
|
||||
4,
|
||||
5,
|
||||
4,
|
||||
5,
|
||||
5,
|
||||
6,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
3,
|
||||
2,
|
||||
3,
|
||||
3,
|
||||
4,
|
||||
2,
|
||||
3,
|
||||
3,
|
||||
4,
|
||||
3,
|
||||
4,
|
||||
4,
|
||||
5,
|
||||
2,
|
||||
3,
|
||||
3,
|
||||
4,
|
||||
3,
|
||||
4,
|
||||
4,
|
||||
5,
|
||||
3,
|
||||
4,
|
||||
4,
|
||||
5,
|
||||
4,
|
||||
5,
|
||||
5,
|
||||
6,
|
||||
2,
|
||||
3,
|
||||
3,
|
||||
4,
|
||||
3,
|
||||
4,
|
||||
4,
|
||||
5,
|
||||
3,
|
||||
4,
|
||||
4,
|
||||
5,
|
||||
4,
|
||||
5,
|
||||
5,
|
||||
6,
|
||||
3,
|
||||
4,
|
||||
4,
|
||||
5,
|
||||
4,
|
||||
5,
|
||||
5,
|
||||
6,
|
||||
4,
|
||||
5,
|
||||
5,
|
||||
6,
|
||||
5,
|
||||
6,
|
||||
6,
|
||||
7,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
3,
|
||||
2,
|
||||
3,
|
||||
3,
|
||||
4,
|
||||
2,
|
||||
3,
|
||||
3,
|
||||
4,
|
||||
3,
|
||||
4,
|
||||
4,
|
||||
5,
|
||||
2,
|
||||
3,
|
||||
3,
|
||||
4,
|
||||
3,
|
||||
4,
|
||||
4,
|
||||
5,
|
||||
3,
|
||||
4,
|
||||
4,
|
||||
5,
|
||||
4,
|
||||
5,
|
||||
5,
|
||||
6,
|
||||
2,
|
||||
3,
|
||||
3,
|
||||
4,
|
||||
3,
|
||||
4,
|
||||
4,
|
||||
5,
|
||||
3,
|
||||
4,
|
||||
4,
|
||||
5,
|
||||
4,
|
||||
5,
|
||||
5,
|
||||
6,
|
||||
3,
|
||||
4,
|
||||
4,
|
||||
5,
|
||||
4,
|
||||
5,
|
||||
5,
|
||||
6,
|
||||
4,
|
||||
5,
|
||||
5,
|
||||
6,
|
||||
5,
|
||||
6,
|
||||
6,
|
||||
7,
|
||||
2,
|
||||
3,
|
||||
3,
|
||||
4,
|
||||
3,
|
||||
4,
|
||||
4,
|
||||
5,
|
||||
3,
|
||||
4,
|
||||
4,
|
||||
5,
|
||||
4,
|
||||
5,
|
||||
5,
|
||||
6,
|
||||
3,
|
||||
4,
|
||||
4,
|
||||
5,
|
||||
4,
|
||||
5,
|
||||
5,
|
||||
6,
|
||||
4,
|
||||
5,
|
||||
5,
|
||||
6,
|
||||
5,
|
||||
6,
|
||||
6,
|
||||
7,
|
||||
3,
|
||||
4,
|
||||
4,
|
||||
5,
|
||||
4,
|
||||
5,
|
||||
5,
|
||||
6,
|
||||
4,
|
||||
5,
|
||||
5,
|
||||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 7, 5, 6, 6, 7, 6, 7, 7, 8,
|
||||
};
|
||||
|
||||
ObExprBitCount::ObExprBitCount(ObIAllocator& alloc)
|
||||
: ObBitwiseExprOperator(alloc, T_FUN_SYS_BIT_COUNT, "bit_count", 1, NOT_ROW_DIMENSION)
|
||||
{}
|
||||
|
||||
ObExprBitCount::~ObExprBitCount()
|
||||
{}
|
||||
|
||||
int ObExprBitCount::calc_result1(ObObj& result, const ObObj& obj1, ObExprCtx& expr_ctx) const
|
||||
ObExprBitCount::ObExprBitCount(ObIAllocator &alloc)
|
||||
: ObBitwiseExprOperator(alloc, T_FUN_SYS_BIT_COUNT, "bit_count", 1, NOT_ROW_DIMENSION)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_ISNULL(expr_ctx.calc_buf_)) {
|
||||
ret = OB_NOT_INIT;
|
||||
LOG_WARN("buf not init", K(ret));
|
||||
} else if (obj1.is_null()) {
|
||||
result.set_null();
|
||||
} else {
|
||||
uint64_t value = 0;
|
||||
const bool is_round = true;
|
||||
if (OB_FAIL(ObBitwiseExprOperator::get_uint64(obj1, expr_ctx, is_round, value))) {
|
||||
LOG_WARN("fail to get uint64_t", K(obj1), K(ret));
|
||||
} else {
|
||||
uint64_t temp_result = 0;
|
||||
temp_result = static_cast<uint64_t>(
|
||||
char_to_num_bits[static_cast<uint8_t>(value)] + char_to_num_bits[static_cast<uint8_t>(value >> 8)] +
|
||||
char_to_num_bits[static_cast<uint8_t>(value >> 16)] + char_to_num_bits[static_cast<uint8_t>(value >> 24)] +
|
||||
char_to_num_bits[static_cast<uint8_t>(value >> 32)] + char_to_num_bits[static_cast<uint8_t>(value >> 40)] +
|
||||
char_to_num_bits[static_cast<uint8_t>(value >> 48)] + char_to_num_bits[static_cast<uint8_t>(value >> 56)]);
|
||||
result.set_uint64(temp_result);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprBitCount::calc_bitcount_expr(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& res_datum)
|
||||
ObExprBitCount::~ObExprBitCount()
|
||||
{
|
||||
}
|
||||
|
||||
int ObExprBitCount::calc_bitcount_expr(const ObExpr &expr, ObEvalCtx &ctx,
|
||||
ObDatum& res_datum)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
uint64_t uint_val = 0;
|
||||
ObDatum* child_res = NULL;
|
||||
ObDatum *child_res = NULL;
|
||||
ObCastMode cast_mode = CM_NONE;
|
||||
void* get_uint_func = NULL;
|
||||
void *get_uint_func = NULL;
|
||||
if (OB_UNLIKELY(1 != expr.arg_cnt_)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("invalid arg cnt", K(ret), K(expr.arg_cnt_));
|
||||
@ -328,26 +68,30 @@ int ObExprBitCount::calc_bitcount_expr(const ObExpr& expr, ObEvalCtx& ctx, ObDat
|
||||
res_datum.set_null();
|
||||
} else if (OB_FAIL(choose_get_int_func(expr.args_[0]->datum_meta_.type_, get_uint_func))) {
|
||||
LOG_WARN("choose_get_int_func failed", K(ret), K(expr.args_[0]->datum_meta_));
|
||||
} else if (OB_FAIL(ObSQLUtils::get_default_cast_mode(false, 0, ctx.exec_ctx_.get_my_session(), cast_mode))) {
|
||||
} else if (OB_FAIL(ObSQLUtils::get_default_cast_mode(false, 0,
|
||||
ctx.exec_ctx_.get_my_session(), cast_mode))) {
|
||||
LOG_WARN("get_default_cast_mode failed", K(ret));
|
||||
} else if (OB_FAIL((reinterpret_cast<GetUIntFunc>(get_uint_func)(*child_res, true, uint_val, cast_mode)))) {
|
||||
} else if (OB_FAIL((reinterpret_cast<GetUIntFunc>(get_uint_func)(*child_res, true,
|
||||
uint_val, cast_mode)))) {
|
||||
LOG_WARN("get uint64 failed", K(ret), K(*child_res));
|
||||
} else {
|
||||
uint64_t temp_result = 0;
|
||||
temp_result = static_cast<uint64_t>(char_to_num_bits[static_cast<uint8_t>(uint_val)] +
|
||||
char_to_num_bits[static_cast<uint8_t>(uint_val >> 8)] +
|
||||
char_to_num_bits[static_cast<uint8_t>(uint_val >> 16)] +
|
||||
char_to_num_bits[static_cast<uint8_t>(uint_val >> 24)] +
|
||||
char_to_num_bits[static_cast<uint8_t>(uint_val >> 32)] +
|
||||
char_to_num_bits[static_cast<uint8_t>(uint_val >> 40)] +
|
||||
char_to_num_bits[static_cast<uint8_t>(uint_val >> 48)] +
|
||||
char_to_num_bits[static_cast<uint8_t>(uint_val >> 56)]);
|
||||
temp_result = static_cast<uint64_t>(
|
||||
char_to_num_bits[static_cast<uint8_t>(uint_val)]
|
||||
+ char_to_num_bits[static_cast<uint8_t>(uint_val >> 8)]
|
||||
+ char_to_num_bits[static_cast<uint8_t>(uint_val >> 16)]
|
||||
+ char_to_num_bits[static_cast<uint8_t>(uint_val >> 24)]
|
||||
+ char_to_num_bits[static_cast<uint8_t>(uint_val >> 32)]
|
||||
+ char_to_num_bits[static_cast<uint8_t>(uint_val >> 40)]
|
||||
+ char_to_num_bits[static_cast<uint8_t>(uint_val >> 48)]
|
||||
+ char_to_num_bits[static_cast<uint8_t>(uint_val >> 56)]);
|
||||
res_datum.set_uint(temp_result);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprBitCount::cg_expr(ObExprCGCtx& expr_cg_ctx, const ObRawExpr& raw_expr, ObExpr& rt_expr) const
|
||||
int ObExprBitCount::cg_expr(ObExprCGCtx &expr_cg_ctx, const ObRawExpr &raw_expr,
|
||||
ObExpr &rt_expr) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
const BitOperator op = BIT_COUNT;
|
||||
|
||||
Reference in New Issue
Block a user