
    IZj                    h   d Z ddlmZ ddlZddlmZmZmZmZm	Z	m
Z
mZ ej        dk    rddlmZ nddlmZ erddlmZ ddlmZ ddlZdd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlm Z  ddl!m"Z" ddl#m$Z$ ddl%m&Z& ddl'm(Z) ddl*m+Z+ ddl,m-Z-m.Z. ddl/m0Z0m1Z1m2Z2 ddl3m4Z4m5Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZA ddlBmCZCmDZDmEZE ddlFmGZG ddlHmIZI ddlJmKZK ddlLmMZM ddlNmOZO dTd$ZPdUd(ZQ	 	 	 dVdWd6ZRdXd8ZSdYd:ZTdZd>ZUd[dAZV G dB dCe.          ZW G dD dE          ZXdddddFd\dRZYdddddFd]dSZZdS )^z
LanceDB Namespace integration module.

This module provides integration with lance_namespace for managing tables
through a namespace abstraction.
    )annotationsN)TYPE_CHECKINGAnyDictIterableListOptionalUnion)      )overrideQuery)	timedelta)JsonArrowDataType)JsonArrowField)JsonArrowSchema)QueryTableRequest)QueryTableRequestColumns)QueryTableRequestFullTextQuery)QueryTableRequestVector)StringFtsQuery)TableNotFoundError)connect_namespace_client)LOOP)AsyncConnectionDBConnection) _normalize_create_namespace_mode_normalize_drop_namespace_mode"_normalize_drop_namespace_behavior)LanceNamespaceconnectCreateNamespaceResponseDescribeNamespaceResponseDropNamespaceResponseListNamespacesResponseListTablesResponseListTablesRequestDescribeNamespaceRequestDropTableRequestListNamespacesRequestCreateNamespaceRequestDropNamespaceRequest)
AsyncTable
LanceTableTable)validate_table_name)DATA)
LanceModel)EmbeddingFunctionConfig   )Sessiontable_id	List[str]query'Query'returnr   c           	     V   ddl m} t          ||          st          dt	          |                     d}|j        t          |j        t          j                  r|j                                        }n_t          |j        t                    r>|j        r7t          |j        d         t          j                  rd |j        D             }n|j        }t          |t                    r.|r,t          |d         t                    rt          |          }nt          |          }d}|j        Et          |j        t                    rt          |j                  }nt          |j        	          }d}|j        |j        }t          |t                    rt!          t#          |
                    }nKt%          |d          r;t!          t#          |j        t%          |d          r|j        nd                    }d}|j        |j         }|j        |j        nd}	| |	||nt                      d}
|j        
|j        |
d<   |j        
|j        |
d<   |||
d<   |||
d<   |||
d<   |j        
|j        |
d<   |j        
|j        |
d<   |j        
|j        |
d<   |j        
|j        |
d<   |j        
|j        |
d<   |j        
|j        |
d<   |j        
|j        |
d<   |j        
|j        |
d<   |j         
|j         |
d<   |j!        
|j!        |
d<   tE          di |
S ) a^  
    Convert a LanceDB Query object to a QueryTableRequest for server-side query.

    Parameters
    ----------
    table_id : List[str]
        The table identifier (namespace path + table name)
    query : Query
        The LanceDB Query object to convert

    Returns
    -------
    QueryTableRequest
        The namespace QueryTableRequest
    r   r   zExpected Query, got Nc                6    g | ]}|                                 S  )	to_pylist).0vs     ]/Users/jameslopez/projects/MentorCore/.venv/lib/python3.11/site-packages/lancedb/namespace.py
<listcomp>z/_query_to_namespace_request.<locals>.<listcomp>j   s     ???Q1;;==???    )multi_vector)single_vector)column_aliases)column_names)r9   )string_queryr9   columns)r9   rJ   
   )idkvectorvector_columnfilter	prefilterfull_text_queryoffsetwith_row_idefnprobesrefine_factorlower_boundupper_boundbypass_vector_indexfast_searchdistance_typer>   )#lancedb.queryr   
