From 6c314920ea2a7bed69056e6a0a0702b80e05e417 Mon Sep 17 00:00:00 2001 From: Mryange Date: Thu, 2 Apr 2026 14:55:51 +0800 Subject: [PATCH 1/2] upd --- ...gregate_function_group_array_set_op_impl.h | 85 ++---------- .../function/array/function_array_cum_sum.cpp | 74 +++------- be/src/exprs/function/least_greast.cpp | 129 +++--------------- 3 files changed, 51 insertions(+), 237 deletions(-) diff --git a/be/src/exprs/aggregate/aggregate_function_group_array_set_op_impl.h b/be/src/exprs/aggregate/aggregate_function_group_array_set_op_impl.h index b6fc8082538380..6b154b3028d242 100644 --- a/be/src/exprs/aggregate/aggregate_function_group_array_set_op_impl.h +++ b/be/src/exprs/aggregate/aggregate_function_group_array_set_op_impl.h @@ -36,80 +36,25 @@ inline AggregateFunctionPtr create_aggregate_function_group_array_impl( const auto& nested_type = remove_nullable( assert_cast(*(argument_types[0])).get_nested_type()); - switch (nested_type->get_primitive_type()) { - case doris::PrimitiveType::TYPE_BOOLEAN: - return creator_without_type::create< - AggregateFunctionGroupArraySetOp>>( - argument_types, result_is_nullable, attr); - case PrimitiveType::TYPE_TINYINT: - return creator_without_type::create< - AggregateFunctionGroupArraySetOp>>( - argument_types, result_is_nullable, attr); - case PrimitiveType::TYPE_SMALLINT: - return creator_without_type::create< - AggregateFunctionGroupArraySetOp>>( - argument_types, result_is_nullable, attr); - case PrimitiveType::TYPE_INT: - return creator_without_type::create< - AggregateFunctionGroupArraySetOp>>( - argument_types, result_is_nullable, attr); - case PrimitiveType::TYPE_BIGINT: - return creator_without_type::create< - AggregateFunctionGroupArraySetOp>>( - argument_types, result_is_nullable, attr); - case PrimitiveType::TYPE_LARGEINT: - return creator_without_type::create< - AggregateFunctionGroupArraySetOp>>( - argument_types, result_is_nullable, attr); - case PrimitiveType::TYPE_DATEV2: - return creator_without_type::create< - AggregateFunctionGroupArraySetOp>>( - argument_types, result_is_nullable, attr); - case PrimitiveType::TYPE_DATETIMEV2: - return creator_without_type::create< - AggregateFunctionGroupArraySetOp>>( - argument_types, result_is_nullable, attr); - case PrimitiveType::TYPE_DOUBLE: - return creator_without_type::create< - AggregateFunctionGroupArraySetOp>>( - argument_types, result_is_nullable, attr); - case PrimitiveType::TYPE_FLOAT: - return creator_without_type::create< - AggregateFunctionGroupArraySetOp>>( - argument_types, result_is_nullable, attr); - case PrimitiveType::TYPE_DECIMAL32: - return creator_without_type::create< - AggregateFunctionGroupArraySetOp>>( - argument_types, result_is_nullable, attr); - case PrimitiveType::TYPE_DECIMAL64: - return creator_without_type::create< - AggregateFunctionGroupArraySetOp>>( - argument_types, result_is_nullable, attr); - case PrimitiveType::TYPE_DECIMAL128I: - return creator_without_type::create< - AggregateFunctionGroupArraySetOp>>( - argument_types, result_is_nullable, attr); - case PrimitiveType::TYPE_DECIMAL256: - return creator_without_type::create< - AggregateFunctionGroupArraySetOp>>( - argument_types, result_is_nullable, attr); - case PrimitiveType::TYPE_IPV4: - return creator_without_type::create< - AggregateFunctionGroupArraySetOp>>( - argument_types, result_is_nullable, attr); - case PrimitiveType::TYPE_IPV6: - return creator_without_type::create< - AggregateFunctionGroupArraySetOp>>( - argument_types, result_is_nullable, attr); - case PrimitiveType::TYPE_STRING: - case PrimitiveType::TYPE_VARCHAR: - case PrimitiveType::TYPE_CHAR: + auto pt = nested_type->get_primitive_type(); + if (pt == PrimitiveType::TYPE_STRING || pt == PrimitiveType::TYPE_VARCHAR || + pt == PrimitiveType::TYPE_CHAR) { return creator_without_type::create>( argument_types, result_is_nullable, attr); - default: + } + + AggregateFunctionPtr result; + dispatch_switch_scalar(pt, [&](auto type_holder) { + using DT = std::decay_t; + result = creator_without_type::create< + AggregateFunctionGroupArraySetOp>>( + argument_types, result_is_nullable, attr); + return true; + }); + if (!result) { LOG(WARNING) << " got invalid of nested type: " << nested_type->get_name(); - return nullptr; } + return result; } } // namespace doris diff --git a/be/src/exprs/function/array/function_array_cum_sum.cpp b/be/src/exprs/function/array/function_array_cum_sum.cpp index d23d54f0e03bf8..5e49adcf416a2a 100644 --- a/be/src/exprs/function/array/function_array_cum_sum.cpp +++ b/be/src/exprs/function/array/function_array_cum_sum.cpp @@ -159,62 +159,28 @@ class FunctionArrayCumSum : public IFunction { const ColumnArray::Offsets64& src_offsets, const NullMapType& src_null_map, ColumnPtr& res_nested_ptr) const { bool res = false; - switch (src_nested_type->get_primitive_type()) { - case TYPE_BOOLEAN: - res = _execute_number(src_column, src_offsets, src_null_map, + dispatch_switch_number(src_nested_type->get_primitive_type(), [&](auto type_holder) { + using SrcDT = std::decay_t; + constexpr auto SrcPType = SrcDT::PType; + if constexpr (SrcPType == TYPE_LARGEINT) { + res = _execute_number(src_column, src_offsets, + src_null_map, res_nested_ptr); + } else if constexpr (SrcPType == TYPE_FLOAT || SrcPType == TYPE_DOUBLE) { + res = _execute_number(src_column, src_offsets, src_null_map, res_nested_ptr); - break; - case TYPE_TINYINT: - res = _execute_number(src_column, src_offsets, src_null_map, - res_nested_ptr); - break; - case TYPE_SMALLINT: - res = _execute_number(src_column, src_offsets, src_null_map, - res_nested_ptr); - break; - case TYPE_INT: - res = _execute_number(src_column, src_offsets, src_null_map, - res_nested_ptr); - break; - case TYPE_BIGINT: - res = _execute_number(src_column, src_offsets, src_null_map, - res_nested_ptr); - break; - case TYPE_LARGEINT: - res = _execute_number(src_column, src_offsets, + } else if constexpr (SrcPType == TYPE_DECIMALV2) { + res = _execute_number(src_column, src_offsets, src_null_map, res_nested_ptr); - break; - case TYPE_FLOAT: - res = _execute_number(src_column, src_offsets, src_null_map, - res_nested_ptr); - break; - case TYPE_DOUBLE: - res = _execute_number(src_column, src_offsets, src_null_map, - res_nested_ptr); - break; - case TYPE_DECIMAL32: - res = _execute_number(src_column, src_offsets, src_null_map, - res_nested_ptr); - break; - case TYPE_DECIMAL64: - res = _execute_number(src_column, src_offsets, src_null_map, - res_nested_ptr); - break; - case TYPE_DECIMAL128I: - res = _execute_number(src_column, src_offsets, src_null_map, - res_nested_ptr); - break; - case TYPE_DECIMAL256: - res = _execute_number(src_column, src_offsets, src_null_map, - res_nested_ptr); - break; - case TYPE_DECIMALV2: - res = _execute_number(src_column, src_offsets, - src_null_map, res_nested_ptr); - break; - default: - break; - } + } else if constexpr (is_decimalv3(SrcPType)) { + res = _execute_number(src_column, src_offsets, src_null_map, + res_nested_ptr); + } else { + // int types: BOOLEAN, TINYINT, SMALLINT, INT, BIGINT + res = _execute_number(src_column, src_offsets, src_null_map, + res_nested_ptr); + } + return true; + }); return res; } diff --git a/be/src/exprs/function/least_greast.cpp b/be/src/exprs/function/least_greast.cpp index b08a591a6ae258..18deddaa6b7ef9 100644 --- a/be/src/exprs/function/least_greast.cpp +++ b/be/src/exprs/function/least_greast.cpp @@ -25,6 +25,7 @@ #include "core/accurate_comparison.h" #include "core/assert_cast.h" +#include "core/call_on_type_index.h" #include "core/block/block.h" #include "core/block/column_numbers.h" #include "core/block/column_with_type_and_name.h" @@ -187,10 +188,9 @@ struct FunctionFieldImpl { DCHECK_EQ(arg_const, false); //TODO: maybe could use hashmap to save column data, not use for loop ervey time to test equals. - switch (data_type->get_primitive_type()) { - case PrimitiveType::TYPE_STRING: - case PrimitiveType::TYPE_CHAR: - case PrimitiveType::TYPE_VARCHAR: { + if (data_type->get_primitive_type() == PrimitiveType::TYPE_STRING || + data_type->get_primitive_type() == PrimitiveType::TYPE_CHAR || + data_type->get_primitive_type() == PrimitiveType::TYPE_VARCHAR) { const auto& column_string = assert_cast(*argument_columns[0]); for (int row = 0; row < input_rows_count; ++row) { const auto& str_data = column_string.get_data_at(row); @@ -204,115 +204,18 @@ struct FunctionFieldImpl { } } } - break; - } - case PrimitiveType::TYPE_TINYINT: { - for (int col = 1; col < arguments.size(); ++col) { - insert_result_data(res_data, argument_columns[0], - argument_columns[col], input_rows_count, col); - } - break; - } - case PrimitiveType::TYPE_SMALLINT: { - for (int col = 1; col < arguments.size(); ++col) { - insert_result_data(res_data, argument_columns[0], - argument_columns[col], input_rows_count, col); - } - break; - } - case PrimitiveType::TYPE_INT: { - for (int col = 1; col < arguments.size(); ++col) { - insert_result_data(res_data, argument_columns[0], argument_columns[col], - input_rows_count, col); - } - break; - } - case PrimitiveType::TYPE_BIGINT: { - for (int col = 1; col < arguments.size(); ++col) { - insert_result_data(res_data, argument_columns[0], - argument_columns[col], input_rows_count, col); - } - break; - } - case PrimitiveType::TYPE_LARGEINT: { - for (int col = 1; col < arguments.size(); ++col) { - insert_result_data(res_data, argument_columns[0], - argument_columns[col], input_rows_count, col); - } - break; - } - case PrimitiveType::TYPE_FLOAT: { - for (int col = 1; col < arguments.size(); ++col) { - insert_result_data(res_data, argument_columns[0], argument_columns[col], - input_rows_count, col); - } - break; - } - case PrimitiveType::TYPE_DOUBLE: { - for (int col = 1; col < arguments.size(); ++col) { - insert_result_data(res_data, argument_columns[0], - argument_columns[col], input_rows_count, col); - } - break; - } - case PrimitiveType::TYPE_DECIMAL32: { - for (int col = 1; col < arguments.size(); ++col) { - insert_result_data(res_data, argument_columns[0], - argument_columns[col], input_rows_count, col); - } - break; - } - case PrimitiveType::TYPE_DECIMAL64: { - for (int col = 1; col < arguments.size(); ++col) { - insert_result_data(res_data, argument_columns[0], - argument_columns[col], input_rows_count, col); - } - break; - } - case PrimitiveType::TYPE_DECIMALV2: { - for (int col = 1; col < arguments.size(); ++col) { - insert_result_data(res_data, argument_columns[0], - argument_columns[col], input_rows_count, col); - } - break; - } - case PrimitiveType::TYPE_DECIMAL128I: { - for (int col = 1; col < arguments.size(); ++col) { - insert_result_data(res_data, argument_columns[0], - argument_columns[col], input_rows_count, col); - } - break; - } - case PrimitiveType::TYPE_DECIMAL256: { - for (int col = 1; col < arguments.size(); ++col) { - insert_result_data(res_data, argument_columns[0], - argument_columns[col], input_rows_count, col); - } - break; - } - case PrimitiveType::TYPE_DATEV2: { - for (int col = 1; col < arguments.size(); ++col) { - insert_result_data(res_data, argument_columns[0], - argument_columns[col], input_rows_count, col); - } - break; - } - case PrimitiveType::TYPE_DATETIMEV2: { - for (int col = 1; col < arguments.size(); ++col) { - insert_result_data(res_data, argument_columns[0], - argument_columns[col], input_rows_count, col); - } - break; - } - case PrimitiveType::TYPE_TIMESTAMPTZ: { - for (int col = 1; col < arguments.size(); ++col) { - insert_result_data(res_data, argument_columns[0], - argument_columns[col], input_rows_count, col); - } - break; - } - default: - break; + } else { + bool dispatched = dispatch_switch_scalar(data_type->get_primitive_type(), + [&](auto type_holder) { + using DT = std::decay_t; + for (int col = 1; col < column_size; ++col) { + insert_result_data(res_data, argument_columns[0], + argument_columns[col], input_rows_count, + col); + } + return true; + }); + DCHECK(dispatched) << "unsupported type: " << data_type->get_name(); } return result_column; From 6c07bcb351fc73ca60ee2ea717dbd53aa903f439 Mon Sep 17 00:00:00 2001 From: Mryange Date: Thu, 2 Apr 2026 15:05:27 +0800 Subject: [PATCH 2/2] format --- be/src/exprs/function/least_greast.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/be/src/exprs/function/least_greast.cpp b/be/src/exprs/function/least_greast.cpp index 18deddaa6b7ef9..8feb67ede7e3fb 100644 --- a/be/src/exprs/function/least_greast.cpp +++ b/be/src/exprs/function/least_greast.cpp @@ -25,10 +25,10 @@ #include "core/accurate_comparison.h" #include "core/assert_cast.h" -#include "core/call_on_type_index.h" #include "core/block/block.h" #include "core/block/column_numbers.h" #include "core/block/column_with_type_and_name.h" +#include "core/call_on_type_index.h" #include "core/column/column.h" #include "core/column/column_const.h" #include "core/column/column_decimal.h" @@ -205,8 +205,8 @@ struct FunctionFieldImpl { } } } else { - bool dispatched = dispatch_switch_scalar(data_type->get_primitive_type(), - [&](auto type_holder) { + bool dispatched = + dispatch_switch_scalar(data_type->get_primitive_type(), [&](auto type_holder) { using DT = std::decay_t; for (int col = 1; col < column_size; ++col) { insert_result_data(res_data, argument_columns[0],