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,10 +10,10 @@
* See the Mulan PubL v2 for more details.
*/
// This file contains implementation of json_object.
#define USING_LOG_PREFIX SQL_ENG
#include "ob_expr_json_object.h"
#include "sql/engine/expr/ob_expr_json_func_helper.h"
#include "sql/engine/ob_exec_context.h"
using namespace oceanbase::common;
using namespace oceanbase::sql;
@ -36,13 +36,23 @@ int ObExprJsonObject::calc_result_typeN(ObExprResType& type,
int64_t param_num,
ObExprTypeCtx& type_ctx) const
{
UNUSED(type_ctx);
INIT_SUCC(ret);
if (OB_UNLIKELY(param_num < 0 || param_num % 2 != 0)) {
ObSQLSessionInfo *session = const_cast<ObSQLSessionInfo *>(type_ctx.get_session());
ObExecContext *exec_ctx = nullptr;
if (OB_ISNULL(session)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("session is NULL", K(ret));
} else if (OB_ISNULL(exec_ctx = session->get_cur_exec_ctx())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("exec context is NULL", K(ret));
} else if (OB_UNLIKELY(param_num < 0 || param_num % 2 != 0)) {
ret = OB_ERR_PARAM_SIZE;
const ObString name = "json_object";
LOG_USER_ERROR(OB_ERR_PARAM_SIZE, name.length(), name.ptr());
} else if (exec_ctx->is_ps_prepare_stage()) {
// the ps prepare stage does not do type deduction, and directly gives a default type.
type.set_json();
type.set_length((ObAccuracy::DDL_DEFAULT_ACCURACY[ObJsonType]).get_length());
} else {
type.set_json();
type.set_length((ObAccuracy::DDL_DEFAULT_ACCURACY[ObJsonType]).get_length());
@ -77,65 +87,12 @@ int ObExprJsonObject::calc_result_typeN(ObExprResType& type,
return ret;
}
// for old sql engine
int ObExprJsonObject::calc_resultN(ObObj &result, const ObObj *objs,
int64_t param_num, ObExprCtx &expr_ctx) const
{
INIT_SUCC(ret);
ObIAllocator *allocator = expr_ctx.calc_buf_;
ObJsonObject j_obj(allocator);
ObIJsonBase *j_base = &j_obj;
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("allcator not init", K(ret));
}
for (int i = 0; OB_SUCC(ret) && i < param_num; i += 2) {
ObString key = objs[i].get_string();
bool is_bool = false;
ObIJsonBase *j_val = NULL;
if (objs[i].is_null()) { // key is null
ret = OB_ERR_JSON_DOCUMENT_NULL_KEY;
LOG_USER_ERROR(OB_ERR_JSON_DOCUMENT_NULL_KEY);
LOG_WARN("failed:json key is null", K(ret));
} else if (OB_FAIL(get_param_is_boolean(expr_ctx, objs[i+1], is_bool))) {
LOG_WARN("get_param_is_boolean failed", K(ret));
} else if (OB_FAIL(ObJsonExprHelper::get_json_val(objs[i+1], 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->object_add(key, j_val))) {
if (ret == OB_ERR_JSON_DOCUMENT_NULL_KEY) {
LOG_USER_ERROR(OB_ERR_JSON_DOCUMENT_NULL_KEY);
}
LOG_WARN("failed:append json object kv failed", K(ret));
}
}
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 ObExprJsonObject::eval_json_object(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &res)
{
INIT_SUCC(ret);
common::ObArenaAllocator &temp_allocator = ctx.get_reset_tmp_alloc();
ObEvalCtx::TempAllocGuard tmp_alloc_g(ctx);
common::ObArenaAllocator &temp_allocator = tmp_alloc_g.get_allocator();
ObJsonObject j_obj(&temp_allocator);
ObIJsonBase *j_base = &j_obj;