
    ɯeiz                       U d dl mZ d dlZd dlZd dlZd dlmZ d dlmZm	Z	 d dl
mZ d dlmZmZmZmZmZmZ d dlmZ dd	lmZ dd
lmZ ddlmZmZmZ ddlmZmZ ddl m!Z!m"Z" ddl#m$Z$m%Z%m&Z&m'Z' ddl(m)Z)m*Z*m+Z+m,Z,m-Z- ddl.m/Z/ ddl.m0Z1 ddl2m3Z3 ddl4m5Z5m6Z6m7Z7 ddl8m9Z9  ee:      Z;dZ<dZ=er(d dl>m?Z? d dl0m@Z@mAZA ddlBmCZC ddlDmEZE ddlFmGZGmHZH ddlImJZJ g ZKdeLd<   dZMd ZNd!ZO	 d.	 	 	 	 	 	 	 	 	 	 	 	 	 d/d"ZPe	 G d# d$e             ZQ G d% d&e      ZR	 	 	 	 	 	 	 	 	 	 d0d'ZS G d( d)ej                        ZU G d* d+eU      ZV G d, d-eU      ZWy)1    )annotationsN)	b64decode)Enumunique)	getLogger)TYPE_CHECKINGAnyCallableIterator
NamedTupleSequence)Self   )ArrowConverterContext)exponential_backoff)OKUNAUTHORIZEDurlparse)FIELD_TYPESIterUnit)'ER_FAILED_TO_CONVERT_ROW_TO_PYTHON_TYPEER_NO_PYARROW)ErrorInterfaceErrorNotSupportedErrorProgrammingError)RetryRequestget_http_retryable_erroris_retryable_http_coderaise_failed_request_errorraise_okta_unauthorized_error)installed_pandas)pyarrow)SecretDetector)
HttpConfigSessionManagerSessionManagerFactory)TimerContextManager
      )	DataFrame)DataTypeTable)SnowflakeConnection)SnowflakeConverterType)ResultMetadataV2SnowflakeCursor)Responsez,list[Callable[[ResultMetadataV2], DataType]]FIELD_TYPE_TO_PA_TYPEz/x-amz-server-side-encryption-customer-algorithmz)x-amz-server-side-encryption-customer-keyAES256c           	         ddl m}m} t        j	                  d       |t
        j                  k(  r |d | |||||      S  |d | |||||      S )Nr   )PyArrowRowIteratorPyArrowTableIteratorz+Using nanoarrow as the arrow data converter)nanoarrow_arrow_iteratorr6   r7   loggerdebugr   ROW_UNIT)	datacontextuse_dict_resultnumpynumber_to_decimalrow_unitcheck_error_on_every_columnr6   r7   s	            b/var/www/html/glpi_dashboard/venv/lib/python3.12/site-packages/snowflake/connector/result_batch.py_create_nanoarrow_iteratorrD   8   sm     S
LL>? x((( 	'	
 "'
    c                      e Zd ZdZdZdZdZy)DownloadMetricsz:Defines the keywords by which to store metrics for chunks.downloadparseloadN)__name__
__module____qualname____doc__rH   rI   rJ    rE   rC   rG   rG   [   s    DHEDrE   rG   c                  0    e Zd ZU dZded<   ded<   ded<   y)RemoteChunkInfozKSmall class that holds information about chunks that are given by back-end.strurlintuncompressedSizecompressedSizeN)rK   rL   rM   rN   __annotations__rO   rE   rC   rQ   rQ   d   s    U	HrE   rQ   c                ^    g }d }|d   }|j                  dd      }|}g }	|dk(  rd fd}
|D cg c]
  } |
