@@ -36,13 +36,13 @@ cdef class ArrowResult:
3636 object _arrow_context
3737 str _iter_unit
3838
39- def __init__ (self , raw_response , cursor ):
39+ def __init__ (self , raw_response , cursor , _chunk_downloader = None ):
4040 self ._reset()
4141 self ._cursor = cursor
4242 self ._connection = cursor.connection
43- self ._chunk_info(raw_response)
43+ self ._chunk_info(raw_response, _chunk_downloader )
4444
45- def _chunk_info (self , data ):
45+ def _chunk_info (self , data , _chunk_downloader = None ):
4646 self .total_row_index = - 1 # last fetched number of rows
4747
4848 self ._chunk_index = 0
@@ -55,6 +55,7 @@ cdef class ArrowResult:
5555 self ._arrow_context = ArrowConverterContext(self ._connection._session_parameters)
5656 self ._current_chunk_row = PyArrowIterator(io.BytesIO(arrow_bytes), self ._arrow_context)
5757 else :
58+ logger.debug(" Data from first gs response is empty" )
5859 self ._current_chunk_row = EmptyPyArrowIterator(None , None )
5960 self ._iter_unit = EMPTY_UNIT
6061
@@ -76,11 +77,12 @@ cdef class ArrowResult:
7677 header_value)
7778
7879 logger.debug(u ' qrmk=%s ' , qrmk)
79- self ._chunk_downloader = self ._connection._chunk_downloader_class(
80- chunks, self ._connection, self ._cursor, qrmk, chunk_headers,
81- query_result_format = ' arrow' ,
82- prefetch_threads = self ._connection.client_prefetch_threads,
83- use_ijson = False )
80+ self ._chunk_downloader = _chunk_downloader if _chunk_downloader \
81+ else self ._connection._chunk_downloader_class(
82+ chunks, self ._connection, self ._cursor, qrmk, chunk_headers,
83+ query_result_format = ' arrow' ,
84+ prefetch_threads = self ._connection.client_prefetch_threads,
85+ use_ijson = False )
8486
8587 def __iter__ (self ):
8688 return self
@@ -171,9 +173,16 @@ cdef class ArrowResult:
171173 raise RuntimeError
172174
173175 try :
174- self ._current_chunk_row.init(self ._iter_unit) # AttributeError if it is iter(())
176+ self ._current_chunk_row.init(self ._iter_unit)
177+ logger.debug(u ' Init table iterator successfully, current chunk index: %s , '
178+ u ' chunk count: %s ' , self ._chunk_index, self ._chunk_count)
175179 while self ._chunk_index <= self ._chunk_count:
176- table = self ._current_chunk_row.__next__()
180+ stop_iteration_except = False
181+ try :
182+ table = self ._current_chunk_row.__next__()
183+ except StopIteration :
184+ stop_iteration_except = True
185+
177186 if self ._chunk_index < self ._chunk_count: # multiple chunks
178187 logger.debug(
179188 u " chunk index: %s , chunk_count: %s " ,
@@ -182,7 +191,11 @@ cdef class ArrowResult:
182191 self ._current_chunk_row = next_chunk.result_data
183192 self ._current_chunk_row.init(self ._iter_unit)
184193 self ._chunk_index += 1
185- yield table
194+
195+ if stop_iteration_except:
196+ continue
197+ else :
198+ yield table
186199 else :
187200 if self ._chunk_count > 0 and \
188201 self ._chunk_downloader is not None :
@@ -196,9 +209,6 @@ cdef class ArrowResult:
196209 self ._chunk_downloader = None
197210 self ._chunk_count = 0
198211 self ._current_chunk_row = EmptyPyArrowIterator(None , None )
199- except AttributeError :
200- # just for handling the case of empty result
201- return None
202212 finally :
203213 if self ._cursor._first_chunk_time:
204214 logger.info(" fetching data into pandas dataframe done" )
0 commit comments