
    7ThK                         S SK r S SKrS SKrSSKJr  SSKJr             SS jr       SS jr    SS jr	S r
S	 rS
 r " S S5      r " S S5      rg)    N   )	url_to_fs)merge_offset_rangesc                    Uc  [        U 40 U=(       d    0 D6S   nUb  [        U5      S:X  a  UR                  XS9$ [        U5      n[	        U /UUUUUU	U
US9	nU(       a  [        [        U5      5      OU nUR                  S0 5      R                  5       nUR                  " U4US0 UEUR                  U0 5      US.ES.UD6$ )a
  
Return a file-like object for a single Parquet file.

The specified parquet `engine` will be used to parse the
footer metadata, and determine the required byte ranges
from the file. The target path will then be opened with
the "parts" (`KnownPartsOfAFile`) caching strategy.

Note that this method is intended for usage with remote
file systems, and is unlikely to improve parquet-read
performance on local file systems.

Parameters
----------
path: str
    Target file path.
mode: str, optional
    Mode option to be passed through to `fs.open`. Default is "rb".
metadata: Any, optional
    Parquet metadata object. Object type must be supported
    by the backend parquet engine. For now, only the "fastparquet"
    engine supports an explicit `ParquetFile` metadata object.
    If a metadata object is supplied, the remote footer metadata
    will not need to be transferred into local memory.
fs: AbstractFileSystem, optional
    Filesystem object to use for opening the file. If nothing is
    specified, an `AbstractFileSystem` object will be inferred.
engine : str, default "auto"
    Parquet engine to use for metadata parsing. Allowed options
    include "fastparquet", "pyarrow", and "auto". The specified
    engine must be installed in the current environment. If
    "auto" is specified, and both engines are installed,
    "fastparquet" will take precedence over "pyarrow".
columns: list, optional
    List of all column names that may be read from the file.
row_groups : list, optional
    List of all row-groups that may be read from the file. This
    may be a list of row-group indices (integers), or it may be
    a list of `RowGroup` metadata objects (if the "fastparquet"
    engine is used).
storage_options : dict, optional
    Used to generate an `AbstractFileSystem` object if `fs` was
    not specified.
strict : bool, optional
    Whether the resulting `KnownPartsOfAFile` cache should
    fetch reads that go beyond a known byte-range boundary.
    If `False` (the default), any read that ends outside a
    known part will be zero padded. Note that using
    `strict=True` may be useful for debugging.
max_gap : int, optional
    Neighboring byte ranges will only be merged when their
    inter-range gap is <= `max_gap`. Default is 64KB.
max_block : int, optional
    Neighboring byte ranges will only be merged when the size of
    the aggregated range is <= `max_block`. Default is 256MB.
footer_sample_size : int, optional
    Number of bytes to read from the end of the path to look
    for the footer metadata. If the sampled bytes do not contain
    the footer, a second read request will be required, and
    performance will suffer. Default is 1MB.
**kwargs :
    Optional key-word arguments to pass to `fs.open`
r   )mode)metadatacolumns
row_groupsenginemax_gap	max_blockfooter_sample_sizecache_optionsparts)datastrict)r   
cache_typer   )
r   lenopen_set_engine_get_parquet_byte_rangesnextiterpopcopyget)pathr   fsr   r	   r
   storage_optionsr   r   r   r   r   kwargsr   fnoptionss                   F/var/www/auris/envauris/lib/python3.13/site-packages/fsspec/parquet.pyopen_parquet_filer$      s    b 
zt7 527: s7|q0wwtw''  F $	
-
D "d4j	tB jj"-224G77



HHR$
	
 
 
    c	           
         [        U[        5      (       a  [        U5      nUb  [        UUUUUUUS9$ UR	                  U 5      n	0 n
/ n/ n/ nSnUcy  Ucv  [        U 5       Hc  u  nn0 U
U'   [        SX   U5       HE  nUR                  U5        UR                  U5        UR                  [        UU-   X   5      5        MG     Me     SnGO/ n/ n[        U 5       H;  u  nnUR                  X   5        [        SX   U-
  5      nUR                  U5        M=     UR                  U UU5      nUR                  5       nSn[        U 5       HK  u  nn[        R                  UU   SS S5      nX   US-   -
  nUUU   :  d  M7  UUU'   [        UUS-   5      nMM     U(       aS  [        R                  " S	U S
35        [        UR                  U UU5      5       H  u  nnUUU   -   UU'   UU   UU'   M     [        U 5       H  u  nnX   U:  aA  UU   S:  a6  UR                  U5        UR                  S5        UR                  UU   5        MO  UR!                  UUUU   UU   S9u  nnUU/[#        U5      -  -  nUU-  nUU-  nM     [%        UUUUUSS9u  pn[        U 5       H  u  nnUU   UU   4UU   0U
U'   M     ['        XXU5        U(       a  [)        U
5        U
$ )a  Get a dictionary of the known byte ranges needed
to read a specific column/row-group selection from a
Parquet dataset. Each value in the output dictionary
is intended for use as the `data` argument for the
`KnownPartsOfAFile` caching strategy of a single path.
)r	   r
   r   r   Tr   Filittle   zYNot enough data was used to sample the parquet footer. Try setting footer_sample_size >= .)r
   footerfooter_startr   r   sort)
isinstancestrr   &_get_parquet_byte_ranges_from_metadatasizes	enumeraterangeappendminmax
cat_rangesr   int
from_byteswarningswarn_parquet_byte_rangesr   r   _transfer_ranges_add_header_magic)pathsr   r   r	   r
   r   r   r   r   
file_sizesresult
data_pathsdata_starts	data_endsadd_header_magicir   bfooter_startsfooter_endssample_sizefooter_samplesmissing_footer_startslarge_footerfooter_sizereal_footer_startblockpath_data_startspath_data_endss                                r#   r   r      s   & &#V$  6!
 	
 %J FJKI:-
 !'GAtF4L1jmY7!!$'""1%  Q]JM!BC 8 ( !  'GAtz}-a1C!CDK  - ( um[I !. 2 2 4 'GAt..):2b)A8LK *q A =#33+<%a("<+/C ( MM55AN!E &)!5 %*N1,=$=q!#8#;a  !'GAt }y( #a' %%d+&&q)$$]1%56 06/J/J%%a(*1-	 0K 0,n 4&3'7#888J++K'I/ (4 .A.
*
 !'GAt*1-{1~>q@QRF4L ( R)D &!Mr%   c           	          UR                  UUU S9u  pxn	[        UUU	UUSS9u  pxn	[        [        U5      5       V
s0 s H  o0 _M     nn
[	        XXxU	5        [        U5        U$ s  sn
f )zSimplified version of `_get_parquet_byte_ranges` for
the case that an engine-specific `metadata` object is
provided, and the remote footer metadata does not need to
be transferred before calculating the required byte ranges.
)r
   r   Fr-   )r=   r   listsetr>   r?   )r   r   r   r	   r
   r   r   rC   rD   rE   r!   rB   s               r#   r1   r1     s      *0)D)D *E *&JY *=*&JY  $C
O454"f4F5R)D fM 6s   A$c                 d    X#U4n[        / UQU R                  " U6 P76  H  u  pgpXU   Xx4'   M     g N)zipr8   )
r   blocksr@   startsendsrangesr   startstopr   s
             r#   r>   r>   H  s@    T"F#&#G#Gv0F#GT&*te]# $Hr%   c                     [        U R                  5       5       H8  nSnX    H  nUS   S:X  d  M  US   S:  d  M  Sn  O   U(       d  M1  SX   S'   M:     g )NTr   r      Fs   PAR1)r   ra   )rU   keys)r   r   	add_magicks       r#   r?   r?   O  sX    TYY[!	AtqyQqTQY!	  9!(DJv "r%   c                    U S:X  a  SnO7[        U [        5      (       d  [        S5      eU S;  a  [        U  S35      eU /nU H(  n US:X  a  [        5       s  $ US:X  a  [	        5       s  $ M*     [        SU S35      e! [
         a     MH  f = f)	Nauto)fastparquetpyarrowzMFailed to set parquet engine! Please pass 'fastparquet', 'pyarrow', or 'auto'z) engine not supported by `fsspec.parquet`rg   rh   zLThe following parquet engines are not installed in your python environment: zS.Please install 'fastparquert' or 'pyarrow' to utilize the `fsspec.parquet` module.)r/   r0   
ValueErrorFastparquetEnginePyarrowEngineImportError)
engine_strtry_enginesr   s      r#   r   r   [  s    V0
C((>
 	
 
5	5J<'PQRR!l 	&(**9$$& %	  ''2m 4/	0   		s   A>A>>
BBc                   2    \ rS rSrS rS r    SS jrSrg)rj   i~  c                     SS K nXl        g Nr   )rg   fp)selfrr   s     r#   __init__FastparquetEngine.__init__  s
     r%   c                 $    UR                  U5      $ rX   )row_group_filename)rs   	row_grouppfs      r#   _row_group_filename%FastparquetEngine._row_group_filename  s    $$Y//r%   Nc           	         Un/ / / pnUc/  U R                   R                  [        R                  " U5      5      nUc  S O