|       }}n0|j                  d      }t         j                  j                        }d|v r|d   }t        j                  dt        |              |j                  d	      }i }d
|v rCi }|d
   j                         D ]*  \  }}|||<   d|vst        j                  d| d|        , nC|At        j                  dt        j                  |              t        |t        <   ||t        <   dd}|dk(  rj|D cg c]^  }t        |d   | ||      || j                   j                  j                   j                  j                   j#                               ` }	}n~|D cg c]s  }t%        |d   | ||      | j                   j                  j&                  | j                  j(                   j                  j                   j#                         	      u }	}|	D ]  }||j*                  z  } |dk(  rWt        j-                  |j                  d      ||| j                   j                  j                   j#                               }nrt$        j-                  ||| j                   j                  j&                  | j                  j(                   j                  j                   j#                               }nt        j/                  d|        t$        j-                  dd| j                   j                  j&                  | j                  j(                   j                  j                   j#                               }|g|	z   S c c}w c c}w c c}w )Nrowtypetotalr   jsonc                ~    | d   j                         }j                  j                  j                  ||       }||fS )Ntype)upper_connection	converterto_python_method)col	type_namepython_methodcursors      rC   col_to_converterz6create_batches_from_response.<locals>.col_to_converterz   sC    F))+I"..88II3M m++rE   rowsetBase64chunkszchunk size=qrmkchunkHeaders
