
    'h\J              	         S SK Jr  S SKrS SKJr  S SKJr  S SKJrJr  S SK	J
r
Jr  S SKJr  S SKJrJr  S S	KJr  S S
KJr  S SKJr  S SKJr  S SKJr  \(       a  S SKJr  S SKJr  S SKJrJrJ r   S SK!J"r"  SSSSSSSSS.                   SS jjr#SSSSSSSS.                 SS jjr$SS.S S jjr%   S!         S"S jjr&S#S jr'S$S jr(g)%    )annotationsN)datetime)Path)TYPE_CHECKINGAny)NullTime)unpack_dtypes)_DELTALAKE_AVAILABLE	deltalake)_get_path_scheme)scan_parquet)scan_pyarrow_dataset)ScanCastOptions)Schema)Literal
DeltaTable)	DataFrameDataType	LazyFrame)CredentialProviderFunctionautoF)versioncolumnsrechunkstorage_optionscredential_providerdelta_table_optionsuse_pyarrowpyarrow_optionsc               j    [        U UUUUUUUS9n	Ub  U	R                  U5      n	U	R                  5       $ )a  
Reads into a DataFrame from a Delta lake table.

Parameters
----------
source
    DeltaTable or a Path or URI to the root of the Delta lake table.

    Note: For Local filesystem, absolute and relative paths are supported but
    for the supported object storages - GCS, Azure and S3 full URI must be provided.
version
    Numerical version or timestamp version of the Delta lake table.

    Note: If `version` is not provided, the latest version of delta lake
    table is read.
columns
    Columns to select. Accepts a list of column names.
rechunk
    Make sure that all columns are contiguous in memory by
    aggregating the chunks into a single array.
storage_options
    Extra options for the storage backends supported by `deltalake`.
    For cloud storages, this may include configurations for authentication etc.

    More info is available `here
    <https://delta-io.github.io/delta-rs/usage/loading-table/>`__.
credential_provider
    Provide a function that can be called to provide cloud storage
    credentials. The function is expected to return a dictionary of
    credential keys along with an optional credential expiry time.

    .. warning::
        This functionality is considered **unstable**. It may be changed
        at any point without it being considered a breaking change.
delta_table_options
    Additional keyword arguments while reading a Delta lake Table.
use_pyarrow
    Flag to enable pyarrow dataset reads.
pyarrow_options
    Keyword arguments while converting a Delta lake Table to pyarrow table.

Returns
-------
DataFrame

Examples
--------
Reads a Delta table from local filesystem.
Note: Since version is not provided, the latest version of the delta table is read.

>>> table_path = "/path/to/delta-table/"
>>> pl.read_delta(table_path)  # doctest: +SKIP

Reads a specific version of the Delta table from local filesystem.
Note: This will fail if the provided version of the delta table does not exist.

>>> pl.read_delta(table_path, version=1)  # doctest: +SKIP

Time travel a delta table from local filesystem using a timestamp version.

>>> pl.read_delta(
...     table_path, version=datetime(2020, 1, 1, tzinfo=timezone.utc)
... )  # doctest: +SKIP

Reads a Delta table from AWS S3.
See a list of supported storage options for S3 `here
<https://docs.rs/object_store/latest/object_store/aws/enum.AmazonS3ConfigKey.html#variants>`__.

>>> table_path = "s3://bucket/path/to/delta-table/"
>>> storage_options = {
...     "AWS_ACCESS_KEY_ID": "THE_AWS_ACCESS_KEY_ID",
...     "AWS_SECRET_ACCESS_KEY": "THE_AWS_SECRET_ACCESS_KEY",
... }
>>> pl.read_delta(table_path, storage_options=storage_options)  # doctest: +SKIP

Reads a Delta table from Google Cloud storage (GCS).
See a list of supported storage options for GCS `here
<https://docs.rs/object_store/latest/object_store/gcp/enum.GoogleConfigKey.html#variants>`__.

>>> table_path = "gs://bucket/path/to/delta-table/"
>>> storage_options = {"SERVICE_ACCOUNT": "SERVICE_ACCOUNT_JSON_ABSOLUTE_PATH"}
>>> pl.read_delta(table_path, storage_options=storage_options)  # doctest: +SKIP

Reads a Delta table from Azure.

Following type of table paths are supported,

