diff --git a/be/src/vec/columns/column_array.cpp b/be/src/vec/columns/column_array.cpp index 2889e7ff381709..fb76a93e95c12c 100644 --- a/be/src/vec/columns/column_array.cpp +++ b/be/src/vec/columns/column_array.cpp @@ -600,17 +600,19 @@ ColumnPtr ColumnArray::filter_string(const Filter& filt, ssize_t result_size_hin size_t col_size = get_offsets().size(); column_match_filter_size(col_size, filt.size()); - if (0 == col_size) return ColumnArray::create(data); + if (!col_size) { + return ColumnArray::create(data); + } auto res = ColumnArray::create(data->clone_empty()); - const ColumnString& src_string = typeid_cast(*data); + const auto& src_string = assert_cast(*data); const ColumnString::Chars& src_chars = src_string.get_chars(); const auto& src_string_offsets = src_string.get_offsets(); const auto& src_offsets = get_offsets(); - ColumnString::Chars& res_chars = typeid_cast(res->get_data()).get_chars(); - auto& res_string_offsets = typeid_cast(res->get_data()).get_offsets(); + ColumnString::Chars& res_chars = assert_cast(res->get_data()).get_chars(); + auto& res_string_offsets = assert_cast(res->get_data()).get_offsets(); auto& res_offsets = res->get_offsets(); if (result_size_hint < 0) { @@ -667,7 +669,7 @@ size_t ColumnArray::filter_string(const Filter& filter) { return ColumnArray::create(data); } - ColumnString& src_string = typeid_cast(*data); + auto& src_string = assert_cast(*data); auto* src_chars = src_string.get_chars().data(); auto* src_string_offsets = src_string.get_offsets().data(); auto* src_offsets = get_offsets().data(); @@ -871,16 +873,18 @@ ColumnPtr ColumnArray::replicate_number(const IColumn::Offsets& replicate_offset MutableColumnPtr res = clone_empty(); - if (0 == col_size) return res; + if (!col_size) { + return res; + } - ColumnArray& res_arr = typeid_cast(*res); + auto& res_arr = assert_cast(*res); const typename ColumnVector::Container& src_data = - typeid_cast&>(*data).get_data(); + assert_cast&>(*data).get_data(); const auto& src_offsets = get_offsets(); typename ColumnVector::Container& res_data = - typeid_cast&>(res_arr.get_data()).get_data(); + assert_cast&>(res_arr.get_data()).get_data(); auto& res_offsets = res_arr.get_offsets(); res_data.reserve(data->size() / col_size * replicate_offsets.back()); @@ -918,17 +922,19 @@ ColumnPtr ColumnArray::replicate_string(const IColumn::Offsets& replicate_offset MutableColumnPtr res = clone_empty(); - if (0 == col_size) return res; + if (!col_size) { + return res; + } - ColumnArray& res_arr = assert_cast(*res); + auto& res_arr = assert_cast(*res); - const ColumnString& src_string = typeid_cast(*data); + const auto& src_string = assert_cast(*data); const ColumnString::Chars& src_chars = src_string.get_chars(); const auto& src_string_offsets = src_string.get_offsets(); const auto& src_offsets = get_offsets(); - ColumnString::Chars& res_chars = typeid_cast(res_arr.get_data()).get_chars(); - auto& res_string_offsets = typeid_cast(res_arr.get_data()).get_offsets(); + ColumnString::Chars& res_chars = assert_cast(res_arr.get_data()).get_chars(); + auto& res_string_offsets = assert_cast(res_arr.get_data()).get_offsets(); auto& res_offsets = res_arr.get_offsets(); res_chars.reserve(src_chars.size() / col_size * replicate_offsets.back()); diff --git a/be/src/vec/columns/column_map.cpp b/be/src/vec/columns/column_map.cpp index b83ff6709dd16d..c7e3fcd9ed6007 100644 --- a/be/src/vec/columns/column_map.cpp +++ b/be/src/vec/columns/column_map.cpp @@ -47,12 +47,7 @@ ColumnMap::ColumnMap(MutableColumnPtr&& keys, MutableColumnPtr&& values, Mutable : keys_column(std::move(keys)), values_column(std::move(values)), offsets_column(std::move(offsets)) { - const COffsets* offsets_concrete = typeid_cast(offsets_column.get()); - - if (!offsets_concrete) { - throw doris::Exception(doris::ErrorCode::INTERNAL_ERROR, - "offsets_column must be a ColumnUInt64."); - } + const auto* offsets_concrete = assert_cast(offsets_column.get()); if (!offsets_concrete->empty() && keys_column && values_column) { auto last_offset = offsets_concrete->get_data().back(); diff --git a/be/src/vec/common/typeid_cast.h b/be/src/vec/common/typeid_cast.h index 85f99b492cdeb9..e135ef3309d2ec 100644 --- a/be/src/vec/common/typeid_cast.h +++ b/be/src/vec/common/typeid_cast.h @@ -29,33 +29,10 @@ #include "common/status.h" #include "vec/common/demangle.h" -#define TYPEID_MAP(_A) \ - template <> \ - inline constexpr TypeIndex TypeToTypeIndex<_A> = TypeIndex::_A; \ - template <> \ - struct TypeIndexToTypeHelper : std::true_type { \ - using T = _A; \ - }; - /** Checks type by comparing typeid. * The exact match of the type is checked. That is, cast to the ancestor will be unsuccessful. * In the rest, behaves like a dynamic_cast. */ -template - requires std::is_reference_v -To typeid_cast(From& from) { - try { - if (typeid(from) == typeid(To)) { - return static_cast(from); - } - } catch (const std::exception& e) { - throw doris::Exception(doris::ErrorCode::BAD_CAST, e.what()); - } - - throw doris::Exception(doris::ErrorCode::BAD_CAST, - "Bad cast from type " + demangle(typeid(from).name()) + " to " + - demangle(typeid(To).name())); -} template To typeid_cast(From* from) { diff --git a/be/src/vec/functions/function_ip.h b/be/src/vec/functions/function_ip.h index 72d38f51e17ac0..30b901b4459dc0 100644 --- a/be/src/vec/functions/function_ip.h +++ b/be/src/vec/functions/function_ip.h @@ -57,40 +57,36 @@ class FunctionIPv4NumToString : public IFunction { using ColumnType = ColumnVector; const ColumnPtr& column = argument.column; - if (const auto* col = typeid_cast(column.get())) { - const typename ColumnType::Container& vec_in = col->get_data(); - auto col_res = ColumnString::create(); - - ColumnString::Chars& vec_res = col_res->get_chars(); - ColumnString::Offsets& offsets_res = col_res->get_offsets(); - - vec_res.resize(vec_in.size() * - (IPV4_MAX_TEXT_LENGTH + 1)); /// the longest value is: 255.255.255.255\0 - offsets_res.resize(vec_in.size()); - char* begin = reinterpret_cast(vec_res.data()); - char* pos = begin; - - auto null_map = ColumnUInt8::create(vec_in.size(), 0); - size_t src_size = std::min(sizeof(ArgType), (unsigned long)4); - for (size_t i = 0; i < vec_in.size(); ++i) { - auto value = vec_in[i]; - if (value < IPV4_MIN_NUM_VALUE || value > IPV4_MAX_NUM_VALUE) { - offsets_res[i] = pos - begin; - null_map->get_data()[i] = 1; - } else { - format_ipv4(reinterpret_cast(&vec_in[i]), src_size, pos); - offsets_res[i] = pos - begin; - } - } + const auto* col = assert_cast(column.get()); + const typename ColumnType::Container& vec_in = col->get_data(); + auto col_res = ColumnString::create(); - vec_res.resize(pos - begin); - block.replace_by_position( - result, ColumnNullable::create(std::move(col_res), std::move(null_map))); - return Status::OK(); - } else { - return Status::RuntimeError("Illegal column {} of argument of function {}", - argument.column->get_name(), get_name()); + ColumnString::Chars& vec_res = col_res->get_chars(); + ColumnString::Offsets& offsets_res = col_res->get_offsets(); + + vec_res.resize(vec_in.size() * + (IPV4_MAX_TEXT_LENGTH + 1)); /// the longest value is: 255.255.255.255\0 + offsets_res.resize(vec_in.size()); + char* begin = reinterpret_cast(vec_res.data()); + char* pos = begin; + + auto null_map = ColumnUInt8::create(vec_in.size(), 0); + size_t src_size = std::min(sizeof(ArgType), (unsigned long)4); + for (size_t i = 0; i < vec_in.size(); ++i) { + auto value = vec_in[i]; + if (value < IPV4_MIN_NUM_VALUE || value > IPV4_MAX_NUM_VALUE) { + offsets_res[i] = pos - begin; + null_map->get_data()[i] = 1; + } else { + format_ipv4(reinterpret_cast(&vec_in[i]), src_size, pos); + offsets_res[i] = pos - begin; + } } + + vec_res.resize(pos - begin); + block.replace_by_position(result, + ColumnNullable::create(std::move(col_res), std::move(null_map))); + return Status::OK(); } public: diff --git a/be/src/vec/functions/function_map.cpp b/be/src/vec/functions/function_map.cpp index 3269dde41cbada..d781fc6cac402b 100644 --- a/be/src/vec/functions/function_map.cpp +++ b/be/src/vec/functions/function_map.cpp @@ -87,11 +87,7 @@ class FunctionMap : public IFunction { size_t num_element = arguments.size(); auto result_col = block.get_by_position(result).type->create_column(); - auto* map_column = typeid_cast(result_col.get()); - if (!map_column) { - return Status::RuntimeError("unsupported types for function {} return {}", get_name(), - block.get_by_position(result).type->get_name()); - } + auto* map_column = assert_cast(result_col.get()); // map keys column auto& result_col_map_keys_data = map_column->get_keys(); diff --git a/be/src/vec/functions/function_struct.cpp b/be/src/vec/functions/function_struct.cpp index a106c14b835b68..a709589a285bc5 100644 --- a/be/src/vec/functions/function_struct.cpp +++ b/be/src/vec/functions/function_struct.cpp @@ -76,11 +76,7 @@ class FunctionStruct : public IFunction { Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, size_t result, size_t input_rows_count) const override { auto result_col = block.get_by_position(result).type->create_column(); - auto struct_column = typeid_cast(result_col.get()); - if (!struct_column) { - return Status::RuntimeError("unsupported types for function {} return {}", get_name(), - block.get_by_position(result).type->get_name()); - } + auto struct_column = assert_cast(result_col.get()); ColumnNumbers args_num; for (size_t i = 0; i < arguments.size(); i++) { if (Impl::pred(i)) { diff --git a/be/src/vec/functions/function_totype.h b/be/src/vec/functions/function_totype.h index e6722a69411963..e86f5444299938 100644 --- a/be/src/vec/functions/function_totype.h +++ b/be/src/vec/functions/function_totype.h @@ -29,7 +29,6 @@ #include "vec/data_types/data_type_nullable.h" #include "vec/data_types/data_type_number.h" #include "vec/data_types/data_type_string.h" -#include "vec/functions/cast_type_to_either.h" #include "vec/functions/function.h" #include "vec/utils/util.hpp" diff --git a/be/src/vec/functions/if.cpp b/be/src/vec/functions/if.cpp index 102d1b63f1006c..ce44358830e561 100644 --- a/be/src/vec/functions/if.cpp +++ b/be/src/vec/functions/if.cpp @@ -171,7 +171,7 @@ size_t count_true_with_notnull(const ColumnPtr& col) { return null_count; } } else { - const auto* bool_col = typeid_cast(col.get()); + const auto* bool_col = assert_cast(col.get()); const auto* __restrict bool_data = bool_col->get_data().data(); return count - simd::count_zero_num((const int8_t*)bool_data, count); } @@ -612,7 +612,7 @@ class FunctionIf : public IFunction { return Status::OK(); } - const auto* cond_col = typeid_cast(arg_cond.column.get()); + const auto* cond_col = assert_cast(arg_cond.column.get()); const ColumnConst* cond_const_col = check_and_get_column_const>(arg_cond.column.get()); @@ -622,13 +622,6 @@ class FunctionIf : public IFunction { return Status::OK(); } - if (!cond_col) { - return Status::InvalidArgument( - "Illegal column {} of first argument of function {},Must be ColumnUInt8 or " - "ColumnConstUInt8.", - arg_cond.column->get_name(), get_name()); - } - WhichDataType which_type(arg_then.type); if (which_type.is_int() || which_type.is_float()) { Status status;