encryptionzadded chunk header: key=z, value=zqrmk=c                0    t        | d   | d   | d         S )NrS   rU   rV   )rS   rU   rV   )rQ   )cs    rC   remote_chunk_infoz7create_batches_from_response.<locals>.remote_chunk_info   s(    "eH!"#5!6 !12 rE   rowCountjson_result_force_utf8_decodingsession_managerrr   rowsetz9Don't know how to construct ResultBatches from response:  )rb   dict[str, Any]returnz"tuple[str, SnowflakeConverterType])rm   rv   rw   rQ   )getr   r_   _session_parametersr9   r:   lenitemsr$   mask_secrets	SSE_C_AESSSE_C_ALGORITHM	SSE_C_KEYJSONResultBatch_use_dict_result _json_result_force_utf8_decoding_session_managercloneArrowResultBatch_numpy_arrow_number_to_decimalrowcount	from_dataerror)re   _formatr<   schemacolumn_convertersarrow_contextrowtypes	total_lenfirst_chunk_lenrest_of_chunksrf   rm   
rowset_b64rh   ri   chunk_headers
header_keyheader_valuern   first_chunks   `                   rC   create_batches_from_responser   l   s    CE26MIHXXgq)IO(*N&	, ;CCQ-a0CCXXn-
-f.@.@.T.TU4h{3v;-01xx(*T!M,0,@,F,F,H (
L,8j)z1LL2:,h|nU LL5!<!<T!B CDE-6M/*'+M)$	 f     jM!%a(%++4:4F4F4g4g$*$6$6$G$G$M$M$O	N 4    !jM!%a(!++&&--&&??$*$6$6$G$G$M$M$O
N   &1::%&&%//HHX##"..??EEG 0 
 
	&00##%%77"..??EEG 1 	
 	PQUPVWX&00##%%77"..??EEG 1 	
 =>))} D>s   N A#N%1A8N*c                     e Zd ZdZ	 d	 	 	 	 	 	 	 	 	 	 	 	 	 ddZedd       Zedd       Zedd       Zedd       Z	edd       Z
e
j                  dd	       Z
ed
        Zej                  dd       Z	 	 ddZ	 d	 	 	 ddZej                   	 	 dd       ZddZej                   dd       Zej                   d d       Zej                   	 d	 	 	 d!d       Zy)"ResultBatchaz  Represents what the back-end calls a result chunk.

    These are parts of a result set of a query. They each know how to retrieve their
    own results and convert them into Python native formats.

    As you are iterating through a ResultBatch you should check whether the yielded
    value is an ``Exception`` in case there was some error parsing the current row
    we might yield one of these to allow iteration to continue instead of raising the
    ``Exception`` when it occurs.

    These objects are pickleable for easy distribution and replication.

    Please note that the URLs stored in these do expire. The lifetime is dictated by the
    Snowflake back-end, at the time of writing this this is 6 hours.

    They can be iterated over multiple times and in different ways. Please follow the
    code in ``cursor.py`` to make sure that you are using this class correctly.

    Nc                   || _         || _        || _        || _        ||D cg c]  }|j	                          c}nd | _        || _        || _        i | _        d | _	        | j                  rFt        | j                  j                        }|j                  j                  dd      }	|	d   | _        y t        | j                         | _        y c c}w )N/r   )r   _chunk_headers_remote_chunk_info_schema_to_result_metadata_v1r   r   r   _metrics_datar   rS   pathrsplitidrR   )
selfr   r   rn   r   r>   rr   s
parsed_url
path_partss
             rC   __init__zResultBatch.__init__   s     !+"3<B<N8AQ%%'8TX 	 !0 !0(*9=
""!$"9"9"="=>J#//Q7J nDG$--(DG 9s   Cc                    | j                   duS )zWhether this chunk is local.Nr   r   s    rC   _localzResultBatch._local  s     zz%%rE   c                H    | j                   ry| j                  j                  S )zzReturns the size of chunk in bytes in compressed form.

        If it's a local chunk this function returns None.
        N)r   r   rV   r   s    rC   compressed_sizezResultBatch.compressed_size  s      ;;&&555rE   c                H    | j                   ry| j                  j                  S )z|Returns the size of chunk in bytes in uncompressed form.

        If it's a local chunk this function returns None.
        N)r   r   rU   r   s    rC   uncompressed_sizezResultBatch.uncompressed_size#  s      ;;&&777rE   c                T    | j                   D cg c]  }|j                   c}S c c}w N)r   name)r   rb   s     rC   column_nameszResultBatch.column_names-  s    $(LL1S111s   %c                    | j                   S r   r   r   s    rC   rr   zResultBatch.session_manager1  s    $$$rE   c                    || _         y r   r   )r   rr   s     rC   rr   zResultBatch.session_manager5  s
     /rE   c                .    | j                   j                  S r   )r   configr   s    rC   http_configzResultBatch.http_config9  s    $$+++rE   c                v    | j                   r|| j                   _        y t        j                  |      | _         y )N)r   )r   r   r'   get_manager)r   r   s     rC   r   zResultBatch.http_config=  s,      +1D!!($9$E$EV$TD!rE   c                "    | j                         S )a  Returns an iterator through the data this chunk holds.

        In case of this chunk being a local one it iterates through the local already
        parsed data and if it's a remote chunk it will download, parse its data and
        return an iterator through it.
        )create_iterr   s    rC   __iter__zResultBatch.__iter__D  s     !!rE   c                   d}||j                   n t                      }t        t              D ]  }	 t	               5 }t
        j                  d| j                          | j                  j                  }|| j                  t        d}|r|j                  ru|j                  j                  _|j                  j                  |d         5 }	t
        j                  d| j                   d|	         |	j                  di |}
ddd       n| j                   :| j                   j#                  |d         5 }	 |	j                  di |}
ddd       nKt
        j                  d| j                   d	       t%        j&                  d
      } |j(                  di |}

j*                  t,        k(  r-t
        j                  d| j                          	 ddd        nnt/        |
j*                        r t1        |
j*                        }t3        |      |
j*                  t4        k(  rt7        d|
       nt9        d|d|
       ddd        jI                         | jJ                  tL        jN                  jP                  <   
S # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   [xY w# t2        t:        f$ r}|t        dz
  k(  r%t=        |t2              r|j>                  d   }||}|tA        |      }t
        jC                  d| j                   d|dz    d| d| d	       tE        jF                  |       Y d}~d}~ww xY w)z;Downloads the data that the ``ResultBatch`` is pointing at.r   Nz%started downloading result batch id: )rS   headerstimeoutrS   zdownloading result batch id: z with existing session rx   z/ with new session through local session managerF)use_poolingz)successfully downloaded result batch id: r   z+Failed to fetch the large result set batch z	 for the z th time, backing off for zs for the reason: '')rx   rO   ))_backoff_generatorr   rangeMAX_DOWNLOAD_RETRYr(   r9   r:   r   r   rS   r   DOWNLOAD_TIMEOUTrestrr   use_requests_sessionrequestr   use_sessionr'   r   rx   status_coder   r   r   r   r   r!   r    	Exception
isinstanceargsnext	exceptiontimesleepget_timing_millisr   rG   rH   value)r   
connectionkwargssleep_timerbackoffretrydownload_metric	chunk_urlrequest_datasessionresponselocal_session_managerr   es                 rC   	_downloadzResultBatch._downloadO  sO     % ))&$&( 	
 -. E	(ED((* 6UoLL#H	!RS $ 7 7 ; ;I(#'#6#6#3$L #&OO&OO;;G (__AA(/ N$"LL"?yH_`g_h i (7w'M'MHN N ..:!22>>(/ N$'6w'M'MHN N ;DGG9Dst 1F0Q0Q(-1- $=#8#<#<#L|#L++r1GyQ W6U 6U\ .h.B.BC'?@T@T'U*511!--=5dHE24E8Tm6UE	(P --/ 	o..445 qN NN N36U 6Up !), (.22%/<%@q	AG GHAG"7m  Awwiy 4''2m3FqcL
 

;''(sn   
J(BJ8J3J8JB
JJ(A#JJ(J	JJJJ%	!J((M7B L==Mc                    t               )a  Downloads the data from from blob storage that this ResultChunk points at.

        This function is the one that does the actual work for ``self.__iter__``.

        It is necessary because a ``ResultBatch`` can return multiple types of
        iterators. A good example of this is simply iterating through
        ``SnowflakeCursor`` and calling ``fetch_pandas_batches`` on it.
        NotImplementedError)r   r   s     rC   r   zResultBatch.create_iter  s    " "##rE   c                Z    t         s%d}t        }t        j                  t        ||d      y )NzOptional dependency: 'pandas' is not installed, please see the following link for install instructions: https://docs.snowflake.com/en/user-guide/python-connector-pandas.html#installationmsgerrno)r"   r   r   errorhandler_make_exceptionr   )r   r   r   s      rC   _check_can_use_pandasz!ResultBatch._check_can_use_pandas  s=    s  "E33 "   rE   c                    t               r   r   r   s    rC   	to_pandaszResultBatch.to_pandas      !##rE   c                    t               r   r   r   s    rC   to_arrowzResultBatch.to_arrow  r   rE   c                    t               )zDownloads the data that the ``ResultBatch`` is pointing at and populates it into self._data.
        Returns the instance itself.r   r   r   r   s      rC   populate_datazResultBatch.populate_data  s     "##rE   r   )r   rT   r   dict[str, str] | Nonern   RemoteChunkInfo | Noner   Sequence[ResultMetadataV2]r>   boolrr   SessionManager | Nonerw   None)rw   r   )rw   z
int | None)rw   z	list[str])rw   r   )rr   r   rw   r   )r   r%   rw   r   )rw   8Iterator[dict | Exception] | Iterator[tuple | Exception])r   SnowflakeConnection | Nonerw   r2   )rw   `Iterator[dict | Exception] | Iterator[tuple | Exception] | Iterator[Table] | Iterator[DataFrame])rw   r   )rw   r+   rw   r-   r   r   rw   r   )rK   rL   rM   rN   r   propertyr   r   r   r   rr   setterr   r   r   abcabstractmethodr   r   r   r   r   rO   rE   rC   r   r      s   6 26)) -) 2	)
 +) ) /) 
): & & 6 6 8 8 2 2 % % 0 0 , , U U	"	A	" 8<T4T	Tl 	$	$ $$  	$ $ 	$ $ 	7;$4$	$ $rE   r   c                       e Zd Zddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZe	 d	 	 	 	 	 	 	 	 	 	 	 dd       ZddZ	 	 ddZddZ	 d	 	 	 dd	Z		 d	 	 	 dd
Z
	 d	 	 	 ddZd Zd Zd Z xZS )r   FNrp   c               J    t         	|   ||||||       || _        || _        y r   )superr   r   r   )
r   r   r   rn   r   r   r>   rq   rr   	__class__s
            rC   r   zJSONResultBatch.__init__  s7     		
 1P-!2rE   c           	     b     | t        |      dd||||      }|j                  |      |_        |S )z:Initializes a ``JSONResultBatch`` from static, local data.Nrs   )rz   _parser   )clsr<   data_lenr   r   r>   rr   	new_chunks           rC   r   zJSONResultBatch.from_data  sA     I+
	 $**40	rE   c                "   | j                   r	 t        |j                  dd      }n|j                  }t        j                  dj                  d|d	g            S # t        $ r+}d|}t        j                  |       t        |      d}~ww xY w)
a  This function loads a compressed JSON file into memory.

        Returns:
            Whatever ``json.loads`` return, but in a list.
            Unfortunately there's no type hint for this.
            For context: https://github.com/python/typing/issues/182
        zutf-8strict)errorsz2failed to decode json result content due to error )r   Nru   [])r   rR   contentr   r9   r   r   textr[   loadsjoin)r   r   	read_dataexcerr_msgs        rC   _loadzJSONResultBatch._load  s     00) 0 0'(K	 !Izz"''3	3"7899  )NsgVW%(()s   A 	B#&B		Bc           
         t         j                  d| j                          g }| j                  re|D ]^  }i }	 t	        | j
                  || j                        D ]$  \  \  }}}}|||n ||      ||j                  <   & |j                  |       ` |S |D ]{  }dgt        | j                        z  }	 d}t	        | j
                  || j                        D ]  \  \  }}}}|||n ||      ||<   |d	z  }! |j                  t!        |             } |S # t        $ rh}	dj                   d d d|	 }
