
    IZj                    j    d dl mZ d dlmZ d dlmZmZmZ erddlm	Z	 ddl
mZ  G d de          Zd	S )
    )annotations)	timedelta)TYPE_CHECKINGListOptional   )DATA)MergeInsertResultc                  T    e Zd ZdZddZddd dZd!dZ	 d"d#dZd$dZ	 	 	 d%d&dZ	dS )'LanceMergeInsertBuilderzBuilder for a LanceDB merge insert operation

    See [`merge_insert`][lancedb.table.Table.merge_insert] for
    more context
    table'Table'on	List[str]c                    || _         || _        d| _        d | _        d| _        d| _        d | _        d | _        d| _        d S )NFT)	_table_on_when_matched_update_all"_when_matched_update_all_condition_when_not_matched_insert_all"_when_not_matched_by_source_delete%_when_not_matched_by_source_condition_timeout
_use_index)selfr   r   s      Y/Users/jameslopez/projects/MentorCore/.venv/lib/python3.11/site-packages/lancedb/merge.py__init__z LanceMergeInsertBuilder.__init__   sL     (-%26/,1)27/592    N)wherer   Optional[str]returnc               "    d| _         || _        | S )a  
        Rows that exist in both the source table (new data) and
        the target table (old data) will be updated, replacing
        the old row with the corresponding matching row.

        If there are multiple matches then the behavior is undefined.
        Currently this causes multiple copies of the row to be created
        but that behavior is subject to change.
        T)r   r   )r   r   s     r   when_matched_update_allz/LanceMergeInsertBuilder.when_matched_update_all&   s     )-%27/r   c                    d| _         | S )zw
        Rows that exist only in the source table (new data) should
        be inserted into the target table.
        T)r   )r   s    r   when_not_matched_insert_allz3LanceMergeInsertBuilder.when_not_matched_insert_all6   s    
 -1)r   	conditionc                &    d| _         ||| _        | S )a  
        Rows that exist only in the target table (old data) will be
        deleted.  An optional condition can be provided to limit what
        data is deleted.

        Parameters
        ----------
        condition: Optional[str], default None
            If None then all such rows will be deleted.  Otherwise the
            condition will be used as an SQL filter to limit what rows
            are deleted.
        T)r   r   )r   r&   s     r   !when_not_matched_by_source_deletez9LanceMergeInsertBuilder.when_not_matched_by_source_delete>   s     37/ 9BD6r   	use_indexboolc                    || _         | S )a  
        Controls whether to use indexes for the merge operation.

        When set to `True` (the default), the operation will use an index if available
        on the join key for improved performance. When set to `False`, it forces a full
        table scan even if an index exists. This can be useful for benchmarking or when
        the query optimizer chooses a suboptimal path.

        Parameters
        ----------
        use_index: bool
            Whether to use indices for the merge operation. Defaults to `True`.
        )r   )r   r)   s     r   r)   z!LanceMergeInsertBuilder.use_indexR   s     $r   error        new_datar	   on_bad_vectorsstr
fill_valuefloattimeoutOptional[timedelta]r
   c                N    ||| _         | j                            | |||          S )a  
        Executes the merge insert operation

        Nothing is returned but the [`Table`][lancedb.table.Table] is updated

        Parameters
        ----------
        new_data: DATA
            New records which will be matched against the existing records
            to potentially insert or update into the table.  This parameter
            can be anything you use for [`add`][lancedb.table.Table.add]
        on_bad_vectors: str, default "error"
            What to do if any of the vectors are not the same size or contains NaNs.
            One of "error", "drop", "fill".
        fill_value: float, default 0.
            The value to use when filling vectors. Only used if on_bad_vectors="fill".
        timeout: Optional[timedelta], default None
            Maximum time to run the operation before cancelling it.

            By default, there is a 30-second timeout that is only enforced after the
            first attempt. This is to prevent spending too long retrying to resolve
            conflicts. For example, if a write attempt takes 20 seconds and fails,
            the second attempt will be cancelled after 10 seconds, hitting the
            30-second timeout. However, a write that takes one hour and succeeds on the
            first attempt will not be cancelled.

            When this is set, the timeout is enforced on all attempts, including
            the first.

        Returns
        -------
        MergeInsertResult
            version: the new version number of the table after doing merge insert.
        )r   r   	_do_merge)r   r.   r/   r1   r3   s        r   executezLanceMergeInsertBuilder.executec   s.    R #DM{$$T8^ZPPPr   )r   r   r   r   )r   r    r!   r   )r!   r   )N)r&   r    r!   r   )r)   r*   r!   r   )r,   r-   N)
r.   r	   r/   r0   r1   r2   r3   r4   r!   r
   )
__name__
__module____qualname____doc__r   r#   r%   r(   r)   r7    r   r   r   r      s             )-          *.    (   ( &'++Q +Q +Q +Q +Q +Q +Qr   r   N)
__future__r   datetimer   typingr   r   r   commonr	   _lancedbr
   objectr   r<   r   r   <module>rC      s   
 # " " " " "       0 0 0 0 0 0 0 0 0 0      
}Q }Q }Q }Q }Qf }Q }Q }Q }Q }Qr   