
    IZj0                        d dl mZ d dlmZmZmZmZ d dlZd dl	Z
d dlZ	ddlmZmZ eee         de
j        ee
j                 f         Zeeej        e
j        e
j        f         Zeeef         ZdZ G d d	e          Zd
edefdZdee
j                 de
j        dee
j                 fdZ	 ddedee
j                 de
j         fdZ!de
j        fdZ"defdZ#dS )    )Path)IterableListOptionalUnionN   )_check_for_pandaspandaszpd.DataFramevectorc                   *    e Zd ZdZdefdZdefdZdS )
CredentialzCredential fieldreturnc                     dS Nz******** selfs    Z/Users/jameslopez/projects/MentorCore/.venv/lib/python3.11/site-packages/lancedb/common.py__repr__zCredential.__repr__       z    c                     dS r   r   r   s    r   __str__zCredential.__str__   r   r   N)__name__
__module____qualname____doc__strr   r   r   r   r   r   r      sP        #          r   r   urir   c                      t          |           S N)r   )r   s    r   sanitize_urir"      s    s88Or   
input_iterschemac              #     K   | D ]}t          |t          j                  st          dt	          |                     |j        |k    r	 t          j                            |g                              |          	                                d         }n2# t          j
        j        $ r t          d| d|j                   w xY w|V  dS )a  
    Wrapper around an iterator of record batches. If the batches don't match the
    schema, try to cast them to the schema. If that fails, raise an error.

    This is helpful for users who might have written the iterator with default
    data types in PyArrow, but specified more specific types in the schema. For
    example, PyArrow defaults to float64 for floating point types, but Lance
    uses float32 for vectors.
    zExpected RecordBatch, got r   zjInput RecordBatch iterator yielded a batch with schema that does not match the expected schema.
Expected:
z
Got:
N)
isinstancepaRecordBatch	TypeErrortyper$   Tablefrom_batchescast
to_batcheslibArrowInvalid
ValueError)r#   r$   batchs      r   _casting_recordbatch_iterr3   "   s         %00 	HFeFFGGG<6!!--ug66;;FCCNNPPQRS6&    ,GM, ,"\, ,    s   AB/Cdatac                    t          |           rMt          | t          j                  r3t          j                            | |                                          S t          | t          j                  r|                                 S t          | t          j                  r2t          j        	                    | g                                          S t          | t          j
        j                  r6t          j
        j                            |                                           S t          | t          j
        j                  r|                                 S t          | t          j                  r| S t          |           j                            d          r6| j        j        dk    r&|                                                                 S t          | t*                    rA|0t-          | |          } t          j        	                    ||           S t/          d          t1          dt          |            d          )z7Convert various types of input into a RecordBatchReaderr$   polars	DataFrameNz>Must provide schema to write dataset from RecordBatch iterablezUnknown data type z. Supported types: list of dicts, pandas DataFrame, polars DataFrame, pyarrow Table/RecordBatch, or Pydantic models. See https://docs.lancedb.com/tables/ for examples.)r	   r&   pdr8   r'   r+   from_pandas	to_readerr(   r,   datasetDatasetScannerfrom_datasetRecordBatchReaderr*   r   
startswith	__class__r   to_arrowr   r3   r1   r)   )r4   r$   s     r   data_to_readerrD   >   s     "
:dBL#A#A "
x##D#88BBDDD	D"(	#	#  
~~	D".	)	) 
x$$dV,,66888 
D"*,	-	- 
z!..t44>>@@@	D"*,	-	- 
~~	D".	/	/ 
T

((22
N#{22}}((***	D(	#	# 
,T6::D'44VTBBBP   Ad A A A
 
 	
r   c                 @    | j         t          | j                    dS dS )z.
    Make sure the metadata is valid utf8
    N)metadata_validate_metadatar6   s    r   validate_schemarH   g   s*     "6?+++++ #"r   rF   c                    |                                  D ]v\  }}t          |t                    r8	 |                    d           1# t          $ r t          d| d          w xY wt          |t                    rt          |           wdS )zo
    Make sure the metadata values are valid utf8 (can be nested)

    Raises ValueError if not valid utf8
    utf8zMetadata key zG is not valid utf8. Consider base64 encode for generic binary metadata.N)itemsr&   bytesdecodeUnicodeDecodeErrorr1   dictrG   )rF   kvs      r   rG   rG   o   s        
" 
"1a 		"    %    JA J J J  
 4   	"q!!!
" 
"s   AA$r!   )$pathlibr   typingr   r   r   r   numpynppyarrowr'   pyarrow.datasetdependenciesr	   r
   r9   rO   r+   r(   DATAlistndarrayArrayChunkedArrayVECr   URIVECTOR_COLUMN_NAMEr   r"   Schemar3   r@   rD   rH   rG   r   r   r   <module>rb      s  
       2 2 2 2 2 2 2 2 2 2 2 2             9 9 9 9 9 9 9 9T$Z8BN3KKLD"*bh78CI        c c    (24)bn   : /3&
 &

&
 +&
&
 &
 &
 &
R,BI , , , ," " " " " " "r   