t         j                  |
       |j                  t        j                  t        |
t        d             Y d}	~	Qd}	~	ww xY w# t        $ rh}	dj                   d d d|	 }
t         j                  |
       |j                  t        j                  t        |
t        d             Y d}	~	`d}	~	ww xY w)
z+Parses downloaded data into its final form.zparsing for result batch id: NzFailed to convert: field z: z::z	, Error: r   r   r   )r9   r:   r   r   zipr   r   r   appendr   r   r   r   r   r   rz   tuple)r   downloaded_dataresult_listrow
row_result_trm   vrb   r   r   idx_cols                rC   r  zJSONResultBatch._parse  s7    	4TWWI>?  & 
+..., UQC
 56IqPQRSPT
388,U  &&z2^ 1 ' "Vc$,,&77
C,/..- !(QD
 01yAI!1Q4
3q!  &&uZ'890 K ! 5chhZr"Rs)TYSZ[C$$S)&&99*'*)P 2 ! 5dii[2$b9UZT[\C$$S)&&99*'*)P s3   AD5AF	F	!AFF		G=AG88G=c                "    d| j                    dS )NzJSONResultChunk()r   r   s    rC   __repr__zJSONResultBatch.__repr__V  s    !$''!,,rE   c                F   | j                  |      }t        j                  d| j                          t	               5 }| j                  |      }d d d        t        j                  d| j                          j                         | j                  t        j                  j                  <   t	               5 }| j                        }d d d        j                         | j                  t        j                  j                  <   S # 1 sw Y   xY w# 1 sw Y   LxY w)Nr   !started loading result batch id: "finished loading result batch id: )r   r9   r:   r   r(   r  r   r   rG   rJ   r   r  rI   )r   r   r   r   load_metricr!  parse_metricparsed_datas           rC   _fetch_datazJSONResultBatch._fetch_dataY  s     >>Z>88	BC " 	3k"jj2O	39$''CD4?4Q4Q4So**001 " 	7l++o6K	75A5S5S5Uo++112	3 	3
	7 	7s   D:DDD c                8     | j                   dd|i|| _        | S Nr   rO   )r4  r   r   s      rC   r   zJSONResultBatch.populate_datai  s%     &T%%FFvF
rE   c                ~    | j                   rt        | j                        S t         | j                  dd|i|      S r6  )r   iterr   r4  r   s      rC   r   zJSONResultBatch.create_itero  s;     ;;

##$D$$E
EfEFFrE   c                2    t        dt        |        d      S )Nz Trying to use arrow fetching on z which is not ArrowResultChunk)r   r]   r   s    rC   _arrow_fetching_errorz%JSONResultBatch._arrow_fetching_errorv  s$     .tDzl ;& '
 	
rE   c                "    | j                         r   r:  r   s    rC   r   zJSONResultBatch.to_pandas|      ((**rE   c                "    | j                         r   r<  r   s    rC   r   zJSONResultBatch.to_arrow  r=  rE   )r   rT   r   r   rn   r   r   r   r   ,Sequence[tuple[str, SnowflakeConverterType]]r>   r   rq   r   rr   r   rw   r   r   )r<   zSequence[Sequence[Any]]r  rT   r   r   r   r?  r>   r   rr   r   )r   r2   rw   list)rw   0list[dict | Exception] | list[tuple | Exception]rw   rR   )r   r   rw   rA  r  )r   r   rw   r   )rK   rL   rM   r   classmethodr   r  r  r,  r4  r   r   r:  r   r   __classcell__r
  s   @rC   r   r     s5    161533 -3 2	3
 +3 H3 3 *.3 /3 
3.  26%  +	
 H  / ,:,6	96p- 8<4	9" 8<4	 8<G4G	AG
++rE   r   c                  6    e Zd Z	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZddZ	 	 	 	 	 	 ddZ	 d	 	 	 	 	 	 	 ddZe	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Z	 d	 	 	 	 	 ddZ		 d	 	 	 ddZ
ddZddd	Z	 d	 	 	 dd
Z	 d	 	 	 ddZ	 d	 	 	 ddZ	 d	 	 	 ddZ xZS )r   c
                X    t         
|   ||||||	       || _        || _        || _        y r   )r	  r   _contextr   _number_to_decimal)r   r   r   rn   r=   r>   r?   r   r@   rr   r
  s             rC   r   zArrowResultBatch.__init__  s<     		
  "3rE   c                "    d| j                    dS )NzArrowResultChunk(r*  r+  r   s    rC   r,  zArrowResultBatch.__repr__  s    "477)1--rE   c                    t        |j                  | j                  | j                  | j                  | j
                  |      S )zCreates a ``PyArrowIterator`` from a response.

        This is used to iterate through results in different ways depending on which
        mode that ``PyArrowIterator`` is in.
        )rD   r  rH  r   r   rI  )r   r   rA   s      rC   r  zArrowResultBatch._load  s=     *MM!!KK##
 	
rE   c           	         t        |      dk(  rt        g       S t        |t              rt	        |      }t        || j                  | j                  | j                  | j                  ||      S )zCreates a ``PyArrowIterator`` files from a str.

        This is used to iterate through results in different ways depending on which
        mode that ``PyArrowIterator`` is in.
        r   )
rz   r8  r   rR   r   rD   rH  r   r   rI  )r   r<   	iter_unitrB   s       rC   
_from_datazArrowResultBatch._from_data  sa     t9>8OdC T?D)MM!!KK##'
 	
rE   c	                6     | |dd||||||	      }	||	_         |	S )z<Initializes an ``ArrowResultBatch`` from static, local data.Nrs   r   )
r  r<   r  r=   r>   r?   r   r@   rr   r  s
             rC   r   zArrowResultBatch.from_data  s8     +

	 	rE   c                   | j                   r0	 | j                  | j                  ||r|j                        S d      S | j                  |      }t        j                  d| j                          t               5 }	 | j                  ||      }	 ddd       t        j                  d| j                          j                         | j                  t        j                  j                   <   S # t        $ r3 |r/t        |dd      r"t        j                  d| j                           w xY w# t        $ r) |r%t        |dd      rt        j                  d|         w xY w# 1 sw Y   xY w)z?Create an iterator for the ResultBatch. Used by get_arrow_iter.N_debug_arrow_chunkFzarrow data can not be parsed: r.  r/  r0  )r   rN  r   ,check_arrow_conversion_error_on_every_columnr   getattrr9   r:   r   r   r(   r  r   r   rG   rJ   r   )r   rM  r   r   r1  loaded_datas         rC   _create_iterzArrowResultBatch._create_iter  sZ    ;;JJ & #OO	  "  >>Z>88	BC " 	k"jj9=	 	9$''CD4?4Q4Q4So**001  '*6JE"RLL#A$**!NO  '*6JE"RLL#A(!LM	 	s.   (C1 C1 ;E%=D01<D-02E""E%%E.c                D    | j                  t        j                  |      S )z?Returns an iterator for this batch which yields a pyarrow TablerM  r   )rU  r   
TABLE_UNIT)r   r   s     rC   _get_arrow_iterz ArrowResultBatch._get_arrow_iter  s        8+>+>: VVrE   c           	     6   t         rt        D cg c]  }|j                   }}| j                  D cg c]5  }t	        j
                  |j                   |j                     |            7 }}t	        j                  |      j                         S c c}w c c}w )z)Returns empty Arrow table based on schema)
r"   r   pa_typer   pafieldr   	type_coder   empty_table)r   r   r3   r   fieldss        rC   _create_empty_tablez$ArrowResultBatch._create_empty_table  s    8C$D1QYY$D!$D \\
 HHQVV?21;;?BC
 
 yy ,,.. %E
s
   B:Bc                b    t        | j                  |      d      }||S | j                         S )z%Returns this batch as a pyarrow Tabler.  N)r   rY  ra  )r   r   vals      rC   r   zArrowResultBatch.to_arrow  s5    4'':'>E?J''))rE   c                j    | j                          | j                  |      } |j                  di |S )z(Returns this batch as a pandas DataFramer.  rO   )r   r   r   )r   r   r   tables       rC   r   zArrowResultBatch.to_pandas  s4     	""$4u(((rE   c                ~    g } | j                   dd|i|}|j                  s|j                  |       t        |      S )z:An iterator for this batch which yields a pandas DataFramer   rO   )r   emptyr  r8  )r   r   r   iterator_data	dataframes        rC   _get_pandas_iterz!ArrowResultBatch._get_pandas_iter'  sA     "DNNCjCFC	  +M""rE   c                   |j                  dt        j                        }|t        j                  k(  r=|j                  dd      }|dk(  r | j                  dd|i|S | j                  |      S | j                  ||      S )zKThe interface used by ResultSet to create an iterator for this ResultBatch.rM  	structurepandasr   r.  rW  rO   )popr   r;   rX  rj  rY  rU  )r   r   r   rM  rl  s        rC   r   zArrowResultBatch.create_iter1  s     %jjh6G6GH	+++

;9IH$,t,,M
MfMM++z+BB$$yZ$PPrE   c                H    | j                  |      j                  | _        | S )Nr.  )r   r  r   r   s      rC   r   zArrowResultBatch.populate_dataD  s!     ^^z^:BB
rE   r   )r   rT   r   r   rn   r   r=   r   r>   r   r?   r   r   r   r@   r   rr   r   rw   r   rB  )r   r2   rA   r   rw   r   T)r<   zstr | bytesrM  r   rB   r   rw   r   )r<   rR   r  rT   r=   r   r>   r   r?   r   r   r   r@   r   rr   r   )rM  r   r   r   rw   zJIterator[dict | Exception] | Iterator[tuple | Exception] | Iterator[Table])r   r   rw   zIterator[Table]r  )r   r   rw   r-   )r   r   rw   r+   )r   r   rw   zIterator[DataFrame])r   r   rw   r   r  )rK   rL   rM   r   r,  r  rN  rC  r   rU  rY  ra  r   r   rj  r   r   rD  rE  s   @rC   r   r     s    2644 -4 2	4
 '4 4 4 +4  4 /4 
40.
 
,4
	A
* -1	

 
 &*	

 
B
6  26  '	
   +   / 8 MQ!/I	SB 8<W4W	W	/* 8<)4)	) 8<#4#	# 8<Q4Q	Q( 8<4	rE   r   rp  )r<   bytesr=   r   r>   r   r?   r   r@   r   rA   r   rB   r   )
re   r1   r   rR   r<   rv   r   r   rw   zlist[ResultBatch])X
__future__r   r  r[   r   base64r   enumr   r   loggingr   typingr   r	   r
   r   r   r   typing_extensionsr   r   r   backoff_policiesr   compatr   r   r   	constantsr   r   	errorcoder   r   r  r   r   r   r   networkr   r   r   r    r!   optionsr"   r#   r\  secret_detectorr$   rr   r%   r&   r'   	time_utilr(   rK   r9   r   r   rm  r+   r,   r-   r   r.   r`   r/   re   r0   r1   vendored.requestsr2   r3   rW   r~   r   r}   rD   rG   rQ   r   ABCr   r   r   rO   rE   rC   <module>r     s   " 
      O O " 0 1 . . , M N N  & " + N N *	8	   '/19+ GI C H D7		 )- 
 "    	 
     "& F d  j s*s*s* s* '	s*
 s*lt$#'' t$ng+k g+TE{ ErE   