patch 4.0
This commit is contained in:
@ -10,7 +10,6 @@
|
||||
* See the Mulan PubL v2 for more details.
|
||||
*/
|
||||
|
||||
// This file is for implementation of func json_array
|
||||
#define USING_LOG_PREFIX SQL_ENG
|
||||
#include "ob_expr_json_array.h"
|
||||
#include "sql/engine/expr/ob_expr_json_func_helper.h"
|
||||
@ -66,63 +65,13 @@ int ObExprJsonArray::calc_result_typeN(ObExprResType& type,
|
||||
return ret;
|
||||
}
|
||||
|
||||
// for old sql engine
|
||||
int ObExprJsonArray::calc_resultN(ObObj &result,
|
||||
const ObObj *objs,
|
||||
int64_t param_num,
|
||||
ObExprCtx &expr_ctx) const
|
||||
{
|
||||
INIT_SUCC(ret);
|
||||
ObIAllocator *allocator = expr_ctx.calc_buf_;
|
||||
|
||||
if (result_type_.get_collation_type() != CS_TYPE_UTF8MB4_BIN) {
|
||||
ret = OB_ERR_INVALID_JSON_CHARSET;
|
||||
LOG_WARN("invalid out put charset", K(ret), K(result_type_));
|
||||
} else if (OB_ISNULL(objs)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid arguments", K(ret), K(objs), K(param_num));
|
||||
} else if (OB_ISNULL(allocator)) { // check allocator
|
||||
ret = OB_NOT_INIT;
|
||||
LOG_WARN("varchar buffer not init", K(ret));
|
||||
} else {
|
||||
ObJsonArray j_arr(allocator);
|
||||
ObIJsonBase *j_base = &j_arr;
|
||||
for (int64_t i = 0; i < param_num && OB_SUCC(ret); ++i) {
|
||||
bool is_bool = false;
|
||||
ObIJsonBase *j_val;
|
||||
|
||||
if (OB_FAIL(get_param_is_boolean(expr_ctx, objs[i], is_bool))) {
|
||||
LOG_WARN("failed: get_param_is_boolean", K(ret));
|
||||
} else if (OB_FAIL(ObJsonExprHelper::get_json_val(objs[i], expr_ctx, is_bool,
|
||||
allocator, j_val))) {
|
||||
ret = OB_ERR_INVALID_JSON_TEXT_IN_PARAM;
|
||||
LOG_USER_ERROR(OB_ERR_INVALID_JSON_TEXT_IN_PARAM);
|
||||
} else if (OB_FAIL(j_base->array_append(j_val))) {
|
||||
LOG_WARN("failed: json array append json value", K(ret), K(objs[i].get_type()));
|
||||
}
|
||||
}
|
||||
|
||||
// set result(json bin)
|
||||
if (OB_SUCC(ret)) {
|
||||
ObString raw_bin;
|
||||
if (OB_FAIL(j_base->get_raw_binary(raw_bin, allocator))) {
|
||||
LOG_WARN("failed: get json raw binary", K(ret));
|
||||
} else {
|
||||
result.set_collation_type(CS_TYPE_UTF8MB4_BIN);
|
||||
result.set_string(ObJsonType, raw_bin.ptr(), raw_bin.length());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// for new sql engine
|
||||
int ObExprJsonArray::eval_json_array(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &res)
|
||||
{
|
||||
INIT_SUCC(ret);
|
||||
ObDatum *json_datum = NULL;
|
||||
common::ObArenaAllocator &temp_allocator = ctx.get_reset_tmp_alloc();
|
||||
ObEvalCtx::TempAllocGuard tmp_alloc_g(ctx);
|
||||
common::ObArenaAllocator &temp_allocator = tmp_alloc_g.get_allocator();
|
||||
ObJsonArray j_arr(&temp_allocator);
|
||||
ObIJsonBase *j_base = &j_arr;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user