From 63157365a42826c1a6076236491a4e92cdc32be9 Mon Sep 17 00:00:00 2001 From: helloamateur Date: Thu, 28 Nov 2024 07:14:44 +0000 Subject: [PATCH] [ARRAY] fix case_when with array type_deduce bug --- deps/oblib/src/lib/udt/ob_array_type.h | 1 + src/sql/engine/expr/ob_expr_operator.cpp | 24 ++++++++++++++++++------ src/sql/engine/expr/ob_expr_operator.h | 1 + 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/deps/oblib/src/lib/udt/ob_array_type.h b/deps/oblib/src/lib/udt/ob_array_type.h index a6dfc7888..c1eb3638c 100644 --- a/deps/oblib/src/lib/udt/ob_array_type.h +++ b/deps/oblib/src/lib/udt/ob_array_type.h @@ -817,6 +817,7 @@ public : uint32_t cardinality() const { return this->length_; } ArrayFormat get_format() const { return ArrayFormat::Vector; } int push_back(float value); + bool is_null(uint32_t idx) const { return false; } void set_scale(ObScale scale) { UNUSED(scale); } int print(const ObCollectionTypeBase *elem_type, ObStringBuffer &format_str, uint32_t begin = 0, uint32_t print_size = 0) const; diff --git a/src/sql/engine/expr/ob_expr_operator.cpp b/src/sql/engine/expr/ob_expr_operator.cpp index 1adb71b3c..e4d1df5bc 100644 --- a/src/sql/engine/expr/ob_expr_operator.cpp +++ b/src/sql/engine/expr/ob_expr_operator.cpp @@ -1407,7 +1407,7 @@ int ObExprOperator::aggregate_result_type_for_merge( LOG_WARN("aggregate_user_defined_sql_type fail", K(ret)); } } else if (ob_is_collection_sql_type(res_type)) { - if (OB_FAIL(aggregate_collection_sql_type(type, types, param_num))) { + if (OB_FAIL(aggregate_collection_sql_type(type_ctx, type, types, param_num))) { LOG_WARN("aggregate_collection_sql_type fail", K(ret)); } } @@ -1757,6 +1757,7 @@ int ObExprOperator::aggregate_user_defined_sql_type( } int ObExprOperator::aggregate_collection_sql_type( + common::ObExprTypeCtx &type_ctx, ObExprResType &type, const ObExprResType *types, int64_t param_num) @@ -1766,12 +1767,23 @@ int ObExprOperator::aggregate_collection_sql_type( ret = OB_ERR_UNEXPECTED; LOG_WARN("types is null or param_num is wrong", K(types), K(param_num), K(ret)); } else { - bool found = false; - for (int64_t i = 0; ! found && i < param_num && OB_SUCC(ret); ++i) { + ObSQLSessionInfo *session = const_cast(type_ctx.get_session()); + ObExecContext *exec_ctx = session->get_cur_exec_ctx(); + bool first = true; + for (int64_t i = 0; i < param_num && OB_SUCC(ret); ++i) { if (ob_is_collection_sql_type(types[i].get_type())) { - found = true; - // choose the first collection subschema id now - type.set_subschema_id(types[i].get_subschema_id()); + if (first) { + // choose the first collection subschema id now + type.set_subschema_id(types[i].get_subschema_id()); + first = false; + } else { + ObExprResType coll_calc_type; + if (OB_FAIL(ObExprResultTypeUtil::get_array_calc_type(exec_ctx, type, types[i], coll_calc_type))) { + LOG_WARN("failed to check array compatibilty", K(ret)); + } else { + type.set_subschema_id(coll_calc_type.get_subschema_id()); + } + } } } } diff --git a/src/sql/engine/expr/ob_expr_operator.h b/src/sql/engine/expr/ob_expr_operator.h index 7912165b2..773641b93 100644 --- a/src/sql/engine/expr/ob_expr_operator.h +++ b/src/sql/engine/expr/ob_expr_operator.h @@ -661,6 +661,7 @@ public: const ObExprResType *types, int64_t param_num); static int aggregate_collection_sql_type( + common::ObExprTypeCtx &type_ctx, ObExprResType &type, const ObExprResType *types, int64_t param_num);