diff --git a/deps/oblib/src/lib/udt/ob_array_type.cpp b/deps/oblib/src/lib/udt/ob_array_type.cpp index 195adbc26..a35243fa5 100644 --- a/deps/oblib/src/lib/udt/ob_array_type.cpp +++ b/deps/oblib/src/lib/udt/ob_array_type.cpp @@ -769,6 +769,26 @@ int ObArrayBinary::push_null() return ret; } +int ObArrayBinary::escape_append(ObStringBuffer &format_str, ObString elem_str) +{ + int ret = OB_SUCCESS; + ObString split_str = elem_str.split_on('\"'); + if (OB_ISNULL(split_str.ptr())) { + if (OB_FAIL(format_str.append(elem_str))) { + OB_LOG(WARN, "fail to append string to format_str", K(ret)); + } + } else { + if (OB_FAIL(format_str.append(split_str))) { + OB_LOG(WARN, "fail to append string to format_str", K(ret)); + } else if (OB_FAIL(format_str.append("\\\""))) { + OB_LOG(WARN, "fail to append \\\" to format_str", K(ret)); + } else if (!elem_str.empty()) { + ret = escape_append(format_str, elem_str); + } + } + return ret; +} + int ObArrayBinary::print(const ObCollectionTypeBase *elem_type, ObStringBuffer &format_str, uint32_t begin, uint32_t print_size) const { int ret = OB_SUCCESS; @@ -790,8 +810,8 @@ int ObArrayBinary::print(const ObCollectionTypeBase *elem_type, ObStringBuffer & } } else if (OB_FAIL(format_str.append("\""))) { OB_LOG(WARN, "fail to append \"\"\" to buffer", K(ret)); - } else if (OB_FAIL(format_str.append((*this)[i]))) { - OB_LOG(WARN, "fail to append string to format_str", K(ret)); + } else if (OB_FAIL(escape_append(format_str, (*this)[i]))) { + OB_LOG(WARN, "fail to escape_append string to format_str", K(ret)); } else if (OB_FAIL(format_str.append("\""))) { OB_LOG(WARN, "fail to append \"\"\" to buffer", K(ret)); } diff --git a/deps/oblib/src/lib/udt/ob_array_type.h b/deps/oblib/src/lib/udt/ob_array_type.h index 9645e15de..2c4000166 100644 --- a/deps/oblib/src/lib/udt/ob_array_type.h +++ b/deps/oblib/src/lib/udt/ob_array_type.h @@ -924,6 +924,7 @@ public : char *get_data() const { return data_;} int push_back(const ObString &value, bool is_null = false); void set_scale(ObScale scale) { UNUSED(scale); } + int static escape_append(ObStringBuffer &format_str, ObString elem_str); int print(const ObCollectionTypeBase *elem_type, ObStringBuffer &format_str, uint32_t begin = 0, uint32_t print_size = 0) const; int print_element(const ObCollectionTypeBase *elem_type, ObStringBuffer &format_str, diff --git a/deps/oblib/src/lib/udt/ob_array_utils.h b/deps/oblib/src/lib/udt/ob_array_utils.h index dcf9242ab..467da74f5 100644 --- a/deps/oblib/src/lib/udt/ob_array_utils.h +++ b/deps/oblib/src/lib/udt/ob_array_utils.h @@ -130,7 +130,7 @@ public : } else if (static_cast(src_array.get_element_type()) == ObUSmallIntType) { FIXED_ARRAY_OBJ_CLONE_EXCEPT(uint16_t); } else if (static_cast(src_array.get_element_type()) == ObUInt64Type) { - FIXED_ARRAY_OBJ_CLONE_EXCEPT(int64_t); + FIXED_ARRAY_OBJ_CLONE_EXCEPT(uint64_t); } else if (static_cast(src_array.get_element_type()) == ObUInt32Type) { FIXED_ARRAY_OBJ_CLONE_EXCEPT(uint32_t); } else if (static_cast(src_array.get_element_type()) == ObFloatType) { diff --git a/src/sql/engine/expr/ob_array_cast.cpp b/src/sql/engine/expr/ob_array_cast.cpp index 073b9e043..4ef366004 100644 --- a/src/sql/engine/expr/ob_array_cast.cpp +++ b/src/sql/engine/expr/ob_array_cast.cpp @@ -122,7 +122,7 @@ int ObArrayCastUtils::cast_get_element(ObIArrayType *src, const ObCollectionBasi break; } case ObUInt32Type: { - ObArrayFixedSize *arr = static_cast *>(src); + ObArrayFixedSize *arr = static_cast *>(src); src_elem.set_uint32((*arr)[idx]); break; } diff --git a/src/sql/engine/expr/ob_expr_array_remove.cpp b/src/sql/engine/expr/ob_expr_array_remove.cpp index aaf9225c0..a22ce6b74 100644 --- a/src/sql/engine/expr/ob_expr_array_remove.cpp +++ b/src/sql/engine/expr/ob_expr_array_remove.cpp @@ -577,6 +577,7 @@ int ObExprArrayRemove::cg_expr(ObExprCGCtx &expr_cg_ctx, if OB_SUCC(ret) { switch (right_tc) { case ObIntTC: + case ObUIntTC: rt_expr.eval_func_ = eval_array_remove_int64_t; rt_expr.eval_batch_func_ = eval_array_remove_batch_int64_t; rt_expr.eval_vector_func_ = eval_array_remove_vector_int64_t; diff --git a/src/sql/resolver/expr/ob_raw_expr_deduce_type.cpp b/src/sql/resolver/expr/ob_raw_expr_deduce_type.cpp index cf649b8a3..e4ce606b3 100644 --- a/src/sql/resolver/expr/ob_raw_expr_deduce_type.cpp +++ b/src/sql/resolver/expr/ob_raw_expr_deduce_type.cpp @@ -3765,9 +3765,35 @@ int ObRawExprDeduceType::set_array_agg_result_type(ObAggFunRawExpr &expr, if (OB_FAIL(ObArrayExprUtils::deduce_nested_array_subschema_id(exec_ctx, elem_type, subschema_id))) { LOG_WARN("failed to deduce nested array subschema id", K(ret)); } - } else if (OB_FAIL(exec_ctx->get_subschema_id_by_collection_elem_type(ObNestedType::OB_ARRAY_TYPE, - elem_type, subschema_id))) { - LOG_WARN("failed to get collection subschema id", K(ret)); + } else { + if (!ob_is_array_supported_type(elem_type.get_obj_type())) { + ret = OB_NOT_SUPPORTED; + LOG_WARN("unsupported element type", K(ret), K(elem_type.get_obj_type())); + LOG_USER_ERROR(OB_NOT_SUPPORTED, "array element type"); + } else if (elem_type.get_obj_type() == ObDecimalIntType) { + ObObjMeta meta; + if (param_expr->get_scale() != 0) { + meta.set_double(); + } else { + meta.set_int(); + } + ObAccuracy acc = ObAccuracy::DDL_DEFAULT_ACCURACY[meta.get_type()]; + elem_type.set_meta_type(meta); + elem_type.set_accuracy(acc); + ObExprResType param_res_type = param_expr->get_result_type(); + param_res_type.set_calc_meta(meta); + param_res_type.set_calc_accuracy(acc); + ObCastMode def_cast_mode = CM_NONE; + if (OB_FAIL(ObSQLUtils::get_default_cast_mode(false, 0, my_session_, def_cast_mode))) { + LOG_WARN("get_default_cast_mode failed", K(ret)); + } else if (OB_FAIL(try_add_cast_expr(expr, 0, param_res_type, def_cast_mode))) { + LOG_WARN("try_add_cast_expr failed", K(ret), K(expr), K(param_res_type)); + } + } + if (OB_SUCC(ret) && OB_FAIL(exec_ctx->get_subschema_id_by_collection_elem_type(ObNestedType::OB_ARRAY_TYPE, + elem_type, subschema_id))) { + LOG_WARN("failed to get collection subschema id", K(ret)); + } } if (OB_SUCC(ret)) { result_type.set_collection(subschema_id);