Skip to content

Commit

Permalink
Proper null handling in LowCardinality columns
Browse files Browse the repository at this point in the history
  • Loading branch information
xzkostyan committed Nov 14, 2019
1 parent af87014 commit 8df7f9a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clickhouse_driver/columns/lowcardinalitycolumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def _write_data(self, items, buf):

if self.nested_column.nullable:
# First element represents NULL if column is nullable.
index.append(0)
index.append(self.nested_column.null_value)
# Prevent null map writing. Reset nested column nullable flag.
self.nested_column.nullable = False

Expand Down
18 changes: 18 additions & 0 deletions tests/columns/test_low_cardinality.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,21 @@ def test_fixed_string(self):

inserted = self.client.execute(query)
self.assertEqual(inserted, data)

@require_server_version(19, 3, 3)
def test_nullable_string(self):
with self.create_table('a LowCardinality(Nullable(String))'):
data = [
('test', ), ('', ), (None, )
]
self.client.execute('INSERT INTO test (a) VALUES', data)

query = 'SELECT * FROM test'
inserted = self.emit_cli(query)
self.assertEqual(
inserted,
'test\n\n\\N\n'
)

inserted = self.client.execute(query)
self.assertEqual(inserted, data)

0 comments on commit 8df7f9a

Please sign in to comment.