isinstance	TypeErrortyperN   paArrayr?   listr   rJ   dictr   rR   strr   r   hasattrr9   
postfilterlimitrO   rP   rS   rT   rU   minimum_nprobesrW   rX   rY   rZ   r[   r\   r   )r7   r9   r   vector_requestvector_listcolumns_requestfull_text_query_request	fts_queryrQ   rM   kwargss              rB   _query_to_namespace_requestrp   I   s   & $#####eU## ><tE{{<<===N|elBH-- 		',0022KKu|T**	'	' 5<?BH55	'
 @?%,???KK,K {D))	P	P ;q>400	P
 5+NNNNN4;OOONO} emT** 	S6emTTTOO6EMRRRO"()	i%% 	&D+)<<<' ' '## Y(( 	&D+#/y)44I--	  ' ' '# I#((	{.BA
  % !.$&& F &"'"5| <x'{*$; !"+y| <x$ % 1}xxt(!1y&"'"5$ % 1}$ % 1} ,(-(A$%$ % 1}&"'"5&&v&&&rD   namespace_clientr!   pa.RecordBatchReaderc                j    t          ||          }|                     |          }t          |          S )a  
    Execute a query on the namespace server and return results as RecordBatchReader.

    Parameters
    ----------
    namespace_client : LanceNamespace
        The namespace client to use
    table_id : List[str]
        The table identifier (namespace path + table name)
    query : Query
        The LanceDB Query object

    Returns
    -------
    pa.RecordBatchReader
        The query results as a RecordBatchReader
    )rp   query_table!_arrow_ipc_to_record_batch_reader)rq   r7   r9   request	ipc_bytess        rB   _execute_server_side_queryrx      s4    , *(E::G ,,W55I,Y777rD   error        dataOptional['DATA']schema&Optional[Union[pa.Schema, LanceModel]]embedding_functions'Optional[List[EmbeddingFunctionConfig]]on_bad_vectorsre   
fill_valuefloatbytesc                   ddl m} ddlm} t	          |t
                    r)t          |t                    r|                                }|	                                }|r|
                    |          }n||j        }nd}| |t          d          |r|                    |          }t          j                    }	t          j                            |	|          5 }
	 ddd           n# 1 swxY w Y   |	                                                                S  || ||||          }t          j                    }	t          j                            |	|j                  5 }
