From b96d7663b585d774ffe9391be9924674fbaa869f Mon Sep 17 00:00:00 2001 From: obdev Date: Wed, 20 Jul 2022 11:33:11 +0800 Subject: [PATCH] [CP] JSON bug fix --- src/sql/engine/aggregate/ob_aggregate_processor.cpp | 5 ++++- src/sql/engine/expr/ob_datum_cast.cpp | 3 ++- src/sql/engine/expr/ob_expr_cast.cpp | 3 ++- src/sql/engine/expr/ob_expr_merge_result_type.map | 8 ++++---- src/sql/engine/expr/ob_expr_relational_cmp_type.map | 4 ++-- src/sql/resolver/expr/ob_raw_expr_wrap_enum_set.cpp | 6 ++++-- 6 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/sql/engine/aggregate/ob_aggregate_processor.cpp b/src/sql/engine/aggregate/ob_aggregate_processor.cpp index 014ed10a8e..165885daa4 100644 --- a/src/sql/engine/aggregate/ob_aggregate_processor.cpp +++ b/src/sql/engine/aggregate/ob_aggregate_processor.cpp @@ -3340,7 +3340,7 @@ int ObAggregateProcessor::get_json_arrayagg_result(const ObAggrInfo &aggr_info, ObString origin_str = converted_datum.get_string(); ObString converted_str; if (OB_FAIL(ObExprUtil::convert_string_collation(origin_str, cs_type, converted_str, - CS_TYPE_UTF8MB4_BIN, tmp_alloc))) { + CS_TYPE_UTF8MB4_BIN, tmp_alloc))) { LOG_WARN("convert string collation failed", K(ret), K(cs_type), K(origin_str.length())); } else { converted_datum.set_string(converted_str); @@ -3445,6 +3445,9 @@ int ObAggregateProcessor::get_json_objectagg_result(const ObAggrInfo &aggr_info, K(tmp_obj[0].get_type()), K(tmp_obj[0].get_collation_type())); ret = OB_ERR_INVALID_JSON_CHARSET; LOG_USER_ERROR(OB_ERR_INVALID_JSON_CHARSET); + } else if (NULL == tmp_obj[0].get_string_ptr()) { + ret = OB_ERR_NULL_VALUE; + LOG_WARN("unexpected null result", K(ret), K(tmp_obj[0])); } else { ObObjType val_type0 = tmp_obj[0].get_type(); ObCollationType cs_type0 = tmp_obj[0].get_collation_type(); diff --git a/src/sql/engine/expr/ob_datum_cast.cpp b/src/sql/engine/expr/ob_datum_cast.cpp index 36ecbbef6f..d1401bc6a1 100644 --- a/src/sql/engine/expr/ob_datum_cast.cpp +++ b/src/sql/engine/expr/ob_datum_cast.cpp @@ -2215,7 +2215,8 @@ static int common_string_json(const ObExpr &expr, if (is_need_charset_convert == false) { j_text.assign_ptr(in_str.ptr(), in_str.length()); } - bool is_enumset_to_str = (expr.args_[0]->type_ == T_FUN_SET_TO_STR); + bool is_enumset_to_str = ((expr.args_[0]->type_ == T_FUN_SET_TO_STR) + || (expr.args_[0]->type_ == T_FUN_ENUM_TO_STR)); ObIJsonBase *j_base = NULL; ObJsonOpaque j_opaque(j_text, in_type); ObJsonString j_string(j_text.ptr(), j_text.length()); diff --git a/src/sql/engine/expr/ob_expr_cast.cpp b/src/sql/engine/expr/ob_expr_cast.cpp index ed2911f9c1..82222f5b71 100644 --- a/src/sql/engine/expr/ob_expr_cast.cpp +++ b/src/sql/engine/expr/ob_expr_cast.cpp @@ -574,7 +574,8 @@ int ObExprCast::calc_result2(ObObj& result, const ObObj& obj1, const ObObj& obj2 if (OB_SUCC(ret)) { if (is_bool) { ret = ObObjCaster::bool_to_json(dest_type, cast_ctx, obj1_round, buf_obj1, res_obj); - } else if (OB_UNLIKELY(item_type_obj1 == T_FUN_SET_TO_STR)) { + } else if (OB_UNLIKELY(item_type_obj1 == T_FUN_SET_TO_STR) + || OB_UNLIKELY(item_type_obj1 == T_FUN_ENUM_TO_STR)) { ret = ObObjCaster::enumset_to_json(dest_type, cast_ctx, obj1_round, buf_obj1, res_obj); } else { ret = ObObjCaster::to_type(dest_type, cast_ctx, obj1_round, buf_obj1, res_obj); diff --git a/src/sql/engine/expr/ob_expr_merge_result_type.map b/src/sql/engine/expr/ob_expr_merge_result_type.map index a2c8590014..547a234b59 100644 --- a/src/sql/engine/expr/ob_expr_merge_result_type.map +++ b/src/sql/engine/expr/ob_expr_merge_result_type.map @@ -1707,7 +1707,7 @@ static ObObjType MERGE_RESULT_TYPE[ObMaxType][ObMaxType] = { ObNCharType, /*ObEnumType=>ObNCharType */ ObMaxType, /*ObEnumType=>URowID*/ ObMaxType, /*ObEnumType=>ObLobType*/ - ObMaxType, /*ObEnumType=>ObJsonType*/ + ObVarcharType, /*ObEnumType=>ObJsonType*/ }, /*ObSetType*/ { @@ -1758,7 +1758,7 @@ static ObObjType MERGE_RESULT_TYPE[ObMaxType][ObMaxType] = { ObNCharType, /*ObSetType=>ObNCharType */ ObMaxType, /*ObSetType=>URowID*/ ObMaxType, /*ObSetType=>ObLobType*/ - ObMaxType, /*ObSetType=>ObJsonType*/ + ObVarcharType, /*ObSetType=>ObJsonType*/ }, /*ObEnumInnerType*/ { @@ -2458,8 +2458,8 @@ static ObObjType MERGE_RESULT_TYPE[ObMaxType][ObMaxType] = { ObJsonType, /* ObJsonType=>ObMediumTextType */ ObJsonType, /* ObJsonType=>ObLongTextType */ ObJsonType, /* ObJsonType=>ObBitType */ - ObMaxType, /* ObJsonType=>ObEnumType */ - ObMaxType, /* ObJsonType=>ObSetType */ + ObVarcharType, /* ObJsonType=>ObEnumType */ + ObVarcharType, /* ObJsonType=>ObSetType */ ObMaxType, /* ObJsonType=>ObEnumInnerType */ ObMaxType, /* ObJsonType=>ObSetInnerType */ ObMaxType, /* ObJsonType=>ObTimestampTZType */ diff --git a/src/sql/engine/expr/ob_expr_relational_cmp_type.map b/src/sql/engine/expr/ob_expr_relational_cmp_type.map index 776e58a025..a5ddbd6e51 100644 --- a/src/sql/engine/expr/ob_expr_relational_cmp_type.map +++ b/src/sql/engine/expr/ob_expr_relational_cmp_type.map @@ -1728,7 +1728,7 @@ static ObObjType RELATIONAL_CMP_TYPE[ObMaxType][ObMaxType] = ObNumberType, /* ObNCharType */ ObNullType, /* ObURowIDType */ ObNullType, /* ObLobType */ - ObMaxType, /* ObJsonType */ + ObNumberType, /* ObJsonType */ }, /*SetType*/ { @@ -2479,7 +2479,7 @@ static ObObjType RELATIONAL_CMP_TYPE[ObMaxType][ObMaxType] = ObJsonType, /*MediumTextType*/ ObJsonType, /*LongTextType*/ ObJsonType, /*BitType*/ - ObMaxType, /* EnumType */ + ObNumberType, /* EnumType */ ObNumberType, /* SetType */ ObMaxType, /* EnumInnerType */ ObMaxType, /* SetInnerType */ diff --git a/src/sql/resolver/expr/ob_raw_expr_wrap_enum_set.cpp b/src/sql/resolver/expr/ob_raw_expr_wrap_enum_set.cpp index af9270fc33..8a9fa2b997 100644 --- a/src/sql/resolver/expr/ob_raw_expr_wrap_enum_set.cpp +++ b/src/sql/resolver/expr/ob_raw_expr_wrap_enum_set.cpp @@ -679,8 +679,10 @@ int ObRawExprWrapEnumSet::visit(ObAggFunRawExpr& expr) int ret = OB_SUCCESS; if (expr.has_enum_set_column() && (T_FUN_GROUP_CONCAT == expr.get_expr_type() || T_FUN_MAX == expr.get_expr_type() || - T_FUN_MIN == expr.get_expr_type())) { - const ObIArray& real_parm_exprs = expr.get_real_param_exprs(); + T_FUN_MIN == expr.get_expr_type() || + T_FUN_JSON_OBJECTAGG == expr.get_expr_type() || + T_FUN_JSON_ARRAYAGG == expr.get_expr_type())) { + const ObIArray &real_parm_exprs = expr.get_real_param_exprs(); const bool is_same_need = false; for (int64_t i = 0; OB_SUCC(ret) && i < real_parm_exprs.count(); ++i) { ObRawExpr* real_param_expr = real_parm_exprs.at(i);