Skip to content

Commit 0167cfd

Browse files
aakash-saravanan-dbIsaac
andcommitted
perf: build Thrift columnar rows from a generator
_convert_columnar_table collected every per-row value list before passing them to _create_rows, so all the lists and all the rows were alive at once. Pass a generator so each list is freed once its row is built, which keeps peak memory where it was before _create_rows. Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com> Co-authored-by: Isaac <no-reply@databricks.com>
1 parent 721ea92 commit 0167cfd

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

‎src/databricks/sql/result_set.py‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -293,14 +293,14 @@ def _fill_results_buffer(self):
293293
def _convert_columnar_table(self, table):
294294
column_names = [c[0] for c in self.description]
295295
ResultRow = Row(*column_names)
296-
result = []
297-
for row_index in range(table.num_rows):
298-
curr_row = []
299-
for col_index in range(table.num_columns):
300-
curr_row.append(table.get_item(col_index, row_index))
301-
result.append(curr_row)
302-
303-
return _create_rows(ResultRow, result)
296+
rows = (
297+
[
298+
table.get_item(col_index, row_index)
299+
for col_index in range(table.num_columns)
300+
]
301+
for row_index in range(table.num_rows)
302+
)
303+
return _create_rows(ResultRow, rows)
304304

305305
def fetchmany_arrow(self, size: int) -> "pyarrow.Table":
306306
"""

0 commit comments

Comments
 (0)