fix compilation errors when OB_ENABLE_PCH=OFF
This commit is contained in:
@ -14,14 +14,13 @@
|
||||
#define USING_LOG_PREFIX SQL_ENG
|
||||
#include "sql/engine/ob_exec_context.h"
|
||||
#include "ob_expr_json_func_helper.h"
|
||||
#include "lib/json_type/ob_json_bin.h"
|
||||
|
||||
using namespace oceanbase::common;
|
||||
using namespace oceanbase::sql;
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace sql
|
||||
{
|
||||
namespace oceanbase {
|
||||
namespace sql {
|
||||
ObJsonInType ObJsonExprHelper::get_json_internal_type(ObObjType type)
|
||||
{
|
||||
return type == ObJsonType ? ObJsonInType::JSON_BIN : ObJsonInType::JSON_TREE;
|
||||
@ -39,10 +38,8 @@ int ObJsonExprHelper::ensure_collation(ObObjType type, ObCollationType cs_type)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObJsonExprHelper::get_json_doc(const ObExpr &expr, ObEvalCtx &ctx,
|
||||
common::ObArenaAllocator &allocator,
|
||||
uint16_t index, ObIJsonBase*& j_base,
|
||||
bool &is_null, bool need_to_tree)
|
||||
int ObJsonExprHelper::get_json_doc(const ObExpr &expr, ObEvalCtx &ctx, common::ObArenaAllocator &allocator,
|
||||
uint16_t index, ObIJsonBase *&j_base, bool &is_null, bool need_to_tree)
|
||||
{
|
||||
INIT_SUCC(ret);
|
||||
ObDatum *json_datum = NULL;
|
||||
@ -63,8 +60,7 @@ int ObJsonExprHelper::get_json_doc(const ObExpr &expr, ObEvalCtx &ctx,
|
||||
ObString j_str = json_datum->get_string();
|
||||
ObJsonInType j_in_type = ObJsonExprHelper::get_json_internal_type(val_type);
|
||||
ObJsonInType expect_type = need_to_tree ? ObJsonInType::JSON_TREE : j_in_type;
|
||||
if (OB_FAIL(ObJsonBaseFactory::get_json_base(&allocator, j_str, j_in_type,
|
||||
expect_type, j_base))) {
|
||||
if (OB_FAIL(ObJsonBaseFactory::get_json_base(&allocator, j_str, j_in_type, expect_type, j_base))) {
|
||||
LOG_WARN("fail to get json base", K(ret), K(j_in_type));
|
||||
ret = OB_ERR_INVALID_JSON_TEXT_IN_PARAM;
|
||||
LOG_USER_ERROR(OB_ERR_INVALID_JSON_TEXT_IN_PARAM);
|
||||
@ -73,9 +69,8 @@ int ObJsonExprHelper::get_json_doc(const ObExpr &expr, ObEvalCtx &ctx,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObJsonExprHelper::get_json_doc(const ObObj *objs, common::ObIAllocator *allocator,
|
||||
uint16_t index, ObIJsonBase*& j_base,
|
||||
bool &is_null, bool need_to_tree)
|
||||
int ObJsonExprHelper::get_json_doc(const ObObj *objs, common::ObIAllocator *allocator, uint16_t index,
|
||||
ObIJsonBase *&j_base, bool &is_null, bool need_to_tree)
|
||||
{
|
||||
INIT_SUCC(ret);
|
||||
ObObjType val_type = objs[index].get_type();
|
||||
@ -92,8 +87,7 @@ int ObJsonExprHelper::get_json_doc(const ObObj *objs, common::ObIAllocator *allo
|
||||
ObString j_str = objs[index].get_string();
|
||||
ObJsonInType j_in_type = ObJsonExprHelper::get_json_internal_type(val_type);
|
||||
ObJsonInType expect_type = need_to_tree ? ObJsonInType::JSON_TREE : j_in_type;
|
||||
if (OB_FAIL(ObJsonBaseFactory::get_json_base(allocator, j_str, j_in_type,
|
||||
expect_type, j_base))) {
|
||||
if (OB_FAIL(ObJsonBaseFactory::get_json_base(allocator, j_str, j_in_type, expect_type, j_base))) {
|
||||
LOG_WARN("fail to get json base", K(ret), K(j_in_type));
|
||||
ret = OB_ERR_INVALID_JSON_TEXT_IN_PARAM;
|
||||
LOG_USER_ERROR(OB_ERR_INVALID_JSON_TEXT_IN_PARAM);
|
||||
@ -102,9 +96,8 @@ int ObJsonExprHelper::get_json_doc(const ObObj *objs, common::ObIAllocator *allo
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObJsonExprHelper::get_json_val(const common::ObObj &data, ObExprCtx &ctx,
|
||||
bool is_bool, common::ObIAllocator *allocator,
|
||||
ObIJsonBase*& j_base, bool to_bin)
|
||||
int ObJsonExprHelper::get_json_val(const common::ObObj &data, ObExprCtx &ctx, bool is_bool,
|
||||
common::ObIAllocator *allocator, ObIJsonBase *&j_base, bool to_bin)
|
||||
{
|
||||
INIT_SUCC(ret);
|
||||
ObObjType val_type = data.get_type();
|
||||
@ -114,7 +107,7 @@ int ObJsonExprHelper::get_json_val(const common::ObObj &data, ObExprCtx &ctx,
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
LOG_WARN("failed: alloscate jsonboolean", K(ret));
|
||||
} else {
|
||||
ObJsonNull *null_node = static_cast<ObJsonNull*>(new(json_node_buf) ObJsonNull());
|
||||
ObJsonNull *null_node = static_cast<ObJsonNull *>(new (json_node_buf) ObJsonNull());
|
||||
if (to_bin) {
|
||||
if (OB_FAIL(ObJsonBaseFactory::transform(allocator, null_node, ObJsonInType::JSON_BIN, j_base))) {
|
||||
LOG_WARN("failed: json tree to bin", K(ret));
|
||||
@ -129,7 +122,7 @@ int ObJsonExprHelper::get_json_val(const common::ObObj &data, ObExprCtx &ctx,
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
LOG_WARN("failed: alloscate jsonboolean", K(ret));
|
||||
} else {
|
||||
ObJsonBoolean *bool_node = (ObJsonBoolean*)new(json_node_buf)ObJsonBoolean(data.get_bool());
|
||||
ObJsonBoolean *bool_node = (ObJsonBoolean *)new (json_node_buf) ObJsonBoolean(data.get_bool());
|
||||
if (to_bin) {
|
||||
if (OB_FAIL(ObJsonBaseFactory::transform(allocator, bool_node, ObJsonInType::JSON_BIN, j_base))) {
|
||||
LOG_WARN("failed: json tree to bin", K(ret));
|
||||
@ -140,8 +133,8 @@ int ObJsonExprHelper::get_json_val(const common::ObObj &data, ObExprCtx &ctx,
|
||||
}
|
||||
} else if (ObJsonExprHelper::is_convertible_to_json(val_type)) {
|
||||
ObCollationType cs_type = data.get_collation_type();
|
||||
if (OB_FAIL(ObJsonExprHelper::transform_convertible_2jsonBase(data, val_type, allocator,
|
||||
cs_type, j_base, to_bin))) {
|
||||
if (OB_FAIL(
|
||||
ObJsonExprHelper::transform_convertible_2jsonBase(data, val_type, allocator, cs_type, j_base, to_bin))) {
|
||||
LOG_WARN("failed: parse value to jsonBase", K(ret), K(val_type));
|
||||
}
|
||||
} else {
|
||||
@ -149,20 +142,17 @@ int ObJsonExprHelper::get_json_val(const common::ObObj &data, ObExprCtx &ctx,
|
||||
if (OB_ISNULL(session)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("session is NULL", K(ret));
|
||||
} else if (OB_FAIL(ObJsonExprHelper::transform_scalar_2jsonBase(data, val_type,
|
||||
allocator, data.get_scale(),
|
||||
session->get_timezone_info(),
|
||||
j_base, to_bin))) {
|
||||
LOG_WARN("failed: parse value to jsonBase", K(ret), K(val_type));
|
||||
} else if (OB_FAIL(ObJsonExprHelper::transform_scalar_2jsonBase(
|
||||
data, val_type, allocator, data.get_scale(), session->get_timezone_info(), j_base, to_bin))) {
|
||||
LOG_WARN("failed: parse value to jsonBase", K(ret), K(val_type));
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObJsonExprHelper::get_json_val(const ObExpr &expr, ObEvalCtx &ctx,
|
||||
common::ObIAllocator *allocator, uint16_t index,
|
||||
ObIJsonBase*& j_base, bool to_bin)
|
||||
int ObJsonExprHelper::get_json_val(const ObExpr &expr, ObEvalCtx &ctx, common::ObIAllocator *allocator, uint16_t index,
|
||||
ObIJsonBase *&j_base, bool to_bin)
|
||||
{
|
||||
INIT_SUCC(ret);
|
||||
ObDatum *json_datum = NULL;
|
||||
@ -176,7 +166,7 @@ int ObJsonExprHelper::get_json_val(const ObExpr &expr, ObEvalCtx &ctx,
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
LOG_WARN("failed: alloscate jsonboolean", K(ret));
|
||||
} else {
|
||||
ObJsonNull *null_node = static_cast<ObJsonNull*>(new(json_node_buf) ObJsonNull());
|
||||
ObJsonNull *null_node = static_cast<ObJsonNull *>(new (json_node_buf) ObJsonNull());
|
||||
if (to_bin) {
|
||||
if (OB_FAIL(ObJsonBaseFactory::transform(allocator, null_node, ObJsonInType::JSON_BIN, j_base))) {
|
||||
LOG_WARN("failed: json tree to bin", K(ret));
|
||||
@ -184,14 +174,14 @@ int ObJsonExprHelper::get_json_val(const ObExpr &expr, ObEvalCtx &ctx,
|
||||
} else {
|
||||
j_base = null_node;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (json_arg->is_boolean_ == 1) {
|
||||
void *json_node_buf = allocator->alloc(sizeof(ObJsonBoolean));
|
||||
if (OB_ISNULL(json_node_buf)) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
LOG_WARN("failed: alloscate jsonboolean", K(ret));
|
||||
} else {
|
||||
ObJsonBoolean *bool_node = (ObJsonBoolean*)new(json_node_buf)ObJsonBoolean(json_datum->get_bool());
|
||||
ObJsonBoolean *bool_node = (ObJsonBoolean *)new (json_node_buf) ObJsonBoolean(json_datum->get_bool());
|
||||
if (to_bin) {
|
||||
if (OB_FAIL(ObJsonBaseFactory::transform(allocator, bool_node, ObJsonInType::JSON_BIN, j_base))) {
|
||||
LOG_WARN("failed: json tree to bin", K(ret));
|
||||
@ -202,9 +192,8 @@ int ObJsonExprHelper::get_json_val(const ObExpr &expr, ObEvalCtx &ctx,
|
||||
}
|
||||
} else if (ObJsonExprHelper::is_convertible_to_json(val_type)) {
|
||||
ObCollationType cs_type = json_arg->datum_meta_.cs_type_;
|
||||
if (OB_FAIL(ObJsonExprHelper::transform_convertible_2jsonBase(*json_datum, val_type,
|
||||
allocator, cs_type,
|
||||
j_base, to_bin))) {
|
||||
if (OB_FAIL(ObJsonExprHelper::transform_convertible_2jsonBase(
|
||||
*json_datum, val_type, allocator, cs_type, j_base, to_bin))) {
|
||||
LOG_WARN("failed: parse value to jsonBase", K(ret), K(val_type));
|
||||
}
|
||||
} else {
|
||||
@ -213,18 +202,15 @@ int ObJsonExprHelper::get_json_val(const ObExpr &expr, ObEvalCtx &ctx,
|
||||
if (OB_ISNULL(session)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("session is NULL", K(ret));
|
||||
} else if (OB_FAIL(ObJsonExprHelper::transform_scalar_2jsonBase(*json_datum, val_type,
|
||||
allocator, scale,
|
||||
session->get_timezone_info(),
|
||||
j_base, to_bin))) {
|
||||
} else if (OB_FAIL(ObJsonExprHelper::transform_scalar_2jsonBase(
|
||||
*json_datum, val_type, allocator, scale, session->get_timezone_info(), j_base, to_bin))) {
|
||||
LOG_WARN("failed: parse value to jsonBase", K(ret), K(val_type));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObJsonExprHelper::json_base_replace(ObIJsonBase *json_old, ObIJsonBase *json_new,
|
||||
ObIJsonBase *&json_doc)
|
||||
int ObJsonExprHelper::json_base_replace(ObIJsonBase *json_old, ObIJsonBase *json_new, ObIJsonBase *&json_doc)
|
||||
{
|
||||
INIT_SUCC(ret);
|
||||
if (json_old == json_doc) {
|
||||
@ -237,7 +223,7 @@ int ObJsonExprHelper::json_base_replace(ObIJsonBase *json_old, ObIJsonBase *json
|
||||
LOG_WARN("fail to transform to tree", K(ret), K(*json_old));
|
||||
} else {
|
||||
ObIJsonBase *parent = static_cast<ObJsonNode *>(json_old_tree)->get_parent();
|
||||
if(OB_NOT_NULL(parent) && parent != json_doc) {
|
||||
if (OB_NOT_NULL(parent) && parent != json_doc) {
|
||||
if (OB_FAIL(parent->replace(json_old_tree, json_new))) {
|
||||
LOG_WARN("json base replace failed", K(ret));
|
||||
}
|
||||
@ -252,12 +238,12 @@ int ObJsonExprHelper::json_base_replace(ObIJsonBase *json_old, ObIJsonBase *json
|
||||
}
|
||||
|
||||
// get json expr path cache context, if not exists cache context do nothing
|
||||
ObJsonPathCache* ObJsonExprHelper::get_path_cache_ctx(const uint64_t& id, ObExecContext *exec_ctx)
|
||||
ObJsonPathCache *ObJsonExprHelper::get_path_cache_ctx(const uint64_t &id, ObExecContext *exec_ctx)
|
||||
{
|
||||
INIT_SUCC(ret);
|
||||
ObJsonPathCacheCtx* cache_ctx = NULL;
|
||||
ObJsonPathCacheCtx *cache_ctx = NULL;
|
||||
if (ObExpr::INVALID_EXP_CTX_ID != id) {
|
||||
cache_ctx = static_cast<ObJsonPathCacheCtx*>(exec_ctx->get_expr_op_ctx(id));
|
||||
cache_ctx = static_cast<ObJsonPathCacheCtx *>(exec_ctx->get_expr_op_ctx(id));
|
||||
if (OB_ISNULL(cache_ctx)) {
|
||||
// if pathcache not exist, create one
|
||||
void *cache_ctx_buf = NULL;
|
||||
@ -270,8 +256,8 @@ ObJsonPathCache* ObJsonExprHelper::get_path_cache_ctx(const uint64_t& id, ObExec
|
||||
return (cache_ctx == NULL) ? NULL : cache_ctx->get_path_cache();
|
||||
}
|
||||
|
||||
int ObJsonExprHelper::find_and_add_cache(ObJsonPathCache* path_cache, ObJsonPath*& res_path,
|
||||
ObString& path_str, int arg_idx, bool enable_wildcard)
|
||||
int ObJsonExprHelper::find_and_add_cache(
|
||||
ObJsonPathCache *path_cache, ObJsonPath *&res_path, ObString &path_str, int arg_idx, bool enable_wildcard)
|
||||
{
|
||||
INIT_SUCC(ret);
|
||||
if (OB_FAIL(path_cache->find_and_add_cache(res_path, path_str, arg_idx))) {
|
||||
@ -305,9 +291,7 @@ bool ObJsonExprHelper::is_convertible_to_json(ObObjType &type)
|
||||
return val;
|
||||
}
|
||||
|
||||
int ObJsonExprHelper::is_valid_for_json(ObExprResType* types_stack,
|
||||
uint32_t index,
|
||||
const char* func_name)
|
||||
int ObJsonExprHelper::is_valid_for_json(ObExprResType *types_stack, uint32_t index, const char *func_name)
|
||||
{
|
||||
INIT_SUCC(ret);
|
||||
ObObjType in_type = types_stack[index].get_type();
|
||||
@ -315,8 +299,7 @@ int ObJsonExprHelper::is_valid_for_json(ObExprResType* types_stack,
|
||||
if (!is_convertible_to_json(in_type)) {
|
||||
ret = OB_ERR_INVALID_TYPE_FOR_JSON;
|
||||
LOG_USER_ERROR(OB_ERR_INVALID_TYPE_FOR_JSON, index + 1, func_name);
|
||||
} else if (ob_is_string_type(in_type)
|
||||
&& types_stack[index].get_collation_type() != CS_TYPE_BINARY) {
|
||||
} else if (ob_is_string_type(in_type) && types_stack[index].get_collation_type() != CS_TYPE_BINARY) {
|
||||
if (types_stack[index].get_charset_type() != CHARSET_UTF8MB4) {
|
||||
types_stack[index].set_calc_collation_type(CS_TYPE_UTF8MB4_BIN);
|
||||
}
|
||||
@ -325,13 +308,11 @@ int ObJsonExprHelper::is_valid_for_json(ObExprResType* types_stack,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObJsonExprHelper::is_valid_for_json(ObExprResType& type,
|
||||
uint32_t index,
|
||||
const char* func_name)
|
||||
int ObJsonExprHelper::is_valid_for_json(ObExprResType &type, uint32_t index, const char *func_name)
|
||||
{
|
||||
INIT_SUCC(ret);
|
||||
ObObjType in_type = type.get_type();
|
||||
|
||||
|
||||
if (!is_convertible_to_json(in_type)) {
|
||||
ret = OB_ERR_INVALID_TYPE_FOR_JSON;
|
||||
LOG_USER_ERROR(OB_ERR_INVALID_TYPE_FOR_JSON, index, func_name);
|
||||
@ -344,7 +325,7 @@ int ObJsonExprHelper::is_valid_for_json(ObExprResType& type,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObJsonExprHelper::is_valid_for_path(ObExprResType* types_stack, uint32_t index)
|
||||
int ObJsonExprHelper::is_valid_for_path(ObExprResType *types_stack, uint32_t index)
|
||||
{
|
||||
INIT_SUCC(ret);
|
||||
ObObjType in_type = types_stack[index].get_type();
|
||||
@ -360,7 +341,7 @@ int ObJsonExprHelper::is_valid_for_path(ObExprResType* types_stack, uint32_t ind
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ObJsonExprHelper::set_type_for_value(ObExprResType* types_stack, uint32_t index)
|
||||
void ObJsonExprHelper::set_type_for_value(ObExprResType *types_stack, uint32_t index)
|
||||
{
|
||||
ObObjType in_type = types_stack[index].get_type();
|
||||
if (in_type == ObNullType) {
|
||||
@ -368,18 +349,18 @@ void ObJsonExprHelper::set_type_for_value(ObExprResType* types_stack, uint32_t i
|
||||
if (types_stack[index].get_charset_type() != CHARSET_UTF8MB4) {
|
||||
types_stack[index].set_calc_collation_type(CS_TYPE_UTF8MB4_BIN);
|
||||
}
|
||||
} else if (in_type == ObJsonType) {
|
||||
} else if (in_type == ObJsonType) {
|
||||
types_stack[index].set_calc_collation_type(CS_TYPE_UTF8MB4_BIN);
|
||||
}
|
||||
}
|
||||
|
||||
int ObJsonExprHelper::is_json_zero(const ObString& data, int& result)
|
||||
int ObJsonExprHelper::is_json_zero(const ObString &data, int &result)
|
||||
{
|
||||
INIT_SUCC(ret);
|
||||
int tmp_result = 0;
|
||||
ObJsonBin j_bin(data.ptr(), data.length());
|
||||
if (data.length() == 0) {
|
||||
result = 1;
|
||||
result = 1;
|
||||
} else if (OB_FAIL(j_bin.reset_iter())) {
|
||||
LOG_WARN("failed: reset iter", K(ret));
|
||||
} else if (OB_FAIL(ObJsonBaseUtil::compare_int_json(0, &j_bin, tmp_result))) {
|
||||
@ -391,26 +372,21 @@ int ObJsonExprHelper::is_json_zero(const ObString& data, int& result)
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int ObJsonExprHelper::transform_scalar_2jsonBase(const T &datum,
|
||||
ObObjType type,
|
||||
common::ObIAllocator *allocator,
|
||||
ObScale scale,
|
||||
const ObTimeZoneInfo *tz_info,
|
||||
ObIJsonBase*& j_base,
|
||||
bool to_bin)
|
||||
int ObJsonExprHelper::transform_scalar_2jsonBase(const T &datum, ObObjType type, common::ObIAllocator *allocator,
|
||||
ObScale scale, const ObTimeZoneInfo *tz_info, ObIJsonBase *&j_base, bool to_bin)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
void* buf = NULL;
|
||||
ObIJsonBase* json_node = NULL;
|
||||
void *buf = NULL;
|
||||
ObIJsonBase *json_node = NULL;
|
||||
|
||||
switch(type) {
|
||||
switch (type) {
|
||||
case ObTinyIntType: {
|
||||
// mysql boolean type
|
||||
// mysql boolean type
|
||||
buf = allocator->alloc(sizeof(ObJsonInt));
|
||||
if (OB_ISNULL(buf)) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
} else {
|
||||
json_node = (ObJsonInt*)new(buf)ObJsonInt(datum.get_int());
|
||||
json_node = (ObJsonInt *)new (buf) ObJsonInt(datum.get_int());
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -422,7 +398,7 @@ int ObJsonExprHelper::transform_scalar_2jsonBase(const T &datum,
|
||||
if (OB_ISNULL(buf)) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
} else {
|
||||
json_node = (ObJsonInt*)new(buf)ObJsonInt(datum.get_int());
|
||||
json_node = (ObJsonInt *)new (buf) ObJsonInt(datum.get_int());
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -435,7 +411,7 @@ int ObJsonExprHelper::transform_scalar_2jsonBase(const T &datum,
|
||||
if (OB_ISNULL(buf)) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
} else {
|
||||
json_node = (ObJsonInt*)new(buf)ObJsonUint(datum.get_uint64());
|
||||
json_node = (ObJsonInt *)new (buf) ObJsonUint(datum.get_uint64());
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -450,26 +426,22 @@ int ObJsonExprHelper::transform_scalar_2jsonBase(const T &datum,
|
||||
node_type = ObJsonNodeType::J_DATE;
|
||||
value = datum.get_date();
|
||||
ob_time.mode_ = DT_TYPE_DATE;
|
||||
if (OB_FAIL(ObTimeConverter::date_to_ob_time(value, ob_time))) {
|
||||
}
|
||||
if (OB_FAIL(ObTimeConverter::date_to_ob_time(value, ob_time))) {}
|
||||
} else if (type == ObTimeType) {
|
||||
node_type = ObJsonNodeType::J_TIME;
|
||||
value = datum.get_time();
|
||||
ob_time.mode_ = DT_TYPE_TIME;
|
||||
if (OB_FAIL(ObTimeConverter::time_to_ob_time(value, ob_time))) {
|
||||
}
|
||||
if (OB_FAIL(ObTimeConverter::time_to_ob_time(value, ob_time))) {}
|
||||
} else if (type == ObDateTimeType) {
|
||||
node_type = ObJsonNodeType::J_DATETIME;
|
||||
value = datum.get_datetime();
|
||||
ob_time.mode_ = DT_TYPE_DATETIME;
|
||||
if (OB_FAIL(ObTimeConverter::datetime_to_ob_time(value, tz_info, ob_time))) {
|
||||
}
|
||||
if (OB_FAIL(ObTimeConverter::datetime_to_ob_time(value, tz_info, ob_time))) {}
|
||||
} else {
|
||||
node_type = ObJsonNodeType::J_TIMESTAMP;
|
||||
value = datum.get_timestamp();
|
||||
ob_time.mode_ = DT_TYPE_DATETIME;
|
||||
if (OB_FAIL(ObTimeConverter::datetime_to_ob_time(value, tz_info, ob_time))) {
|
||||
}
|
||||
if (OB_FAIL(ObTimeConverter::datetime_to_ob_time(value, tz_info, ob_time))) {}
|
||||
}
|
||||
|
||||
if (OB_SUCC(ret)) {
|
||||
@ -477,7 +449,7 @@ int ObJsonExprHelper::transform_scalar_2jsonBase(const T &datum,
|
||||
if (OB_ISNULL(buf)) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
} else {
|
||||
json_node = (ObJsonDatetime *)new(buf)ObJsonDatetime(node_type, ob_time);
|
||||
json_node = (ObJsonDatetime *)new (buf) ObJsonDatetime(node_type, ob_time);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -491,7 +463,7 @@ int ObJsonExprHelper::transform_scalar_2jsonBase(const T &datum,
|
||||
if (OB_ISNULL(buf)) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
} else {
|
||||
json_node = (ObJsonDouble *)new(buf)ObJsonDouble(datum.get_double());
|
||||
json_node = (ObJsonDouble *)new (buf) ObJsonDouble(datum.get_double());
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -507,7 +479,7 @@ int ObJsonExprHelper::transform_scalar_2jsonBase(const T &datum,
|
||||
;
|
||||
} else {
|
||||
// shadow copy
|
||||
json_node = (ObJsonDecimal *)new(buf)ObJsonDecimal(num, -1, scale);
|
||||
json_node = (ObJsonDecimal *)new (buf) ObJsonDecimal(num, -1, scale);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -516,12 +488,11 @@ int ObJsonExprHelper::transform_scalar_2jsonBase(const T &datum,
|
||||
if (OB_ISNULL(buf)) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
} else {
|
||||
json_node = (ObJsonOpaque *)new(buf)ObJsonOpaque(datum.get_string(), type);
|
||||
json_node = (ObJsonOpaque *)new (buf) ObJsonOpaque(datum.get_string(), type);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
default: {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
}
|
||||
}
|
||||
@ -540,32 +511,27 @@ int ObJsonExprHelper::transform_scalar_2jsonBase(const T &datum,
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int ObJsonExprHelper::transform_convertible_2jsonBase(const T &datum,
|
||||
ObObjType type,
|
||||
common::ObIAllocator *allocator,
|
||||
ObCollationType cs_type,
|
||||
ObIJsonBase*& j_base,
|
||||
bool to_bin,
|
||||
bool deep_copy)
|
||||
int ObJsonExprHelper::transform_convertible_2jsonBase(const T &datum, ObObjType type, common::ObIAllocator *allocator,
|
||||
ObCollationType cs_type, ObIJsonBase *&j_base, bool to_bin, bool deep_copy)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
void* buf = NULL;
|
||||
ObIJsonBase* json_node = NULL;
|
||||
void *buf = NULL;
|
||||
ObIJsonBase *json_node = NULL;
|
||||
|
||||
switch(type) {
|
||||
switch (type) {
|
||||
case ObNullType: {
|
||||
buf = allocator->alloc(sizeof(ObJsonNull));
|
||||
if (OB_ISNULL(buf)) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
} else {
|
||||
json_node = (ObJsonNull*)new(buf)ObJsonNull();
|
||||
json_node = (ObJsonNull *)new (buf) ObJsonNull();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ObVarcharType:
|
||||
case ObCharType:
|
||||
case ObTinyTextType:
|
||||
case ObTextType :
|
||||
case ObTextType:
|
||||
case ObMediumTextType:
|
||||
case ObLongTextType: {
|
||||
ObString value;
|
||||
@ -585,7 +551,7 @@ int ObJsonExprHelper::transform_convertible_2jsonBase(const T &datum,
|
||||
if (OB_ISNULL(buf)) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
} else {
|
||||
json_node = (ObJsonString*)new(buf)ObJsonString(ptr, len);
|
||||
json_node = (ObJsonString *)new (buf) ObJsonString(ptr, len);
|
||||
}
|
||||
}
|
||||
|
||||
@ -594,23 +560,20 @@ int ObJsonExprHelper::transform_convertible_2jsonBase(const T &datum,
|
||||
case ObJsonType: {
|
||||
ObString value;
|
||||
if (deep_copy) {
|
||||
if (OB_FAIL(deep_copy_ob_string(*allocator, datum.get_string(), value))) {
|
||||
}
|
||||
if (OB_FAIL(deep_copy_ob_string(*allocator, datum.get_string(), value))) {}
|
||||
} else {
|
||||
value = datum.get_string();
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
ObJsonInType to_type = to_bin ? ObJsonInType::JSON_BIN : ObJsonInType::JSON_TREE;
|
||||
if (OB_FAIL(ObJsonBaseFactory::get_json_base(allocator, value, ObJsonInType::JSON_BIN,
|
||||
to_type, json_node))) {
|
||||
if (OB_FAIL(ObJsonBaseFactory::get_json_base(allocator, value, ObJsonInType::JSON_BIN, to_type, json_node))) {
|
||||
ret = OB_ERR_INVALID_JSON_TEXT_IN_PARAM;
|
||||
LOG_WARN("fail to get json base", K(ret));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
default: {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
}
|
||||
}
|
||||
@ -628,5 +591,5 @@ int ObJsonExprHelper::transform_convertible_2jsonBase(const T &datum,
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace sql
|
||||
} // namespace oceanbase
|
||||
|
||||
Reference in New Issue
Block a user