Skip to content

Commit

Permalink
Merge pull request #161 from dourvaris/fix/empty-nested-array
Browse files Browse the repository at this point in the history
Fix issue when row contains an empty nested array
  • Loading branch information
xzkostyan authored Aug 14, 2020
2 parents d80c330 + 503bbc4 commit 7c6cd15
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
9 changes: 5 additions & 4 deletions clickhouse_driver/columns/arraycolumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,11 @@ def _read(self, size, buf):
else:
prev_offset += size

data = nested_column._read_data(
nested_column_size, buf,
nulls_map=nulls_map
)
data = []
if nested_column_size:
data = nested_column._read_data(
nested_column_size, buf, nulls_map=nulls_map
)

# Build nested tuple structure.
for slices, nulls_map in reversed(slices_series):
Expand Down
18 changes: 18 additions & 0 deletions tests/columns/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,24 @@ def test_nested_of_nested(self):
inserted = self.client.execute(query)
self.assertEqual(inserted, data)

def test_empty_nested(self):
columns = "a Array(Array(Array(Int32))), b Array(Array(Array(Int32)))"
data = [
([], [[]],),
]

with self.create_table(columns):
self.client.execute("INSERT INTO test (a, b) VALUES", data)

query = "SELECT * FROM test"
inserted = self.emit_cli(query)
self.assertEqual(
inserted, "[]\t[[]]\n",
)

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

def test_type_mismatch_error(self):
columns = 'a Array(Int32)'
data = [('test', )]
Expand Down

0 comments on commit 7c6cd15

Please sign in to comment.