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

@ -16,24 +16,29 @@
using namespace oceanbase::common;
namespace oceanbase {
namespace sql {
namespace oceanbase
{
namespace sql
{
ObExprMakeSet::ObExprMakeSet(ObIAllocator& alloc)
: ObStringExprOperator(alloc, T_FUN_SYS_MAKE_SET, "make_set", MORE_THAN_ONE)
ObExprMakeSet::ObExprMakeSet(ObIAllocator &alloc)
: ObStringExprOperator(alloc, T_FUN_SYS_MAKE_SET, "make_set", MORE_THAN_ONE)
{
need_charset_convert_ = false;
}
ObExprMakeSet::~ObExprMakeSet()
{}
{
}
int ObExprMakeSet::calc_result_typeN(
ObExprResType& type, ObExprResType* types, int64_t param_num, ObExprTypeCtx& type_ctx) const
int ObExprMakeSet::calc_result_typeN(ObExprResType &type,
ObExprResType *types,
int64_t param_num,
ObExprTypeCtx &type_ctx) const
{
UNUSED(type_ctx);
int ret = OB_SUCCESS;
if (OB_UNLIKELY(param_num <= 1)) {
if(OB_UNLIKELY(param_num <= 1)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid argument number, param should not less than 2", K(ret), K(param_num));
} else {
@ -47,7 +52,7 @@ int ObExprMakeSet::calc_result_typeN(
// set expected type of results
type.set_varchar();
type.set_length(max_len);
if OB_FAIL (aggregate_charsets_for_string_result(type, &types[1], param_num - 1, type_ctx.get_coll_type())) {
if OB_FAIL(aggregate_charsets_for_string_result(type, &types[1], param_num - 1, type_ctx.get_coll_type())) {
LOG_WARN("aggregate charset for string result failed", K(ret));
} else {
for (int64_t i = 1; i < param_num; i++) {
@ -58,65 +63,11 @@ int ObExprMakeSet::calc_result_typeN(
return ret;
}
int ObExprMakeSet::calc_resultN(ObObj& result, const ObObj* objs, int64_t param_num, ObExprCtx& expr_ctx) const
int ObExprMakeSet::calc_make_set_expr(const ObExpr &expr, ObEvalCtx &ctx,
ObDatum &res)
{
int ret = OB_SUCCESS;
const ObString sep_str = ObCharsetUtils::get_const_str(result_type_.get_collation_type(), ',');
if (OB_ISNULL(expr_ctx.calc_buf_)) {
ret = OB_NOT_INIT;
LOG_WARN("varchar buffer not init", K(ret));
} else if (OB_ISNULL(objs) || OB_UNLIKELY(param_num < 2)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid argument", K(ret), K(param_num), K(objs));
} else if (sep_str.empty()) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get empty separator string", K(ret), K(result_type_));
} else if (objs[0].is_null()) {
result.set_null();
} else {
// compute input bits representation
TYPE_CHECK(objs[0], ObIntType);
uint64_t input_bits = static_cast<uint64_t>(objs[0].get_int());
if (param_num <= 64) {
input_bits &= ((ulonglong)1 << (param_num - 1)) - 1;
}
// compute number of valid input string, including separator
int valid_input_num = 1;
for (int64_t pos = 1, temp_input_bits = input_bits; temp_input_bits > 0; temp_input_bits >>= 1, ++pos) {
if (((temp_input_bits & 1) > 0) && (!objs[pos].is_null())) {
++valid_input_num;
}
}
// compute result
int64_t alloc_size = valid_input_num * sizeof(ObObj);
ObObj* valid_input = static_cast<ObObj*>(expr_ctx.calc_buf_->alloc(alloc_size));
if (valid_input == NULL) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("alloc make_set memory failed", K(alloc_size));
} else {
valid_input[0].set_varchar(sep_str); // first input is separator
int cur_pos = 1;
for (int64_t pos = 1, temp_input_bits = input_bits; temp_input_bits > 0; temp_input_bits >>= 1, ++pos) {
if (((temp_input_bits & 1) > 0) && (!objs[pos].is_null())) {
valid_input[cur_pos] = objs[pos];
++cur_pos;
}
}
if (OB_FAIL(ObExprConcatWs::calc(result, sep_str, valid_input, valid_input_num, expr_ctx))) {
LOG_WARN("fail to calc function make_set", K(ret), K(result));
} else if (!result.is_null()) {
result.set_collation(result_type_);
} else { /*do nothing.*/
}
}
}
return ret;
}
int ObExprMakeSet::calc_make_set_expr(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& res)
{
int ret = OB_SUCCESS;
ObDatum* input_bits_dat = NULL;
ObDatum *input_bits_dat = NULL;
if (OB_UNLIKELY(expr.arg_cnt_ < 2)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid argument", K(ret), K(expr.arg_cnt_));
@ -128,12 +79,12 @@ int ObExprMakeSet::calc_make_set_expr(const ObExpr& expr, ObEvalCtx& ctx, ObDatu
// compute input bits representation
uint64_t input_bits = static_cast<uint64_t>(input_bits_dat->get_int());
if (expr.arg_cnt_ <= 64) {
input_bits &= ((ulonglong)1 << (expr.arg_cnt_ - 1)) - 1;
input_bits &= ((ulonglong) 1 << (expr.arg_cnt_ - 1)) - 1;
}
ObSEArray<ObString, 32> words;
for (int64_t pos = 1, temp_input_bits = input_bits; OB_SUCC(ret) && temp_input_bits > 0;
temp_input_bits >>= 1, ++pos) {
const ObDatum& dat = expr.locate_param_datum(ctx, pos);
const ObDatum &dat = expr.locate_param_datum(ctx, pos);
if (((temp_input_bits & 1) > 0) && (!dat.is_null())) {
if (OB_FAIL(words.push_back(dat.get_string()))) {
LOG_WARN("push back word failed", K(ret));
@ -161,7 +112,8 @@ int ObExprMakeSet::calc_make_set_expr(const ObExpr& expr, ObEvalCtx& ctx, ObDatu
return ret;
}
int ObExprMakeSet::cg_expr(ObExprCGCtx& expr_cg_ctx, const ObRawExpr& raw_expr, ObExpr& rt_expr) const
int ObExprMakeSet::cg_expr(ObExprCGCtx &expr_cg_ctx, const ObRawExpr &raw_expr,
ObExpr &rt_expr) const
{
int ret = OB_SUCCESS;
UNUSED(expr_cg_ctx);