
    hc                       S SK Jr  S SKrS SKrS SKrS SKrS SKJrJrJ	r	  S SK
Jr  S SKJr  S SKJrJrJrJr  \(       a8  S SKJr  S SKJr  S SKrS S	K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#  \RH                  " \%5         S SK&J'r'  \'RP                  " \\\\S9  SSS5         " S S5      r) " S S5      r*      SS jr+g! , (       d  f       N.= f)    )annotationsN)TYPE_CHECKINGAnyLiteral)issue_unstable_warning)wrap_ldf)CatalogInfo
ColumnInfoNamespaceInfo	TableInfo)	Generator)datetime)
SchemaDict)DataSourceFormat	TableType)	DataFrame)CredentialProviderFunction CredentialProviderFunctionReturnCredentialProviderBuilder)	LazyFrame)PyCatalogClient)catalog_info_clsnamespace_info_clstable_info_clscolumn_info_clsc                     \ rS rSrSrSSS.       S S jjrS!S jrS"S jrS#S	 jr        S$S
 jr	      S%S jr
SSSSSS.                 S&S jjrSSSSSS.                   S'S jjrSSS.       S(S jjrSS.     S)S jjrSSS.         S*S jjrSS.       S+S jjrSSSSS.                   S,S jjr        S-S jr            S.S jr\S/S j5       rSrg)0Catalog-   z
Unity catalog client.

.. warning::
        This functionality is considered **unstable**. It may be changed
        at any point without it being considered a breaking change.
autoT)bearer_tokenrequire_httpsc                  [        S5        U(       a'  UR                  S5      (       d  SU S3n[        U5      eUS:X  dh  US:X  ar  S[        R                  ;   a^  UR                  S5      (       aH  UR                  S5      R                  SS	5      S
   R                  S5      (       a  U R                  5       nUS:X  a  Sn[        R                  " X5      U l        g)as  
Initialize a catalog client.

.. warning::
    This functionality is considered **unstable**. It may be changed
    at any point without it being considered a breaking change.

Parameters
----------
workspace_url
    URL of the workspace, or alternatively the URL of the Unity catalog
    API endpoint.
bearer_token
    Bearer token to authenticate with. This can also be set to:

    * "auto": Automatically retrieve bearer tokens from the environment.
    * "databricks-sdk": Use the Databricks SDK to retrieve and use the
      bearer token from the environment.
require_https
    Require the `workspace_url` to use HTTPS.
z/`Catalog` functionality is considered unstable.zhttps://z%a non-HTTPS workspace_url was given (z5). To allow non-HTTPS URLs, pass require_https=False.zdatabricks-sdkr    DATABRICKS_RUNTIME_VERSION/   r   z.cloud.databricks.comN)r   
startswith
ValueErrorosenvironremoveprefixsplitendswith_get_databricks_tokenr   new_client)selfworkspace_urlr!   r"   msgs        U/home/james-whalen/.local/lib/python3.13/site-packages/polars/catalog/unity/client.py__init__Catalog.__init__6   s    8 	PQ!9!9*!E!E7 GB B  S/!++F" -

:((44**:6sAq"123
  557L6!L&**=G    c                6    U R                   R                  5       $ )z
List the available catalogs.

.. warning::
    This functionality is considered **unstable**. It may be changed
    at any point without it being considered a breaking change.
)r0   list_catalogs)r1   s    r4   r9   Catalog.list_catalogso   s     ||))++r7   c                8    U R                   R                  U5      $ )a  
List the available namespaces (unity schema) under the specified catalog.

.. warning::
    This functionality is considered **unstable**. It may be changed
    at any point without it being considered a breaking change.

Parameters
----------
catalog_name
    Name of the catalog.
)r0   list_namespaces)r1   catalog_names     r4   r<   Catalog.list_namespacesy   s     ||++L99r7   c                8    U R                   R                  X5      $ )a;  
List the available tables under the specified schema.

.. warning::
    This functionality is considered **unstable**. It may be changed
    at any point without it being considered a breaking change.

Parameters
----------
catalog_name
    Name of the catalog.
