fix print issue when string array contains quote and unsigned bugs of array types

This commit is contained in:
qijiax 2024-12-03 11:15:18 +00:00 committed by ob-robot
parent e7fca2c311
commit d267a08d40
6 changed files with 55 additions and 7 deletions

View File

@ -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));
}

View File

@ -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,

View File

@ -130,7 +130,7 @@ public :
} else if (static_cast<ObObjType>(src_array.get_element_type()) == ObUSmallIntType) {
FIXED_ARRAY_OBJ_CLONE_EXCEPT(uint16_t);
} else if (static_cast<ObObjType>(src_array.get_element_type()) == ObUInt64Type) {
FIXED_ARRAY_OBJ_CLONE_EXCEPT(int64_t);
FIXED_ARRAY_OBJ_CLONE_EXCEPT(uint64_t);
} else if (static_cast<ObObjType>(src_array.get_element_type()) == ObUInt32Type) {
FIXED_ARRAY_OBJ_CLONE_EXCEPT(uint32_t);
} else if (static_cast<ObObjType>(src_array.get_element_type()) == ObFloatType) {

View File

@ -122,7 +122,7 @@ int ObArrayCastUtils::cast_get_element(ObIArrayType *src, const ObCollectionBasi
break;
}
case ObUInt32Type: {
ObArrayFixedSize<int32_t> *arr = static_cast<ObArrayFixedSize<int32_t> *>(src);
ObArrayFixedSize<uint32_t> *arr = static_cast<ObArrayFixedSize<uint32_t> *>(src);
src_elem.set_uint32((*arr)[idx]);
break;
}

View File

@ -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;

View File

@ -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);