@@ -1454,19 +1454,19 @@ def fetchmany_arrow(self, size: int) -> "pyarrow.Table":
14541454 results = self .results .next_n_rows (size )
14551455 n_remaining_rows = size - results .num_rows
14561456 self ._next_row_index += results .num_rows
1457-
1457+ partial_result_chunks = [ results ]
14581458 while (
14591459 n_remaining_rows > 0
14601460 and not self .has_been_closed_server_side
14611461 and self .has_more_rows
14621462 ):
14631463 self ._fill_results_buffer ()
14641464 partial_results = self .results .next_n_rows (n_remaining_rows )
1465- results = pyarrow . concat_tables ([ results , partial_results ] )
1465+ partial_result_chunks . append ( partial_results )
14661466 n_remaining_rows -= partial_results .num_rows
14671467 self ._next_row_index += partial_results .num_rows
14681468
1469- return results
1469+ return pyarrow . concat_tables ( partial_result_chunks , use_threads = True )
14701470
14711471 def merge_columnar (self , result1 , result2 ):
14721472 """
@@ -1514,7 +1514,8 @@ def fetchall_arrow(self) -> "pyarrow.Table":
15141514 """Fetch all (remaining) rows of a query result, returning them as a PyArrow table."""
15151515 results = self .results .remaining_rows ()
15161516 self ._next_row_index += results .num_rows
1517-
1517+
1518+ partial_result_chunks = [results ]
15181519 while not self .has_been_closed_server_side and self .has_more_rows :
15191520 self ._fill_results_buffer ()
15201521 partial_results = self .results .remaining_rows ()
@@ -1523,7 +1524,7 @@ def fetchall_arrow(self) -> "pyarrow.Table":
15231524 ):
15241525 results = self .merge_columnar (results , partial_results )
15251526 else :
1526- results = pyarrow . concat_tables ([ results , partial_results ] )
1527+ partial_result_chunks . append ( partial_results )
15271528 self ._next_row_index += partial_results .num_rows
15281529
15291530 # If PyArrow is installed and we have a ColumnTable result, convert it to PyArrow Table
@@ -1534,7 +1535,7 @@ def fetchall_arrow(self) -> "pyarrow.Table":
15341535 for name , col in zip (results .column_names , results .column_table )
15351536 }
15361537 return pyarrow .Table .from_pydict (data )
1537- return results
1538+ return pyarrow . concat_tables ( partial_result_chunks , use_threads = True )
15381539
15391540 def fetchall_columnar (self ):
15401541 """Fetch all (remaining) rows of a query result, returning them as a Columnar table."""
0 commit comments