[	        U5      n
U
bb  [        US5      (       aQ  UR                  R                  S/ 5       Vs/ s H  n[        U[        5      (       a  M  UPM     nnU
[	        U5      -  n
U(       a  [        US   [        5      (       d  S nOUnUR                  n[        U5       H  u  pUb  X;   d  M  U R                  X5      nUR                   H  nUR                  R                   S   nU
b  UU
;   d  M'  UR                  R"                  nUc  UR                  R$                  nUR                  R&                  nUb  UU:  d  Mw  UR)                  U5        UR)                  U5        U	R)                  [+        UU-   U=(       d    UU-   5      5        M     M     U(       a  XxU	4$ X4$ s  snf )Npandas_metadataindex_columnsr   )rr   ParquetFileioBytesIOrV   hasattrr}   r   r/   dictr9   r
   r3   rz   r	   	meta_datapath_in_schemadictionary_page_offsetdata_page_offsettotal_compressed_sizer5   r6   )rs   r	   r
   r   r+   r,   ry   rC   rD   rE   
column_setindmd_indexrow_group_indicesrrx   r!   columnnamefile_offset0	num_bytess                        r#   r=   &FastparquetEngine._parquet_byte_ranges  s    -/R
:$$RZZ%78B %_T#g,
!gb2C&D&D --11/2FFC!#t, F   #h-'J jA<< $ !+J &j1LA !(A,B--i<'//F!++::1=D ")TZ-?'-'7'7'N'N'/+1+;+;+L+LL$*$4$4$J$J	'/<,3N&--b1'..|<%,, #$09$<$0$N\I5M!" 0 24  I55%%cs   <G/G/)rr   NNNN__name__
__module____qualname____firstlineno__rt   rz   r=   __static_attributes__ r%   r#   rj   rj   ~  s     
0 C&r%   rj   c                   2    \ rS rSrS rS r    SS jrSrg)rk   i  c                     SS K Jn  Xl        g rq   )pyarrow.parquetparquetpq)rs   r   s     r#   rt   PyarrowEngine.__init__  s
    $r%   c                     [         erX   )NotImplementedError)rs   rx   r   s      r#   rz   !PyarrowEngine._row_group_filename  s    !!r%   Nc                 *   Ub  [        S5      e/ / pvU R                  R                  [        R                  " U5      5      R
                  nUc  S O
[        U5      n	U	b  UR                  R                  5       n
U
R
                  S L=(       a    SU
R
                  ;   nU(       aw  [        R                  " U
R
                  S   R                  S5      5      R                  S/ 5       Vs/ s H  n[        U[        5      (       a  M  UPM     nnU	[        U5      -  n	[        UR                   5       H  nUb  X;   d  M  UR#                  U5      n[        UR$                  5       H  nUR'                  U5      nUR(                  nUR+                  S5      S   nU	b  UU	;   d  UU	;   d  ME  UR,                  nUc  UR.                  nUR0                  nUU:  d  Mt  UR3                  U5        UR3                  [5        UU-   U5      5        M     M     Xg4$ s  snf )Nz.metadata input not supported for PyarrowEngines   pandasutf8r~   r*   r   )ri   r   r   r   r   r   rV   schemato_arrow_schemajsonloadsdecoder   r/   r   r4   num_row_groupsrx   num_columnsr   r   splitr   r   r   r5   r6   )rs   r	   r
   r   r+   r,   rD   rE   mdr   r   has_pandas_metadatar   r   r   rx   cr   r   
split_namer   r   s                         r#   r=   "PyarrowEngine._parquet_byte_ranges  s    MNN!#RYWW  F!34== %_T#g,
!YY..0Ft+L	V__0L   #  $zz	299&A c/2. / / &c40  /   c(m+
 r(()A !Q_LLO	y445A&--a0F!00D "&C!3J"*:-%3'-'D'D'/+1+B+BL$*$@$@	',6'..|<%,, #L9$<l K# 6 *2 %%Is   'HH)r   r   r   r   r%   r#   rk   rk     s    
" ;&r%   rk   )rbNNNNNFrf       @B@B )NNNr   r   r   rf   )NNr   r   )r   r   r;   corer   utilsr   r$   r   r1   r>   r?   r   rj   rk   r   r%   r#   <module>r      s    	    & 
 y~  Nj 'T+	) FR& R&jJ& J&r%   