
    j                        d dl mZ d dlmZ d dlmZmZ d dlZd dl	m
Z erd dlmZ d dlmZmZ ddd	ddZ	 ddddddZdS )    )annotations)partial)TYPE_CHECKINGAnyNpyarrow)Iterator)	DataFrame	LazyFrameT)allow_pyarrow_filter
batch_sizedspa.dataset.Datasetr   boolr   
int | Nonereturnr   c                   t          t          | ||          }t          j                            | j        ||          S )a'  
    Pickle the partially applied function `_scan_pyarrow_dataset_impl`.

    The bytes are then sent to the polars logical plan. It can be deserialized once
    executed and ran.

    Parameters
    ----------
    ds
        pyarrow dataset
    allow_pyarrow_filter
        Allow predicates to be pushed down to pyarrow. This can lead to different
        results if comparisons are done with null values as pyarrow handles this
        different than polars does.
    batch_size
        The maximum row count for scanned pyarrow record batches.
    r   user_batch_sizer   )r   _scan_pyarrow_dataset_implplr   _scan_python_functionschema)r   r   r   funcs       m/home/longshao/multi-rider-rag/.venv/lib/python3.11/site-packages/polars/io/pyarrow_dataset/anonymous_scan.py_scan_pyarrow_datasetr      sO    2 "
1"	  D <--
	4!5 .       r   with_columnslist[str] | None	predicatestr | bytes | Nonen_rowsr    tuple[Iterator[DataFrame], bool]c                    d}|r:|8ddl m}m}	m}
m} ddlm}m}m} t          |t          |||||	|
|d          }|}||d||n|}||d<   d fd
}|du} |            |fS )an  
    Take the projected columns and materialize an arrow table.

    Parameters
    ----------
    ds
        pyarrow dataset.
    with_columns
        Columns that are projected.
    predicate
        pyarrow expression string (when `allow_pyarrow_filter=True`) or
        serialized Polars predicate bytes (when `allow_pyarrow_filter=False`).
    n_rows:
        Materialize only `n` rows from the arrow dataset.
    batch_size
        The maximum row count for scanned pyarrow record batches.
    allow_pyarrow_filter
        If True, evaluate predicate and return DataFrame directly.
        If False, return `(generator, False)` tuple for IOPlugin path.
    user_batch_size
        User-specified `batch_size` (takes precedence over Rust-provided `batch_size`).

    Warnings
    --------
    Don't use this if you accept untrusted user inputs. Predicates will be evaluated
    with python 'eval'. There is sanitation in place, but it is a possible attack
    vector.

    Returns
    -------
    tuple[Iterator[DataFrame], bool]
    A generator over the DataFrames and a boolean indicating if the
    predicates is applied.
    Nr   )
to_py_dateto_py_datetime
to_py_timeto_py_timedelta)DateDatetimeDuration)par)   r*   r+   r%   r&   r'   r(   )columnsfilterr   r   Iterator[DataFrame]c               3  4  K   dk    r$t          j         j        fi           V  d S }  j        di D ]Z}|j        dk    r| 4| dk    r d S |j        | k    r|                    d|           }| |j        z  } t          j        |          V  [d S )Nr    )r   r
   head
to_batchesnum_rowsslice
from_arrow)	remainingbatchcommon_paramsr   r"   s     r   framesz*_scan_pyarrow_dataset_impl.<locals>.frames   s      Q;;,wrwv????@@@@@F	"R]33]33 	' 	'E~"" $>>EE>I--!KK955EU^+	-&&&&&&	' 	'r   )r   r/   )polars._utils.convertr%   r&   r'   r(   polars.datatypesr)   r*   r+   evalr,   )r   r   r    r"   r   r   r   filter_r%   r&   r'   r(   r)   r*   r+   vr:   "applies_predicate_in_this_functionr9   s   `  `              @r   r   r   3   s(   ^ G 	 5	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	>=========$$("0(#2	 	
 
 >G0<$P$PM$3$?ZJ&0l#' ' ' ' ' ' ' '* *1)<&688777r   )r   r   r   r   r   r   r   r   )N)r   r   r   r   r    r!   r"   r   r   r   r   r   r   r   r   r#   )
__future__r   	functoolsr   typingr   r   polarsr   polars._dependenciesr   r,   collections.abcr	   r
   r   r   r   r1   r   r   <module>rG      s    " " " " " "       % % % % % % % %     . . . . . . ,((((((++++++++ "&!	! ! ! ! ! !R "f8 "&"&f8 f8 f8 f8 f8 f8 f8 f8r   