77
88from base64 import b64decode
99import io
10- from logging import getLogger
1110from .telemetry import TelemetryField
1211from .time_util import get_time_millis
1312from .arrow_iterator import PyArrowIterator
@@ -16,12 +15,14 @@ from .arrow_iterator import ROW_UNIT, TABLE_UNIT, EMPTY_UNIT
1615from .arrow_context import ArrowConverterContext
1716from .options import pandas, installed_pandas
1817
19- logger = getLogger(__name__ )
18+ from snowflake.connector.snow_logging import getSnowLogger
19+
20+ snow_logger = getSnowLogger(__name__ )
2021
2122if installed_pandas:
2223 from pyarrow import concat_tables
2324else :
24- logger .info(" Failed to import optional packages, pyarrow" )
25+ snow_logger .info(path_name = " arrow_result.pyx " , msg = " Failed to import optional packages, pyarrow" )
2526
2627
2728cdef class ArrowResult:
@@ -70,14 +71,16 @@ cdef class ArrowResult:
7071 self ._arrow_context, self ._use_dict_result,
7172 self ._use_numpy)
7273 else :
73- logger.debug(" Data from first gs response is empty" )
74+ snow_logger.debug(path_name = " arrow_result.pyx" , func_name = " _chunk_info" ,
75+ msg = " Data from first gs response is empty" )
7476 self ._current_chunk_row = EmptyPyArrowIterator()
7577 self ._iter_unit = EMPTY_UNIT
7678
7779 if ' chunks' in data:
7880 chunks = data[' chunks' ]
7981 self ._chunk_count = len (chunks)
80- logger.debug(' chunk size=%s ' , self ._chunk_count)
82+ snow_logger.debug(path_name = " arrow_result.pyx" , func_name = " _chunk_info" ,
83+ msg = ' chunk size={}' .format(self ._chunk_count))
8184 # prepare the downloader for further fetch
8285 qrmk = data[' qrmk' ] if ' qrmk' in data else None
8386 chunk_headers = None
@@ -86,12 +89,11 @@ cdef class ArrowResult:
8689 for header_key, header_value in data[
8790 ' chunkHeaders' ].items():
8891 chunk_headers[header_key] = header_value
89- logger.debug(
90- ' added chunk header: key=%s , value=%s ' ,
91- header_key,
92- header_value)
92+ snow_logger.debug(path_name = " arrow_result.pyx" , func_name = " _chunk_info" ,
93+ msg = " added chunk header: key={}, value={}" .format(header_key, header_value))
9394
94- logger.debug(' qrmk=%s ' , qrmk)
95+ snow_logger.debug(path_name = " arrow_result.pyx" , func_name = " _chunk_info" ,
96+ msg = ' qrmk={}' .format(qrmk))
9597 self ._chunk_downloader = _chunk_downloader if _chunk_downloader \
9698 else self ._connection._chunk_downloader_class(
9799 chunks, self ._connection, self ._cursor, qrmk, chunk_headers,
@@ -106,7 +108,8 @@ cdef class ArrowResult:
106108 self ._iter_unit = ROW_UNIT
107109 self ._current_chunk_row.init(self ._iter_unit)
108110 elif self ._iter_unit == TABLE_UNIT:
109- logger.debug(' The iterator has been built for fetching arrow table' )
111+ snow_logger.debug(path_name = " arrow_result.pyx" , func_name = " __next__" ,
112+ msg = ' The iterator has been built for fetching arrow table' )
110113 raise RuntimeError
111114
112115 is_done = False
@@ -117,9 +120,8 @@ cdef class ArrowResult:
117120 row = self ._current_chunk_row.__next__()
118121 except StopIteration :
119122 if self ._chunk_index < self ._chunk_count:
120- logger.debug(
121- " chunk index: %s , chunk_count: %s " ,
122- self ._chunk_index, self ._chunk_count)
123+ snow_logger.debug(path_name = " arrow_result.pyx" , func_name = " __next__" ,
124+ msg = " chunk index:{}, chunk_count:{}" .format(self ._chunk_index, self ._chunk_count))
123125 next_chunk = self ._chunk_downloader.next_chunk()
124126 self ._current_chunk_row = next_chunk.result_data
125127 self ._current_chunk_row.init(self ._iter_unit)
@@ -154,7 +156,7 @@ cdef class ArrowResult:
154156 return None
155157 finally :
156158 if is_done and self ._cursor._first_chunk_time:
157- logger .info(" fetching data done" )
159+ snow_logger .info(path_name = " arrow_result.pyx " , func_name = " __next__ " , msg = " fetching data done" )
158160 time_consume_last_result = get_time_millis() - self ._cursor._first_chunk_time
159161 self ._cursor._log_telemetry_job_data(
160162 TelemetryField.TIME_CONSUME_LAST_RESULT,
@@ -181,13 +183,15 @@ cdef class ArrowResult:
181183 if self ._iter_unit == EMPTY_UNIT:
182184 self ._iter_unit = TABLE_UNIT
183185 elif self ._iter_unit == ROW_UNIT:
184- logger.debug(' The iterator has been built for fetching row' )
186+ snow_logger.debug(path_name = " arrow_result.pyx" , func_name = " _fetch_arrow_batches" ,
187+ msg = " The iterator has been built for fetching row" )
185188 raise RuntimeError
186189
187190 try :
188191 self ._current_chunk_row.init(self ._iter_unit)
189- logger.debug(' Init table iterator successfully, current chunk index: %s , '
190- ' chunk count: %s ' , self ._chunk_index, self ._chunk_count)
192+ snow_logger.debug(path_name = " arrow_result.pyx" , func_name = " _fetch_arrow_batches" ,
193+ msg = ' Init table iterator successfully, current chunk index: {},'
194+ ' chunk count: {}' .format(self ._chunk_index, self ._chunk_count))
191195 while self ._chunk_index <= self ._chunk_count:
192196 stop_iteration_except = False
193197 try :
@@ -196,9 +200,8 @@ cdef class ArrowResult:
196200 stop_iteration_except = True
197201
198202 if self ._chunk_index < self ._chunk_count: # multiple chunks
199- logger.debug(
200- " chunk index: %s , chunk_count: %s " ,
201- self ._chunk_index, self ._chunk_count)
203+ snow_logger.debug(path_name = " arrow_result.pyx" , func_name = " _fetch_arrow_batches" ,
204+ msg = " chunk index: {}, chunk_count: {}" .format(self ._chunk_index, self ._chunk_count))
202205 next_chunk = self ._chunk_downloader.next_chunk()
203206 self ._current_chunk_row = next_chunk.result_data
204207 self ._current_chunk_row.init(self ._iter_unit)
@@ -223,7 +226,8 @@ cdef class ArrowResult:
223226 self ._current_chunk_row = EmptyPyArrowIterator()
224227 finally :
225228 if self ._cursor._first_chunk_time:
226- logger.info(" fetching data into pandas dataframe done" )
229+ snow_logger.info(path_name = " arrow_result.pyx" , func_name = " _fetch_arrow_batches" ,
230+ msg = " fetching data into pandas dataframe done" )
227231 time_consume_last_result = get_time_millis() - self ._cursor._first_chunk_time
228232 self ._cursor._log_telemetry_job_data(
229233 TelemetryField.TIME_CONSUME_LAST_RESULT,
0 commit comments