Ë
    kQêj�  ã                  ór   — d dl mZ d dlmZ d dlmZmZmZmZ ddl	m
Z
 erddlmZ ddlmZ  G d„ d	e«      Zy
)é    )Úannotations)Ú	timedelta)ÚTYPE_CHECKINGÚListÚOptionalÚUnioné   )ÚExpr)ÚDATA)ÚMergeInsertResultc                  óˆ   — 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	„Z		 	 	 	 dd
„Z
	 	 	 d	 	 	 	 	 	 	 	 	 dd„Zy)ÚLanceMergeInsertBuilderz‚Builder for a LanceDB merge insert operation

    See [`merge_insert`][lancedb.table.Table.merge_insert] for
    more context
    c                ó¬   — || _         || _        d| _        d | _        d| _        d| _        d | _        d | _        d | _        d| _	        d | _
        d | _        y )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Ú*_when_not_matched_by_source_condition_exprÚ_timeoutÚ
_use_indexÚ_use_rteÚ_validate_single_shard)ÚselfÚtableÚons      úR/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/lancedb/merge.pyÚ__init__z LanceMergeInsertBuilder.__init__   s_   € ð ˆŒØˆŒØ(-ˆÔ%Ø26ˆÔ/Ø,1ˆÔ)Ø27ˆÔ/Ø59ˆÔ2Ø:>ˆÔ7ØˆŒØˆŒØˆŒØ&*ˆÕ#ó    N)Úwherec               ó"   — 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.

        Parameters
        ----------
        where: Optional[str], default None
            An optional filter to limit which rows are updated. Column
            references in this expression must be prefixed with "target."
            to refer to the existing table data. For example, to only
            update rows where the existing color is red, use:
            ``where="target.color = 'red'"``
        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_allD   s   € ð
 -1ˆÔ)Øˆr!   c                ó„   — d| _         t        |t        «      r|j                  | _        d| _        | S || _        d| _        | S )aP  
        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: str or :class:`~lancedb.expr.Expr` or None, default None
            If None then all such rows will be deleted.  Otherwise the
            condition will be used as a filter to limit what rows are deleted.
            Can be a SQL string or a type-safe :class:`~lancedb.expr.Expr`
            built with :func:`~lancedb.expr.col` and :func:`~lancedb.expr.lit`.
        TN)r   Ú
isinstancer
   Ú_innerr   r   )r   Ú	conditions     r   Ú!when_not_matched_by_source_deletez9LanceMergeInsertBuilder.when_not_matched_by_source_deleteL   sK   € ð  37ˆÔ/Ü�i¤Ô&Ø>G×>NÑ>NˆDÔ;Ø9=ˆDÔ6ð ˆð :CˆDÔ6Ø>BˆDÔ;Øˆr!   c                ó   — || _         | 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   Ú	use_indexs     r   r-   z!LanceMergeInsertBuilder.use_indexe   s   € ð $ˆŒØˆr!   c                ó   — || _         | S )aá  
        Control RTE routing for this merge.

        By default (unset), a `merge_insert` on a table with an RTE write spec is
        routed through Lance's MemWAL shard writer, and a table without one uses
        the standard path.

        Parameters
        ----------
        enable: bool
            ``True`` forces RTE routing and errors if the table has no RTE
            write spec. ``False`` forces the standard write path even when a spec
            is set.
        )r   )r   Úenables     r   Úuse_rtezLanceMergeInsertBuilder.use_rtev   s   € ð ˆŒØˆr!   c                ó   — || _         | S )u®  
        Controls how an LSM merge checks that its input targets a single shard.

        When a table has an RTE write spec, every row in a `merge_insert` call
        must route to the same shard. When `True` (the default), every row is
        inspected to verify this. When `False`, only the first row is inspected
        and the shard it routes to is used for the whole input â€” a faster path
        for callers that have already pre-sharded their input.

        Has no effect on tables without an RTE write spec.

        Parameters
        ----------
        validate_single_shard: bool
            Whether to check every row routes to one shard. Defaults to `True`.
        )r   )r   Úvalidate_single_shards     r   r2   z-LanceMergeInsertBuilder.validate_single_shardˆ   s   € ð& '<ˆÔ#Øˆr!   c                óP   — |�|| _         | j                  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   Únew_dataÚon_bad_vectorsÚ
fill_valueÚtimeouts        r   ÚexecutezLanceMergeInsertBuilder.executež   s-   € ðR ÐØ#ˆDŒMØ�{‰{×$Ñ$ T¨8°^ÀZÓPÐPr!   )r   z'Table'r   z	List[str])r"   zOptional[str]Úreturnr   )r:   r   )N)r*   zUnion[str, Expr, None]r:   r   )r-   Úboolr:   r   )r/   r;   r:   r   )r2   r;   r:   r   )Úerrorg        N)
r5   r   r6   Ústrr7   Úfloatr8   zOptional[timedelta]r:   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r    r$   r&   r+   r-   r0   r2   r9   © r!   r   r   r      sª   „ ñó+ð$ )-ñØ%ðà	 óó2ð 37ðØ/ðà	 óó2ó"ð$Ø%)ðà	 óð2 &ØØ'+ð+Qàð+Qð ð+Qð ð	+Qð
 %ð+Qð 
ô+Qr!   r   N)Ú
__future__r   Údatetimer   Útypingr   r   r   r   Úexprr
   Úcommonr   Ú_lancedbr   Úobjectr   rC   r!   r   ú<module>rK      s1   ðõ
 #å ß 7Ó 7å áÝõô
vQ˜fõ vQr!   