99
1010#include < gtest/gtest.h>
1111
12+ #include < tuple>
13+
1214namespace {
1315using namespace clickhouse ;
1416}
@@ -21,6 +23,33 @@ TEST(CreateColumnByType, CreateSimpleAggregateFunction) {
2123 ASSERT_NE (nullptr , col->As <ColumnInt32>());
2224}
2325
26+ // SimpleAggregateFunction is transparent on the wire: the created column must
27+ // match its value (inner) type. The inner type may itself be a wrapper such as
28+ // LowCardinality, Nullable, Array or Map, which previously produced a nullptr
29+ // because only terminal inner types were handled (issue #540).
30+ class CreateColumnBySimpleAggregateFunctionType
31+ : public ::testing::TestWithParam<std::tuple<const char * /* type*/ , const char * /* expected inner type name*/ >>
32+ {};
33+
34+ TEST_P (CreateColumnBySimpleAggregateFunctionType, CreateColumnByType) {
35+ const auto & [type_name, expected_inner_name] = GetParam ();
36+ const auto col = CreateColumnByType (type_name);
37+ ASSERT_NE (nullptr , col) << " CreateColumnByType returned nullptr for " << type_name;
38+ EXPECT_EQ (expected_inner_name, col->GetType ().GetName ());
39+ }
40+
41+ INSTANTIATE_TEST_SUITE_P (InnerType, CreateColumnBySimpleAggregateFunctionType, ::testing::Values(
42+ // Terminal inner type — handled before the fix; must stay unchanged.
43+ std::make_tuple (" SimpleAggregateFunction(sum, UInt64)" , " UInt64" ),
44+ // Non-terminal (wrapper) inner types — returned nullptr before the fix.
45+ std::make_tuple(" SimpleAggregateFunction(anyLast, LowCardinality(String))" , " LowCardinality(String)" ),
46+ std::make_tuple(" SimpleAggregateFunction(anyLast, Nullable(String))" , " Nullable(String)" ),
47+ std::make_tuple(" SimpleAggregateFunction(groupArrayArray, Array(UInt64))" , " Array(UInt64)" ),
48+ std::make_tuple(" SimpleAggregateFunction(sumMap, Map(String, UInt64))" , " Map(String, UInt64)" ),
49+ std::make_tuple(" SimpleAggregateFunction(anyLast, Enum8('a' = 1, 'b' = 2))" , " Enum8('a' = 1, 'b' = 2)" ),
50+ std::make_tuple(" SimpleAggregateFunction(anyLast, Tuple(UInt64, String))" , " Tuple(UInt64, String)" )
51+ ));
52+
2453TEST (CreateColumnByType, UnmatchedBrackets) {
2554 // When type string has unmatched brackets, CreateColumnByType must return nullptr.
2655 ASSERT_EQ (nullptr , CreateColumnByType (" FixedString(10" ));
0 commit comments