namespace
    Name of the namespace (unity schema).
)r0   list_tables)r1   r=   	namespaces      r4   r@   Catalog.list_tables   s     ||''@@r7   c                :    U R                   R                  XU5      $ )aU  
Retrieve the metadata of the specified table.

.. warning::
    This functionality is considered **unstable**. It may be changed
    at any point without it being considered a breaking change.

Parameters
----------
catalog_name
    Name of the catalog.
namespace
    Name of the namespace (unity schema).
table_name
    Name of the table.
)r0   get_table_infor1   r=   rA   
table_names       r4   rD   Catalog.get_table_info   s    & ||**<JOOr7   c               4    U R                   R                  XS9$ )N)table_idwrite)r0   get_table_credentials)r1   rI   rJ   s      r4   _get_table_credentialsCatalog._get_table_credentials   s     ||1181QQr7   N   )delta_table_versiondelta_table_optionsstorage_optionscredential_providerretriesc               x   U R                  XU5      n	[        U	S5      u  pU R                  UUU	SSS9u  pvUS;   a  SSKJn  U" U
UUUUS9$ Ub  S
U 3n[        U5      eUb  SU 3n[        U5      eU(       a  [        UR                  5       5      nOS	n[        U R                  R                  UUUUUUS95      $ )a  
Retrieve the metadata of the specified table.

.. warning::
    This functionality is considered **unstable**. It may be changed
    at any point without it being considered a breaking change.

Parameters
----------
catalog_name
    Name of the catalog.
namespace
    Name of the namespace (unity schema).
table_name
    Name of the table.
delta_table_version
    Version of the table to scan (Deltalake only).
delta_table_options
    Additional keyword arguments while reading a Deltalake table.
storage_options
    Options that indicate how to connect to a cloud provider.

    The cloud providers currently supported are AWS, GCP, and Azure.
    See supported keys here:

    * `aws <https://docs.rs/object_store/latest/object_store/aws/enum.AmazonS3ConfigKey.html>`_
    * `gcp <https://docs.rs/object_store/latest/object_store/gcp/enum.GoogleConfigKey.html>`_
    * `azure <https://docs.rs/object_store/latest/object_store/azure/enum.AzureConfigKey.html>`_
    * Hugging Face (`hf://`): Accepts an API key under the `token` parameter:             `{'token': '...'}`, or by setting the `HF_TOKEN` environment variable.

    If `storage_options` is not provided, Polars will try to infer the
    information from environment variables.
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.
retries
    Number of retries if accessing a cloud instance fails.


scan tableFzCatalog.scan_tablerJ   caller_nameDELTADELTASHARINGr   )
scan_delta)versionrP   rQ   rR   Nz3cannot apply delta_table_version for table of type z3cannot apply delta_table_options for table of type )rR   cloud_optionsrS   )rD   !_extract_location_and_data_format_init_credentialspolars.io.deltar[   r(   listitemsr   r0   
scan_table)r1   r=   rA   rF   rO   rP   rQ   rR   rS   
table_infostorage_locationdata_source_formatr[   r3   s                 r4   rc   Catalog.scan_table   s   v ((*M
/P0
, 04/E/E, 0F 0
, !::2 +$7 /$7  *E%&(  S/!*E%&(  S/!"?#8#8#:;O #OLL##$7- $ 	
 		
r7   error)
delta_modedelta_write_optionsdelta_merge_optionsrQ   rR   c          	         U R                  X#U5      n
[        U
S5      u  pU R                  U	UU
SSS9u  pUS;   a  UR                  UUU	UUUS9$ SU SU SU S	U S
3	n[	        U5      e)a	  
Write a DataFrame to a catalog table.

.. warning::
    This functionality is considered **unstable**. It may be changed
    at any point without it being considered a breaking change.

Parameters
----------
df
    DataFrame to write.
catalog_name
    Name of the catalog.
namespace
    Name of the namespace (unity schema).
table_name
    Name of the table.
delta_mode : {'error', 'append', 'overwrite', 'ignore', 'merge'}
    (For delta tables) How to handle existing data.

    - If 'error', throw an error if the table already exists (default).
    - If 'append', will add new data.
    - If 'overwrite', will replace table with new data.
    - If 'ignore', will not write anything if table already exists.
    - If 'merge', return a `TableMerger` object to merge data from the DataFrame
      with the existing data.
delta_write_options
    (For delta tables) Additional keyword arguments while writing a
    Delta lake Table.
    See a list of supported write options `here <https://delta-io.github.io/delta-rs/api/delta_writer/#deltalake.write_deltalake>`__.
delta_merge_options
    (For delta tables) Keyword arguments which are required to `MERGE` a
    Delta lake Table.
    See a list of supported merge options `here <https://delta-io.github.io/delta-rs/api/delta_table/#deltalake.DeltaTable.merge>`__.
storage_options
    Options that indicate how to connect to a cloud provider.

    The cloud providers currently supported are AWS, GCP, and Azure.
    See supported keys here:

    * `aws <https://docs.rs/object_store/latest/object_store/aws/enum.AmazonS3ConfigKey.html>`_
    * `gcp <https://docs.rs/object_store/latest/object_store/gcp/enum.GoogleConfigKey.html>`_
    * `azure <https://docs.rs/object_store/latest/object_store/azure/enum.AzureConfigKey.html>`_
    * Hugging Face (`hf://`): Accepts an API key under the `token` parameter:             `{'token': '...'}`, or by setting the `HF_TOKEN` environment variable.

    If `storage_options` is not provided, Polars will try to infer the
    information from environment variables.
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.
rU   TzCatalog.write_tablerV   rX   )rQ   rR   moderj   rk   zwrite_table: table format of .z (z) is unsupported.)rD   r^   r_   write_deltaNotImplementedError)r1   dfr=   rA   rF   ri   rj   rk   rQ   rR   rd   re   rf   r3   s                 r4   write_tableCatalog.write_table%  s    T ((*M
/P0
, 04/E/E- 0F 0
, !::>>  /$7$7$7 "   0.)Aj\ :&''8: 
 &c**r7   )commentstorage_rootc               6    U R                   R                  XUS9$ )aQ  
Create a catalog.

.. warning::
    This functionality is considered **unstable**. It may be changed
    at any point without it being considered a breaking change.

Parameters
----------
catalog_name
    Name of the catalog.
comment
    Leaves a comment about the catalog.
storage_root
    Base location at which to store the catalog.
)r=   rt   ru   )r0   create_catalog)r1   r=   rt   ru   s       r4   rw   Catalog.create_catalog  s%    . ||**%\ + 
 	
r7   F)forcec               6    U R                   R                  XS9  g)a  
Delete a catalog.

