mrhhsg commented on code in PR #23474: URL: https://github.com/apache/doris/pull/23474#discussion_r1308292963
########## be/src/vec/aggregate_functions/aggregate_function_collect.h: ########## @@ -99,7 +99,8 @@ struct AggregateFunctionCollectSetData { read_var_int(max_size, buf); } - void insert_result_into(IColumn& to) const { + void insert_result_into(IColumn& to, bool shownull = false) const { + DCHECK(shownull == false); Review Comment: `shownull` was not used ########## be/src/vec/aggregate_functions/aggregate_function_collect.h: ########## @@ -333,7 +378,12 @@ class AggregateFunctionCollect if constexpr (ENABLE_ARENA) { data.add(*columns[0], row_num, arena); } else { - data.add(*columns[0], row_num); + if (ShowNull::value && columns[0]->is_nullable()) { + auto& nullable_col = assert_cast<const ColumnNullable&>(*columns[0]); + data.add(nullable_col.get_nested_column(), row_num); Review Comment: Need to check the data is null or not. ########## be/src/vec/aggregate_functions/aggregate_function_collect.h: ########## @@ -282,30 +304,53 @@ struct AggregateFunctionCollectListData<StringRef, HasLimit> { void reset() { data->clear(); } - void insert_result_into(IColumn& to) const { - auto& to_str = assert_cast<ColVecType&>(to); - to_str.insert_range_from(*data, 0, size()); + void insert_result_into(IColumn& to, bool shownull = false) const { + if (shownull == false) { + auto& to_str = assert_cast<ColVecType&>(to); + to_str.insert_range_from(*data, 0, size()); + } else { + auto& to_arr = assert_cast<ColumnArray&>(to); + auto& to_nested_col = to_arr.get_data(); + size_t num_rows = data->size(); + DCHECK(to_nested_col.is_nullable()); + auto col_null = reinterpret_cast<ColumnNullable*>(&to_nested_col); + for (size_t i = 0; i < num_rows; ++i) { + auto column = data->get_data_at(i); + assert_cast<ColVecType&>(col_null->get_nested_column()) + .insert_data(column.data, column.size); + if (column.data == NULL || column.size == 0) { + col_null->get_null_map_data().push_back(1); + } else { + col_null->get_null_map_data().push_back(0); + } + } + to_arr.get_offsets().push_back(to_nested_col.size()); + } } }; -template <typename Data, typename HasLimit> +template <typename Data, typename HasLimit, typename ShowNull> Review Comment: Better to add some comment about this template argument. ########## be/src/vec/aggregate_functions/aggregate_function_collect.cpp: ########## @@ -27,21 +27,25 @@ namespace doris::vectorized { -template <typename T, typename HasLimit> +template <typename T, typename HasLimit, typename ShowNull> AggregateFunctionPtr do_create_agg_function_collect(bool distinct, const DataTypes& argument_types, const bool result_is_nullable) { - if (distinct) { - return creator_without_type::create< - AggregateFunctionCollect<AggregateFunctionCollectSetData<T, HasLimit>, HasLimit>>( + if (ShowNull::value) { Review Comment: You might consider that `array_agg` is exactly the same as `collect_list` when the argument is non-nullable, and nothing needs to be changed. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org