Skip to content

Commit

Permalink
Fix empty map read #433
Browse files Browse the repository at this point in the history
  • Loading branch information
xzkostyan committed Apr 23, 2024
1 parent 2b35f97 commit c123f2c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clickhouse_driver/columns/mapcolumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ def write_state_prefix(self, buf):
self.value_column.write_state_prefix(buf)

def read_items(self, n_items, buf):
if not n_items:
return [{}]

offsets = list(self.offset_column.read_items(n_items, buf))
last_offset = offsets[-1]
keys = self.key_column.read_data(last_offset, buf)
Expand Down
13 changes: 13 additions & 0 deletions tests/columns/test_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,16 @@ def test_decimal(self):
)
inserted = self.client.execute(query)
self.assertEqual(inserted, data)

def test_only_empty_map(self):
columns = 'a Map(String, Map(String, Int32))'
with self.create_table(columns):
data = [
({}, ),
]
self.client.execute('INSERT INTO test (a) VALUES', data)
query = 'SELECT * FROM test'
inserted = self.emit_cli(query)
self.assertEqual(inserted, '{}\n')
inserted = self.client.execute(query)
self.assertEqual(inserted, data)

0 comments on commit c123f2c

Please sign in to comment.