@@ -36,8 +36,8 @@ class ResultSet(ABC):
3636
3737 def __init__ (
3838 self ,
39- connection : " Connection" ,
40- backend : " DatabricksClient" ,
39+ connection : Connection ,
40+ backend : DatabricksClient ,
4141 arraysize : int ,
4242 buffer_size_bytes : int ,
4343 command_id : CommandId ,
@@ -54,8 +54,8 @@ def __init__(
5454 A ResultSet manages the results of a single command.
5555
5656 Parameters:
57- :param connection: The parent connection
58- :param backend: The backend client
57+ :param connection: The parent connection that was used to execute this command
58+ :param backend: The backend specialised backend client to be invoked in the fetch phase
5959 :param arraysize: The max number of rows to fetch at a time (PEP-249)
6060 :param buffer_size_bytes: The size (in bytes) of the internal buffer + max fetch
6161 :param command_id: The command ID
@@ -190,9 +190,9 @@ class ThriftResultSet(ResultSet):
190190
191191 def __init__ (
192192 self ,
193- connection : " Connection" ,
194- execute_response : " ExecuteResponse" ,
195- thrift_client : " ThriftDatabricksClient" ,
193+ connection : Connection ,
194+ execute_response : ExecuteResponse ,
195+ thrift_client : ThriftDatabricksClient ,
196196 session_id_hex : Optional [str ],
197197 buffer_size_bytes : int = 104857600 ,
198198 arraysize : int = 10000 ,
@@ -319,6 +319,7 @@ def fetchmany_arrow(self, size: int) -> "pyarrow.Table":
319319 if size < 0 :
320320 raise ValueError ("size argument for fetchmany is %s but must be >= 0" , size )
321321 results = self .results .next_n_rows (size )
322+ partial_result_chunks = [results ]
322323 n_remaining_rows = size - results .num_rows
323324 self ._next_row_index += results .num_rows
324325
@@ -329,11 +330,11 @@ def fetchmany_arrow(self, size: int) -> "pyarrow.Table":
329330 ):
330331 self ._fill_results_buffer ()
331332 partial_results = self .results .next_n_rows (n_remaining_rows )
332- results = pyarrow . concat_tables ([ results , partial_results ] )
333+ partial_result_chunks . append ( partial_results )
333334 n_remaining_rows -= partial_results .num_rows
334335 self ._next_row_index += partial_results .num_rows
335336
336- return results
337+ return pyarrow . concat_tables ( partial_result_chunks )
337338
338339 def fetchmany_columnar (self , size : int ):
339340 """
@@ -364,7 +365,7 @@ def fetchall_arrow(self) -> "pyarrow.Table":
364365 """Fetch all (remaining) rows of a query result, returning them as a PyArrow table."""
365366 results = self .results .remaining_rows ()
366367 self ._next_row_index += results .num_rows
367-
368+ partial_result_chunks = [ results ]
368369 while not self .has_been_closed_server_side and self .is_direct_results :
369370 self ._fill_results_buffer ()
370371 partial_results = self .results .remaining_rows ()
@@ -373,7 +374,7 @@ def fetchall_arrow(self) -> "pyarrow.Table":
373374 ):
374375 results = self .merge_columnar (results , partial_results )
375376 else :
376- results = pyarrow . concat_tables ([ results , partial_results ] )
377+ partial_result_chunks . append ( partial_results )
377378 self ._next_row_index += partial_results .num_rows
378379
379380 # If PyArrow is installed and we have a ColumnTable result, convert it to PyArrow Table
@@ -384,7 +385,7 @@ def fetchall_arrow(self) -> "pyarrow.Table":
384385 for name , col in zip (results .column_names , results .column_table )
385386 }
386387 return pyarrow .Table .from_pydict (data )
387- return results
388+ return pyarrow . concat_tables ( partial_result_chunks )
388389
389390 def fetchall_columnar (self ):
390391 """Fetch all (remaining) rows of a query result, returning them as a Columnar table."""
0 commit comments