diff --git a/clickhouse_driver/columns/simpleaggregatefunctioncolumn.py b/clickhouse_driver/columns/simpleaggregatefunctioncolumn.py index 41d3e523..e6aa12be 100644 --- a/clickhouse_driver/columns/simpleaggregatefunctioncolumn.py +++ b/clickhouse_driver/columns/simpleaggregatefunctioncolumn.py @@ -2,6 +2,6 @@ def create_simple_aggregate_function_column(spec, column_by_spec_getter): # SimpleAggregateFunction(Func, Type) -> Type - inner = spec[24:-1].split(',')[1].strip() + inner = spec[24:-1].split(',', maxsplit=1)[1].strip() nested = column_by_spec_getter(inner) return nested diff --git a/tests/columns/test_enum.py b/tests/columns/test_enum.py index c9a2309f..9b6e1ee1 100644 --- a/tests/columns/test_enum.py +++ b/tests/columns/test_enum.py @@ -149,3 +149,64 @@ def test_nullable(self): (None, ), ('hello', ), (None, ), ('world', ), ] ) + + def test_simple_agg_function(self): + columns = "a SimpleAggregateFunction(anyLast, " \ + "Enum8('hello' = -1, 'world' = 2))" + + data = [(A.hello,), (A.world,), (-1,), (2,)] + with self.create_table(columns): + self.client.execute( + 'INSERT INTO test (a) VALUES', data + ) + + query = 'SELECT * FROM test' + inserted = self.emit_cli(query) + self.assertEqual( + inserted, ( + 'hello\n' + 'world\n' + 'hello\n' + 'world\n' + ) + ) + + inserted = self.client.execute(query) + self.assertEqual( + inserted, [ + ('hello',), ('world',), + ('hello',), ('world',) + ] + ) + + def test_simple_agg_function_nullable(self): + columns = "a SimpleAggregateFunction(anyLast, " \ + "Nullable(Enum8('hello' = -1, 'world' = 2)))" + + data = [(A.hello,), (A.world,), (None,), (-1,), (2,)] + with self.create_table(columns): + self.client.execute( + 'INSERT INTO test (a) VALUES', data + ) + + query = 'SELECT * FROM test' + inserted = self.emit_cli(query) + self.assertEqual( + inserted, ( + 'hello\n' + 'world\n' + '\\N\n' + 'hello\n' + 'world\n' + ) + ) + + inserted = self.client.execute(query) + self.assertEqual( + inserted, [ + ('hello',), ('world',), + (None, ), + ('hello',), ('world',) + ] + ) +