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

@ -10,7 +10,6 @@
* See the Mulan PubL v2 for more details.
*/
// This file contains implementation for json_keys.
#define USING_LOG_PREFIX SQL_ENG
#include "ob_expr_json_keys.h"
#include "ob_expr_json_func_helper.h"
@ -62,77 +61,6 @@ int ObExprJsonKeys::calc_result_typeN(ObExprResType& type,
return ret;
}
// for old sql engine
int ObExprJsonKeys::calc_resultN(ObObj &result,
const ObObj *params,
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(allocator)) { // check allocator
ret = OB_NOT_INIT;
LOG_WARN("varchar buffer not init", K(ret));
} else {
ObIJsonBase *json_doc = NULL;
bool is_null_result = false;
if (OB_FAIL(ObJsonExprHelper::get_json_doc(params, allocator, 0,
json_doc, is_null_result))) {
LOG_WARN("get_json_doc failed", K(ret));
}
if (!is_null_result && OB_SUCC(ret) && param_num == 2) {
// parse path
ObJsonPathCache ctx_cache(allocator);
ObJsonPathCache* path_cache = &ctx_cache;
ObObjType val_type = params[1].get_type();
if (val_type == ObNullType || params[1].is_null()) {
is_null_result = true;
} else {
ObJsonBaseVector sub_json_targets;
ObJsonPath *json_path;
ObString path_val = params[1].get_string();
if (OB_FAIL(ObJsonExprHelper::find_and_add_cache(path_cache, json_path, path_val, 1, false))) {
LOG_WARN("json parse failed or illegal", K(path_val), K(ret));
} else if (OB_FAIL(json_doc->seek(*json_path, json_path->path_node_cnt(),
false, true, sub_json_targets))) {
LOG_WARN("json seek failed", K(path_val), K(ret));
} else {
if (sub_json_targets.size() != 1) {
is_null_result = true;
} else {
json_doc = sub_json_targets[0];
}
}
}
}
if (!is_null_result && OB_SUCC(ret) && json_doc->json_type() != ObJsonNodeType::J_OBJECT) {
is_null_result = true;
}
// set result
if (OB_UNLIKELY(OB_FAIL(ret))) {
LOG_WARN("json_keys failed", K(ret));
} else if (is_null_result){
result.set_null();
} else {
ObString raw_bin;
if (OB_FAIL(get_keys_from_wrapper(json_doc, allocator, raw_bin))) {
LOG_WARN("get_keys_from_wrapper failed", K(ret));
} else {
result.set_collation_type(CS_TYPE_UTF8MB4_BIN);
result.set_string(ObJsonType, raw_bin.ptr(), raw_bin.length());
}
}
}
return ret;
}
int ObExprJsonKeys::get_keys_from_wrapper(ObIJsonBase *json_doc,
ObIAllocator *allocator,
ObString &str)
@ -170,7 +98,8 @@ int ObExprJsonKeys::eval_json_keys(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &
INIT_SUCC(ret);
ObIJsonBase *json_doc = NULL;
bool is_null_result = false;
common::ObArenaAllocator &temp_allocator = ctx.get_reset_tmp_alloc();
ObEvalCtx::TempAllocGuard tmp_alloc_g(ctx);
common::ObArenaAllocator &temp_allocator = tmp_alloc_g.get_allocator();
if (expr.datum_meta_.cs_type_ != CS_TYPE_UTF8MB4_BIN) {
ret = OB_ERR_INVALID_JSON_CHARSET;
LOG_WARN("invalid out put charset", K(ret), K(expr.datum_meta_.cs_type_));