This is an automated email from the ASF dual-hosted git repository. panxiaolei pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new 349f51ce5e0 [Chore](execution) remove unused function get_least_supertype (#36743) 349f51ce5e0 is described below commit 349f51ce5e058f33d9191a6933b703f97bd46a46 Author: Pxl <pxl...@qq.com> AuthorDate: Wed Jun 26 12:41:56 2024 +0800 [Chore](execution) remove unused function get_least_supertype (#36743) ## Proposed changes remove unused function get_least_supertype --- be/src/vec/columns/column_object.cpp | 18 +- be/src/vec/common/schema_util.cpp | 24 +- be/src/vec/common/schema_util.h | 3 - be/src/vec/data_types/get_least_supertype.cpp | 368 ++++---------------------- be/src/vec/data_types/get_least_supertype.h | 27 +- be/src/vec/functions/function_map.cpp | 19 +- be/test/vec/core/get_common_type_test.cpp | 4 +- 7 files changed, 64 insertions(+), 399 deletions(-) diff --git a/be/src/vec/columns/column_object.cpp b/be/src/vec/columns/column_object.cpp index 3a16db82263..043c442e275 100644 --- a/be/src/vec/columns/column_object.cpp +++ b/be/src/vec/columns/column_object.cpp @@ -269,7 +269,7 @@ public: } void get_scalar_type(TypeIndex* type) const { DataTypePtr data_type; - get_least_supertype<LeastSupertypeOnError::Jsonb>(type_indexes, &data_type); + get_least_supertype_jsonb(type_indexes, &data_type); *type = data_type->get_type_id(); } bool contain_nulls() const { return have_nulls; } @@ -389,7 +389,7 @@ void ColumnObject::Subcolumn::insert(Field field, FieldInfo info) { << getTypeName(least_common_type.get_type_id()); DataTypePtr base_data_type; TypeIndex base_data_type_id; - get_least_supertype<LeastSupertypeOnError::Jsonb>( + get_least_supertype_jsonb( TypeIndexSet {base_type.idx, least_common_type.get_base_type_id()}, &base_data_type); type_changed = true; @@ -421,9 +421,8 @@ void ColumnObject::Subcolumn::insertRangeFrom(const Subcolumn& src, size_t start add_new_column_part(src.get_least_common_type()); } else if (!least_common_type.get()->equals(*src.get_least_common_type())) { DataTypePtr new_least_common_type; - get_least_supertype<LeastSupertypeOnError::Jsonb>( - DataTypes {least_common_type.get(), src.get_least_common_type()}, - &new_least_common_type); + get_least_supertype_jsonb(DataTypes {least_common_type.get(), src.get_least_common_type()}, + &new_least_common_type); if (!new_least_common_type->equals(*least_common_type.get())) { add_new_column_part(std::move(new_least_common_type)); } @@ -450,8 +449,7 @@ void ColumnObject::Subcolumn::insertRangeFrom(const Subcolumn& src, size_t start Status st = schema_util::cast_column({column, column_type, ""}, least_common_type.get(), &casted_column); if (!st.ok()) { - throw doris::Exception(ErrorCode::INVALID_ARGUMENT, - st.to_string() + ", real_code:{}", st.code()); + throw doris::Exception(ErrorCode::INVALID_ARGUMENT, st.to_string()); } data.back()->insert_range_from(*casted_column, from, n); return; @@ -460,8 +458,7 @@ void ColumnObject::Subcolumn::insertRangeFrom(const Subcolumn& src, size_t start Status st = schema_util::cast_column({casted_column, column_type, ""}, least_common_type.get(), &casted_column); if (!st.ok()) { - throw doris::Exception(ErrorCode::INVALID_ARGUMENT, st.to_string() + ", real_code:{}", - st.code()); + throw doris::Exception(ErrorCode::INVALID_ARGUMENT, st.to_string()); } data.back()->insert_range_from(*casted_column, 0, n); }; @@ -554,8 +551,7 @@ void ColumnObject::Subcolumn::finalize() { ColumnPtr ptr; Status st = schema_util::cast_column({part, from_type, ""}, to_type, &ptr); if (!st.ok()) { - throw doris::Exception(ErrorCode::INVALID_ARGUMENT, - st.to_string() + ", real_code:{}", st.code()); + throw doris::Exception(ErrorCode::INVALID_ARGUMENT, st.to_string()); } part = ptr->convert_to_full_column_if_const(); } diff --git a/be/src/vec/common/schema_util.cpp b/be/src/vec/common/schema_util.cpp index 9f3975576df..bbb4be93096 100644 --- a/be/src/vec/common/schema_util.cpp +++ b/be/src/vec/common/schema_util.cpp @@ -236,28 +236,6 @@ TabletColumn get_column_by_type(const vectorized::DataTypePtr& data_type, const return result; } -TabletColumn get_least_type_column(const TabletColumn& original, const DataTypePtr& new_type, - const ExtraInfo& ext_info, bool* changed) { - TabletColumn result_column; - vectorized::DataTypePtr original_type = original.get_vec_type(); - vectorized::DataTypePtr common_type; - vectorized::get_least_supertype<vectorized::LeastSupertypeOnError::Jsonb>( - vectorized::DataTypes {original_type, new_type}, &common_type); - if (!original_type->equals(*common_type)) { - // update to common type - *changed = true; - vectorized::schema_util::get_column_by_type(common_type, original.name(), result_column, - ext_info); - } else { - *changed = false; - result_column = original; - result_column.set_parent_unique_id(ext_info.parent_unique_id); - result_column.set_unique_id(ext_info.unique_id); - result_column.set_path_info(ext_info.path_info); - } - return result_column; -} - void update_least_schema_internal(const std::map<PathInData, DataTypes>& subcolumns_types, TabletSchemaSPtr& common_schema, bool update_sparse_column, int32_t variant_col_unique_id, @@ -286,7 +264,7 @@ void update_least_schema_internal(const std::map<PathInData, DataTypes>& subcolu continue; } DataTypePtr common_type; - get_least_supertype<LeastSupertypeOnError::Jsonb>(subtypes, &common_type); + get_least_supertype_jsonb(subtypes, &common_type); if (!common_type->is_nullable()) { common_type = make_nullable(common_type); } diff --git a/be/src/vec/common/schema_util.h b/be/src/vec/common/schema_util.h index f519e4dacae..4c04f2f8334 100644 --- a/be/src/vec/common/schema_util.h +++ b/be/src/vec/common/schema_util.h @@ -79,9 +79,6 @@ struct ExtraInfo { TabletColumn get_column_by_type(const vectorized::DataTypePtr& data_type, const std::string& name, const ExtraInfo& ext_info); -TabletColumn get_least_type_column(const TabletColumn& original, const DataTypePtr& new_type, - const ExtraInfo& ext_info, bool* changed); - struct ParseContext { // record an extract json column, used for encoding row store bool record_raw_json_column = false; diff --git a/be/src/vec/data_types/get_least_supertype.cpp b/be/src/vec/data_types/get_least_supertype.cpp index 8d5662b9bed..97ff3f77f23 100644 --- a/be/src/vec/data_types/get_least_supertype.cpp +++ b/be/src/vec/data_types/get_least_supertype.cpp @@ -20,13 +20,7 @@ #include "vec/data_types/get_least_supertype.h" -#include <fmt/core.h> -#include <fmt/format.h> -#include <glog/logging.h> -#include <stddef.h> - #include <algorithm> -#include <boost/iterator/iterator_facade.hpp> #include <memory> #include <ostream> #include <string> @@ -48,49 +42,6 @@ namespace doris::vectorized { -namespace { - -String type_to_string(const DataTypePtr& type) { - return type->get_name(); -} -String type_to_string(const TypeIndex& type) { - return getTypeName(type); -} - -template <typename DataTypes> -String get_exception_message_prefix(const DataTypes& types) { - std::stringstream res; - res << "There is no supertype for types "; - bool first = true; - for (const auto& type : types) { - if (!first) res << ", "; - first = false; - res << type_to_string(type); - } - return res.str(); -} - -template <LeastSupertypeOnError on_error, typename DataTypes> -void throw_or_return(const DataTypes& types, int error_code, std::string_view message_suffix, - DataTypePtr* expected) { - if constexpr (on_error == LeastSupertypeOnError::String) { - *expected = std::make_shared<DataTypeString>(); - return; - } - if constexpr (on_error == LeastSupertypeOnError::Jsonb) { - *expected = std::make_shared<DataTypeJsonb>(); - return; - } - if constexpr (on_error == LeastSupertypeOnError::Null) { - *expected = nullptr; - } - throw doris::Exception(error_code, "There is no supertype for types {} {}", - get_exception_message_prefix(types), message_suffix); -} - -} // namespace - -template <LeastSupertypeOnError on_error> void get_numeric_type(const TypeIndexSet& types, DataTypePtr* type) { bool all_numbers = true; @@ -99,43 +50,46 @@ void get_numeric_type(const TypeIndexSet& types, DataTypePtr* type) { size_t max_mantissa_bits_of_floating = 0; auto maximize = [](size_t& what, size_t value) { - if (value > what) what = value; + if (value > what) { + what = value; + } }; for (const auto& type : types) { - if (type == TypeIndex::UInt8) + if (type == TypeIndex::UInt8) { maximize(max_bits_of_unsigned_integer, 8); - else if (type == TypeIndex::UInt16) + } else if (type == TypeIndex::UInt16) { maximize(max_bits_of_unsigned_integer, 16); - else if (type == TypeIndex::UInt32) + } else if (type == TypeIndex::UInt32) { maximize(max_bits_of_unsigned_integer, 32); - else if (type == TypeIndex::UInt64) + } else if (type == TypeIndex::UInt64) { maximize(max_bits_of_unsigned_integer, 64); - else if (type == TypeIndex::UInt128) + } else if (type == TypeIndex::UInt128) { maximize(max_bits_of_unsigned_integer, 128); - else if (type == TypeIndex::Int8 || type == TypeIndex::Enum8) + } else if (type == TypeIndex::Int8 || type == TypeIndex::Enum8) { maximize(max_bits_of_signed_integer, 8); - else if (type == TypeIndex::Int16 || type == TypeIndex::Enum16) + } else if (type == TypeIndex::Int16 || type == TypeIndex::Enum16) { maximize(max_bits_of_signed_integer, 16); - else if (type == TypeIndex::Int32) + } else if (type == TypeIndex::Int32) { maximize(max_bits_of_signed_integer, 32); - else if (type == TypeIndex::Int64) + } else if (type == TypeIndex::Int64) { maximize(max_bits_of_signed_integer, 64); - else if (type == TypeIndex::Int128) + } else if (type == TypeIndex::Int128) { maximize(max_bits_of_signed_integer, 128); - else if (type == TypeIndex::Float32) + } else if (type == TypeIndex::Float32) { maximize(max_mantissa_bits_of_floating, 24); - else if (type == TypeIndex::Float64) + } else if (type == TypeIndex::Float64) { maximize(max_mantissa_bits_of_floating, 53); - else + } else { all_numbers = false; + } } if (max_bits_of_signed_integer || max_bits_of_unsigned_integer || max_mantissa_bits_of_floating) { if (!all_numbers) { - *type = nullptr; - return throw_or_return<on_error>(types, doris::ErrorCode::INVALID_ARGUMENT, "", type); + *type = std::make_shared<DataTypeJsonb>(); + return; } /// If there are signed and unsigned types of same bit-width, the result must be signed number with at least one more bit. @@ -164,13 +118,8 @@ void get_numeric_type(const TypeIndexSet& types, DataTypePtr* type) { VLOG_DEBUG << " because some of them are integers and some are floating point " "but there is no floating point type, that can exactly represent " "all required integers"; - *type = nullptr; - return throw_or_return<on_error>( - types, doris::ErrorCode::INVALID_ARGUMENT, - " because some of them are integers and some are floating point " - "but there is no floating point type, that can exactly represent " - "all required integers", - type); + *type = std::make_shared<DataTypeJsonb>(); + return; } } @@ -192,12 +141,8 @@ void get_numeric_type(const TypeIndexSet& types, DataTypePtr* type) { VLOG_DEBUG << " because some of them are signed integers and some are unsigned " "integers, but there is no signed integer type, that can exactly " "represent all required unsigned integer values"; - return throw_or_return<on_error>( - types, doris::ErrorCode::INVALID_ARGUMENT, - " because some of them are signed integers and some are unsigned " - "integers, but there is no signed integer type, that can exactly " - "represent all required unsigned integer values", - type); + *type = std::make_shared<DataTypeJsonb>(); + return; } } @@ -219,67 +164,16 @@ void get_numeric_type(const TypeIndexSet& types, DataTypePtr* type) { LOG(WARNING) << "Logical error: " << "but as all data types are unsigned integers, we must have found " "maximum unsigned integer type"; - *type = nullptr; - return throw_or_return<on_error>( - types, doris::ErrorCode::INVALID_ARGUMENT, - " but as all data types are unsigned integers, we must have found " - "maximum unsigned integer type", - type); + *type = std::make_shared<DataTypeJsonb>(); + return; } } } *type = nullptr; } -template <LeastSupertypeOnError on_error> -void get_least_supertype(const DataTypes& types, DataTypePtr* type) { - /// Trivial cases - if (types.empty()) { - *type = std::make_shared<DataTypeNothing>(); - return; - } - - if (types.size() == 1) { - *type = types[0]; - return; - } - - /// All types are equal - { - bool all_equal = true; - for (size_t i = 1, size = types.size(); i < size; ++i) { - if (!types[i]->equals(*types[0])) { - all_equal = false; - break; - } - } - - if (all_equal) { - *type = types[0]; - return; - } - } - - /// Recursive rules - - /// If there are Nothing types, skip them - { - DataTypes non_nothing_types; - non_nothing_types.reserve(types.size()); - - for (const auto& type : types) { - if (!typeid_cast<const DataTypeNothing*>(type.get())) { - non_nothing_types.emplace_back(type); - } - } - - if (non_nothing_types.size() < types.size()) { - get_least_supertype<on_error>(non_nothing_types, type); - return; - } - } - - /// For Nullable +void get_least_supertype_jsonb(const DataTypes& types, DataTypePtr* type) { + // For Nullable { bool have_nullable = false; @@ -287,8 +181,7 @@ void get_least_supertype(const DataTypes& types, DataTypePtr* type) { nested_types.reserve(types.size()); for (const auto& type : types) { - if (const DataTypeNullable* type_nullable = - typeid_cast<const DataTypeNullable*>(type.get())) { + if (const auto* type_nullable = typeid_cast<const DataTypeNullable*>(type.get())) { have_nullable = true; nested_types.emplace_back(type_nullable->get_nested_type()); @@ -299,70 +192,20 @@ void get_least_supertype(const DataTypes& types, DataTypePtr* type) { if (have_nullable) { DataTypePtr nested_type; - get_least_supertype<on_error>(nested_types, &nested_type); + get_least_supertype_jsonb(nested_types, &nested_type); *type = std::make_shared<DataTypeNullable>(nested_type); return; } } - /// Non-recursive rules - - phmap::flat_hash_set<TypeIndex> type_ids; - for (const auto& type : types) { - type_ids.insert(type->get_type_id()); - } - - /// For String and FixedString, or for different FixedStrings, the common type is String. - /// No other types are compatible with Strings. TODO Enums? - { - UInt32 have_string = type_ids.count(TypeIndex::String); - UInt32 have_fixed_string = type_ids.count(TypeIndex::FixedString); - - if (have_string || have_fixed_string) { - bool all_strings = type_ids.size() == (have_string + have_fixed_string); - if (!all_strings) { - VLOG_DEBUG - << get_exception_message_prefix(types) - << " because some of them are String/FixedString and some of them are not"; - return throw_or_return<on_error>(types, doris::ErrorCode::INVALID_ARGUMENT, - " because some of them are String/FixedString and " - "some of them are not", - type); - } - - *type = std::make_shared<DataTypeString>(); - return; - } - } - - /// For Date and DateTime, the common type is DateTime. No other types are compatible. - { - UInt32 have_date = type_ids.count(TypeIndex::Date); - UInt32 have_datetime = type_ids.count(TypeIndex::DateTime); - - if (have_date || have_datetime) { - bool all_date_or_datetime = type_ids.size() == (have_date + have_datetime); - if (!all_date_or_datetime) { - VLOG_DEBUG << get_exception_message_prefix(types) - << " because some of them are Date/DateTime and some of them are not"; - return throw_or_return<on_error>( - types, doris::ErrorCode::INVALID_ARGUMENT, - " because some of them are Date/DateTime and some of them are not", type); - } - - *type = std::make_shared<DataTypeDateTime>(); - return; - } - } - - /// For Arrays + // For Arrays { bool have_array = false; bool all_arrays = true; DataTypes nested_types; nested_types.reserve(types.size()); for (const auto& type : types) { - if (const DataTypeArray* type_array = typeid_cast<const DataTypeArray*>(type.get())) { + if (const auto* type_array = typeid_cast<const DataTypeArray*>(type.get())) { have_array = true; nested_types.emplace_back(type_array->get_nested_type()); } else { @@ -371,12 +214,11 @@ void get_least_supertype(const DataTypes& types, DataTypePtr* type) { } if (have_array) { if (!all_arrays) { - return throw_or_return<on_error>( - types, ErrorCode::INVALID_ARGUMENT, - "because some of them are Array and some of them are not", type); + *type = std::make_shared<DataTypeJsonb>(); + return; } DataTypePtr nested_type; - get_least_supertype<on_error>(nested_types, &nested_type); + get_least_supertype_jsonb(nested_types, &nested_type); /// When on_error == LeastSupertypeOnError::Null and we cannot get least supertype, /// nested_type will be nullptr, we should return nullptr in this case. if (!nested_type) { @@ -388,111 +230,14 @@ void get_least_supertype(const DataTypes& types, DataTypePtr* type) { } } - /// Decimals - { - UInt32 have_decimal32 = type_ids.count(TypeIndex::Decimal32); - UInt32 have_decimal64 = type_ids.count(TypeIndex::Decimal64); - UInt32 have_decimal128 = type_ids.count(TypeIndex::Decimal128V2); - UInt32 have_decimal128i = type_ids.count(TypeIndex::Decimal128V3); - UInt32 have_decimal256 = type_ids.count(TypeIndex::Decimal256); - - if (have_decimal32 || have_decimal64 || have_decimal128 || have_decimal128i || - have_decimal256) { - UInt32 num_supported = have_decimal32 + have_decimal64 + have_decimal128 + - have_decimal128i + have_decimal256; - - std::vector<TypeIndex> int_ids = { - TypeIndex::Int8, TypeIndex::UInt8, TypeIndex::Int16, TypeIndex::UInt16, - TypeIndex::Int32, TypeIndex::UInt32, TypeIndex::Int64, TypeIndex::UInt64}; - std::vector<UInt32> num_ints(int_ids.size(), 0); - - TypeIndex max_int = TypeIndex::Nothing; - for (size_t i = 0; i < int_ids.size(); ++i) { - UInt32 num = type_ids.count(int_ids[i]); - num_ints[i] = num; - num_supported += num; - if (num) max_int = int_ids[i]; - } - - if (num_supported != type_ids.size()) { - VLOG_DEBUG << get_exception_message_prefix(types) - << " because some of them have no lossless convertion to Decimal"; - return throw_or_return<on_error>( - types, doris::ErrorCode::INVALID_ARGUMENT, - " because some of them have no lossless convertion to Decimal", type); - } - - UInt32 max_scale = 0; - for (const auto& type : types) { - UInt32 scale = get_decimal_scale(*type); - if (scale > max_scale) max_scale = scale; - } - - UInt32 min_precision = max_scale + least_decimal_precision_for(max_int); - - /// special cases Int32 -> Dec32, Int64 -> Dec64 - if (max_scale == 0) { - if (max_int == TypeIndex::Int32) - min_precision = DataTypeDecimal<Decimal32>::max_precision(); - else if (max_int == TypeIndex::Int64) - min_precision = DataTypeDecimal<Decimal64>::max_precision(); - } - - if (min_precision > DataTypeDecimal<Decimal256>::max_precision()) { - VLOG_DEBUG << fmt::format("{} because the least supertype is Decimal({},{})", - get_exception_message_prefix(types), min_precision, - max_scale); - return throw_or_return<on_error>( - types, doris::ErrorCode::INVALID_ARGUMENT, - fmt::format(" because some of them have no lossless " - "convertion to Decimal({},{})", - min_precision, max_scale), - type); - } - - if (have_decimal256 || min_precision > DataTypeDecimal<Decimal128V3>::max_precision()) { - *type = std::make_shared<DataTypeDecimal<Decimal256>>( - DataTypeDecimal<Decimal256>::max_precision(), max_scale); - return; - } - if (have_decimal128 || min_precision > DataTypeDecimal<Decimal64>::max_precision()) { - *type = std::make_shared<DataTypeDecimal<Decimal128V2>>( - DataTypeDecimal<Decimal128V2>::max_precision(), max_scale); - return; - } - if (have_decimal128i || min_precision > DataTypeDecimal<Decimal64>::max_precision()) { - *type = std::make_shared<DataTypeDecimal<Decimal128V3>>( - DataTypeDecimal<Decimal128V3>::max_precision(), max_scale); - return; - } - if (have_decimal64 || min_precision > DataTypeDecimal<Decimal32>::max_precision()) { - *type = std::make_shared<DataTypeDecimal<Decimal64>>( - DataTypeDecimal<Decimal64>::max_precision(), max_scale); - return; - } - *type = std::make_shared<DataTypeDecimal<Decimal32>>( - DataTypeDecimal<Decimal32>::max_precision(), max_scale); - return; - } - } - - /// For numeric types, the most complicated part. - { - DataTypePtr numeric_type = nullptr; - get_numeric_type<on_error>(type_ids, &numeric_type); - if (numeric_type) { - *type = numeric_type; - return; - } + phmap::flat_hash_set<TypeIndex> type_ids; + for (const auto& type : types) { + type_ids.insert(type->get_type_id()); } - - /// All other data types (UUID, AggregateFunction, Enum...) are compatible only if they are the same (checked in trivial cases). - *type = nullptr; - return throw_or_return<on_error>(types, ErrorCode::INVALID_ARGUMENT, "", type); + get_least_supertype_jsonb(type_ids, type); } -template <LeastSupertypeOnError on_error> -void get_least_supertype(const TypeIndexSet& types, DataTypePtr* type) { +void get_least_supertype_jsonb(const TypeIndexSet& types, DataTypePtr* type) { if (types.empty()) { *type = std::make_shared<DataTypeNothing>(); return; @@ -518,16 +263,14 @@ void get_least_supertype(const TypeIndexSet& types, DataTypePtr* type) { *type = std::make_shared<DataTypeJsonb>(); return; } - return throw_or_return<on_error>( - types, ErrorCode::INVALID_ARGUMENT, - "because cannot get common type by type indexes with non-simple types", type); + *type = std::make_shared<DataTypeJsonb>(); + return; } if (types.contains(TypeIndex::String)) { bool only_string = types.size() == 2 && types.contains(TypeIndex::Nothing); if (!only_string) { - return throw_or_return<on_error>( - types, ErrorCode::INVALID_ARGUMENT, - "because some of them are String and some of them are not", type); + *type = std::make_shared<DataTypeJsonb>(); + return; } *type = std::make_shared<DataTypeString>(); return; @@ -535,9 +278,8 @@ void get_least_supertype(const TypeIndexSet& types, DataTypePtr* type) { if (types.contains(TypeIndex::JSONB)) { bool only_json = types.size() == 2 && types.contains(TypeIndex::Nothing); if (!only_json) { - return throw_or_return<on_error>( - types, ErrorCode::INVALID_ARGUMENT, - "because some of them are Json and some of them are not", type); + *type = std::make_shared<DataTypeJsonb>(); + return; } *type = std::make_shared<DataTypeJsonb>(); return; @@ -545,29 +287,13 @@ void get_least_supertype(const TypeIndexSet& types, DataTypePtr* type) { /// For numeric types, the most complicated part. DataTypePtr numeric_type = nullptr; - get_numeric_type<on_error>(types, &numeric_type); + get_numeric_type(types, &numeric_type); if (numeric_type) { *type = numeric_type; return; } /// All other data types (UUID, AggregateFunction, Enum...) are compatible only if they are the same (checked in trivial cases). - *type = nullptr; - return throw_or_return<on_error>(types, ErrorCode::INVALID_ARGUMENT, "", type); + *type = std::make_shared<DataTypeJsonb>(); } -template void get_least_supertype<LeastSupertypeOnError::Throw>(const DataTypes& types, - DataTypePtr* type); -template void get_least_supertype<LeastSupertypeOnError::Throw>(const TypeIndexSet& types, - DataTypePtr* type); - -template void get_least_supertype<LeastSupertypeOnError::String>(const DataTypes& types, - DataTypePtr* type); -template void get_least_supertype<LeastSupertypeOnError::String>(const TypeIndexSet& types, - DataTypePtr* type); - -template void get_least_supertype<LeastSupertypeOnError::Jsonb>(const DataTypes& types, - DataTypePtr* type); -template void get_least_supertype<LeastSupertypeOnError::Jsonb>(const TypeIndexSet& types, - DataTypePtr* type); - } // namespace doris::vectorized diff --git a/be/src/vec/data_types/get_least_supertype.h b/be/src/vec/data_types/get_least_supertype.h index cee07f030b6..1538a625c9d 100644 --- a/be/src/vec/data_types/get_least_supertype.h +++ b/be/src/vec/data_types/get_least_supertype.h @@ -25,34 +25,15 @@ #include "common/status.h" #include "vec/data_types/data_type.h" -namespace doris { -namespace vectorized { +namespace doris::vectorized { enum class TypeIndex; -} // namespace vectorized -} // namespace doris +} // namespace doris::vectorized namespace doris::vectorized { -/** Get data type that covers all possible values of passed data types. - * If there is no such data type, throws an exception. - * - * Examples: least common supertype for UInt8, Int8 - Int16. - * Examples: there is no least common supertype for Array(UInt8), Int8. - */ - -enum class LeastSupertypeOnError { - Throw, - String, - Jsonb, - Null, -}; - using TypeIndexSet = phmap::flat_hash_set<TypeIndex>; -template <LeastSupertypeOnError on_error = LeastSupertypeOnError::Throw> -void get_least_supertype(const DataTypes& types, DataTypePtr* type); - -template <LeastSupertypeOnError on_error = LeastSupertypeOnError::Throw> -void get_least_supertype(const TypeIndexSet& types, DataTypePtr* type); +void get_least_supertype_jsonb(const DataTypes& types, DataTypePtr* type); +void get_least_supertype_jsonb(const TypeIndexSet& types, DataTypePtr* type); } // namespace doris::vectorized diff --git a/be/src/vec/functions/function_map.cpp b/be/src/vec/functions/function_map.cpp index 3ed681b1181..23a01aaa73b 100644 --- a/be/src/vec/functions/function_map.cpp +++ b/be/src/vec/functions/function_map.cpp @@ -46,7 +46,6 @@ #include "vec/data_types/data_type_map.h" #include "vec/data_types/data_type_nullable.h" #include "vec/data_types/data_type_number.h" -#include "vec/data_types/get_least_supertype.h" #include "vec/functions/array/function_array_index.h" #include "vec/functions/function.h" #include "vec/functions/simple_function_factory.h" @@ -76,20 +75,8 @@ public: DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { DCHECK(arguments.size() % 2 == 0) << "function: " << get_name() << ", arguments should not be even number"; - - DataTypes key_types; - DataTypes val_types; - for (size_t i = 0; i < arguments.size(); i += 2) { - key_types.push_back(arguments[i]); - val_types.push_back(arguments[i + 1]); - } - - DataTypePtr key_type; - DataTypePtr val_type; - get_least_supertype(key_types, &key_type); - get_least_supertype(val_types, &val_type); - - return std::make_shared<DataTypeMap>(make_nullable(key_type), make_nullable(val_type)); + return std::make_shared<DataTypeMap>(make_nullable(arguments[0]), + make_nullable(arguments[1])); } Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, @@ -100,7 +87,7 @@ public: size_t num_element = arguments.size(); auto result_col = block.get_by_position(result).type->create_column(); - auto map_column = typeid_cast<ColumnMap*>(result_col.get()); + auto* map_column = typeid_cast<ColumnMap*>(result_col.get()); if (!map_column) { return Status::RuntimeError("unsupported types for function {} return {}", get_name(), block.get_by_position(result).type->get_name()); diff --git a/be/test/vec/core/get_common_type_test.cpp b/be/test/vec/core/get_common_type_test.cpp index b1a08712732..c8c60a3776c 100644 --- a/be/test/vec/core/get_common_type_test.cpp +++ b/be/test/vec/core/get_common_type_test.cpp @@ -119,13 +119,13 @@ class LeastSuperTypeTest : public TypeTest {}; TEST_P(LeastSuperTypeTest, getLeastSupertype) { DataTypePtr result_type; if (this->expected_type) { - get_least_supertype(this->from_types, &result_type); + get_least_supertype_jsonb(this->from_types, &result_type); std::cout << std::endl << " " << this->expected_type->get_name() << " " << result_type->get_name() << std::endl; ASSERT_EQ(*(this->expected_type), *result_type); } else { - EXPECT_ANY_THROW(get_least_supertype(this->from_types, &result_type)); + EXPECT_ANY_THROW(get_least_supertype_jsonb(this->from_types, &result_type)); } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org