Note that depending on the table type and catalog server, this may not
delete the actual data files from storage. For more details, please
consult the documentation of the catalog provider you are using.

.. warning::
    This functionality is considered **unstable**. It may be changed
    at any point without it being considered a breaking change.

Parameters
----------
catalog_name
    Name of the catalog.
force
    Forcibly delete the catalog even if it is not empty.
)r=   ry   N)r0   delete_catalog)r1   r=   ry   s      r4   r{   Catalog.delete_catalog  s    0 	###Kr7   c               :    U R                   R                  UUUUS9$ )a  
Create a namespace (unity schema) in the catalog.

.. warning::
    This functionality is considered **unstable**. It may be changed
    at any point without it being considered a breaking change.

Parameters
----------
catalog_name
    Name of the catalog.
namespace
    Name of the namespace (unity schema).
comment
    Leaves a comment about the table.
storage_root
    Base location at which to store the namespace.
)r=   rA   rt   ru   )r0   create_namespace)r1   r=   rA   rt   ru   s        r4   r~   Catalog.create_namespace  s,    4 ||,,%%	 - 
 	
r7   c               8    U R                   R                  XUS9  g)aE  
Delete a namespace (unity schema) in the catalog.

Note that depending on the table type and catalog server, this may not
delete the actual data files from storage. For more details, please
consult the documentation of the catalog provider you are using.

.. warning::
    This functionality is considered **unstable**. It may be changed
    at any point without it being considered a breaking change.

Parameters
----------
catalog_name
    Name of the catalog.
namespace
    Name of the namespace (unity schema).
