Λ
    θΛh   γ                  σ~    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	 dgZ
edddd«       Zedd	«       Zdddd
Zy)ι    )Ϊannotations)ΪTYPE_CHECKINGΪLiteralΪoverload)Ϊ	DataFrame)Ϊ	LazyFrameΪsqlF)Ϊeagerc                σ    y ©N© ©Ϊqueryr
   s     ϊp/var/www/html/wine-match-dev/backend/winematch-backend/venv/lib/python3.12/site-packages/polars/sql/functions.pyr	   r	      s    ΨDGσ    c                σ    y r   r   r   s     r   r	   r	      s    Ψ;>r   c               σ4    ddl m} |j                  | |¬«      S )uΌ  
    Execute a SQL query against frames in the global namespace.

    .. versionadded:: 0.20.31

    Parameters
    ----------
    query
        SQL query to execute.
    eager
        Automatically collect the result and return a DataFrame instead of a LazyFrame.

    Notes
    -----
    * The Polars SQL engine can operate against Polars DataFrame, LazyFrame, and Series
      objects, as well as Pandas DataFrame and Series, PyArrow Table and RecordBatch.
    * Additional control over registration and execution behaviour is available
      with the :class:`SQLContext` object.

    See Also
    --------
    SQLContext

    Examples
    --------
    >>> lf1 = pl.LazyFrame({"a": [1, 2, 3], "b": [6, 7, 8], "c": ["z", "y", "x"]})
    >>> lf2 = pl.LazyFrame({"a": [3, 2, 1], "d": [125, -654, 888]})

    Query the LazyFrame using SQL:

    >>> lf1.sql("SELECT c, b FROM self WHERE a > 1").collect()
    shape: (2, 2)
    βββββββ¬ββββββ
    β c   β b   β
    β --- β --- β
    β str β i64 β
    βββββββͺββββββ‘
    β y   β 7   β
    β x   β 8   β
    βββββββ΄ββββββ

    Join two LazyFrames:

    >>> pl.sql(
    ...     '''
    ...     SELECT lf1.*, d
    ...     FROM lf1
    ...     INNER JOIN lf2 USING (a)
    ...     WHERE a > 1 AND b < 8
    ...     '''
    ... ).collect()
    shape: (1, 4)
    βββββββ¬ββββββ¬ββββββ¬βββββββ
    β a   β b   β c   β d    β
    β --- β --- β --- β ---  β
    β i64 β i64 β str β i64  β
    βββββββͺββββββͺββββββͺβββββββ‘
    β 2   β 7   β y   β -654 β
    βββββββ΄ββββββ΄ββββββ΄βββββββ

    Apply SQL transforms and subsequently filter natively (you can freely mix SQL and
    native operations):

    >>> pl.sql(
    ...     query='''
    ...         SELECT
    ...             a,
    ...             (a % 2 == 0) AS a_is_even,
    ...             (b::float4 / 2) AS "b/2",
    ...             CONCAT_WS(':', c, c, c) AS c_c_c
    ...         FROM lf1
    ...         ORDER BY a
    ...     ''',
    ... ).filter(~pl.col("c_c_c").str.starts_with("x")).collect()
    shape: (2, 4)
    βββββββ¬ββββββββββββ¬ββββββ¬ββββββββ
    β a   β a_is_even β b/2 β c_c_c β
    β --- β ---       β --- β ---   β
    β i64 β bool      β f32 β str   β
    βββββββͺββββββββββββͺββββββͺββββββββ‘
    β 1   β false     β 3.0 β z:z:z β
    β 2   β true      β 3.5 β y:y:y β
    βββββββ΄ββββββββββββ΄ββββββ΄ββββββββ

    Join polars LazyFrame with a pandas DataFrame and a pyarrow Table:

    >>> import pandas as pd
    >>> import pyarrow as pa
    >>> pl_frame = lf1
    >>> pd_frame = pd.DataFrame({"a": [2, 3, 4], "d": [-0.5, 0.0, 0.5]})
    >>> pa_table = pa.Table.from_arrays(
    ...     [pa.array([1, 2, 3]), pa.array(["x", "y", "z"])],
    ...     names=["a", "e"],
    ... )
    >>> pl.sql(
    ...     query='''
    ...         SELECT pl_frame.*, d, e
    ...         FROM pl_frame
    ...         JOIN pd_frame USING(a)
    ...         JOIN pa_table USING(a)
    ...     ''',
    ... ).collect()
    shape: (2, 5)
    βββββββ¬ββββββ¬ββββββ¬βββββββ¬ββββββ
    β a   β b   β c   β d    β e   β
    β --- β --- β --- β ---  β --- β
    β i64 β i64 β str β f64  β str β
    βββββββͺββββββͺββββββͺβββββββͺββββββ‘
    β 2   β 7   β y   β -0.5 β y   β
    β 3   β 8   β x   β 0.0  β z   β
    βββββββ΄ββββββ΄ββββββ΄βββββββ΄ββββββ
    r   )Ϊ
SQLContextr   )Ϊ
polars.sqlr   Ϊexecute_global)r   r
   r   s      r   r	   r	      s&    υb &ΰΧ$Ρ$ΨΨπ %σ π r   N)r   Ϊstrr
   zLiteral[False]Ϊreturnr   )r   r   r
   zLiteral[True]r   r   )r   r   r
   Ϊboolr   zDataFrame | LazyFrame)Ϊ
__future__r   Ϊtypingr   r   r   Ϊpolars.dataframer   Ϊpolars.lazyframer   Ϊ__all__r	   r   r   r   ϊ<module>r      sN   πέ "η 3Ρ 3αέ*έ*π 'π 
Ψ/4Τ Gσ 
Ψ Gπ 
Ϊ >σ 
Ψ >π &+φ vr   