|D ]}|
                    |           	 ddd           n# 1 swxY w Y   |	                                                                S )a?  
    Convert data to Arrow IPC format (file format) for server-side create_table.

    If data is None but schema is provided, creates an empty IPC stream with
    just the schema in the header (zero batches). This is used to create
    empty tables with just a schema.

    Returns the serialized Arrow IPC bytes.
    r   )EmbeddingFunctionRegistry)_sanitize_dataNz>Either data or schema is required for server-side create_table)target_schemametadatar   r   )lancedb.embeddingsr   lancedb.tabler   r^   r`   
issubclassr3   to_arrow_schemaget_instanceget_table_metadatar   
ValueErrorwith_metadatara   BufferOutputStreamipc
new_streamgetvalue
to_pybytesr}   write_batch)r{   r}   r   r   r   r   r   registryr   sinkwriterreaderbatchs                rB   _data_to_arrow_ipcr      s\     =<<<<<,,,,,,&$ *Jvz$B$B *'')) )5577H ../BCC		? |>P    	4))(33F$&&VtV,, 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	}}))+++^%  F  ""D			4	/	/ &6 	& 	&Eu%%%%	&& & & & & & & & & & & & & & & ==??%%'''s$    C..C25C2'FFFrw   c                    t          j        |           }t           j                            |          fdt	          j                  D             }t           j                            j        |          S )z9
    Convert Arrow IPC bytes to a RecordBatchReader.
    c                :    g | ]}                     |          S r>   )	get_batch)r@   ir   s     rB   rC   z5_arrow_ipc_to_record_batch_reader.<locals>.<listcomp>  s'    MMMqv""MMMrD   )	ra   	py_bufferr   	open_filerangenum_record_batchesRecordBatchReaderfrom_batchesr}   )rw   bufbatchesr   s      @rB   ru   ru     sh     ,y
!
!CVc""FMMMME&2K,L,LMMMG,,V]GDDDrD   modec                p    |                                  }|dk    rdS |dk    rdS t          d|  d          )z5Normalize create table mode string for namespace API.createCreate	overwrite	OverwritezInvalid mode: z!. Must be 'create' or 'overwrite')lowerr   )r   
mode_lowers     rB   _normalize_create_table_moder   #  sI    JXx	{	"	"{Q$QQQRRRrD   
arrow_typepa.DataTyper   c                   t           j                            |           rd}nt           j                            |           rd}nt           j                            |           rd}nt           j                            |           rd}nt           j                            |           rd}nt           j                            |           rd}net           j                            |           rd}nBt           j        	                    |           rd}nt           j        
                    |           rd	}nt           j                            |           rd
}nt           j                            |           rd}nt           j                            |           rd}nt           j                            |           rd}nut           j                            |           rd}nSt           j                            |           rd}n1t           j                            |           rd}nt%          |           }t'          |          S )z.Convert PyArrow DataType to JsonArrowDataType.nullboolint8uint8int16uint16int32uint32int64uint64float32float64utf8binaryrc   fixed_size_list)r`   )ra   typesis_null
is_booleanis_int8is_uint8is_int16	is_uint16is_int32	is_uint32is_int64	is_uint64
is_float32
is_float64	is_string	is_binaryis_listis_fixed_size_listre   r   )r   	type_names     rB   _convert_pyarrow_type_to_jsonr   .  s   	x
## #$					Z	(	( !$					*	%	% $					:	&	& $					:	&	& $					J	'	' $					:	&	& $					J	'	' $					:	&	& $					J	'	' $					Z	(	( $					Z	(	( $					J	'	' $					J	'	' 	$					*	%	% $				$	$Z	0	0 $%		 
OO	),,,,rD   	pa.Schemar   c                   g }| D ]K}t          |j        t          |j                  |j        |j                  }|                    |           Ld}| j        r#d | j                                        D             }t          ||          S )z*Convert PyArrow Schema to JsonArrowSchema.)namer`   nullabler   Nc                f    i | ].\  }}|                     d           |                     d           /S )zutf-8)decode)r@   rM   rA   s      rB   
<dictcomp>z3_convert_pyarrow_schema_to_json.<locals>.<dictcomp>g  sC     
 
 
59QAHHWqxx00
 
 
rD   )fieldsr   )	r   r   r   r`   r   r   appenditemsr   )r}   r   field
json_fieldmetas        rB   _convert_pyarrow_schema_to_jsonr   X  s    F " "#.uz::^^	
 
 

 	j!!!! D 

 
=C_=R=R=T=T
 
 
 &48888rD   c                     e Zd ZdZddddddddTdZedUd            Ze	 	 dVdddWd            Ze	 	 	 	 	 	 	 dXddddd!dYd3            Zedddd4dZd7            Z	ed[d\d8            Z
e	 	 d]d^d=            Zed>             Zed[d_d?            Ze	 	 	 d`dadA            Ze	 	 d]dbdE            Ze	 	 d]dcdH            ZedddJ            Ze	 	 	 d`dedL            ZddddddMdfdRZedgdS            ZdS )hLanceNamespaceDBConnectionz
    A LanceDB connection that uses a namespace for table management.

    This connection delegates table URI resolution to a lance_namespace instance,
    while using the standard LanceTable for actual table operations.
    Nread_consistency_intervalstorage_optionssession$namespace_client_pushdown_operationsnamespace_client_implnamespace_client_propertiesrq   r!   r   Optional[timedelta]r   Optional[Dict[str, str]]r   Optional[Session]r   Optional[List[str]]r   Optional[str]r   c               8   || _         || _        |pi | _        || _        t	          |pg           | _        || _        || _        t          t          |||
                                nd| j        pd|t          | j                  ||                    | _        dS )a  
        Initialize a namespace-based LanceDB connection.

        Parameters
        ----------
        namespace_client : LanceNamespace
            The namespace client to use for table management
        read_consistency_interval : Optional[timedelta]
            The interval at which to check for updates to the table from other
            processes. If None, then consistency is not checked.
        storage_options : Optional[Dict[str, str]]
            Additional options for the storage backend
        session : Optional[Session]
            A session to use for this connection
        namespace_client_pushdown_operations : Optional[List[str]]
            List of namespace operations to push down to the namespace server.
            Supported values:

            - "QueryTable": Execute queries on the namespace server via
              namespace.query_table() instead of locally.
            - "CreateTable": Execute table creation on the namespace server via
              namespace.create_table() instead of using declare_table + local write.

            Default is None (no pushdown, all operations run locally).
        namespace_client_impl : Optional[str]
            The namespace implementation name used to create this connection.
            Stored for serialization purposes.
        namespace_client_properties : Optional[Dict[str, str]]
            The namespace properties used to create this connection.
            Stored for serialization purposes.
        Nr   )_namespace_clientr   r   r   set%_namespace_client_pushdown_operations_namespace_client_impl_namespace_client_propertiesr   _connect_namespace_clienttotal_secondsrc   _inner)selfrq   r   r   r   r   r   r   s           rB   __init__z#LanceNamespaceDBConnection.__init__v  s    T "2)B&.4"5806B6
 6
2 '<#,G)%%  1< .;;=== $ 4 <CDD&;,G  
 
rD   r;   re   c           	         dd l }|                    d| j        | j        t	          | j                  | j        pd | j        r| j                                        nd d          S )Nr   	namespace)connection_typer   r   r   r   !read_consistency_interval_seconds)	jsondumpsr   r   sortedr   r   r   r   )r   r  s     rB   	serializez$LanceNamespaceDBConnection.serialize  s~    zz#.)-)D/3/P8>>9 9 $(#7#?4 5D2@@BBB 
 
 	
rD   rK   namespace_path
page_tokenrh   intr  Iterable[str]c                   ddl }|                    dt          d           |g }t          |||          }| j                            |          }|j        r|j        ng S )z
        List table names in the database.

        .. deprecated::
            Use :meth:`list_tables` instead, which provides proper pagination support.
        r   N6table_names() is deprecated, use list_tables() instead   
stacklevelrL   r	  rh   warningswarnDeprecationWarningr(   r   list_tablestablesr   r	  rh   r  r  rv   responses          rB   table_namesz&LanceNamespaceDBConnection.table_names  s     	D 	 	
 	
 	

 !N#*E
 
 
 )55g>>"*/9xr9rD   r   Fry   rz   r  r   data_storage_versionenable_v2_manifest_pathsr   r{   Optional[DATA]r}   r~   r   exist_okr   r   r   r   r   r   r  r  Optional[bool]r0   c	                  |	g }	|                                 dvrt          d          t          |           t          j        | j                            |||||||||	|

  
                  }t          | ||	| j        | j	        |          S )Nr   r   +mode must be either 'create' or 'overwrite')r}   r   r  r   r   r   r  r   r  rq   pushdown_operations_async)
r   r   r1   r   runr   create_tabler/   r   r   )r   r   r{   r}   r   r  r   r   r   r  r   r  r  async_tables                 rB   r(  z'LanceNamespaceDBConnection.create_table  s    " !N::<<666JKKKD!!!hK$$!-%$7- / %  
 
 )!3 $ J
 
 
 	
rD   r  r   index_cache_sizer+  Optional[int]c               J   |g }	 t          j        | j                            ||||                    }nO# t          $ rB}dt          |          v r+||gz   }t          dd                    |                      d }~ww xY wt          | ||| j	        | j
        |          S )Nr*  Table not foundTable not found: $r$  )r   r'  r   
open_tableRuntimeErrorre   r   joinr/   r   r   )r   r   r  r   r+  r)  er7   s           rB   r1  z%LanceNamespaceDBConnection.open_table  s     !N	(&&#1$3%5	 '   KK  	 	 	 CFF**)TF2()QSXXh=O=O)Q)QRRR		 )!3 $ J
 
 
 	
s   07 
B=A>>Bc                n    |g }||gz   }t          |          }| j                            |           d S )NrL   r*   r   
drop_tabler   r   r  r7   rv   s        rB   r8  z%LanceNamespaceDBConnection.drop_table>  sH     !N!TF*"h///))'22222rD   cur_namenew_namecur_namespace_pathnew_namespace_pathc                0    |g }|g }t          d          )N7rename_table is not supported for namespace connectionsNotImplementedErrorr   r:  r;  r<  r=  s        rB   rename_tablez'LanceNamespaceDBConnection.rename_tableG  s1     %!#%!#!E
 
 	
rD   c                     t          d          )N8drop_database is deprecated, use drop_all_tables insteadr@  r   s    rB   drop_databasez(LanceNamespaceDBConnection.drop_databaseW  s    !F
 
 	
rD   c                n    |g }|                      |          D ]}|                     ||           d S )Nr  r  r8  )r   r  
table_names      rB   drop_all_tablesz*LanceNamespaceDBConnection.drop_all_tables]  sT    !N**.*II 	G 	GJOOJ~OFFFF	G 	GrD   r&   c                    |g }t          |||          }| j                            |          }t          |j        r|j        ng |j                  S a  
        List child namespaces under the given namespace.

        Parameters
        ----------
        namespace_path : Optional[List[str]]
            The parent namespace path to list children from.
            If None, lists root-level namespaces.
        page_token : Optional[str]
            Token for pagination. Use the token from a previous response
            to get the next page of results.
        limit : int, optional
            Maximum number of namespaces to return.

        Returns
        -------
        ListNamespacesResponse
            Response containing namespace names and optional page_token for pagination.
        Nr  )
namespacesr	  r+   r   list_namespacesr&   rN  r	  r   r  r	  rh   rv   r  s         rB   rP  z*LanceNamespaceDBConnection.list_namespacesd  sr    4 !N'*E
 
 
 )99'BB%.6.AIx**r*
 
 
 	
rD   r8   
propertiesr#   c                    t          |t          |          |          }| j                            |          }t	          t          |d          r|j        nd          S a8  
        Create a new namespace.

        Parameters
        ----------
        namespace_path : List[str]
            The namespace path to create.
        mode : str, optional
            Creation mode - "create" (fail if exists), "exist_ok" (skip if exists),
            or "overwrite" (replace if exists). Case insensitive.
        properties : Dict[str, str], optional
            Properties to set on the namespace.

        Returns
        -------
        CreateNamespaceResponse
            Response containing the properties of the created namespace.
        )rL   r   rR  rR  NrR  r,   r   r   create_namespacer#   rf   rR  r   r  r   rR  rv   r  s         rB   rW  z+LanceNamespaceDBConnection.create_namespace  ss    2 )1$77!
 
 

 )::7CC&.5h.M.MWx**SW
 
 
 	
rD   behaviorr%   c                   t          |t          |          t          |                    }| j                            |          }t          t          |d          r|j        ndt          |d          r|j        nd          S a+  
        Drop a namespace.

        Parameters
        ----------
        namespace_path : List[str]
            The namespace path to drop.
        mode : str, optional
            Whether to skip if not exists ("SKIP") or fail ("FAIL"). Case insensitive.
        behavior : str, optional
            Whether to restrict drop if not empty ("RESTRICT") or cascade ("CASCADE").
            Case insensitive.

        Returns
        -------
        DropNamespaceResponse
            Response containing properties and transaction_id if applicable.
        )rL   r   rY  rR  Ntransaction_id)rR  r\  	r-   r   r    r   drop_namespacer%   rf   rR  r\  r   r  r   rY  rv   r  s         rB   r^  z)LanceNamespaceDBConnection.drop_namespace  s    2 '/557AA
 
 

 )88AA$'.x'F'FP##D ,38=M+N+NX''TX
 
 
 	
rD   r$   c                    t          |          }| j                            |          }t          t	          |d          r|j        nd          S a   
        Describe a namespace.

        Parameters
        ----------
        namespace_path : List[str]
            The namespace identifier to describe.

        Returns
        -------
        DescribeNamespaceResponse
            Response containing the namespace properties.
        r6  rR  NrU  r)   r   describe_namespacer$   rf   rR  r   r  rv   r  s       rB   rc  z-LanceNamespaceDBConnection.describe_namespace  s\    " +n===)<<WEE(.5h.M.MWx**SW
 
 
 	
rD   r'   c                    |g }t          |||          }| j                            |          }t          |j        r|j        ng |j                  S a  
        List all tables in this database with pagination support.

        Parameters
        ----------
        namespace_path : List[str], optional
            The namespace to list tables in.
            None or empty list represents root namespace.
        page_token : str, optional
            Token for pagination. Use the token from a previous response
            to get the next page of results.
        limit : int, optional
            The maximum number of results to return.

        Returns
        -------
        ListTablesResponse
            Response containing table names and optional page_token for pagination.
        Nr  )r  r	  r(   r   r  r'   r  r	  rQ  s         rB   r  z&LanceNamespaceDBConnection.list_tables  so    4 !N#*E
 
 
 )55g>>!&.o=8??2*
 
 
 	
rD   )r  r   r+  rq   managed_versioning	table_uriOptional[Any]rh  r/   c                   |g }t          j        | j                            ||||d ||                    }t	          | |||||| j        |          S )N)r  r   r+  locationrq   rh  )r  rl  rq   rh  r%  r&  )r   r'  r   r1  r/   r   )	r   r   ri  r  r   r+  rq   rh  r)  s	            rB   _lance_table_from_uriz0LanceNamespaceDBConnection._lance_table_from_uri  s     !NhK""- /!1!1#5 #  

 

 )-1 $ J	
 	
 	
 		
rD   c                    | j         S a!  Get the namespace client for this connection.

        For namespace connections, this returns the backing namespace client
        that was provided during construction.

        Returns
        -------
        LanceNamespace
            The namespace client for this connection.
        r   rF  s    rB   rq   z+LanceNamespaceDBConnection.namespace_client9  s     %%rD   )rq   r!   r   r   r   r   r   r   r   r   r   r   r   r   )r;   re   NrK   r	  r   rh   r
  r  r   r;   r  NNr   Fry   rz   N)r   re   r{   r  r}   r~   r   re   r  r   r   re   r   r   r   r   r  r   r   r   r  r   r  r   r;   r0   )
r   re   r  r   r   r   r+  r,  r;   r0   Nr   re   r  r   NNr:  re   r;  re   r<  r   r=  r   r  r   NNNr  r   r	  r   rh   r,  r;   r&   r  r8   r   r   rR  r   r;   r#   r  r8   r   r   rY  r   r;   r%   r  r8   r;   r$   r  r   r	  r   rh   r,  r;   r'   )r   re   ri  re   r  r   r   r   r+  r,  rq   rj  rh  r   r;   r/   r;   r!   )__name__
__module____qualname____doc__r   r   r  r  r(  r1  r8  rC  rG  rK  rP  rW  r^  rc  r  rm  rq   r>   rD   rB   r   r   n  s         :>48%)DH/3@DC
 C
 C
 C
 C
 C
J 
 
 
 X
(  %):
 /3: : : : : X:8   $9=%GK+
 /348.237+
 +
 +
 +
 +
 X+
Z 
 /348*. 
  
  
  
  
 X 
D 3 3 3 3 X3 
 3726
 
 
 
 X
 
 
 X

 G G G G XG  /3$(#	"
 "
 "
 "
 X"
H  #/3	 
  
  
  
 X 
D  #"&	%
 %
 %
 %
 X%
N 
 
 
 X
,  /3$(#	"
 "
 "
 "
 X"
R /348*.*.-1'
 '
 '
 '
 '
 '
R & & & X& & &rD   r   c                      e Zd ZdZddddddKdZ	 	 dLdddMdZ	 	 	 	 	 	 	 dNddddddOd0Zdddd1dPd4ZdQdRd5Z	 	 dSdTd:Z	d; Z
dQdUd<Z	 	 	 dVdWd>Z	 	 dSdXdBZ	 	 dSdYdEZdZdGZ	 	 	 dVd[dIZd\dJZdS )]AsyncLanceNamespaceDBConnectionz
    An async LanceDB connection that uses a namespace for table management.

    This connection delegates table URI resolution to a lance_namespace instance,
    while providing async methods for all operations.
    Nr   r   r   r   rq   r!   r   r   r   r   r   r   r   r   c                  || _         || _        |pi | _        || _        t	          |pg           | _        t          t          |||                                nd| j        pd|t          | j                  dd                    | _
        dS )a~  
        Initialize an async namespace-based LanceDB connection.

        Parameters
        ----------
        namespace_client : LanceNamespace
            The namespace client to use for table management
        read_consistency_interval : Optional[timedelta]
            The interval at which to check for updates to the table from other
            processes. If None, then consistency is not checked.
        storage_options : Optional[Dict[str, str]]
            Additional options for the storage backend
        session : Optional[Session]
            A session to use for this connection
        namespace_client_pushdown_operations : Optional[List[str]]
            List of namespace operations to push down to the namespace server.
            Supported values:

            - "QueryTable": Execute queries on the namespace server via
              namespace.query_table() instead of locally.
            - "CreateTable": Execute table creation on the namespace server via
              namespace.create_table() instead of using declare_table + local write.

            Default is None (no pushdown, all operations run locally).
        Nr   )r   r   r   r   r   r   r   r   r   rc   r   )r   rq   r   r   r   r   s         rB   r   z(AsyncLanceNamespaceDBConnection.__init__P  s    D "2)B&.4"5806B6
 6
2 &%  1< .;;=== $ 4 <CDD&*,0  
 
rD   rK   r  r	  r   rh   r
  r  r;   r  c                  K   ddl }|                    dt          d           |g }t          |||          }| j                            |          }|j        r|j        ng S )z
        List table names in the namespace.

        .. deprecated::
            Use :meth:`list_tables` instead, which provides proper pagination support.
        r   Nr  r  r  r  r  r  s          rB   r  z+AsyncLanceNamespaceDBConnection.table_names  s       	D 	 	
 	
 	

 !N#*E
 
 
 )55g>>"*/9xr9rD   r   Fry   rz   r  r   re   r{   r  r}   r~   r   r  r   r   r   r   r   r   r  r  r   r.   c	                  K   |	g }	|                                 dvrt          d          t          |           | j                            ||||||||	||

  
         d{V S )z$Create a new table in the namespace.Nr"  r#  )r}   r   r  r   r   r  r   r   )r   r   r1   r   r(  )r   r   r{   r}   r   r  r   r   r   r  r   r  r  s                rB   r(  z,AsyncLanceNamespaceDBConnection.create_table  s      " !N::<<666JKKKD!!![--)!) 3+ . 
 
 
 
 
 
 
 
 	
rD   r*  r+  r,  c                  K   |g }	 | j                             ||||           d{V S # t          $ rB}dt          |          v r+||gz   }t	          dd                    |                      d}~ww xY w)z*Open an existing table from the namespace.Nr*  r.  r/  r0  )r   r1  r2  re   r   r3  )r   r   r  r   r+  r4  r7   s          rB   r1  z*AsyncLanceNamespaceDBConnection.open_table  s       !N	//- /!1	 0           	 	 	 CFF**)TF2()QSXXh=O=O)Q)QRRR		s   #, 
A8=A33A8c                r   K   |g }||gz   }t          |          }| j                            |           dS )z Drop a table from the namespace.Nr6  r7  r9  s        rB   r8  z*AsyncLanceNamespaceDBConnection.drop_table  sJ      !N!TF*"h///))'22222rD   r:  r;  r<  r=  c                4   K   |g }|g }t          d          )z2Rename is not supported for namespace connections.Nr?  r@  rB  s        rB   rC  z,AsyncLanceNamespaceDBConnection.rename_table  s5       %!#%!#!E
 
 	
rD   c                $   K   t          d          )zDeprecated method.rE  r@  rF  s    rB   rG  z-AsyncLanceNamespaceDBConnection.drop_database  s      !F
 
 	
rD   c                   K   |g }|                      |           d{V }|D ]}|                     ||           d{V   dS )z!Drop all tables in the namespace.Nr  rI  )r   r  r  rJ  s       rB   rK  z/AsyncLanceNamespaceDBConnection.drop_all_tables   s      !N ,,N,KKKKKKKK% 	M 	MJ//*^/LLLLLLLLLL	M 	MrD   r&   c                   K   |g }t          |||          }| j                            |          }t          |j        r|j        ng |j                  S rM  rO  rQ  s         rB   rP  z/AsyncLanceNamespaceDBConnection.list_namespaces  sv      2 !N'*E
 
 
 )99'BB%.6.AIx**r*
 
 
 	
rD   r8   rR  r#   c                   K   t          |t          |          |          }| j                            |          }t	          t          |d          r|j        nd          S rT  rV  rX  s         rB   rW  z0AsyncLanceNamespaceDBConnection.create_namespace,  sw      0 )1$77!
 
 

 )::7CC&.5h.M.MWx**SW
 
 
 	
rD   rY  r%   c                  K   t          |t          |          t          |                    }| j                            |          }t          t          |d          r|j        ndt          |d          r|j        nd          S r[  r]  r_  s         rB   r^  z.AsyncLanceNamespaceDBConnection.drop_namespaceN  s      0 '/557AA
 
 

 )88AA$'.x'F'FP##D ,38=M+N+NX''TX
 
 
 	
rD   r$   c                   K   t          |          }| j                            |          }t          t	          |d          r|j        nd          S ra  rb  rd  s       rB   rc  z2AsyncLanceNamespaceDBConnection.describe_namespaceu  s`        +n===)<<WEE(.5h.M.MWx**SW
 
 
 	
rD   r'   c                   K   |g }t          |||          }| j                            |          }t          |j        r|j        ng |j                  S rf  rg  rQ  s         rB   r  z+AsyncLanceNamespaceDBConnection.list_tables  ss      2 !N#*E
 
 
 )55g>>!&.o=8??2*
 
 
 	
