diff --git a/clickhouse_driver/columns/arraycolumn.py b/clickhouse_driver/columns/arraycolumn.py index 5b3745a3..fe6e4d92 100644 --- a/clickhouse_driver/columns/arraycolumn.py +++ b/clickhouse_driver/columns/arraycolumn.py @@ -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): diff --git a/tests/columns/test_array.py b/tests/columns/test_array.py index 33caf8a2..a448a878 100644 --- a/tests/columns/test_array.py +++ b/tests/columns/test_array.py @@ -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', )]