force
    Forcibly delete the namespace even if it is not empty.
)r=   rA   ry   N)r0   delete_namespace)r1   r=   rA   ry   s       r4   r   Catalog.delete_namespace  s     6 	%%%% 	& 	
r7   )rf   rt   ru   
propertiesc                   U R                   R                  UUUUUUUU[        U	=(       d    0 R                  5       5      S9	$ )aW  
Create a table in the catalog.

.. warning::
    This functionality is considered **unstable**. It may be changed
    at any point without it being considered a breaking change.

Parameters
----------
catalog_name
    Name of the catalog.
namespace
    Name of the namespace (unity schema).
table_name
    Name of the table.
schema
    Schema of the table.
table_type
    Type of the table
data_source_format
    Storage format of the table.
comment
    Leaves a comment about the table.
storage_root
    Base location at which to store the table.
properties
    Extra key-value metadata to store.
)	r=   rA   rF   schema
table_typerf   rt   ru   r   )r0   create_tablera   rb   )
r1   r=   rA   rF   r   r   rf   rt   ru   r   s
             r4   r   Catalog.create_table  sO    R ||((%!!1%Z-24467 ) 

 
	
r7   c                :    U R                   R                  UUUS9  g)a  
Delete the table stored at this location.

Note that depending on the table type and catalog server, this may not
delete the actual data files from storage. For more details, please
consult the documentation of the catalog provider you are using.

If you would like to perform manual deletions, the storage location of
the files can be found using `get_table_info`.

.. warning::
    This functionality is considered **unstable**. It may be changed
    at any point without it being considered a breaking change.

Parameters
----------
catalog_name
    Name of the catalog.
namespace
    Name of the namespace (unity schema).
