Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Enum type parsing when it wrapped in SimpleAggregateFunction #170

Merged
merged 1 commit into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clickhouse_driver/columns/simpleaggregatefunctioncolumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
61 changes: 61 additions & 0 deletions tests/columns/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',)
]
)