HappenLee commented on a change in pull request #8373: URL: https://github.com/apache/incubator-doris/pull/8373#discussion_r822418648
########## File path: be/src/vec/aggregate_functions/aggregate_function_hll_union_agg.h ########## @@ -52,73 +51,115 @@ struct AggregateFunctionHLLData { Int64 get_cardinality() const { return dst_hll.estimate_cardinality(); } - HyperLogLog get() const { - return dst_hll; + HyperLogLog get() const { return dst_hll; } + + void result_union_agg_impl(IColumn& to) const { + if constexpr (is_nullable) { + auto& null_column = assert_cast<ColumnNullable&>(to); + null_column.get_null_map_data().push_back(0); + assert_cast<ColumnInt64&>(null_column.get_nested_column()) + .get_data() + .push_back(get_cardinality()); + } else { + assert_cast<ColumnInt64&>(to).get_data().push_back(get_cardinality()); + } + } + + void result_union_impl(IColumn& to) const { + if constexpr (is_nullable) { + auto& null_column = assert_cast<ColumnNullable&>(to); + null_column.get_null_map_data().push_back(0); + assert_cast<ColumnHLL&>(null_column.get_nested_column()).get_data().emplace_back(get()); + } else { + auto& column = static_cast<ColumnHLL&>(to); + column.get_data().emplace_back(get()); + } + } + + static const DataTypePtr return_type_union_agg() { + if constexpr (is_nullable) { + return make_nullable(std::make_shared<DataTypeInt64>()); + } else { + return std::make_shared<DataTypeInt64>(); + } } + static const DataTypePtr return_type_union() { + if constexpr (is_nullable) { + return make_nullable(std::make_shared<DataTypeHLL>()); + } else { + return std::make_shared<DataTypeHLL>(); + } + } + + void add(const IColumn* column, size_t row_num) { + if (auto* nullable_column = check_and_get_column<const ColumnNullable>(*column)) { + if (nullable_column->is_null_at(row_num)) { + return; + } + const auto& sources = + static_cast<const ColumnHLL&>((nullable_column->get_nested_column())); + dst_hll.merge(sources.get_element(row_num)); + } else { + const auto& sources = static_cast<const ColumnHLL&>(*column); + dst_hll.merge(sources.get_element(row_num)); + } + } +}; + +template <typename Data> Review comment: refactor the struct template -- 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