table_name
    Name of the table.
)r=   rA   rF   N)r0   delete_tablerE   s       r4   r   Catalog.delete_table8  s$    : 	!!%! 	" 	
r7   c          
        SSK Jn  US:w  a  U(       a  UR                  " U5      U4$ S U4$ [        R                  " S5      S:H  n[        XR                  US9n UR                  5       n	[        U	5      n
U
(       a  0 U=(       d    0 EU
EnU	 H  nM     U(       a;  UR                  nUR                  nSU< SU< S	3n[        U[        R                  S
9  UR                  " U5      U4$ ! [         aT  nU(       aC  UR                  nUR                  nSU< SU< SU< SU< S	3	n[        U[        R                  S
9   S nAOS nAff = fSSK Jn  U" SUR                  X%5      U4$ )Nr   r   r    POLARS_VERBOSE1rJ   z9auto-selected CatalogCredentialProvider for table_name = z (table_id = ))filez3error auto-initializing CatalogCredentialProvider: z table_name = z) (write = )!_init_credential_provider_builder),polars.io.cloud.credential_provider._builderr   from_initialized_providerr)   getenvCatalogCredentialProviderrI   _credentials_iternextnameprintsysstderr	Exceptionr   re   )r1   rR   rQ   rd   rJ   rW   r   verbosecatalog_credential_providervstorage_update_options_rF   rI   r3   er   s                    r4   r_   Catalog._init_credentials[  s   	
 &("0JJ'"# # _,,)),-4&?%%U'
#	+==?A%)!W"%"Wo&;"W@V"W  '__
%..%!o^}A7  c

+,FF+ '  	,'__
%..I! O%!o^}LzD  c

+	,6	
 1J//
 	s   :C* *
E4A
EEc                    [         R                  R                  S5      c  Sn[        U5      e[         R                  " S5      R
                  nUS   " 5       " US   " 5       5      " 5       S   SS  $ )Nzdatabricks.sdkz?could not get Databricks token: databricks-sdk is not installedzdatabricks.sdk.coreDefaultCredentialsConfigAuthorization   )	importlibutil	find_specImportErrorimport_module__dict__)clsr3   ms      r4   r.   Catalog._get_databricks_token  sj    >>##$45=SCc"" ##$9:CC%&(879/J12NNr7   )r0   )r2   strr!   
str | Noner"   boolreturnNone)r   zlist[CatalogInfo])r=   r   r   zlist[NamespaceInfo])r=   r   rA   r   r   zlist[TableInfo])r=   r   rA   r   rF   r   r   r   )rI   r   rJ   r   r   z1tuple[dict[str, str] | None, dict[str, str], int])r=   r   rA   r   rF   r   rO   zint | str | datetime | NonerP   dict[str, Any] | NonerQ   r   rR   3CredentialProviderFunction | Literal['auto'] | NonerS   intr   r   )rq   r   r=   r   rA   r   rF   r   ri   z:Literal['error', 'append', 'overwrite', 'ignore', 'merge']rj   r   rk   r   rQ   dict[str, str] | NonerR   r   r   z"None | deltalake.table.TableMerger)r=   r   rt   r   ru   r   r   r	   )r=   r   ry   r   r   r   )
r=   r   rA   r   rt   r   ru   r   r   r   )r=   r   rA   r   ry   r   r   r   )r=   r   rA   r   rF   r   r   zSchemaDict | Noner   r   rf   zDataSourceFormat | Nonert   r   ru   r   r   r   r   r   )r=   r   rA   r   rF   r   r   r   )rR   r   rQ   r   rd   r   rJ   r   rW   r   r   z>tuple[CredentialProviderBuilder | None, dict[str, Any] | None])r   r   )__name__
__module____qualname____firstlineno____doc__r5   r9   r<   r@   rD   rL   rc   rr   rw   r{   r~   r   r   r   r_   classmethodr.   __static_attributes__ r7   r4   r   r   -   si    $*"7H7H !	7H
 7H 
7Hr,:A"PP,/P=@P	P*RR'+R	:R <@5915 p
p
 p
 	p
 9p
 3p
 /p
 @p
 p
 
p
v 595915 g+g+ g+ 	g+
 g+
g+ 3g+ 3g+ /g+g+  
,!g+Z ##'

 	

 !
 

> 	LL 	L
 
L> ##'

 

 
 !
 

L 

 

 
 

N 7;"#',03
3
 3
 	3
 "3
 3
 43
 3
 !3
 *3
 
3
j!
!
 !
 	!

 
!
FIPI /I 	I I I
IV O Or7   r   c                  :    \ rS rSrSrSS jrS	S jr  S
S jrSrg)r   i  zGRetrieves credentials from the Unity catalog temporary credentials API.c               (    Xl         X l        X0l        g NcatalogrI   rJ   )r1   r   rI   rJ   s       r4   r5   "CatalogCredentialProvider.__init__  s     
r7   c                2    U R                  5       u  nu  p#X#4$ r   )r   )r1   r   credsexpirys       r4   __call__"CatalogCredentialProvider.__call__  s    !335?E}r7   c              #     #    U R                   R                  U R                  U R                  S9u  pnUv   U(       d  U R                  nSU< 3n[	        U5      eX4v   g 7f)Nr   zJdid not receive credentials from temporary credentials API for table_id = )r   rL   rI   rJ   r   )r1   r   r   r   rI   r3   s         r4   r   +CatalogCredentialProvider._credentials_iter  so      150S0SMM 1T 1
-v %$}}H-!  C. ms   A A"r   N)r   r   rI   r   rJ   r   r   r   )r   r   )r   zGenerator[Any])	r   r   r   r   r   r5   r   r   r   r   r7   r4   r   r     s    Q
	r7   r   c                    U R                   c  SU S3n[        U5      eU R                  c  SU S3n[        U5      eU R                   U R                  4$ )Nzcannot z: no storage_location foundz: no data_source_format found)re   r(   rf   )rd   	operationr3   s      r4   r^   r^     se     ""*	{"=>o$$,	{"?@o&&
(E(EEEr7   )rd   r   r   r   r   ztuple[str, DataSourceFormat]),
__future__r   
contextlibr   r)   r   typingr   r   r   polars._utils.unstabler   polars._utils.wrapr   polars.catalog.unity.modelsr	   r
   r   r   collections.abcr   r   	deltalakepolars._typingr   r   r   polars.dataframe.framer   polars.io.cloudr   r   r   r   polars.lazyframer   suppressr   polars._plrr   init_classesr   r   r^   r   r7   r4   <module>r      s    "   	 
 . . 9 '  )!)G0 W*%+  $( "	 &B
O B
OJ @FF&)F!Fa &%s   
C
C