* az://<container>/<path>
* adl://<container>/<path>
* abfs://<container>/<path>

See a list of supported storage options for Azure `here
<https://docs.rs/object_store/latest/object_store/azure/enum.AzureConfigKey.html#variants>`__.

>>> table_path = "az://container/path/to/delta-table/"
>>> storage_options = {
...     "AZURE_STORAGE_ACCOUNT_NAME": "AZURE_STORAGE_ACCOUNT_NAME",
...     "AZURE_STORAGE_ACCOUNT_KEY": "AZURE_STORAGE_ACCOUNT_KEY",
... }
>>> pl.read_delta(table_path, storage_options=storage_options)  # doctest: +SKIP

Reads a Delta table with additional delta specific options. In the below example,
`without_files` option is used which loads the table without file tracking
information.

>>> table_path = "/path/to/delta-table/"
>>> delta_table_options = {"without_files": True}
>>> pl.read_delta(
...     table_path, delta_table_options=delta_table_options
... )  # doctest: +SKIP
)sourcer   r   r   r   r    r!   r   )
scan_deltaselectcollect)
r#   r   r   r   r   r   r   r    r!   dfs
             bC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\polars/io/delta.py
read_deltar)      sI    v 
'//'	
B YYw::<    )r   r   r   r   r    r!   r   c                  [        5         0 nSSKJn	  SSKJn
  SSKJn  [        X	5      (       d  U
" X0US5      nOUb  US:w  a  Sn[        U5      eSnAU(       a(  UR                  5       =n(       a  U" U5      =(       d    0 n[        U UUc  Ub  0 U=(       d    0 EUEOSUS	9n[        X	5      (       a2  U R                  c  Ub"  0 U R                  =(       d    0 EU=(       d    0 EnU(       a(  U=(       d    0 nUR                  " S0 UD6n[        U5      $ Ub  S
n[        U5      eSSKJn  SSKJnJnJn  UR)                  5       nUR*                  U:  d  UR*                  U:X  a  SUR*                   SU SU 3nU" U5      eUR*                  S:  aG  UR,                  b:  1 UR,                  kR/                  U5      n[1        U5      S:  a  SU S3nU" U5      eUR3                  5       n[5        U5      nUR7                  5       R8                  n      SS jnU" UU5      u  nnUR;                  5       nUR<                  R?                  S5      (       a"  U Vs/ s H  nURA                  SS5      PM     nn[C        UU[1        U5      S:  a  UOS[D        RF                  " 5       SS[1        U5      S:  UUU=(       d    SS9
$ s  snf )a  
Lazily read from a Delta lake table.

Parameters
----------
source
    DeltaTable or a Path or URI to the root of the Delta lake table.

    Note: For Local filesystem, absolute and relative paths are supported but
    for the supported object storages - GCS, Azure and S3 full URI must be provided.
version
    Numerical version or timestamp version of the Delta lake table.

    Note: If `version` is not provided, the latest version of delta lake
    table is read.
storage_options
    Extra options for the storage backends supported by `deltalake`.
    For cloud storages, this may include configurations for authentication etc.

    More info is available `here
    <https://delta-io.github.io/delta-rs/usage/loading-table/>`__.
credential_provider
    Provide a function that can be called to provide cloud storage
    credentials. The function is expected to return a dictionary of
    credential keys along with an optional credential expiry time.

    .. warning::
        This functionality is considered **unstable**. It may be changed
        at any point without it being considered a breaking change.
delta_table_options
    Additional keyword arguments while reading a Delta lake Table.
use_pyarrow
    Flag to enable pyarrow dataset reads.
pyarrow_options
    Keyword arguments while converting a Delta lake Table to pyarrow table.
    Use this parameter when filtering on partitioned columns or to read
    from a 'fsspec' supported filesystem.
rechunk
    Make sure that all columns are contiguous in memory by
    aggregating the chunks into a single array.

Returns
-------
LazyFrame

Examples
--------
Creates a scan for a Delta table from local filesystem.
Note: Since version is not provided, the latest version of the delta table is read.

>>> table_path = "/path/to/delta-table/"
>>> pl.scan_delta(table_path).collect()  # doctest: +SKIP

Creates a scan for a specific version of the Delta table from local filesystem.
Note: This will fail if the provided version of the delta table does not exist.

>>> pl.scan_delta(table_path, version=1).collect()  # doctest: +SKIP

Time travel a delta table from local filesystem using a timestamp version.

>>> pl.scan_delta(
...     table_path, version=datetime(2020, 1, 1, tzinfo=timezone.utc)
... ).collect()  # doctest: +SKIP

Creates a scan for a Delta table from AWS S3.
See a list of supported storage options for S3 `here
<https://docs.rs/object_store/latest/object_store/aws/enum.AmazonS3ConfigKey.html#variants>`__.

>>> table_path = "s3://bucket/path/to/delta-table/"
>>> storage_options = {
...     "AWS_REGION": "eu-central-1",
...     "AWS_ACCESS_KEY_ID": "THE_AWS_ACCESS_KEY_ID",
...     "AWS_SECRET_ACCESS_KEY": "THE_AWS_SECRET_ACCESS_KEY",
... }
>>> pl.scan_delta(
...     table_path, storage_options=storage_options
... ).collect()  # doctest: +SKIP

Creates a scan for a Delta table from Google Cloud storage (GCS).
See a list of supported storage options for GCS `here
<https://docs.rs/object_store/latest/object_store/gcp/enum.GoogleConfigKey.html#variants>`__.

>>> table_path = "gs://bucket/path/to/delta-table/"
>>> storage_options = {"SERVICE_ACCOUNT": "SERVICE_ACCOUNT_JSON_ABSOLUTE_PATH"}
>>> pl.scan_delta(
...     table_path, storage_options=storage_options
... ).collect()  # doctest: +SKIP

Creates a scan for a Delta table from Azure.
Supported options for Azure are available `here
<https://docs.rs/object_store/latest/object_store/azure/enum.AzureConfigKey.html#variants>`__.

Following type of table paths are supported,

* az://<container>/<path>
* adl://<container>/<path>
* abfs[s]://<container>/<path>

>>> table_path = "az://container/path/to/delta-table/"
>>> storage_options = {
...     "AZURE_STORAGE_ACCOUNT_NAME": "AZURE_STORAGE_ACCOUNT_NAME",
...     "AZURE_STORAGE_ACCOUNT_KEY": "AZURE_STORAGE_ACCOUNT_KEY",
... }
>>> pl.scan_delta(
...     table_path, storage_options=storage_options
... ).collect()  # doctest: +SKIP

Creates a scan for a Delta table with additional delta specific options.
In the below example, `without_files` option is used which loads the table without
file tracking information.

>>> table_path = "/path/to/delta-table/"
>>> delta_table_options = {"without_files": True}
>>> pl.scan_delta(
...     table_path, delta_table_options=delta_table_options
... ).collect()  # doctest: +SKIP
r   r   )!_init_credential_provider_builder)+_get_credentials_from_provider_expiry_awarer$   Nr   z?cannot use credential_provider when passing a DeltaTable object)
table_pathr   r   r   z7To make use of pyarrow_options, set use_pyarrow to True)DeltaProtocolError)MAX_SUPPORTED_READER_VERSIONNOT_SUPPORTED_READER_VERSIONSUPPORTED_READER_FEATURESz&The table's minimum reader version is z5 but polars delta scanner only supports version 1 or z with these reader features:    z)The table has set these reader features: z= but these are not yet supported by the polars delta scanner.c                    [        U5      S:X  a  U [        / 5      4$ / n/ nU R                  5        H0  u  pEXA;   a  UR                  XE45        M  UR                  XE45        M2     [        U5      [        U5      4$ )Nr   )lenr   itemsappend)schemapartition_columnsmain_schemahive_schemanamedtypes         r(   _split_schema!scan_delta.<locals>._split_schema~  sz      !Q&6":%%!<<>KD(""D=1""D=1	 * k"F;$777r*   z	lakefs://zs3://insertignoreF)	r8   r;   cast_optionsmissing_columnsextra_columnshive_partitioningr   r   r    )r8   r   r9   z	list[str]returnztuple[Schema, Schema])$_check_if_delta_availabler   r   ,polars.io.cloud.credential_provider._builderr,   .polars.io.cloud.credential_provider._providersr-   
isinstance
ValueErrorbuild_credential_provider_get_delta_lake_table_storage_optionsto_pyarrow_datasetr   deltalake.exceptionsr/   deltalake.tabler0   r1   r2   protocolmin_reader_versionreader_features
differencer5   r8   r   metadatar9   	file_uris	table_uri
startswithreplacer   r   _default_iceberg)r#   r   r   r   r   r    r!   r   credential_provider_credsr   r,   r-   credential_provider_buildermsgproviderdl_tblpa_dsr/   r0   r1   r2   table_protocolmissing_featuresdelta_schemapolars_schemar9   r>   r:   r;   rX   file_uris                                  r(   r$   r$      s/   @  "$ f))&G,'
# 
	(-@F-JOo&*#"/IIKKK 8AGR 	" # *.I.U E%2D*CD/	F &%%+/JXf55;XAVTVX)/R))<O<#E**"Go7  __&N)),HH,,0LL 5^5V5V4W XCC_B``}  X  ~YZ 	 !%%))Q.**6<^;;<GG%
  1$=>N=O  PM  NC$S))==?L<(M);;88+48	8"  -]<MNK  "I "";//LUVIX%%k7;I	V#&'8#9A#=K4$557 /014'7 5  Ws   KT)strictc                   [        [        U 5      c.  [        U 5      R                  5       R	                  U5      5      nU$ U 5      nU$ )N)strr   r   
expanduserresolve)rY   rh   resolved_uris      r(   _resolve_delta_lake_urirn     sP    I&. 	Y""$,,V4L  L r*   c                   [        5         [        U [        R                  5      (       a5  [	        USLUSLUSL/5      (       a  [
        R                  " S[        SS9  U $ Uc  0 n[        U 5      n[        U[        [        45      (       d  [        R                  " U4UUS.UD6nU$ [        R                  " U 4SU0UD6nUR                  U5        U$ )z
Initialize a Delta lake table for use in read and scan operations.

Notes
-----
Make sure to install deltalake>=0.8.0. Read the documentation
`here <https://delta-io.github.io/delta-rs/usage/installation/>`_.
NzWhen supplying a DeltaTable directly, `version`, `storage_options`, and `delta_table_options` are ignored.
                To silence this warning, don't supply those parameters.   )
stacklevel)r   r   r   )rH   rK   r   r   anywarningswarnRuntimeWarningrn   rj   r   load_as_version)r.   r   r   r   rm   ra   s         r(   rN   rN     s     *i2233t#t+#4/
 
 MMK	 " *:6LgX//%%
+
 "	
 M %%
+
 "

 	w'Mr*   c                 4    [         (       d  Sn [        U 5      eg )Nz=deltalake is not installed

Please run: pip install deltalake)r   ModuleNotFoundError)r_   s    r(   rH   rH     s    O!#&&  r*   c                d    [        U 6 n[        [        1nX-  =n(       a  SU< 3n[        U5      eg )Nz+dataframe contains unsupported data types: )r
   r	   r   	TypeError)dtypesschema_dtypesunsupported_typesoverlapr_   s        r(   _check_for_unsupported_typesr     sA    !6*Mt
  33w3;G;Gn 4r*   )r#   str | Path | DeltaTabler   int | str | datetime | Noner   zlist[str] | Noner   bool | Noner   dict[str, Any] | Noner   3CredentialProviderFunction | Literal['auto'] | Noner   r   r    boolr!   r   rG   r   )r#   r   r   r   r   r   r   r   r   r   r    r   r!   r   r   r   rG   r   )rY   z
str | Pathrh   r   rG   rj   )NNN)
r.   r   r   r   r   r   r   r   rG   zdeltalake.DeltaTable)rG   None)r{   zlist[DataType]rG   r   ))
__future__r   rs   r   pathlibr   typingr   r   polars.datatypesr   r	   polars.datatypes.convertr
   polars.dependenciesr   r   polars.io.cloud._utilsr   polars.io.parquetr   #polars.io.pyarrow_dataset.functionsr   #polars.io.scan_options.cast_optionsr   polars.schemar   r   r   polarsr   r   r   polars.io.cloudr   r)   r$   rn   rN   rH   r   rF   r*   r(   <module>r      s   "    % ' 2 ? 3 * D ?  $55: ,0 $-1OU15-1H#H )H 	H
 H +H MH /H H +H H\ ,0-1OU15-1~#~ )~ +	~
 M~ /~ ~ +~ ~ ~B FJ  ,0-115	1'1(1 +1 /	1
 1h'	r*   