rD   c                   K   | j         S ro  rp  rF  s    rB   rq   z0AsyncLanceNamespaceDBConnection.namespace_client  s       %%rD   )
rq   r!   r   r   r   r   r   r   r   r   rq  rr  rs  )r   re   r{   r  r}   r~   r   re   r  r   r   re   r   r   r   r   r  r   r   r   r  r   r  r   r;   r.   )
r   re   r  r   r   r   r+  r,  r;   r.   rt  ru  rv  rw  rx  ry  rz  r{  r|  r}  r~  r  )r  r  r  r  r   r  r(  r1  r8  rC  rG  rK  rP  rW  r^  rc  r  rq   r>   rD   rB   r  r  H  s
         :>48%)DH9
 9
 9
 9
 9
 9
z %):
 /3: : : : : :>  $9=%GK!
 /348.237!
 !
 !
 !
 !
 !
N /348*.     03 3 3 3 3 3726
 
 
 
 
 
 
 
M M M M M /3$(#	"
 "
 "
 "
 "
N #/3	 
  
  
  
  
J #"&	%
 %
 %
 %
 %
N
 
 
 
0 /3$(#	"
 "
 "
 "
 "
H& & & & & &rD   r  r  r   r   Dict[str, str]r   r   r   r   r   r   r   r   c          	     N    t          | |          }t          |||||| |          S )a1  
    Connect to a LanceDB database through a namespace.

    Parameters
    ----------
    namespace_client_impl : str
        The namespace client implementation to use. For examples:

        - "dir" for DirectoryNamespace
        - "rest" for REST-based namespace
        - Full module path for custom implementations
    namespace_client_properties : Dict[str, str]
        Configuration properties for the namespace client implementation.
        Different namespace implementations have different config properties.
        For example, use DirectoryNamespace with {"root": "/path/to/directory"}
    read_consistency_interval : Optional[timedelta]
        The interval at which to check for updates to the table from other
        processes. If None, then consistency is not checked.
    storage_options : Optional[Dict[str, str]]
        Additional options for the storage backend
    session : Optional[Session]
        A session to use for this connection
    namespace_client_pushdown_operations : Optional[List[str]]
        List of namespace operations to push down to the namespace server.
        Supported values:

        - "QueryTable": Execute queries on the namespace server via
          namespace.query_table() instead of locally.
        - "CreateTable": Execute table creation on the namespace server via
          namespace.create_table() instead of using declare_table + local write.

        Default is None (no pushdown, all operations run locally).

    Returns
    -------
    LanceNamespaceDBConnection
        A namespace-based connection to LanceDB
    )rq   r   r   r   r   r   r   )namespace_connectr   r   r   r   r   r   r   rq   s          rB   connect_namespacer    sI    ^ ):  &)";'-Q3$?   rD   c               J    t          | |          }t          |||||          S )aa  
    Connect to a LanceDB database through a namespace (returns async connection).

    This function is synchronous but returns an AsyncLanceNamespaceDBConnection
    that provides async methods for all database operations.

    Parameters
    ----------
    namespace_client_impl : str
        The namespace client implementation to use. For examples:

        - "dir" for DirectoryNamespace
        - "rest" for REST-based namespace
        - Full module path for custom implementations
    namespace_client_properties : Dict[str, str]
        Configuration properties for the namespace client implementation.
        Different namespace implementations have different config properties.
        For example, use DirectoryNamespace with {"root": "/path/to/directory"}
    read_consistency_interval : Optional[timedelta]
        The interval at which to check for updates to the table from other
        processes. If None, then consistency is not checked.
    storage_options : Optional[Dict[str, str]]
        Additional options for the storage backend
    session : Optional[Session]
        A session to use for this connection
    namespace_client_pushdown_operations : Optional[List[str]]
        List of namespace operations to push down to the namespace server.
        Supported values:

        - "QueryTable": Execute queries on the namespace server via
          namespace.query_table() instead of locally.
        - "CreateTable": Execute table creation on the namespace server via
          namespace.create_table() instead of using declare_table + local write.

        Default is None (no pushdown, all operations run locally).

    Returns
    -------
    AsyncLanceNamespaceDBConnection
        An async namespace-based connection to LanceDB

    Examples
    --------
    >>> import lancedb
    >>> # This function is sync, but returns an async connection
    >>> db = lancedb.connect_namespace_async("dir", {"root": "/path/to/db"})
    >>> # Use async methods on the connection
    >>> async def use_db():
    ...     tables = await db.table_names()
    ...     table = await db.create_table("my_table", schema=schema)
    )rq   r   r   r   r   )r  r  r  s          rB   connect_namespace_asyncr    sC    x ):  +)";'-Q   rD   )r7   r8   r9   r:   r;   r   )rq   r!   r7   r8   r9   r:   r;   rr   )Nry   rz   )r{   r|   r}   r~   r   r   r   re   r   r   r;   r   )rw   r   r;   rr   )r   re   r;   re   )r   r   r;   r   )r}   r   r;   r   )r   re   r   r  r   r   r   r   r   r   r   r   r;   r   )r   re   r   r  r   r   r   r   r   r   r   r   r;   r  )[r  
__future__r   systypingr   r   r   r   r   r	   r
   version_infor   	overridesr]   r   datetimer   pyarrowra   :lance_namespace_urllib3_client.models.json_arrow_data_typer   6lance_namespace_urllib3_client.models.json_arrow_fieldr   7lance_namespace_urllib3_client.models.json_arrow_schemar   9lance_namespace_urllib3_client.models.query_table_requestr   Alance_namespace_urllib3_client.models.query_table_request_columnsr   Ilance_namespace_urllib3_client.models.query_table_request_full_text_queryr   @lance_namespace_urllib3_client.models.query_table_request_vectorr   6lance_namespace_urllib3_client.models.string_fts_queryr   lance_namespace.errorsr   lancedb._lancedbr   r   lancedb.background_loopr   
lancedb.dbr   r   lancedb.namespace_utilsr   r   r    lance_namespacer!   r"   r  r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r   r.   r/   r0   lancedb.utilr1   lancedb.commonr2   lancedb.pydanticr3   r   r4   _lancedbr6   rp   rx   r   ru   r   r   r   r   r  r  r  r>   rD   rB   <module>r     s    # " " " " " 



 L L L L L L L L L L L L L L L L L Lw"""""" $######           X X X X X X Q Q Q Q Q Q S S S S S S W W W W W W                R Q Q Q Q Q 5 5 5 5 5 5 R R R R R R ( ( ( ( ( ( 4 4 4 4 4 4 4 4         
                              8 7 7 7 7 7 7 7 7 7 , , , , , ,       ' ' ' ' ' ' 6 6 6 6 6 6      u' u' u' u'p8 8 8 8< DH!:( :( :( :( :(zE E E ES S S S'- '- '- '-T9 9 9 9,W& W& W& W& W& W& W& W&tr& r& r& r& r& r& r& r&r 6:04!%@D; ; ; ; ; ;D 6:04!%@DF F F F F F F FrD   