o
    8Di                    @  sK  U d Z ddlmZ ddlZddlZddlZddlZddlZddlZ	ddl
mZ ddlmZ ddlmZ ddlmZ ddlmZ dd	lmZmZ dd
lmZmZmZmZmZmZmZmZ ddl m!Z!m"Z" e	j#rddl$m%Z% ddl&m'Z'm(Z( ddl)m*Z* e	j+dddZ,e	j+dddZ-G dd de.Z/dZ0dZ1dZ2dZ3dZ4G dd de/dZ5e	j6e7e	j8e5 e	j9e	j6e7e	j8e5 f  f Z:e	j6e7e5f Z;G dd de5Z<G d d! d!e<Z=G d"d# d#e5Z>G d$d de5Z?G d%d& d&e>Z@G d'd( d(e5ZAG d)d* d*e5ZBG d+d, d,e5ZCG d-d. d.e5ZDG d/d0 d0e5ZEG d1d2 d2eDZFG d3d4 d4e5ZGG d5d6 d6e5ZHG d7d8 d8e5ZIG d9d: d:e5ZJG d;d< d<e5ZKG d=d> d>e5ZLG d?d@ d@e5ZMG dAdB dBe5ZNG dCdD dDe5ZOG dEdF dFe5ZPG dGdH dHe5ZQG dIdJ dJe5ZRG dKdL dLe5ZSG dMdN dNe5ZTG dOdP dPe5ZUG dQdR dRe5ZVG dSdT dTe5ZWG dUdV dVe5ZXG dWdX dXe5ZYG dYdZ dZe5ZZG d[d\ d\e>Z[G d]d^ d^e5Z\G d_d` d`e5Z]G dadb dbe<Z^G dcdd dde<Z_G dedf dfe<Z`G dgdh dhe<ZaG didj dje<ZbG dkdl dle<ZcG dmdn dne5ZdG dodp dpe5ZeG dqdr dre5ZfG dsdt dte5ZgG dudv dve5ZhG dwdx dxe5ZiG dydz dze5ZjG d{d| d|e5ZkG d}d~ d~e5ZlG dd de5ZmG dd de5ZnG dd de5ZoG dd de5ZpG dd de5ZqG dd de5ZrG dd de5ZsG dd de5ZtG dd detZuG dd detZvG dd detZwG dd detZxG dd detZyG dd detZzG dd detZ{G dd detZ|G dd detZ}G dd detZ~G dd detZG dd detZG dd detZG dd detZG dd de5ZG dd detZG dd detZG dd detZG dd detZG dd detZG dd detZG dd detZG dd detZG dd detZG dd detZG dd detZG ddĄ detZG ddƄ detZG ddȄ de5ZG ddʄ detZG dd̄ detZG dd΄ detZG ddЄ de5ZG dd҄ deEZG ddԄ de5ZG ddք de5ZG dd؄ de5ZG ddڄ de5ZG dd܄ de5ZG ddބ de5ZG dd de5ZG dd deEZG dd de5ZG dd de5ZG dd de5ZG dd de5ZG dd de5ZG dd de5ZG dd de5ZG dd de5ZG dd de5ZG dd de5ZG dd de5ZG dd de5ZG dd de5ZG dd de5ZG dd  d e5ZG dd deDeEZG dd de5ZG dd de5ZG dd de5ZG d	d
 d
e5ZG dd de5ZG dd de5ZG dd de5ZG dd de5ZG dd de5ZG dd de5ZG dd de5ZG dd de5ZG dd de5ZG dd de5ZG dd  d e5ZG d!d" d"e5ZG d#d$ d$e5ZG d%d& d&e5ZG d'd( d(e5ZG d)d* d*e5ZG d+d, d,e<ZG d-d. d.e5ZG d/d0 d0e@ZG d1d2 d2e@ZG d3d4 d4e5ZG d5d6 d6e5ZG d7d8 d8e5ZG d9d: d:e5ZG d;d< d<e5ZG d=d> d>e5ZG d?d@ d@e˃ZG dAdB dBe˃ZG dCdD dDe˃ZG dEdF dFe5ZG dGdH dHe5ZG dIdJ dJe5ZG dKdL dLe5ZG dMdN dNe5ZG dOdP dPeуZG dQdR dReуZG dSdT dTeуZG dUdV dVeуZG dWdX dXeуZG dYdZ dZeуZG d[d\ d\eуZG d]d^ d^eуZG d_d` d`eуZG dadb dbeуZG dcdd ddeуZG dedf dfeуZG dgdh dheуZG didj djeуZG dkdl dleуZG dmdn dneуZG dodp dpeуZG dqdr dreуZG dsdt dteуZG dudv dveуZG dwdx dxeуZG dydz dzeуZG d{d| d|eуZG d}d~ d~eуZG dd deуZG dd deуZG dd deуZG dd deуZG dd deуZG dd deуZG dd deуZG dd deуZG dd deуZG dd deуZG dd deуZG dd deуZG dd deуZG dd deуZG dd deуZG dd deуZG dd deуZG dd deуZG dd deуZG dd deуZ G dd deуZG dd deуZG dd deуZG dd deуZG dd deуZG dd deуZG dd deуZG dd deуZG dd deуZ	G dd deуZ
G dd deуZG dd de5ZG dd deуZG dd de5ZG dÐdĄ deуZG dŐdƄ deуZG dǐdȄ deуZG dɐdʄ deуZG dːd̄ deуZG d͐d΄ deуZG dϐdЄ deуZG dѐd҄ deуZG dӐdԄ de5ZG dՐdք deуZG dאd؄ deуZG dِdڄ deуZG dېd܄ deуZG dݐdބ deуZG dߐd deуZG dd deуZG dd deуZG dd deуZ G dd deуZ!G dd deуZ"G dd deуZ#G dd deуZ$G dd deуZ%G dd deуZ&G dd deteуZ'G dd deуZ(G dd deуZ)G dd deуZ*G dd deуZ+G dd deуZ,G dd  d eуZ-G dd deуZ.G dd deуZ/G dd deуZ0G dd deуZ1G d	d
 d
eуZ2G dd deуZ3G dd deуZ4G dd deуZ5G dd de5Z6G dd de5Z7G dd de5Z8G dd de5Z9G dd de5Z:G dd de5Z;i ddddd dd!dd"dd#dd$dd%dd&dd'dd(dd)dd*dd+dd,dd-dd.ddddddd/Z<G d0d1 d1e5Z=G d2d3 d3e5Z>G d4d5 d5e5Z?G d6d7 d7e5Z@G d8d9 d9e5ZAG d:d; d;e5ZBG d<d= d=e5ZCG d>d de?ZDG d?d@ d@eDZ6G dAdB dBeDZEG dCdD dDeDZFG dEdF dFeEZGG dGdH dHe@ZHG dIdJ dJe5ZIG dKdL dLe5ZJG dMdN dNe5ZKG dOdP dPe5ZLG dQdR dRe?ZMeMeDfZNG dSdT dTe>e?ZOG dUdV dVe5ZPG dWdX dXe5ZQG dYdZ dZe5ZRG d[d\ d\e5ZSG d]d^ d^e<ZTG d_d` d`e5ZUG dadb dbe5ZVG dcdd dde5ZWG dedf dfe5ZXG dgdh dhe<ZYG didj dje<ZZG dkdl dle<Z[G dmdn dne<Z\G dodp dpe<Z]G dqdr dre5Z^G dsdt dte5Z_G dudv dve_Z`G dwdx dxe_ZaG dydz dze=ZbG d{d| d|ebZcG d}d~ d~ebZdG dd de5ZeG dd de5ZfG dd de5ZgG dd de5ZhG dd de5ZiG dd de5ZjG dd de5ZkG dd de5ZlG dd de5ZmG dd de5ZnG dd de5ZoG dd de5ZpG dd de5ZqG dd de5ZrG dd de5ZsG dd de5ZtG dd de5ZuG dd de5ZvG dd de5ZwG dd de5ZxG dd de<ZyG dd deyZzG dd deyZ{G dd deyZ|G dd deyZ}G dd deyZ~G dd deyZG dd deyZG dd deyZG dd deyZG dd deyZe	j6e7eee_e_j8f ZG dd deyZG dd deye=ZG dd deye=ZG dÐdĄ dĐeye=ZG dŐdƄ dƐeyZG dǐdȄ dȐeyZG dɐdʄ dʐeyZG dːd̄ d̐eye=ZG d͐d΄ dΐeye=ZG dϐdЄ dАeye=ZG dѐd҄ dҐeye=ZG dӐdԄ dԐeye=ZG dՐdք d֐eyZG dאd؄ dؐeye=ZG dِdڄ dڐeyZG dېd܄ dܐeye=ZG dݐdބ dސeye=ZG dߐd deye=ZG dd deye=ZG dd deyZG dd deyZG dd deye=ZG dd deyZG dd deye=ZG dd deyZG dd deyZG dd de<ZG dd deZG dd deZG dd deZG dd deZG dd de5ZG dd deZG dd  d e5ZG dd de5ZG dd de5ZG dd de5ZG dd de5ZG d	d
 d
e5ZG dd de=ZG dd de<ZG dd de5ZG dd de=ZG dd de5ZG dd de5ZG dd deZG dd de_ZG dd deZG dd de5ZG dd  d e5ZG d!d" d"e5ZG d#d$ d$e<ZG d%d& d&eZG d'd( d(eZG d)d* d*eZG d+d, d,eZG d-d. d.eZG d/d0 d0eZG d1d2 d2eZG d3d4 d4eZG d5d6 d6eZG d7d8 d8eZG d9d: d:eZG d;d< d<eZG d=d> d>eăZG d?d@ d@eZG dAdB dBeZG dCdD dDeZG dEdF dFeZG dGdH dHeZG dIdJ dJeZG dKdL dLeZG dMdN dNeZG dOdP dPeZG dQdR dReZG dSdT dTeZG dUdV dVeZG dWdX dXeZG dYdZ dZeZG d[d\ d\eZG d]d^ d^eZG d_d` d`eՃZG dadb dbeZG dcdd ddeZG dedf dfeZG dgdh dheZG didj djeZG dkdl dleZG dmdn dneZG dodp dpeyeZG dqdr dreyeZG dsdt dteZG dudv dveZG dwdx dxeZG dydz dzeZG d{d| d|eZG d}d~ d~eZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deyeZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd de5ZG dd deyeZ G dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dÐdĄ dĐeZG dŐdƄ dƐeZ	G dǐdȄ dȐeZ
G dɐdʄ dʐeZG dːd̄ d̐eZG d͐d΄ dΐeZG dϐdЄ dАeZG dѐd҄ dҐeZG dӐdԄ dԐeZG dՐdք d֐eZG dאd؄ dؐeeZG dِdڄ dڐeeZG dېd܄ dܐeeZG dݐdބ dސeeZG dߐd deZG dd deZG dd deeZG dd deeZG dd deeZG dd deeZG dd deZG dd deZG dd deZG dd deZG dd deZ G dd deZ!G dd deZ"G dd deZ#G dd deeZ$G dd deZ%G dd  d eebZ&G dd deZ'G dd deeZ(G dd deeZ)G dd deeZ*G d	d
 d
eeZ+G dd deeZ,G dd deeZ-G dd deeZ.G dd deeZ/G dd deZ0G dd deZ1G dd deZ2G dd deZ3G dd deZ4G dd deZ5G dd  d eZ6G d!d" d"eZ7G d#d$ d$eZ8G d%d& d&eZ9G d'd( d(eZ:G d)d* d*eZ;G d+d, d,ee@Z<G d-d. d.eZ=G d/d0 d0e<Z>G d1d2 d2e<Z?G d3d4 d4e?e>Z@G d5d6 d6ee@ZAG d7d8 d8eZBG d9d: d:eZCG d;d< d<eZDG d=d> d>eZEG d?d@ d@eZFG dAdB dBeZGG dCdD dDeZHG dEdF dFeZIG dGdH dHeZJG dIdJ dJe5ZKG dKdL dLeZLG dMdN dNeZMG dOdP dPeMZNG dQdR dRe{eZOG dSdT dTe{eZPG dUdV dVe{eZQG dWdX dXeZRG dYdZ dZeZSG d[d\ d\eZTG d]d^ d^eZUG d_d` d`eZVG dadb dbeZWG dcdd ddeZXG dedf dfe5ZYG dgdh dhe5ZZG didj dje5Z[G dkdl dle[Z\G dmdn dne[Z]G dodp dpe[Z^G dqdr dre[Z_G dsdt dte[Z`G dudv dve[ZaG dwdx dxe[ZbG dydz dze[ZcG d{d| d|e[ZdG d}d~ d~e[ZeG dd de5ZfG dd de5ZgG dd deZhG dd deZiG dd deZjG dd deZkG dd deZlG dd deZmG dd de5ZnG dd de5ZoG dd de5ZpG dd deZqG dd deZrG dd deZsG dd de5ZtG dd deZuG dd deyeZvG dd deZwG dd deyeZxG dd de5ZyG dd deZzG dd deyeZ{G dd deyeZ|G dd deyeZ}G dd deZ~G dd deye=eZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dÐdĄ dĐeZG dŐdƄ dƐeZG dǐdȄ dȐeZG dɐdʄ dʐeZG dːd̄ d̐eZG d͐d΄ dΐeZG dϐdЄ de5ZG dѐd҄ de5ZG dӐdԄ dԐeZG dՐdք d֐eZG dאd؄ dؐeZG dِdڄ dڐeZG dېd܄ dܐeZG dݐdބ dސeZG dߐd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deyeZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd  d eZG dd deZG dd deZG dd deZG dd deZG d	d
 d
eZG dd deyeZG dd deyeZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd  d eZG d!d" d"eZG d#d$ d$eZG d%d& d&eZG d'd( d(eZG d)d* d*eZG d+d, d,eZG d-d. d.eZG d/d0 d0eZG d1d2 d2eZG d3d4 d4eZG d5d6 d6eZG d7d8 d8eZG d9d: d:eZG d;d< d<eZG d=d> d>eZG d?d@ d@eZG dAdB dBeZG dCdD dDeZG dEdF dFeZG dGdH dHeZG dIdJ dJeZG dKdL dLeZG dMdN dNeZG dOdP dPeZG dQdR dReZG dSdT dTeZG dUdV dVeZG dWdX dXeZG dYdZ dZeZG d[d\ d\eZG d]d^ d^eZG d_d` d`eZG dadb dbeeZG dcdd ddeeZG dedf dfeZG dgdh dheZG didj djeZG dkdl dleZG dmdn dneZG dodp dpeZG dqdr dreZG dsdt dteZG dudv dveZG dwdx dxeZG dydz dzeZG d{d| d|eZG d}d~ d~eZG dd deZG dd deZG dd deZG dd deyeZG dd deZG dd deZG dd deyeZG dd deyeZG dd deZG dd deZG dd deZG dd de5ZG dd de5ZG dd deZG dd de5ZG dd deEZG dd de5ZG dd de5ZG dd deZG dd de5ZG dd de5Zdd ZeeeeeÐefZdd eD Zeee[e[fZeefZ e	jdddddddZe	jddddddddZddddddddZe	jdddĐdńZe	jdddƐdńZddǐdńZdddϐdЄZdѐd҄ Z					ӐddԐdՄZddddddd֜dאd؄ZddddddٜdڐdۄZdddddܜdݐdބZ							ddddZ
			ddddZe	jdddZe	jdddZdddZdddddddZddddddd ZdddddddZdddddddZdddddZdddd	Z					ddddZ			ddddZ					ddddZddddddd Z	ddd!d"Zdddd#dd$d%Zdddd#dd&d'Zdddd#dd(d)Zddd*d+Zddd,d-Zed.Zd/ed0< e	jddd3d4Z e	j	ddd6d4Z dd7d4Z ddÐd8d9Z!ed:Z"dĐd=d>Z#	ddŐd@dAZ$			dƐdǐdCdDZ%				dȐdɐdGdHZ&		dʐdːdJdKZ'e	j			ddddLd̐dRdSZ(e	j			dddddTd͐dWdSZ(			dddddTdXdSZ(	dΐdϐd[d\Z)				dАdѐd^d_Z*		dʐdҐdcd`Z+dӐdddeZ,	ddԐdhdiZ-		dʐdՐdndoZ.d֐dאdqdrZ/dؐdudvZ0	ddِdydzZ1dڐdېd~dZ2dܐdݐddjZ3ddސddZ4	ddߐddZ5dddZ6		ddddZ7ddddddZ8	ddddZ9ddddddZ:ddddddZ;dddZ<dddZ=dddZ>eÐe]fZ?eÐe]e\fZ@dS (  aK  
## Expressions

Every AST node in SQLGlot is represented by a subclass of `Expression`.

This module contains the implementation of all supported `Expression` types. Additionally,
it exposes a number of helper functions, which are mainly used to programmatically build
SQL expressions, such as `sqlglot.expressions.select`.

----
    )annotationsN)dequedeepcopy)Decimal)autoreduce)
ErrorLevel
ParseError)AutoNamecamel_to_snake_caseensure_collectionensure_listseq_getsplit_num_words
subclassesto_bool)Token
TokenError)Self)ELit)DialectTypeQQuery)boundSSetOperationc                      s   e Zd Z fddZ  ZS )_Expressionc                   s,   t  | |||}| |_|jpd|_|S N )super__new__lowerkey__doc__)clsclsnamebasesattrsklass	__class__ L/var/www/Datamplify/venv/lib/python3.10/site-packages/sqlglot/expressions.pyr#   3   s   
z_Expression.__new__)__name__
__module____qualname__r#   __classcell__r.   r.   r,   r/   r   2   s    r   zsqlglot.metazsqlglot.anonymous)thisdbcatalogr4   tabler5   r6   linecolstartendc                   @  s  e Zd ZdZdZddiZdZd-dd	Zd.ddZe	d/ddZ
d0ddZe	d/ddZe	d/ddZe	d1ddZd2ddZe	d.ddZe	d.dd Zd/d!d"Ze	d.d#d$Ze	d.d%d&Ze	d2d'd(Ze	d3d*d+Ze	d2d,d-Ze	d2d.d/Ze	d2d0d1Ze	d4d3d4Zejd5d8d4Zd.d9d:Zd.d;d<Ze	d6d>d?Zd@dA Zd7dCdDZ d8d9dJdKZ!d3dLdMZ"d:dPdQZ#	E	d;d<dUdVZ$d=d>dWdXZ%e	d0dYdZZ&d?d@d]d^Z'dd_dAdddeZ(dd_dBdgdhZ)dCdidjZ*e	dDdldmZ+e	d.dndoZ,dEdpdqZ-	EdFdGdtduZ.	Ed=dHdvdwZ/	Ed=dHdxdyZ0dzd{ Z1d|d} Z2d~d Z3dIddZ4d2ddZ5d2ddZ6d2ddZ7d=dJddZ8dddKddZ9e:j;dLddZ<e:j;dMddZ<dd Z<dNddZ=dOddZ>d=dPddZ?dd Z@eAdd ZBdEddddQddZCdEddddQddZDdIdRddZE	Ed=dSddZF	E	E	dTdUddZGd?dVddZHdWddZIdXddĄZJdEdEddŜdYdd˄ZKdIdZddЄZLd[ddԄZMd\ddׄZNd]ddڄZOd^dd݄ZPd_ddZQd`ddZRdadbddZSdIdcddZTd?dcddZUddddZVdeddZWdfddZXdgddZYdhddZZdhddZ[diddZ\diddZ]djddZ^djdd	Z_dkd
dZ`dkddZadlddZbdlddZcdmddZddmddZednddZfdnddZgdoddZhdod d!Zidpd#d$Zjdpd%d&Zkdqd(d)Zldrd+d,ZmdES (s  
Expressiona  
    The base class for all expressions in a syntax tree. Each Expression encapsulates any necessary
    context, such as its child expressions, their names (arg keys), and whether a given child expression
    is optional or not.

    Attributes:
        key: a unique key for each class in the Expression hierarchy. This is useful for hashing
            and representing expressions as strings.
        arg_types: determines the arguments (child nodes) supported by an expression. It maps
            arg keys to booleans that indicate whether the corresponding args are optional.
        parent: a reference to the parent expression (or None, in case of root expressions).
        arg_key: the arg key an expression is associated with, i.e. the name its parent expression
            uses to refer to it.
        index: the index of an expression if it is inside of a list argument in its parent.
        comments: a list of comments that are associated with a given expression. This is used in
            order to preserve comments when transpiling SQL code.
        type: the `sqlglot.expressions.DataType` type of an expression. This is inferred by the
            optimizer, in order to enable some transformations that require type information.
        meta: a dictionary that can be used to store useful metadata for a given expression.

    Example:
        >>> class Foo(Expression):
        ...     arg_types = {"this": True, "expression": False}

        The above definition informs us that Foo is an Expression that requires an argument called
        "this" and may also optionally receive an argument called "expression".

    Args:
        args: a mapping used for retrieving the arguments of an expression, given their arg keys.
    
expressionr4   T)argsparentarg_keyindexcomments_type_meta_hashr@   t.Anyc                 K  sT   || _ d | _d | _d | _d | _d | _d | _d | _| j  D ]
\}}| 	|| qd S N)
r@   rA   rB   rC   rD   rE   rF   rG   items_set_parent)selfr@   rB   valuer.   r.   r/   __init__k   s   zExpression.__init__returnboolc                 C  s    t | t |u ot| t|kS rI   )typehashrL   otherr.   r.   r/   __eq__x   s    zExpression.__eq__c                 C     t dd | j D S )Nc                 s  s^    | ]*\}}|d u s|du st |tu r|r|t |tu r&tdd |D nt|fV  qd S )NFc                 s  s    | ]}t |V  qd S rI   )	_norm_arg).0ar.   r.   r/   	<genexpr>~       z5Expression.hashable_args.<locals>.<genexpr>.<genexpr>)rQ   listtuplerW   rX   kvr.   r.   r/   rZ   }   s     (z+Expression.hashable_args.<locals>.<genexpr>)	frozensetr@   rJ   rL   r.   r.   r/   hashable_args{   s   zExpression.hashable_argsintc                 C  s    | j d ur| j S t| j| jfS rI   )rG   rR   r-   rc   rb   r.   r.   r/   __hash__   s   
zExpression.__hash__c                 C     | j dS )z9
        Retrieves the argument with key "this".
        r4   r@   getrb   r.   r.   r/   r4         zExpression.thisc                 C  rf   )z?
        Retrieves the argument with key "expression".
        r?   rg   rb   r.   r.   r/   r?      ri   zExpression.expressiont.List[t.Any]c                 C     | j dpg S )z@
        Retrieves the argument with key "expressions".
        expressionsrg   rb   r.   r.   r/   rl      s   zExpression.expressionsstrc                 C  sH   | j |}t|tr|S t|tttfr|jS t|tt	fr"|j
S dS )z
        Returns a textual representation of the argument corresponding to "key". This can only be used
        for args that are strings or leaf Expression instances, such as identifiers and literals.
        r!   )r@   rh   
isinstancerm   
IdentifierLiteralVarr4   StarNullname)rL   r%   fieldr.   r.   r/   text   s   
zExpression.textc                 C  s   t | to	| jd S )zB
        Checks whether a Literal expression is a string.
        	is_string)rn   rp   r@   rb   r.   r.   r/   rw         zExpression.is_stringc                 C  s(   t | tr| jd  pt | to| jjS )zB
        Checks whether a Literal expression is a number.
        rw   )rn   rp   r@   Negr4   	is_numberrb   r.   r.   r/   rz      s   zExpression.is_numberc                 C  s   t |  d)zE
        Returns a Python object equivalent of the SQL node.
        z( cannot be converted to a Python object.)
ValueErrorrb   r.   r.   r/   to_py   s   zExpression.to_pyc                 C  s   | j o	t|  tS )z=
        Checks whether an expression is an integer.
        )rz   rn   r|   rd   rb   r.   r.   r/   is_int   rx   zExpression.is_intc                 C  s    t | tpt | tot | jtS )z'Checks whether an expression is a star.)rn   rr   Columnr4   rb   r.   r.   r/   is_star   s    zExpression.is_starc                 C  s(   t | jdtr| jd jS | dS )z^
        Returns the alias of the expression, or an empty string if it's not aliased.
        alias)rn   r@   rh   
TableAliasrt   rv   rb   r.   r.   r/   r      s   
zExpression.aliast.List[str]c                 C  s.   | j d}|s
g S dd |j dpg D S )Nr   c                 S     g | ]}|j qS r.   rt   rX   cr.   r.   r/   
<listcomp>       z1Expression.alias_column_names.<locals>.<listcomp>columnsrg   )rL   table_aliasr.   r.   r/   alias_column_names   s   zExpression.alias_column_namesc                 C  
   |  dS )Nr4   rv   rb   r.   r.   r/   rt         
zExpression.namec                 C  s   | j p| jS rI   )r   rt   rb   r.   r.   r/   alias_or_name      zExpression.alias_or_namec                 C     dS )a  
        Name of the output column if this expression is a selection.

        If the Expression has no output name, an empty string is returned.

        Example:
            >>> from sqlglot import parse_one
            >>> parse_one("SELECT a").expressions[0].output_name
            'a'
            >>> parse_one("SELECT b AS c").expressions[0].output_name
            'c'
            >>> parse_one("SELECT 1 + 2").expressions[0].output_name
            ''
        r!   r.   rb   r.   r.   r/   output_name   s   zExpression.output_namet.Optional[DataType]c                 C     | j S rI   )rE   rb   r.   r.   r/   rQ         zExpression.typedtype*t.Optional[DataType | DataType.Type | str]Nonec                 C  s"   |rt |tst|}|| _d S rI   )rn   DataTypebuildrE   )rL   r   r.   r.   r/   rQ      s   

c                 G  s   | j d uo
| j j| S rI   )rQ   is_typerL   dtypesr.   r.   r/   r        zExpression.is_typec                 C  s   t dd | j D  S )Nc                 s  s    | ]
}t |ttfV  qd S rI   )rn   r>   r\   rX   r`   r.   r.   r/   rZ         z%Expression.is_leaf.<locals>.<genexpr>)anyr@   valuesrb   r.   r.   r/   is_leaf  s   zExpression.is_leaft.Dict[str, t.Any]c                 C  s   | j d u ri | _ | j S rI   )rF   rb   r.   r.   r/   meta  s   
zExpression.metac           	      C  s.  |   }| |fg}|r| \}}|jd urt|j|_|jd ur't|j|_|jd ur2t|j|_|jd ur;|j|_|j D ]R\}}t	|dr]|
||  f |||d d  q@t|tu rg |j|< |D ]!}t	|dr|
||  f |
||d d  qj|
|| qjq@||j|< q@|s|S )NrA   )r-   poprD   r   rE   rF   rG   r@   rJ   hasattrappendsetrQ   r\   )	rL   memorootstacknodecopyr_   vsr`   r.   r.   r/   __deepcopy__  s6   







zExpression.__deepcopy__r   c                 C     t | S )z8
        Returns a deep copy of the expression.
        r   rb   r.   r.   r/   r   0  s   zExpression.copyNFrD   t.Optional[t.List[str]]prependc           
      C  s   | j d u rg | _ |rO|D ]8}|t^}}|r<d|dD ]}|d^}}|r0|d  nd}	t|	| j| < q|sD| j | q|rQ|| j  | _ d S d S d S )Nr!   ,=r   T)rD   splitSQLGLOT_METAjoinstripr   r   r   )
rL   rD   r   comment_r   kvr_   r`   rM   r.   r.   r/   add_comments6  s"   
zExpression.add_commentsc                 C  s   | j pg }d | _ |S rI   )rD   )rL   rD   r.   r.   r/   pop_commentsI  s   
zExpression.pop_commentsrB   rM   c                 C  sV   t | j|turg | j|< | || | j| }t|dr$t||_|| dS )z
        Appends value to arg_key if it's a list or sets it as a new list.

        Args:
            arg_key (str): name of the list expression arg
            value (Any): value to append to the list
        rA   N)	rQ   r@   rh   r\   rK   r   lenrC   r   )rL   rB   rM   r   r.   r.   r/   r   N  s   



zExpression.appendrC   t.Optional[int]	overwritec                 C  s   |durP| j |pg }t||du rdS |du r/|| ||d D ]}|jd |_q$dS t|tr@|| ||||< n|rG|||< n||| |}n|du r]| j |d dS || j |< | ||| dS )a  
        Sets arg_key to value.

        Args:
            arg_key: name of the expression arg.
            value: value to set the arg to.
            index: if the arg is a list, this specifies what position to add the value in it.
            overwrite: assuming an index is given, this determines whether to overwrite the
                list entry instead of only inserting a new value (i.e., like list.insert).
        N   )	r@   rh   r   r   rC   rn   r\   insertrK   )rL   rB   rM   rC   r   rl   r`   r.   r.   r/   r   ^  s*   




zExpression.setc                 C  sb   t |dr| |_||_||_d S t|tu r-t|D ]\}}t |dr,| |_||_||_qd S d S )NrA   )r   rA   rB   rC   rQ   r\   	enumerate)rL   rB   rM   rC   r`   r.   r.   r/   rK     s   


zExpression._set_parentc                 C  s   | j r	| j jd S dS )z1
        Returns the depth of this tree.
        r   r   )rA   depthrb   r.   r.   r/   r     s   zExpression.depthreverset.Iterator[Expression]c                 c  sl    |r
t | j n| j D ]$}t|tu r+|rt |n|D ]
}t|dr)|V  qqt|dr3|V  qdS )zEYields the key and expression for all arguments, exploding list args.rA   N)reversedr@   r   rQ   r\   r   )rL   r   r   r`   r.   r.   r/   iter_expressions  s    

zExpression.iter_expressionsbfsexpression_types	t.Type[E]r   t.Optional[E]c                G  s   t | j|d|idS )a~  
        Returns the first node in this tree which matches at least one of
        the specified types.

        Args:
            expression_types: the expression type(s) to match.
            bfs: whether to search the AST using the BFS algorithm (DFS is used if false).

        Returns:
            The node which matches the criteria or None if no such node was found.
        r   N)nextfind_all)rL   r   r   r.   r.   r/   find  s   zExpression.findt.Iterator[E]c                g  s(    | j |dD ]
}t||r|V  qdS )a  
        Returns a generator object which visits all nodes in this tree and only
        yields those that match at least one of the specified expression types.

        Args:
            expression_types: the expression type(s) to match.
            bfs: whether to search the AST using the BFS algorithm (DFS is used if false).

        Returns:
            The generator object.
        r   N)walkrn   )rL   r   r   r?   r.   r.   r/   r     s   
zExpression.find_allc                 G  s,   | j }|rt||s|j }|rt||r
|S )z
        Returns a nearest parent matching expression_types.

        Args:
            expression_types: the expression type(s) to match.

        Returns:
            The parent node.
        )rA   rn   )rL   r   ancestorr.   r.   r/   find_ancestor  s
   
zExpression.find_ancestort.Optional[Select]c                 C  s
   |  tS )z6
        Returns the parent select statement.
        )r   Selectrb   r.   r.   r/   parent_select  s   
zExpression.parent_selectc                 C  s   t | j| ju S )z2Returns if the parent is the same class as itself.)rQ   rA   r-   rb   r.   r.   r/   same_parent  s   zExpression.same_parentc                 C  s   | }|j r|j }|j s|S )z;
        Returns the root expression of this tree.
        )rA   rL   r?   r.   r.   r/   r     s
   zExpression.rootprune*t.Optional[t.Callable[[Expression], bool]]c                 c  s2    |r| j |dE dH  dS | j|dE dH  dS )a  
        Returns a generator object which visits all nodes in this tree.

        Args:
            bfs: if set to True the BFS traversal order will be applied,
                otherwise the DFS traversal will be used instead.
            prune: callable that returns True if the generator should stop traversing
                this branch of the tree.

        Returns:
            the generator object.
        r   N)r   dfs)rL   r   r   r.   r.   r/   r     s   zExpression.walkc                 c  sP    | g}|r&|  }|V  |r||rq|jddD ]}|| q|sdS dS )z
        Returns a generator object which visits all nodes in this tree in
        the DFS (Depth-first) order.

        Returns:
            The generator object.
        Tr   N)r   r   r   )rL   r   r   r   r`   r.   r.   r/   r      s   
zExpression.dfsc                 c  sP    t | g}|r&| }|V  |r||rq| D ]}|| q|sdS dS )z
        Returns a generator object which visits all nodes in this tree in
        the BFS (Breadth-first) order.

        Returns:
            The generator object.
        N)r   popleftr   r   )rL   r   queuer   r`   r.   r.   r/   r     s   

zExpression.bfsc                 C  s&   | }t |tu r|j}t |tu s|S )zB
        Returns the first non parenthesis child or self.
        )rQ   Parenr4   r   r.   r.   r/   unnest.  s
   zExpression.unnestc                 C  s   t | tr| jS | S )zC
        Returns the inner expression if this is an Alias.
        )rn   Aliasr4   rb   r.   r.   r/   unalias7  s   
zExpression.unaliasc                 C  s   t dd |  D S )z7
        Returns unnested operands as a tuple.
        c                 s  s    | ]}|  V  qd S rI   )r   rX   argr.   r.   r/   rZ   C  r[   z-Expression.unnest_operands.<locals>.<genexpr>)r]   r   rb   r.   r.   r/   unnest_operands?  s   zExpression.unnest_operandsc                 #  sJ     j  fdddD ]}t| jur"|rt|ts| n|V  qdS )z
        Returns a generator which yields child nodes whose parents are the same class.

        A AND B AND C -> [A, B, C]
        c                   s   | j o	t|  juS rI   )rA   rQ   r-   nrb   r.   r/   <lambda>K      z$Expression.flatten.<locals>.<lambda>r   N)r   rQ   r-   rn   Subqueryr   )rL   r   r   r.   rb   r/   flattenE  s   zExpression.flattenc                 C  s   |   S rI   )sqlrb   r.   r.   r/   __str__O     zExpression.__str__c                 C  r   rI   _to_srb   r.   r.   r/   __repr__R  r   zExpression.__repr__c                 C  s   t | ddS )z
        Same as __repr__, but includes additional information which can be useful
        for debugging, like empty or missing args and the AST nodes' object IDs.
        Tverboser   rb   r.   r.   r/   to_sU  ri   zExpression.to_sdialectr   c                 K  s$   ddl m} ||j| fi |S )a!  
        Returns SQL string representation of this tree.

        Args:
            dialect: the dialect of the output SQL string (eg. "spark", "hive", "presto", "mysql").
            opts: other `sqlglot.generator.Generator` options.

        Returns:
            The SQL string.
        r   Dialect)sqlglot.dialectsr   get_or_raisegenerate)rL   r   optsr   r.   r.   r/   r   \  s   zExpression.sqlr   fun
t.Callabler   c          
        s   d}d |r
|   n| j fdddD ],}|j|j|j}}}	||g|R i | |s1 }q|r@|r@ |ur@|| |	 q|sEJ |tS )aZ  
        Visits all tree nodes (excluding already transformed ones)
        and applies the given transformation function to each node.

        Args:
            fun: a function which takes a node as an argument and returns a
                new transformed node or the same node without modifications. If the function
                returns None, then the corresponding node will be removed from the syntax tree.
            copy: if set to True a new tree instance is constructed, otherwise the tree is
                modified in place.

        Returns:
            The transformed tree.
        Nc                   s   |  uS rI   r.   r   new_noder.   r/   r   }  s    z&Expression.transform.<locals>.<lambda>r   )r   r   rA   rB   rC   r   	assert_isr>   )
rL   r  r   r@   kwargsr   r   rA   rB   rC   r.   r  r/   	transformk  s   $
zExpression.transformr   c                 C     d S rI   r.   r   r.   r.   r/   replace     zExpression.replacec                 C  r  rI   r.   r   r.   r.   r/   r	    r
  c                 C  sz   | j }|r	||u r|S | j}|j|}t|tu r&t|tr&|j | n|	||| j
 || ur;d| _ d| _d| _
|S )a  
        Swap out this expression with a new expression.

        For example::

            >>> tree = Select().select("x").from_("tbl")
            >>> tree.find(Column).replace(column("y"))
            Column(
              this=Identifier(this=y, quoted=False))
            >>> tree.sql()
            'SELECT y FROM tbl'

        Args:
            expression: new node

        Returns:
            The new expression or expressions.
        N)rA   rB   r@   rh   rQ   r\   rn   r>   r	  r   rC   )rL   r?   rA   r%   rM   r.   r.   r/   r	    s   rL   c                 C  s   |  d | S )zk
        Remove this expression from its AST.

        Returns:
            The popped expression.
        N)r	  rb   r.   r.   r/   r     s   
zExpression.poptype_c                 C  s"   t | |st|  d| d| S )a  
        Assert that this `Expression` is an instance of `type_`.

        If it is NOT an instance of `type_`, this raises an assertion error.
        Otherwise, this returns this expression.

        Examples:
            This is useful for type security in chained expressions:

            >>> import sqlglot
            >>> sqlglot.parse_one("SELECT x from y").assert_is(Select).select("z").sql()
            'SELECT x, z FROM y'
        z is not .)rn   AssertionError)rL   r  r.   r.   r/   r    s   
zExpression.assert_ist.Optional[t.Sequence]c                 C  s   g }| j D ]}|| jvr|d| d| j  q| j D ]#\}}| j |}|rA|du s5t|trA|sA|d| d| j  q|rft| trft	|t	| jkrf| j
sf|dt	| dt	| j d |S )	a  
        Checks if this expression is valid (e.g. all mandatory args are set).

        Args:
            args: a sequence of values that were used to instantiate a Func expression. This is used
                to check that the provided arguments don't exceed the function argument limit.

        Returns:
            A list of error messages for all possible errors that were found.
        zUnexpected keyword: 'z' for NzRequired keyword: 'z' missing for z"The number of provided arguments (z=) is greater than the maximum number of supported arguments ())r@   	arg_typesr   r-   rJ   rh   rn   r\   Funcr   is_var_len_args)rL   r@   errorsr_   	mandatoryr`   r.   r.   r/   error_messages  s.   

zExpression.error_messagesc                 C  s   ddl m} || S )zC
        Dump this Expression to a JSON-serializable dict.
        r   )dump)sqlglot.serder  )rL   r  r.   r.   r/   r    s   zExpression.dumpc                 C  s   ddl m} ||S )z]
        Load a dict (as returned by `Expression.dump`) into an Expression instance.
        r   )load)r  r  )r'   objr  r.   r.   r/   r    s   zExpression.loadr   r   wraprl   t.Optional[ExpOrStr]r  	Conditionc                O     t | g|R |||d|S )aG  
        AND this condition with one or multiple expressions.

        Example:
            >>> condition("x=1").and_("y=1").sql()
            'x = 1 AND y = 1'

        Args:
            *expressions: the SQL code strings to parse.
                If an `Expression` instance is passed, it will be used as-is.
            dialect: the dialect used to parse the input expression.
            copy: whether to copy the involved expressions (only applies to Expressions).
            wrap: whether to wrap the operands in `Paren`s. This is true by default to avoid
                precedence issues, but can be turned off when the produced AST is too deep and
                causes recursion-related issues.
            opts: other options to use to parse the input expressions.

        Returns:
            The new And condition.
        r  )and_rL   r   r   r  rl   r   r.   r.   r/   r       zExpression.and_c                O  r  )aC  
        OR this condition with one or multiple expressions.

        Example:
            >>> condition("x=1").or_("y=1").sql()
            'x = 1 OR y = 1'

        Args:
            *expressions: the SQL code strings to parse.
                If an `Expression` instance is passed, it will be used as-is.
            dialect: the dialect used to parse the input expression.
            copy: whether to copy the involved expressions (only applies to Expressions).
            wrap: whether to wrap the operands in `Paren`s. This is true by default to avoid
                precedence issues, but can be turned off when the produced AST is too deep and
                causes recursion-related issues.
            opts: other options to use to parse the input expressions.

        Returns:
            The new Or condition.
        r  )or_r   r.   r.   r/   r"  %  r!  zExpression.or_c                 C     t | |dS )z
        Wrap this condition with NOT.

        Example:
            >>> condition("x=1").not_().sql()
            'NOT x = 1'

        Args:
            copy: whether to copy this object.

        Returns:
            The new Not instance.
        r   )not_)rL   r   r.   r.   r/   r$  C  s   zExpression.not_rT   t.Optional[Token | Expression]r  c                 K  sl   t |tr| jdd |j D  n|dur'| j|j|j|j|jd | jdd | D  | S )z
        Update this expression with positions from a token or other expression.

        Args:
            other: a token or expression to update this expression with.

        Returns:
            The updated expression.
        c                 S     i | ]\}}|t v r||qS r.   POSITION_META_KEYSr^   r.   r.   r/   
<dictcomp>`      z/Expression.update_positions.<locals>.<dictcomp>Nr9   c                 S  r&  r.   r'  r^   r.   r.   r/   r)  j  r*  )	rn   r>   r   updaterJ   r:   r;   r<   r=   )rL   rT   r  r.   r.   r/   update_positionsS  s   
zExpression.update_positionsr   str | Identifierquotedt.Optional[bool]r   c                 K  s   t | |f|||d|S )N)r.  r   r   )alias_)rL   r   r.  r   r   r   r.   r.   r/   as_m  s   zExpression.as_r+   c                 C  sX   |   }t|dd}t||st||st|t}t|t}|r&|||dS |||dS )NTr   r4   r?   )r   convertrn   _wrapBinary)rL   r+   rT   r   r4   r.   r.   r/   _binopw  s   

zExpression._binopExpOrStr | t.Tuple[ExpOrStr]Bracketc                 C  s   t |  dd t|D dS )Nc                 S  s   g | ]}t |d dqS )Tr   r3  rX   er.   r.   r/   r         z*Expression.__getitem__.<locals>.<listcomp>r4   rl   )r8  r   r   rS   r.   r.   r/   __getitem__  s   zExpression.__getitem__
t.Iteratorc                 C  s2   d| j v rt| jdpg S td| jj d)Nrl   'z' object is not iterable)r  iterr@   rh   	TypeErrorr-   r0   rb   r.   r.   r/   __iter__  s   
zExpression.__iter__queryr   r   rE  r   -t.Optional[ExpOrStr] | t.Collection[ExpOrStr]Inc                  s   |rt |fd ind }|rt|ts|jdd}tt|   fdd|D ||r<t fddt|D ddS d dS )	Nr   Fr   c                      g | ]}t | d qS r   r9  r:  r   r.   r/   r     r<  z#Expression.isin.<locals>.<listcomp>c                   (   g | ]}t tt|fd  iqS r   maybe_parsetcastExpOrStrr:  r   r   r.   r/   r         rl   r4   rl   rE  r   )rL  rn   r   subqueryrG  
maybe_copyUnnestr   )rL   rE  r   r   rl   r   rT  r.   rP  r/   isin  s    zExpression.isinlowhighBetweenc                 K  s4   t t| |t|fd|i|t|fd|i|dS )Nr   r4   rX  rY  )rZ  rU  r3  )rL   rX  rY  r   r   r.   r.   r/   between  s
   zExpression.betweenrO  Isc                 C     |  t|S rI   )r6  r]  rS   r.   r.   r/   is_     zExpression.is_Likec                 C  r^  rI   )r6  ra  rS   r.   r.   r/   like  r`  zExpression.likeILikec                 C  r^  rI   )r6  rc  rS   r.   r.   r/   ilike  r`  zExpression.ilikeEQc                 C  r^  rI   )r6  re  rS   r.   r.   r/   eq  r`  zExpression.eqNEQc                 C  r^  rI   )r6  rg  rS   r.   r.   r/   neq  r`  zExpression.neq
RegexpLikec                 C  r^  rI   )r6  ri  rS   r.   r.   r/   rlike  r`  zExpression.rliketypedsafeDivc                 C  s$   |  t|}||jd< ||jd< |S )Nrk  rl  )r6  rm  r@   )rL   rT   rk  rl  divr.   r.   r/   rn    s   

zExpression.divnulls_firstOrderedc                 C  s   t |  |dS )N)r4   ro  rp  r   rL   ro  r.   r.   r/   asc     zExpression.ascc                 C  s   t |  d|dS )NT)r4   descro  rq  rr  r.   r.   r/   ru    s   zExpression.descLTc                 C  r^  rI   )r6  rv  rS   r.   r.   r/   __lt__  r`  zExpression.__lt__LTEc                 C  r^  rI   )r6  rx  rS   r.   r.   r/   __le__  r`  zExpression.__le__GTc                 C  r^  rI   )r6  rz  rS   r.   r.   r/   __gt__  r`  zExpression.__gt__GTEc                 C  r^  rI   )r6  r|  rS   r.   r.   r/   __ge__  r`  zExpression.__ge__Addc                 C  r^  rI   r6  r~  rS   r.   r.   r/   __add__  r`  zExpression.__add__c                 C     | j t|ddS NTr   r  rS   r.   r.   r/   __radd__  rt  zExpression.__radd__Subc                 C  r^  rI   r6  r  rS   r.   r.   r/   __sub__  r`  zExpression.__sub__c                 C  r  r  r  rS   r.   r.   r/   __rsub__  rt  zExpression.__rsub__Mulc                 C  r^  rI   r6  r  rS   r.   r.   r/   __mul__  r`  zExpression.__mul__c                 C  r  r  r  rS   r.   r.   r/   __rmul__  rt  zExpression.__rmul__c                 C  r^  rI   r6  rm  rS   r.   r.   r/   __truediv__  r`  zExpression.__truediv__c                 C  r  r  r  rS   r.   r.   r/   __rtruediv__  rt  zExpression.__rtruediv__IntDivc                 C  r^  rI   r6  r  rS   r.   r.   r/   __floordiv__  r`  zExpression.__floordiv__c                 C  r  r  r  rS   r.   r.   r/   __rfloordiv__  rt  zExpression.__rfloordiv__Modc                 C  r^  rI   r6  r  rS   r.   r.   r/   __mod__  r`  zExpression.__mod__c                 C  r  r  r  rS   r.   r.   r/   __rmod__  rt  zExpression.__rmod__Powc                 C  r^  rI   r6  r  rS   r.   r.   r/   __pow__  r`  zExpression.__pow__c                 C  r  r  r  rS   r.   r.   r/   __rpow__  rt  zExpression.__rpow__Andc                 C  r^  rI   r6  r  rS   r.   r.   r/   __and__  r`  zExpression.__and__c                 C  r  r  r  rS   r.   r.   r/   __rand__  rt  zExpression.__rand__Orc                 C  r^  rI   r6  r  rS   r.   r.   r/   __or__  r`  zExpression.__or__c                 C  r  r  r  rS   r.   r.   r/   __ror__  rt  zExpression.__ror__ry   c                 C  s   t t|  tdS Nr4   )ry   r4  r   r5  rb   r.   r.   r/   __neg__     zExpression.__neg__Notc                 C  s   t |  S rI   )r$  r   rb   r.   r.   r/   
__invert__  r`  zExpression.__invert__)r@   rH   rO   rP   rO   rH   )rO   rd   )rO   rj   rO   rm   rO   r   rO   r   )r   r   rO   r   )rO   r   )rO   r   NF)rD   r   r   rP   rO   r   )rB   rm   rM   rH   rO   r   NT)
rB   rm   rM   rH   rC   r   r   rP   rO   r   rI   )rB   rm   rM   rH   rC   r   rO   r   F)r   rP   rO   r   )r   r   r   rP   rO   r   )r   r   r   rP   rO   r   )r   r   rO   r   )rO   r   rO   r>   TN)r   rP   r   r   rO   r   )r   r   rO   r   T)r   r   rO   rm   )r  r  r@   rH   r   rP   rO   r>   )r?   r   rO   r   )r?   r   rO   r   )rL   r   rO   r   )r  r   rO   r   )r@   r  rO   r   
rl   r  r   r   r   rP   r  rP   rO   r  )r   rP   )rL   r   rT   r%  r  rH   rO   r   NNT)
r   r-  r.  r/  r   r   r   rP   rO   r   )r+   r   rT   rH   r   rP   rO   r   )rT   r7  rO   r8  )rO   r?  
rl   rH   rE  r  r   rF  r   rP   rO   rG  )rX  rH   rY  rH   r   rP   rO   rZ  )rT   rO  rO   r]  )rT   rO  rO   ra  )rT   rO  rO   rc  )rT   rH   rO   re  )rT   rH   rO   rg  )rT   rO  rO   ri  )FF)rT   rO  rk  rP   rl  rP   rO   rm  )ro  rP   rO   rp  )rT   rH   rO   rv  )rT   rH   rO   rx  )rT   rH   rO   rz  )rT   rH   rO   r|  )rT   rH   rO   r~  )rT   rH   rO   r  )rT   rH   rO   r  )rT   rH   rO   rm  )rT   rH   rO   r  )rT   rH   rO   r  )rT   rH   rO   r  )rT   rH   rO   r  )rT   rH   rO   r  )rO   ry   )rO   r  )nr0   r1   r2   r&   r%   r  	__slots__rN   rU   propertyrc   re   r4   r?   rl   rv   rw   rz   r|   r}   r   r   r   rt   r   r   rQ   setterr   r   r   r   r   r   r   r   r   rK   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  rM  overloadr	  r   r  r  r  classmethodr  r  r"  r$  r,  r1  r6  r>  rC  rW  r\  r_  rb  rd  rf  rh  rj  rn  rs  ru  rw  ry  r{  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r.   r.   r.   r/   r>   G   s$   ",
	
)
"
!

r>   )	metaclassc                   @     e Zd ZdZdS )r  z,Logical conditions like x AND y, or simply xNr0   r1   r2   r&   r.   r.   r.   r/   r         r  c                   @  r  )	Predicatez(Relationships like x = y, x > 1, x >= y.Nr  r.   r.   r.   r/   r  $  r  r  c                   @  s(   e Zd Zed	ddZed
ddZdS )DerivedTablerO   t.List[Expression]c                 C     t | jtr
| jjS g S rI   )rn   r4   r   selectsrb   r.   r.   r/   r  )  s   zDerivedTable.selectsr   c                 C     dd | j D S )Nc                 S  r   r.   )r   )rX   selectr.   r.   r/   r   /  r   z.DerivedTable.named_selects.<locals>.<listcomp>)r  rb   r.   r.   r/   named_selects-     zDerivedTable.named_selectsNrO   r  r  )r0   r1   r2   r  r  r  r.   r.   r.   r/   r  (  
    r  c                   @  s   e Zd Zd;d<d	d
Z	d;d=ddZ	d;d=ddZddddd>ddZed?ddZed@ddZ	edAd!d"Z
ddddd>d#d$Zddddd>d%d&Z						'dBdCd.d/Zddd0dDd3d4Zddd0dEd6d7Zddd0dFd9d:ZdS )Gr   NTr   r  r   rP   rO   r   c                 C  s6   t | |}t|ts|rtt|dnd}t||dS )a  
        Returns a `Subquery` that wraps around this query.

        Example:
            >>> subquery = Select().select("x").from_("tbl").subquery()
            >>> Select().select("x").from_(subquery).sql()
            'SELECT x FROM (SELECT x FROM tbl)'

        Args:
            alias: an optional alias for the subquery.
            copy: if `False`, modify this expression instance in-place.
        r  Nr4   r   )rU  rn   r>   r   to_identifierr   )rL   r   r   instancer.   r.   r/   rT  3  s   

zQuery.subqueryrL   r   r?   ExpOrStr | intr   r   c                 K      t d|| dtd||dd|S )a  
        Adds a LIMIT clause to this query.

        Example:
            >>> select("1").union(select("1")).limit(1).sql()
            'SELECT 1 UNION SELECT 1 LIMIT 1'

        Args:
            expression: the SQL code string to parse.
                This can also be an integer.
                If a `Limit` instance is passed, it will be used as-is.
                If another `Expression` instance is passed, it will be wrapped in a `Limit`.
            dialect: the dialect used to parse the input expression.
            copy: if `False`, modify this expression instance in-place.
            opts: other options to use to parse the input expressions.

        Returns:
            A limited Select expression.
        limitLIMITr?   r?   r  r   intoprefixr   r   into_argNr.   )_apply_builderLimitrL   r?   r   r   r   r.   r.   r/   r  F     	zQuery.limitc                 K  r  )a  
        Set the OFFSET expression.

        Example:
            >>> Select().from_("tbl").select("x").offset(10).sql()
            'SELECT x FROM tbl OFFSET 10'

        Args:
            expression: the SQL code string to parse.
                This can also be an integer.
                If a `Offset` instance is passed, this is used as-is.
                If another `Expression` instance is passed, it will be wrapped in a `Offset`.
            dialect: the dialect used to parse the input expression.
            copy: if `False`, modify this expression instance in-place.
            opts: other options to use to parse the input expressions.

        Returns:
            The modified Select expression.
        offsetOFFSETr?   r  Nr.   )r  Offsetr  r.   r.   r/   r  h  r  zQuery.offsetr   r   r   rl   r   c             
   O     t || d||dt|d|S )aU  
        Set the ORDER BY expression.

        Example:
            >>> Select().from_("tbl").select("x").order_by("x DESC").sql()
            'SELECT x FROM tbl ORDER BY x DESC'

        Args:
            *expressions: the SQL code strings to parse.
                If a `Group` instance is passed, this is used as-is.
                If another `Expression` instance is passed, it will be wrapped in a `Order`.
            append: if `True`, add to any existing expressions.
                Otherwise, this flattens all the `Order` expression into a single expression.
            dialect: the dialect used to parse the input expression.
            copy: if `False`, modify this expression instance in-place.
            opts: other options to use to parse the input expressions.

        Returns:
            The modified Select expression.
        orderzORDER BYr  r   r   r   r  r  r   )_apply_child_list_builderOrderrL   r   r   r   rl   r   r.   r.   r/   order_by     	zQuery.order_byt.List[CTE]c                 C     | j d}|r|jS g S )z6Returns a list of all the CTEs attached to this query.withr@   rh   rl   rL   with_r.   r.   r/   ctes     z
Query.ctesr  c                 C     t d)z Returns the query's projections.z&Query objects must implement `selects`NotImplementedErrorrb   r.   r.   r/   r       zQuery.selectsr   c                 C  r  )z4Returns the output names of the query's projections.z,Query objects must implement `named_selects`r  rb   r.   r.   r/   r    r  zQuery.named_selectsc                O  r  )a  
        Append to or set the SELECT expressions.

        Example:
            >>> Select().select("x", "y").sql()
            'SELECT x, y'

        Args:
            *expressions: the SQL code strings to parse.
                If an `Expression` instance is passed, it will be used as-is.
            append: if `True`, add to any existing expressions.
                Otherwise, this resets the expressions.
            dialect: the dialect used to parse the input expressions.
            copy: if `False`, modify this expression instance in-place.
            opts: other options to use to parse the input expressions.

        Returns:
            The modified Query expression.
        z%Query objects must implement `select`r  r  r.   r.   r/   r    s   zQuery.selectc             	   O  s&   t dd |D | d|t||d|S )aM  
        Append to or set the WHERE expressions.

        Examples:
            >>> Select().select("x").from_("tbl").where("x = 'a' OR x < 'b'").sql()
            "SELECT x FROM tbl WHERE x = 'a' OR x < 'b'"

        Args:
            *expressions: the SQL code strings to parse.
                If an `Expression` instance is passed, it will be used as-is.
                Multiple expressions are combined with an AND operator.
            append: if `True`, AND the new expressions to any existing expression.
                Otherwise, this resets the expression.
            dialect: the dialect used to parse the input expressions.
            copy: if `False`, modify this expression instance in-place.
            opts: other options to use to parse the input expressions.

        Returns:
            The modified expression.
        c                 S  s    g | ]}t |tr|jn|qS r.   )rn   Wherer4   )rX   exprr.   r.   r/   r          zQuery.where.<locals>.<listcomp>wherer  r   r   r  r   r   _apply_conjunction_builderr  r  r.   r.   r/   r    s   zQuery.whereFrO  r1  	recursiver/  materializedscalarc	           
   	   K  s"   t | ||f||||||d|	S )a  
        Append to or set the common table expressions.

        Example:
            >>> Select().with_("tbl2", as_="SELECT * FROM tbl").select("x").from_("tbl2").sql()
            'WITH tbl2 AS (SELECT * FROM tbl) SELECT x FROM tbl2'

        Args:
            alias: the SQL code string to parse as the table name.
                If an `Expression` instance is passed, this is used as-is.
            as_: the SQL code string to parse as the table expression.
                If an `Expression` instance is passed, it will be used as-is.
            recursive: set the RECURSIVE part of the expression. Defaults to `False`.
            materialized: set the MATERIALIZED part of the expression.
            append: if `True`, add to any existing expressions.
                Otherwise, this resets the expressions.
            dialect: the dialect used to parse the input expression.
            copy: if `False`, modify this expression instance in-place.
            scalar: if `True`, this is a scalar common table expression.
            opts: other options to use to parse the input expressions.

        Returns:
            The modified expression.
        )r  r  r   r   r   r  _apply_cte_builder)
rL   r   r1  r  r  r   r   r   r  r   r.   r.   r/   r    s   $
zQuery.with_distinctr   r  Unionc                O     t | g|R ||d|S )a  
        Builds a UNION expression.

        Example:
            >>> import sqlglot
            >>> sqlglot.parse_one("SELECT * FROM foo").union("SELECT * FROM bla").sql()
            'SELECT * FROM foo UNION SELECT * FROM bla'

        Args:
            expressions: the SQL code strings.
                If `Expression` instances are passed, they will be used as-is.
            distinct: set the DISTINCT flag if and only if this is true.
            dialect: the dialect used to parse the input expression.
            opts: other options to use to parse the input expressions.

        Returns:
            The new Union expression.
        r  )unionrL   r  r   rl   r   r.   r.   r/   r  7     zQuery.union	Intersectc                O  r  )a  
        Builds an INTERSECT expression.

        Example:
            >>> import sqlglot
            >>> sqlglot.parse_one("SELECT * FROM foo").intersect("SELECT * FROM bla").sql()
            'SELECT * FROM foo INTERSECT SELECT * FROM bla'

        Args:
            expressions: the SQL code strings.
                If `Expression` instances are passed, they will be used as-is.
            distinct: set the DISTINCT flag if and only if this is true.
            dialect: the dialect used to parse the input expression.
            opts: other options to use to parse the input expressions.

        Returns:
            The new Intersect expression.
        r  )	intersectr  r.   r.   r/   r  N  r  zQuery.intersectExceptc                O  r  )a  
        Builds an EXCEPT expression.

        Example:
            >>> import sqlglot
            >>> sqlglot.parse_one("SELECT * FROM foo").except_("SELECT * FROM bla").sql()
            'SELECT * FROM foo EXCEPT SELECT * FROM bla'

        Args:
            expressions: the SQL code strings.
                If `Expression` instance are passed, they will be used as-is.
            distinct: set the DISTINCT flag if and only if this is true.
            dialect: the dialect used to parse the input expression.
            opts: other options to use to parse the input expressions.

        Returns:
            The new Except expression.
        r  )except_r  r.   r.   r/   r  e  r  zQuery.except_r  )r   r  r   rP   rO   r   )
rL   r   r?   r  r   r   r   rP   rO   r   )rL   r   rl   r  r   rP   r   r   r   rP   rO   r   rO   r  r  r  NNTNTF)rL   r   r   rO  r1  rO  r  r/  r  r/  r   rP   r   r   r   rP   r  rP   rO   r   )rl   rO  r  rP   r   r   rO   r   )rl   rO  r  rP   r   r   rO   r  )rl   rO  r  rP   r   r   rO   r  )r0   r1   r2   rT  r  r  r  r  r  r  r  r  r  r  r  r  r  r.   r.   r.   r/   r   2  sJ    #%( +2c                   @     e Zd ZedddZdS )UDTFrO   r  c                 C  r  )Nr   )r@   rh   r   )rL   r   r.   r.   r/   r  ~     zUDTF.selectsNr  )r0   r1   r2   r  r  r.   r.   r.   r/   r  }      r  c                   @     e Zd ZdddddZdS )CacheTF)r4   lazyoptionsr?   Nr0   r1   r2   r  r.   r.   r.   r/   r        
r  c                   @     e Zd ZdddZdS )UncacheTFr4   existsNr  r.   r.   r.   r/   r        r  c                   @     e Zd ZdS )RefreshNr0   r1   r2   r.   r.   r.   r/   r        r  c                   @  s6   e Zd ZedddZedddZedd	d
ZdS )DDLrO   r  c                 C  r  )z:Returns a list of all the CTEs attached to this statement.r  r  r  r.   r.   r/   r    r  zDDL.ctesr  c                 C  r  )zWIf this statement contains a query (e.g. a CTAS), this returns the query's projections.)rn   r?   r   r  rb   r.   r.   r/   r    s   zDDL.selectsr   c                 C  r  )z
        If this statement contains a query (e.g. a CTAS), this returns the output
        names of the query's projections.
        )rn   r?   r   r  rb   r.   r.   r/   r    s   zDDL.named_selectsNr	  r  r  )r0   r1   r2   r  r  r  r  r.   r.   r.   r/   r    s    r  c                   @  s   e Zd Z		ddddZdS )DMLNTr?   rO  r   r   r   rP   rO   'Self'c              
   K  s   t d|| dd||td|S )ay  
        Set the RETURNING expression. Not supported by all dialects.

        Example:
            >>> delete("tbl").returning("*", dialect="postgres").sql()
            'DELETE FROM tbl RETURNING *'

        Args:
            expression: the SQL code strings to parse.
                If an `Expression` instance is passed, it will be used as-is.
            dialect: the dialect used to parse the input expressions.
            copy: if `False`, modify this expression instance in-place.
            opts: other options to use to parse the input expressions.

        Returns:
            Delete: the modified expression.
        	returning	RETURNING)r?   r  r   r  r   r   r  Nr.   )r  	Returningr  r.   r.   r/   r!    s   zDML.returningr  )r?   rO  r   r   r   rP   rO   r   )r0   r1   r2   r!  r.   r.   r.   r/   r    s    r  c                   @  s~   e Zd Zi ddddddddddddd	dd
dddddddddddddddddZedddZdS )Creater  Fr4   Tkindr?   r  
propertiesr	  refreshuniqueindexesno_schema_bindingbeginr=   cloneconcurrently	clusteredrO   t.Optional[str]c                 C     | j d}|o| S Nr%  r@   rh   upperrL   r%  r.   r.   r/   r%       zCreate.kindNrO   r/  r0   r1   r2   r  r  r%  r.   r.   r.   r/   r$    sH    	
r$  c                   @      e Zd ZddddddddZdS )SequencePropertiesF)	incrementminvaluemaxvaluecacher<   ownedr  Nr  r.   r.   r.   r/   r9        
r9  c                	   @  s"   e Zd ZdddddddddZdS )TruncateTableTF)rl   is_databaser  onlyclusteridentityoption	partitionNr  r.   r.   r.   r/   r@        
r@  c                   @     e Zd ZddddZdS )CloneTF)r4   shallowr   Nr  r.   r.   r.   r/   rI        rI  c                   @     e Zd ZdddddddZdS )DescribeTF)r4   styler%  rl   rF  formatNr  r.   r.   r.   r/   rM  	      
rM  c                   @  rH  )AttachTF)r4   r  rl   Nr  r.   r.   r.   r/   rQ    rK  rQ  c                   @  r  )DetachTFr  Nr  r.   r.   r.   r/   rR    r  rR  c                   @  r  )	SummarizeTF)r4   r8   Nr  r.   r.   r.   r/   rS    r  rS  c                   @  r  )KillTFr4   r%  Nr  r.   r.   r.   r/   rT  #  r  rT  c                   @  r  )PragmaNr  r.   r.   r.   r/   rV  '  r  rV  c                   @     e Zd ZddiZdS )Declarerl   TNr  r.   r.   r.   r/   rX  +      rX  c                   @     e Zd ZddddZdS )DeclareItemTF)r4   r%  defaultNr  r.   r.   r.   r/   r[  /  rK  r[  c                   @     e Zd ZddddZdS )SetF)rl   unsettagNr  r.   r.   r.   r/   r^  3  rK  r^  c                   @  r  )HeredocTF)r4   r`  Nr  r.   r.   r.   r/   ra  7  r  ra  c                   @     e Zd ZddddddZdS )SetItemF)r4   rl   r%  collateglobalNr  r.   r.   r.   r/   rc  ;      
rc  c                   @  s   e Zd Zi ddddddddddddd	dd
dddddddddddddddddddddddddZdS )Showr4   ThistoryFtersetargetr  starts_withr  fromrb  r  r5   scope
scope_kindfullmutexrE  channel)re  logpositiontypes
privilegesNr  r.   r.   r.   r/   rg  E  sT    	
rg  c                   @  rH  )UserDefinedFunctionTF)r4   rl   wrappedNr  r.   r.   r.   r/   rv  `  rK  rv  c                   @  r  )CharacterSetTFr4   r\  Nr  r.   r.   r.   r/   rx  d  r  rx  c                   @     e Zd ZdddddZdS )RecursiveWithSearchTF)r%  r4   r?   usingNr  r.   r.   r.   r/   r{  h      r{  c                   @  s&   e Zd ZddddZed	ddZdS )
WithTF)rl   r  searchrO   rP   c                 C     t | jdS )Nr  rP   r@   rh   rb   r.   r.   r/   r  o  r  zWith.recursiveNr  )r0   r1   r2   r  r  r  r.   r.   r.   r/   r~  l      r~  c                   @  r  )WithinGroupTFr2  Nr  r.   r.   r.   r/   r  t  r  r  c                   @     e Zd ZdddddZdS )CTETF)r4   r   r  r  Nr  r.   r.   r.   r/   r  z  r  r  c                   @     e Zd ZdddZdS )ProjectionDefTr2  Nr  r.   r.   r.   r/   r    r  r  c                   @  "   e Zd ZdddZedd ZdS )r   Fr4   r   c                 C  rk   )Nr   rg   rb   r.   r.   r/   r     r  zTableAlias.columnsN)r0   r1   r2   r  r  r   r.   r.   r.   r/   r         
r   c                   @  r  )	BitStringNr  r.   r.   r.   r/   r    r  r  c                   @  r  )	HexStringTF)r4   
is_integerNr  r.   r.   r.   r/   r    r  r  c                   @  r  )
ByteStringNr  r.   r.   r.   r/   r    r  r  c                   @  r  )	RawStringNr  r.   r.   r.   r/   r    r  r  c                   @  r  )UnicodeStringTF)r4   escapeNr  r.   r.   r.   r/   r    r  r  c                   @  sn   e Zd ZddddddZedddZeddd	Zedd
dZedddZedddZ	ddddZ
dS )r~   TF)r4   r8   r5   r6   	join_markrO   rm   c                 C  r   )Nr8   r   rb   r.   r.   r/   r8     r   zColumn.tablec                 C  r   Nr5   r   rb   r.   r.   r/   r5     r   z	Column.dbc                 C  r   Nr6   r   rb   r.   r.   r/   r6     r   zColumn.catalogc                 C  r   rI   r   rb   r.   r.   r/   r     r   zColumn.output_namet.List[Identifier]c                   s    fdddD S )z?Return the parts of a column in order catalog, db, table, name.c                   s*   g | ]} j |rtt j | qS r.   )r@   rh   rM  rN  ro   rX   partrb   r.   r/   r     s    
z Column.parts.<locals>.<listcomp>)r6   r5   r8   r4   r.   rb   r.   rb   r/   parts  s   
zColumn.partsinclude_dotsrP   Dot | Identifierc                 C  sX   | j }| j}|rt|tr||j |j}t|tst|dkr(tt|S |d S )z*Converts the column into a dot expression.r   r   )	r  rA   rn   Dotr   r?   r   r   r   )rL   r  r  rA   r.   r.   r/   to_dot  s   

"zColumn.to_dotNr  )rO   r  r  )r  rP   rO   r  )r0   r1   r2   r  r  r8   r5   r6   r   r  r  r.   r.   r.   r/   r~     s    r~   c                   @  r  )ColumnPositionFT)r4   rs  Nr  r.   r.   r.   r/   r    r  r  c                   @  s<   e Zd ZddddddddZedddZedd	d
ZdS )	ColumnDefTF)r4   r%  constraintsr  rs  r\  outputrO   t.List[ColumnConstraint]c                 C  rk   )Nr  rg   rb   r.   r.   r/   r    r  zColumnDef.constraintsr   c                 C  rf   r1  rg   rb   r.   r.   r/   r%    r   zColumnDef.kindN)rO   r  r  )r0   r1   r2   r  r  r  r%  r.   r.   r.   r/   r    s    
r  c                
   @  s$   e Zd Zdddddddddd	ZdS )AlterColumnTF)	r4   r   rd  r|  r\  dropr   
allow_nullvisibleNr  r.   r.   r.   r/   r        
r  c                   @  r  )
AlterIndexT)r4   r  Nr  r.   r.   r.   r/   r    r  r  c                   @  r  )AlterDistStyleNr  r.   r.   r.   r/   r    r  r  c                   @  r]  )AlterSortKeyF)r4   rl   compoundNr  r.   r.   r.   r/   r    rK  r  c                
   @  $   e Zd Zdddddddddd	ZdS )AlterSetF)	rl   rE  
tablespaceaccess_methodfile_formatcopy_optionsr`  locationserdeNr  r.   r.   r.   r/   r     r  r  c                   @  rZ  )RenameColumnTFr4   tor  Nr  r.   r.   r.   r/   r    rK  r  c                   @  r  )AlterRenameNr  r.   r.   r.   r/   r    r  r  c                   @  r  )	SwapTableNr  r.   r.   r.   r/   r    r  r  c                   @  s   e Zd ZddddddZdS )CommentTF)r4   r%  r?   r  r  Nr  r.   r.   r.   r/   r    rf  r  c                   @  rz  )ComprehensionTF)r4   r?   iterator	conditionNr  r.   r.   r.   r/   r  $  r}  r  c                   @     e Zd ZddddddZdS )MergeTreeTTLActionTF)r4   delete
recompressto_disk	to_volumeNr  r.   r.   r.   r/   r  )  rf  r  c                   @  r  )MergeTreeTTLTF)rl   r  group
aggregatesNr  r.   r.   r.   r/   r  4  r  r  c                   @  r8  )IndexConstraintOptionF)key_block_sizer|  parserr   r  engine_attrsecondary_engine_attrNr  r.   r.   r.   r/   r  >  r?  r  c                   @  $   e Zd ZdddZed	ddZdS )
ColumnConstraintFTrU  rO   ColumnConstraintKindc                 C  
   | j d S r1  r@   rb   r.   r.   r/   r%  M  r   zColumnConstraint.kindN)rO   r  r7  r.   r.   r.   r/   r  J      
r  c                   @  r  )r  Nr  r.   r.   r.   r/   r  R  r  r  c                   @  r  )AutoIncrementColumnConstraintNr  r.   r.   r.   r/   r  V  r  r  c                   @  r  )PeriodForSystemTimeConstraintTr2  Nr  r.   r.   r.   r/   r  Z  r  r  c                   @  rW  )CaseSpecificColumnConstraintr$  TNr  r.   r.   r.   r/   r  ^  rY  r  c                   @  rW  )CharacterSetColumnConstraintr4   TNr  r.   r.   r.   r/   r  b  rY  r  c                   @  r  )CheckColumnConstraintTF)r4   enforcedNr  r.   r.   r.   r/   r  f  r  r  c                   @  r  )ClusteredColumnConstraintNr  r.   r.   r.   r/   r  j  r  r  c                   @  r  )CollateColumnConstraintNr  r.   r.   r.   r/   r  n  r  r  c                   @  r  )CommentColumnConstraintNr  r.   r.   r.   r/   r  r  r  r  c                   @  rW  )CompressColumnConstraintr4   FNr  r.   r.   r.   r/   r  v  rY  r  c                   @  rW  )DateFormatColumnConstraintr4   TNr  r.   r.   r.   r/   r  z  rY  r  c                   @  r  )DefaultColumnConstraintNr  r.   r.   r.   r/   r  ~  r  r  c                   @  r  )EncodeColumnConstraintNr  r.   r.   r.   r/   r    r  r  c                   @  r  )ExcludeColumnConstraintNr  r.   r.   r.   r/   r    r  r  c                   @  rW  )EphemeralColumnConstraintr4   FNr  r.   r.   r.   r/   r    rY  r  c                   @  r  )WithOperatorT)r4   opNr  r.   r.   r.   r/   r    r  r  c                
   @  r  )#GeneratedAsIdentityColumnConstraintF)	r4   r?   on_nullr<   r:  r;  r<  cycler  Nr  r.   r.   r.   r/   r    s    
r  c                   @  r  )GeneratedAsRowColumnConstraintF)r<   hiddenNr  r.   r.   r.   r/   r    r  r  c                   @  r8  )IndexColumnConstraintF)r4   rl   r%  
index_typer  r?   granularityNr  r.   r.   r.   r/   r    r?  r  c                   @  r  )InlineLengthColumnConstraintNr  r.   r.   r.   r/   r    r  r  c                   @  r  )NonClusteredColumnConstraintNr  r.   r.   r.   r/   r    r  r  c                   @     e Zd Zi ZdS )!NotForReplicationColumnConstraintNr  r.   r.   r.   r/   r    r  r  c                   @  r  )MaskingPolicyColumnConstraintTFr=  Nr  r.   r.   r.   r/   r    r  r  c                   @  rW  )NotNullColumnConstraintr  FNr  r.   r.   r.   r/   r    rY  r  c                   @  r  )OnUpdateColumnConstraintNr  r.   r.   r.   r/   r    r  r  c                   @  r  )PrimaryKeyColumnConstraintF)ru  r  Nr  r.   r.   r.   r/   r    r  r  c                   @  r  )TitleColumnConstraintNr  r.   r.   r.   r/   r    r  r  c                   @  rb  )UniqueColumnConstraintF)r4   r  on_conflictnullsr  Nr  r.   r.   r.   r/   r    rf  r  c                   @  s   e Zd ZU i Zded< dS )UppercaseColumnConstraintr   r  N)r0   r1   r2   r  __annotations__r.   r.   r.   r/   r    s   
 r  c                   @  r  )WatermarkColumnConstraintTr2  Nr  r.   r.   r.   r/   r    r  r  c                   @  r  )PathColumnConstraintNr  r.   r.   r.   r/   r    r  r  c                   @  r  ) ProjectionPolicyColumnConstraintNr  r.   r.   r.   r/   r    r  r  c                   @  rH  )ComputedColumnConstraintTF)r4   	persistednot_nullNr  r.   r.   r.   r/   r    rK  r  c                   @  r  )
ConstraintTr=  Nr  r.   r.   r.   r/   r    r  r  c                	   @  sF   e Zd ZdddddddddZ		ddddZdddddddZdS )DeleteF)r  r4   r|  r  r!  r  tablesrC  NTr8   rO  r   r   r   rP   rO   c              	   K  s   t d|| d|t|d|S )a  
        Create a DELETE expression or replace the table on an existing DELETE expression.

        Example:
            >>> delete("tbl").sql()
            'DELETE FROM tbl'

        Args:
            table: the table from which to delete.
            dialect: the dialect used to parse the input expression.
            copy: if `False`, modify this expression instance in-place.
            opts: other options to use to parse the input expressions.

        Returns:
            Delete: the modified expression.
        r4   )r?   r  r   r   r  r   Nr.   r  Table)rL   r8   r   r   r   r.   r.   r/   r    s   zDelete.deleter  rl   r  r   c             	   O     t || d|t||d|S )a>  
        Append to or set the WHERE expressions.

        Example:
            >>> delete("tbl").where("x = 'a' OR x < 'b'").sql()
            "DELETE FROM tbl WHERE x = 'a' OR x < 'b'"

        Args:
            *expressions: the SQL code strings to parse.
                If an `Expression` instance is passed, it will be used as-is.
                Multiple expressions are combined with an AND operator.
            append: if `True`, AND the new expressions to any existing expression.
                Otherwise, this resets the expression.
            dialect: the dialect used to parse the input expressions.
            copy: if `False`, modify this expression instance in-place.
            opts: other options to use to parse the input expressions.

        Returns:
            Delete: the modified expression.
        r  r  r  r  r.   r.   r/   r  )     zDelete.wherer  )r8   rO  r   r   r   rP   rO   r  )
rl   r  r   rP   r   r   r   rP   rO   r  )r0   r1   r2   r  r  r  r.   r.   r.   r/   r    s"    $r  c                   @  s6   e Zd ZddddddddddddZedddZdS )	DropF)r4   r%  rl   r  	temporaryr  cascader  purgerC  r-  rO   r/  c                 C  r0  r1  r2  r4  r.   r.   r/   r%  `  r5  z	Drop.kindNr6  r7  r.   r.   r.   r/   r  Q  s    r  c                   @     e Zd ZddddZdS )ExportTF)r4   
connectionr  Nr  r.   r.   r.   r/   r	  g  rK  r	  c                   @  r  )FilterTr2  Nr  r.   r.   r.   r/   r  k  r  r  c                   @  r  )CheckNr  r.   r.   r.   r/   r  o  r  r  c                   @  rH  )ChangesTF)information	at_beforer=   Nr  r.   r.   r.   r/   r  s  rK  r  c                   @  r  )ConnectFT)r<   connectnocycleNr  r.   r.   r.   r/   r  x  rK  r  c                   @  rH  )CopyParameterTFr4   r?   rl   Nr  r.   r.   r.   r/   r  |  rK  r  c                   @  s   e Zd ZdddddddZdS )CopyTF)r4   r%  filescredentialsrO  paramsNr  r.   r.   r.   r/   r    rP  r  c                   @  rb  )CredentialsF)r  
encryptionstorageiam_roleregionNr  r.   r.   r.   r/   r    rf  r  c                   @  r  )PriorNr  r.   r.   r.   r/   r    r  r  c                   @  rH  )	DirectoryTF)r4   local
row_formatNr  r.   r.   r.   r/   r    s    r  c                   @  rb  )
ForeignKeyF)rl   	referencer  r+  r  Nr  r.   r.   r.   r/   r"    rf  r"  c                   @  r  )ColumnPrefixTr2  Nr  r.   r.   r.   r/   r$    r  r$  c                   @  r  )
PrimaryKeyTF)rl   r  Nr  r.   r.   r.   r/   r%    r  r%  c                   @  rb  )IntoF)r4   r  unloggedbulk_collectrl   Nr  r.   r.   r.   r/   r&    rf  r&  c                   @  s(   e Zd ZedddZedddZdS )	FromrO   rm   c                 C     | j jS rI   r4   rt   rb   r.   r.   r/   rt        z	From.namec                 C  r*  rI   r4   r   rb   r.   r.   r/   r     r,  zFrom.alias_or_nameNr  )r0   r1   r2   r  rt   r   r.   r.   r.   r/   r)    r  r)  c                   @  r  )HavingNr  r.   r.   r.   r/   r.    r  r.  c                   @  rW  )Hintrl   TNr  r.   r.   r.   r/   r/    rY  r/  c                   @  r  )JoinHintTr=  Nr  r.   r.   r.   r/   r0    r  r0  c                   @  sD   e Zd ZdddddZedddZedd	d
ZedddZdS )ro   TF)r4   r.  re  r  rO   rP   c                 C  r  )Nr.  r  rb   r.   r.   r/   r.    r  zIdentifier.quotedrH   c                 C  s   | j | jfS rI   r4   r.  rb   r.   r.   r/   rc     r   zIdentifier.hashable_argsrm   c                 C  r   rI   r   rb   r.   r.   r/   r     r   zIdentifier.output_nameNr  r  r  )r0   r1   r2   r  r  r.  rc   r   r.   r.   r.   r/   ro     s    ro   c                   @  r  )OpclassTr2  Nr  r.   r.   r.   r/   r2    r  r2  c                   @     e Zd ZdddddddZdS )IndexF)r4   r8   r(  primaryampr  Nr  r.   r.   r.   r/   r4    rP  r4  c                	   @  "   e Zd ZdddddddddZdS )IndexParametersF)r|  includer   with_storagepartition_byr  r  onNr  r.   r.   r.   r/   r8    rG  r8  c                   @  s   e Zd Zi ddddddddddddddd	dd
dddddddddddddddddZ					d#d$d!d"ZdS )%InserthintFr  is_functionr4   r?   conflictr!  r   r  alternativer  ignoreby_namestoredrF  settingssourceNTr   rO  r1  r  r/  r  r   rP   r   r   r   rO   c           	      K      t | ||f|||||d|S )aO  
        Append to or set the common table expressions.

        Example:
            >>> insert("SELECT x FROM cte", "t").with_("cte", as_="SELECT * FROM tbl").sql()
            'WITH cte AS (SELECT * FROM tbl) INSERT INTO t SELECT x FROM cte'

        Args:
            alias: the SQL code string to parse as the table name.
                If an `Expression` instance is passed, this is used as-is.
            as_: the SQL code string to parse as the table expression.
                If an `Expression` instance is passed, it will be used as-is.
            recursive: set the RECURSIVE part of the expression. Defaults to `False`.
            materialized: set the MATERIALIZED part of the expression.
            append: if `True`, add to any existing expressions.
                Otherwise, this resets the expressions.
            dialect: the dialect used to parse the input expression.
            copy: if `False`, modify this expression instance in-place.
            opts: other options to use to parse the input expressions.

        Returns:
            The modified expression.
        r  r  r   r   r   r  	rL   r   r1  r  r  r   r   r   r   r.   r.   r/   r  	     "	zInsert.with_NNTNT)r   rO  r1  rO  r  r/  r  r/  r   rP   r   r   r   rP   rO   r=  )r0   r1   r2   r  r  r.   r.   r.   r/   r=    sT    	
r=  c                   @  rH  )ConditionalInsertTF)r4   r?   else_Nr  r.   r.   r.   r/   rL  C	  rK  rL  c                   @  r]  )MultitableInsertsT)rl   r%  rF  Nr  r.   r.   r.   r/   rN  G	  rK  rN  c                   @  r3  )
OnConflictF)	duplicaterl   actionconflict_keys
constraintr  Nr  r.   r.   r.   r/   rO  K	  rP  rO  c                   @  r]  )OnConditionF)erroremptynullNr  r.   r.   r.   r/   rT  V	  rK  rT  c                   @  r  )r#  TF)rl   r  Nr  r.   r.   r.   r/   r#  Z	  r  r#  c                   @  r  )
IntroducerTr2  Nr  r.   r.   r.   r/   rX  _	  r  rX  c                   @  r  )NationalNr  r.   r.   r.   r/   rY  d	  r  rY  c                   @  s    e Zd ZddddddddZdS )LoadDataTF)r4   r   r   inpathrF  input_formatr  Nr  r.   r.   r.   r/   rZ  h	  r?  rZ  c                   @  r  )	PartitionTF)rl   subpartitionNr  r.   r.   r.   r/   r]  t	  r  r]  c                   @  r  )PartitionRangeTr2  Nr  r.   r.   r.   r/   r_  x	  r  r_  c                   @  r  )PartitionIdNr  r.   r.   r.   r/   r`  }	  r  r`  c                   @  r]  )FetchF)	directioncountlimit_optionsNr  r.   r.   r.   r/   ra  	  
    
ra  c                   @  s   e Zd ZddddddZdS )GrantTF)ru  r%  	securable
principalsgrant_optionNr  r.   r.   r.   r/   rf  	  rf  rf  c                   @  r3  )GroupF)rl   grouping_setscuberolluptotalsallNr  r.   r.   r.   r/   rj  	  rP  rj  c                   @  rW  )Cuberl   FNr  r.   r.   r.   r/   rp  	  rY  rp  c                   @  rW  )Rolluprl   FNr  r.   r.   r.   r/   rq  	  rY  rq  c                   @  rW  )GroupingSetsrl   TNr  r.   r.   r.   r/   rr  	  rY  rr  c                   @  rZ  )LambdaTF)r4   rl   colonNr  r.   r.   r.   r/   rs  	  rK  rs  c                   @  s   e Zd ZddddddZdS )r  FT)r4   r?   r  rd  rl   Nr  r.   r.   r.   r/   r  	  rf  r  c                   @  r]  )LimitOptionsF)percentrows	with_tiesNr  r.   r.   r.   r/   ru  	  re  ru  c                   @  sX   e Zd ZdddZedddZedddZedd	d
ZedddZ	dddZ
dS )rp   Tr4   rw   rO   rH   c                 C  s   | j | jdfS )Nrw   )r4   r@   rh   rb   r.   r.   r/   rc   	     zLiteral.hashable_argsc                 C     | t |ddS )NFry  rm   )r'   numberr.   r.   r/   r}  	  r  zLiteral.numberc                 C  r{  )NTry  r|  )r'   stringr.   r.   r/   r~  	  r  zLiteral.stringrm   c                 C  r   rI   r   rb   r.   r.   r/   r   	  r   zLiteral.output_nameint | str | Decimalc                 C  s6   | j rzt| jW S  ty   t| j Y S w | jS rI   )rz   rd   r4   r{   r   rb   r.   r.   r/   r|   	  s   zLiteral.to_pyNr  )rO   rp   r  )rO   r  )r0   r1   r2   r  r  rc   r  r}  r~  r   r|   r.   r.   r.   r/   rp   	  s    
rp   c                   @  s   e Zd ZddddddddddddZedddZeddd	Zedd
dZedddZedddZ	ed ddZ
ddddd!ddZddddd!ddZdS )"JoinTF)r4   r<  sider%  r|  methodre  r>  match_conditionrl   pivotsrO   rm   c                 C     |  d S )Nr  rv   r3  rb   r.   r.   r/   r  	     zJoin.methodc                 C  r  r1  r  rb   r.   r.   r/   r%  	  r  z	Join.kindc                 C  r  Nr  r  rb   r.   r.   r/   r  	  r  z	Join.sidec                 C  r  )Nr>  r  rb   r.   r.   r/   r>  	  r  z	Join.hintc                 C  r*  rI   r-  rb   r.   r.   r/   r   	  r,  zJoin.alias_or_namerP   c                 C  s
   | j dv S )N)SEMIANTI)r%  rb   r.   r.   r/   is_semi_or_anti_join	  r   zJoin.is_semi_or_anti_joinNr  rl   r  r   r   r   r   c                O  4   t || d|||d|}|jdkr|dd |S )aG  
        Append to or set the ON expressions.

        Example:
            >>> import sqlglot
            >>> sqlglot.parse_one("JOIN x", into=Join).on("y = 1").sql()
            'JOIN x ON y = 1'

        Args:
            *expressions: the SQL code strings to parse.
                If an `Expression` instance is passed, it will be used as-is.
                Multiple expressions are combined with an AND operator.
            append: if `True`, AND the new expressions to any existing expression.
                Otherwise, this resets the expression.
            dialect: the dialect used to parse the input expressions.
            copy: if `False`, modify this expression instance in-place.
            opts: other options to use to parse the input expressions.

        Returns:
            The modified Join expression.
        r<  r  r   r   r   r   CROSSr%  N)r  r%  r   rL   r   r   r   rl   r   r   r.   r.   r/   r<  
  s   

zJoin.onc                O  r  )a  
        Append to or set the USING expressions.

        Example:
            >>> import sqlglot
            >>> sqlglot.parse_one("JOIN x", into=Join).using("foo", "bla").sql()
            'JOIN x USING (foo, bla)'

        Args:
            *expressions: the SQL code strings to parse.
                If an `Expression` instance is passed, it will be used as-is.
            append: if `True`, concatenate the new expressions to the existing "using" list.
                Otherwise, this resets the expression.
            dialect: the dialect used to parse the input expressions.
            copy: if `False`, modify this expression instance in-place.
            opts: other options to use to parse the input expressions.

        Returns:
            The modified Join expression.
        r|  r  r  r%  N)_apply_list_builderr%  r   r  r.   r.   r/   r|  /
  s   

z
Join.usingr  r  )
rl   r  r   rP   r   r   r   rP   rO   r  )r0   r1   r2   r  r  r  r%  r  r>  r   r  r<  r|  r.   r.   r.   r/   r  	  sB    /r  c                   @  rL  )LateralTF)r4   viewouterr   cross_apply
ordinalityNr  r.   r.   r.   r/   r  [
  rP  r  c                   @  r  )TableFromRowsTF)r4   r   joinsr  sampleNr  r.   r.   r.   r/   r  h
  rf  r  c                   @  r  )MatchRecognizeMeasureTF)r4   window_frameNr  r.   r.   r.   r/   r  r
      
r  c                	   @  r7  )MatchRecognizeF)r;  r  measuresrw  afterpatterndefiner   Nr  r.   r.   r.   r/   r  y
  rG  r  c                   @  r  )FinalNr  r.   r.   r.   r/   r  
  r  r  c                   @  r  )r  FTr  Nr  r.   r.   r.   r/   r  
  rK  r  c                   @  r  )r  FT)r4   rl   siblingsNr  r.   r.   r.   r/   r  
  rK  r  c                   @     e Zd ZdddddZdS )WithFillF)rl  r  stepinterpolateNr  r.   r.   r.   r/   r  
  r  r  c                   @  r  )ClusterNr  r.   r.   r.   r/   r  
  r  r  c                   @  r  )
DistributeNr  r.   r.   r.   r/   r  
  r  r  c                   @  r  )SortNr  r.   r.   r.   r/   r  
  r  r  c                   @  s(   e Zd ZdddddZed	ddZdS )
rp  TF)r4   ru  ro  	with_fillrO   rm   c                 C  r*  rI   r+  rb   r.   r.   r/   rt   
  r,  zOrdered.nameNr  r0   r1   r2   r  r  rt   r.   r.   r.   r/   rp  
  s    rp  c                   @  r  )PropertyTr4   rM   Nr  r.   r.   r.   r/   r  
  r  r  c                   @  r  )GrantPrivilegeTFr=  Nr  r.   r.   r.   r/   r  
  r  r  c                   @  r  )GrantPrincipalTFrU  Nr  r.   r.   r.   r/   r  
  r  r  c                   @  rW  )AllowedValuesPropertyrl   TNr  r.   r.   r.   r/   r  
  rY  r  c                   @  rW  )AlgorithmPropertyr4   TNr  r.   r.   r.   r/   r  
  rY  r  c                   @  rW  )AutoIncrementPropertyr4   TNr  r.   r.   r.   r/   r  
  rY  r  c                   @  rW  )AutoRefreshPropertyr4   TNr  r.   r.   r.   r/   r  
  rY  r  c                   @  rW  )BackupPropertyr4   TNr  r.   r.   r.   r/   r  
  rY  r  c                   @  rb  )BlockCompressionPropertyF)autotempalwaysr\  manualneverNr  r.   r.   r.   r/   r  
  rf  r  c                   @  r  )CharacterSetPropertyTry  Nr  r.   r.   r.   r/   r  
  r  r  c                   @  r  )ChecksumPropertyF)r<  r\  Nr  r.   r.   r.   r/   r  
  r  r  c                   @  r  )CollatePropertyTFry  Nr  r.   r.   r.   r/   r  
  r  r  c                   @  r  )CopyGrantsPropertyNr  r.   r.   r.   r/   r  
  r  r  c                   @  rb  )DataBlocksizePropertyF)sizeunitsminimummaximumr\  Nr  r.   r.   r.   r/   r  
  rf  r  c                   @  rH  )DataDeletionPropertyTF)r<  
filter_colretention_periodNr  r.   r.   r.   r/   r  
  rK  r  c                   @  rW  )DefinerPropertyr4   TNr  r.   r.   r.   r/   r  
  rY  r  c                   @  rW  )DistKeyPropertyr4   TNr  r.   r.   r.   r/   r    rY  r  c                   @  s   e Zd ZdddddZdS )DistributedByPropertyFT)rl   r%  bucketsr  Nr  r.   r.   r.   r/   r    r}  r  c                   @  rW  )DistStylePropertyr4   TNr  r.   r.   r.   r/   r    rY  r  c                   @  rW  )DuplicateKeyPropertyrl   TNr  r.   r.   r.   r/   r    rY  r  c                   @  rW  )EnginePropertyr4   TNr  r.   r.   r.   r/   r    rY  r  c                   @  r  )HeapPropertyNr  r.   r.   r.   r/   r    r  r  c                   @  rW  )ToTablePropertyr4   TNr  r.   r.   r.   r/   r    rY  r  c                   @  rW  )ExecuteAsPropertyr4   TNr  r.   r.   r.   r/   r    rY  r  c                   @  rW  )ExternalPropertyr4   FNr  r.   r.   r.   r/   r  #  rY  r  c                   @  r  )FallbackPropertyTF)no
protectionNr  r.   r.   r.   r/   r  '  r  r  c                   @  r]  )FileFormatPropertyF)r4   rl   hive_formatNr  r.   r.   r.   r/   r  ,  rK  r  c                   @  rW  )CredentialsPropertyrl   TNr  r.   r.   r.   r/   r  0  rY  r  c                   @  r  )FreespacePropertyTF)r4   rv  Nr  r.   r.   r.   r/   r  4  r  r  c                   @  r  )GlobalPropertyNr  r.   r.   r.   r/   r  8  r  r  c                   @  r  )IcebergPropertyNr  r.   r.   r.   r/   r  <  r  r  c                   @  rW  )InheritsPropertyrl   TNr  r.   r.   r.   r/   r  @  rY  r  c                   @  rW  )InputModelPropertyr4   TNr  r.   r.   r.   r/   r  D  rY  r  c                   @  rW  )OutputModelPropertyr4   TNr  r.   r.   r.   r/   r  H  rY  r  c                   @  r]  )IsolatedLoadingPropertyF)r  
concurrentrj  Nr  r.   r.   r.   r/   r  L  rK  r  c                   @  rb  )JournalPropertyF)r  dualbeforer   r  Nr  r.   r.   r.   r/   r  P  rf  r  c                   @  rW  )LanguagePropertyr4   TNr  r.   r.   r.   r/   r  Z  rY  r  c                   @  rW  )EnviromentPropertyrl   TNr  r.   r.   r.   r/   r  ^  rY  r  c                   @  r  )ClusteredByPropertyTF)rl   	sorted_byr  Nr  r.   r.   r.   r/   r  c  rK  r  c                   @  rZ  )DictPropertyTF)r4   r%  rE  Nr  r.   r.   r.   r/   r  g  rK  r  c                   @  r  )DictSubPropertyNr  r.   r.   r.   r/   r  k  r  r  c                   @  r]  )	DictRangeT)r4   minmaxNr  r.   r.   r.   r/   r  o  rK  r  c                   @  r  )DynamicPropertyNr  r.   r.   r.   r/   r  s  r  r  c                   @  rW  )	OnClusterr4   TNr  r.   r.   r.   r/   r  y  rY  r  c                   @  r  )EmptyPropertyNr  r.   r.   r.   r/   r  ~  r  r  c                   @  r  )LikePropertyTFr=  Nr  r.   r.   r.   r/   r    r  r  c                   @  rW  )LocationPropertyr4   TNr  r.   r.   r.   r/   r    rY  r  c                   @  rW  )LockPropertyr4   TNr  r.   r.   r.   r/   r    rY  r  c                   @  s   e Zd ZddddddZdS )LockingPropertyFT)r4   r%  	for_or_in	lock_typeoverrideNr  r.   r.   r.   r/   r    rf  r  c                   @  rW  )LogPropertyr  TNr  r.   r.   r.   r/   r    rY  r  c                   @  rW  )MaterializedPropertyr4   FNr  r.   r.   r.   r/   r    rY  r  c                   @  r  )MergeBlockRatioPropertyF)r4   r  r\  rv  Nr  r.   r.   r.   r/   r    r}  r  c                   @  r  )NoPrimaryIndexPropertyNr  r.   r.   r.   r/   r    r  r  c                   @  rW  )
OnPropertyr4   TNr  r.   r.   r.   r/   r    rY  r  c                   @  rW  )OnCommitPropertyr  FNr  r.   r.   r.   r/   r    rY  r  c                   @  rW  )PartitionedByPropertyr4   TNr  r.   r.   r.   r/   r    rY  r  c                   @  r  )PartitionedByBucketTr2  Nr  r.   r.   r.   r/   r    r  r  c                   @  r  )PartitionByTruncateTr2  Nr  r.   r.   r.   r/   r    r  r  c                   @  r  )PartitionByRangePropertyT)partition_expressionscreate_expressionsNr  r.   r.   r.   r/   r    r  r  c                   @  r  )PartitionByRangePropertyDynamicFT)r4   r<   r=   everyNr  r.   r.   r.   r/   r    r}  r  c                   @  rW  )UniqueKeyPropertyrl   TNr  r.   r.   r.   r/   r    rY  r  c                   @  r  )PartitionBoundSpecF)r4   r?   from_expressionsto_expressionsNr  r.   r.   r.   r/   r    s    
r  c                   @  r  )PartitionedOfPropertyTr2  Nr  r.   r.   r.   r/   r    s    r  c                   @  r  )StreamingTablePropertyNr  r.   r.   r.   r/   r    r  r  c                   @  rW  )!RemoteWithConnectionModelPropertyr4   TNr  r.   r.   r.   r/   r	    rY  r	  c                   @  r  )ReturnsPropertyF)r4   is_tabler8   rW  Nr  r.   r.   r.   r/   r
    r}  r
  c                   @  r  )StrictPropertyNr  r.   r.   r.   r/   r    r  r  c                   @  rW  )RowFormatPropertyr4   TNr  r.   r.   r.   r/   r    rY  r  c                   @  r8  )RowFormatDelimitedPropertyF)fieldsescapedcollection_itemsmap_keyslinesrW  r  Nr  r.   r.   r.   r/   r    s    
r  c                   @  r  )RowFormatSerdePropertyTF)r4   serde_propertiesNr  r.   r.   r.   r/   r    r  r  c                   @  s    e Zd ZddddddddZdS )QueryTransformTF)rl   command_scriptschemarow_format_beforerecord_writerrow_format_afterrecord_readerNr  r.   r.   r.   r/   r    r?  r  c                   @  rW  )SamplePropertyr4   TNr  r.   r.   r.   r/   r    rY  r  c                   @  rW  )SecurityPropertyr4   TNr  r.   r.   r.   r/   r    rY  r  c                   @  rW  )SchemaCommentPropertyr4   TNr  r.   r.   r.   r/   r    rY  r  c                   @  r  )SerdePropertiesTF)rl   r  Nr  r.   r.   r.   r/   r     r  r   c                   @  rW  )SetPropertymultiTNr  r.   r.   r.   r/   r!    rY  r!  c                   @  rW  )SharingPropertyr4   FNr  r.   r.   r.   r/   r#  "  rY  r#  c                   @  rW  )SetConfigPropertyr4   TNr  r.   r.   r.   r/   r$  &  rY  r$  c                   @  rW  )SettingsPropertyrl   TNr  r.   r.   r.   r/   r%  *  rY  r%  c                   @  r  )SortKeyPropertyTF)r4   r  Nr  r.   r.   r.   r/   r&  .  r  r&  c                   @  rW  )SqlReadWritePropertyr4   TNr  r.   r.   r.   r/   r'  2  rY  r'  c                   @  rW  )SqlSecurityPropertydefinerTNr  r.   r.   r.   r/   r(  6  rY  r(  c                   @  rW  )StabilityPropertyr4   TNr  r.   r.   r.   r/   r*  :  rY  r*  c                   @  rW  )StorageHandlerPropertyr4   TNr  r.   r.   r.   r/   r+  >  rY  r+  c                   @  rW  )TemporaryPropertyr4   FNr  r.   r.   r.   r/   r,  B  rY  r,  c                   @  r  )SecurePropertyNr  r.   r.   r.   r/   r-  F  r  r-  c                   @  rW  )Tagsrl   TNr  r.   r.   r.   r/   r.  K  rY  r.  c                   @  rW  )TransformModelPropertyrl   TNr  r.   r.   r.   r/   r/  O  rY  r/  c                   @  rW  )TransientPropertyr4   FNr  r.   r.   r.   r/   r0  S  rY  r0  c                   @  r  )UnloggedPropertyNr  r.   r.   r.   r/   r1  W  r  r1  c                   @  rW  )UsingTemplatePropertyr4   TNr  r.   r.   r.   r/   r2  \  rY  r2  c                   @  rW  )ViewAttributePropertyr4   TNr  r.   r.   r.   r/   r3  a  rY  r3  c                   @  rW  )VolatilePropertyr4   FNr  r.   r.   r.   r/   r4  e  rY  r4  c                   @  r  )WithDataPropertyTF)r  
statisticsNr  r.   r.   r.   r/   r5  i  r  r5  c                   @  rW  )WithJournalTablePropertyr4   TNr  r.   r.   r.   r/   r7  m  rY  r7  c                   @  rW  )WithSchemaBindingPropertyr4   TNr  r.   r.   r.   r/   r8  q  rY  r8  c                   @  s   e Zd ZddddddZdS )WithSystemVersioningPropertyFT)r<  r4   data_consistencyr  r  Nr  r.   r.   r.   r/   r9  u  rf  r9  c                   @  rW  )WithProcedureOptionsrl   TNr  r.   r.   r.   r/   r;    rY  r;  c                   @  rH  )EncodePropertyTF)r4   r&  r%   Nr  r.   r.   r.   r/   r<    rK  r<  c                   @  rH  )IncludePropertyTF)r4   r   
column_defNr  r.   r.   r.   r/   r=    rK  r=  c                   @  r  )ForcePropertyNr  r.   r.   r.   r/   r?    r  r?  c                   @  s   e Zd ZddiZi dededededede	d	e
d
edededededededededeeeeeeedZdd e D ZG dd deZe dddZ!dS ) 
Propertiesrl   T	ALGORITHMAUTO_INCREMENTzCHARACTER SETCLUSTERED_BYCOLLATECOMMENTCREDENTIALSDEFINERDISTKEYDISTRIBUTED_BY	DISTSTYLEENGINEz
EXECUTE ASFORMATLANGUAGELOCATIONLOCK)PARTITIONED_BYRETURNS
ROW_FORMATSORTKEYENCODEINCLUDEc                 C     i | ]\}}||qS r.   r.   r^   r.   r.   r/   r)        zProperties.<dictcomp>c                   @  s<   e Zd Ze Ze Ze Ze Ze Ze Z	e Z
e ZdS )zProperties.LocationN)r0   r1   r2   r   POST_CREATE	POST_NAMEPOST_SCHEMA	POST_WITH
POST_ALIASPOST_EXPRESSION
POST_INDEXUNSUPPORTEDr.   r.   r.   r/   Location  s    
r`  properties_dictt.DictrO   c                 C  sf   g }|  D ]'\}}| j| }|r||t|d q|tt|t|d q| |dS )Nr  r  rR  )	rJ   NAME_TO_PROPERTYrh   r3  r   r3  r  rp   r~  )r'   ra  rl   r%   rM   property_clsr.   r.   r/   	from_dict  s   
zProperties.from_dictN)ra  rb  rO   r@  )"r0   r1   r2   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r
  r  r&  r<  r=  rc  rJ   PROPERTY_TO_NAMEr   r`  r  re  r.   r.   r.   r/   r@    s`    	

r@  c                   @  r  )QualifyNr  r.   r.   r.   r/   rg    r  rg  c                   @  r  )InputOutputFormatF)r\  output_formatNr  r.   r.   r.   r/   rh    r  rh  c                   @  r  )ReturnNr  r.   r.   r.   r/   rj    r  rj  c                   @  rH  )	ReferenceTF)r4   rl   r  Nr  r.   r.   r.   r/   rk    rK  rk  c                   @  s(   e Zd ZddiZdddddddZdS )Tuplerl   FNTrD  rH   rE  r  r   rF  r   rP   rO   rG  c                  sb   t t|   fdd|D |rt|fd ind |r-t fddt|D ddS d dS )Nc                   rH  rI  r9  r:  r   r.   r/   r     r<  zTuple.isin.<locals>.<listcomp>r   c                   rJ  r   rK  r:  rP  r.   r/   r     rQ  rR  rS  )rG  rU  rL  rV  r   )rL   rE  r   r   rl   r   r.   rP  r/   rW    s   z
Tuple.isinr  )r0   r1   r2   r  rW  r.   r.   r.   r/   rl    s    rl  matchFlateralsr  r  r  prewherer  r  havingqualifywindows
distributesortrC  r  r  r  )locksr  rE  rO  r  c                   @  r  )QueryOptionTFr2  Nr  r.   r.   r.   r/   rv    r  rv  c                   @  rW  )WithTableHintrl   TNr  r.   r.   r.   r/   rw     rY  rw  c                   @  rH  )IndexTableHintTF)r4   rl   rj  Nr  r.   r.   r.   r/   rx  %  rK  rx  c                   @  r]  )HistoricalDataTr4   r%  r?   Nr  r.   r.   r.   r/   ry  *  rK  ry  c                   @  rZ  )PutTFr4   rj  r&  Nr  r.   r.   r.   r/   r{  /  rK  r{  c                   @  rZ  )GetTFr|  Nr  r.   r.   r.   r/   r}  4  rK  r}  c                   @  s   e Zd Zi ddddddddddddddd	dd
ddddddddddddddddddddZed+ddZed+ddZed+ddZed,ddZed-d d!Z	ed,d"d#Z
d.d/d(d)Zd*S )0r  r4   Fr   r5   r6   rn  r  r  hintssystem_timeversionrO  r  r  whenrB  rF  changes)	rows_fromr  rO   rm   c                 C  s   | j r	t| j trdS | j jS r    )r4   rn   r  rt   rb   r.   r.   r/   rt   O  s   z
Table.namec                 C  r   r  r   rb   r.   r.   r/   r5   U  r   zTable.dbc                 C  r   r  r   rb   r.   r.   r/   r6   Y  r   zTable.catalogr  c                 C     g S rI   r.   rb   r.   r.   r/   r  ]     zTable.selectsr   c                 C  r  rI   r.   rb   r.   r.   r/   r  a  r  zTable.named_selectsc                 C  sL   g }dD ]}| j |}t|tr||  qt|tr#|| q|S )z8Return the parts of a table in order catalog, db, table.)r6   r5   r4   )r@   rh   rn   r  extendr   r>   r   )rL   r  r   r  r.   r.   r/   r  e  s   


zTable.partsTr   rP   r>   c                 C  sf   | j }|d }t|trtt|dd |dd  |d}n|}| jd}|r1t||j|d}|S )Nr   r      )r  r   r   r   )	r  rn   ro   columnr   r@   rh   r0  r4   )rL   r   r  	last_partr;   r   r.   r.   r/   	to_columnt  s   
&zTable.to_columnNr  r  r  r  )r   rP   rO   r>   )r0   r1   r2   r  r  rt   r5   r6   r  r  r  r  r.   r.   r.   r/   r  8  sh    	
r  c                	   @  s   e Zd ZdddddddddeZddddd$ddZed%ddZed&ddZed'ddZ	ed(ddZ
ed(ddZed)d d!Zed)d"d#ZdS )*r   FT)r  r4   r?   r  rC  r  r%  r<  Nr  rL   r   rl   r  r   rP   r   r   r   rO   c                O  sJ   t | |}|j j|||dd| |j j|||dd| |S NFr  )rU  r4   r   r  r?   rL   r   r   r   rl   r   r4   r.   r.   r/   r    s   

zSetOperation.selectr   c                 C     | j  jS rI   )r4   r   r  rb   r.   r.   r/   r    r   zSetOperation.named_selectsc                 C  s   | j jp| jjS rI   )r4   r   r?   rb   r.   r.   r/   r     r  zSetOperation.is_starr  c                 C  r  rI   )r4   r   r  rb   r.   r.   r/   r    r   zSetOperation.selectsr   c                 C  r   rI   r  rb   r.   r.   r/   left  r   zSetOperation.leftc                 C  r   rI   r?   rb   r.   r.   r/   right  r   zSetOperation.rightrm   c                 C  r  r1  r  rb   r.   r.   r/   r%    r  zSetOperation.kindc                 C  r  r  r  rb   r.   r.   r/   r    r  zSetOperation.side)rL   r   rl   r  r   rP   r   r   r   rP   rO   r   r  r  r  )rO   r   r  )r0   r1   r2   QUERY_MODIFIERSr  r  r  r  r   r  r  r  r%  r  r.   r.   r.   r/   r     s<    	c                   @  r  )r   Nr  r.   r.   r.   r/   r     r  r   c                   @  r  )r  Nr  r.   r.   r.   r/   r    r  r  c                   @  r  )r  Nr  r.   r.   r.   r/   r    r  r  c                	   @  s   e Zd ZdddddddddZ	d d!ddZddddd"ddZddddd#ddZ			d$d%ddZ					d&d'ddZdS )(UpdateFT)r  r4   rl   rl  r  r!  r  r  Nr?   rO  r   r   r   rP   rO   c              
   K  s   t d|| dtd||d|S )a  
        Set the table to update.

        Example:
            >>> Update().table("my_table").set_("x = 1").sql()
            'UPDATE my_table SET x = 1'

        Args:
            expression : the SQL code strings to parse.
                If a `Table` instance is passed, this is used as-is.
                If another `Expression` instance is passed, it will be wrapped in a `Table`.
            dialect: the dialect used to parse the input expression.
            copy: if `False`, modify this expression instance in-place.
            opts: other options to use to parse the input expressions.

        Returns:
            The modified Update expression.
        r4   Nr?   r  r   r  r  r   r   r.   r   r  r.   r.   r/   r8        zUpdate.tabler  rl   r   c             
   O     t || d|td||d|S )a  
        Append to or set the SET expressions.

        Example:
            >>> Update().table("my_table").set_("x = 1").sql()
            'UPDATE my_table SET x = 1'

        Args:
            *expressions: the SQL code strings to parse.
                If `Expression` instance(s) are passed, they will be used as-is.
                Multiple expressions are combined with a comma.
            append: if `True`, add the new expressions to any existing SET expressions.
                Otherwise, this resets the expressions.
            dialect: the dialect used to parse the input expressions.
            copy: if `False`, modify this expression instance in-place.
            opts: other options to use to parse the input expressions.
        rl   Nr  r   r   r  r  r   r   r  r>   r  r.   r.   r/   set_  s   	zUpdate.set_r  r   c             	   O  r  )aY  
        Append to or set the WHERE expressions.

        Example:
            >>> Update().table("tbl").set_("x = 1").where("x = 'a' OR x < 'b'").sql()
            "UPDATE tbl SET x = 1 WHERE x = 'a' OR x < 'b'"

        Args:
            *expressions: the SQL code strings to parse.
                If an `Expression` instance is passed, it will be used as-is.
                Multiple expressions are combined with an AND operator.
            append: if `True`, AND the new expressions to any existing expression.
                Otherwise, this resets the expression.
            dialect: the dialect used to parse the input expressions.
            copy: if `False`, modify this expression instance in-place.
            opts: other options to use to parse the input expressions.

        Returns:
            Select: the modified expression.
        r  r  r  r  r.   r.   r/   r    r  zUpdate.wherec              
   K  s,   |st | |S td|| dtd||d|S )a  
        Set the FROM expression.

        Example:
            >>> Update().table("my_table").set_("x = 1").from_("baz").sql()
            'UPDATE my_table SET x = 1 FROM baz'

        Args:
            expression : the SQL code strings to parse.
                If a `From` instance is passed, this is used as-is.
                If another `Expression` instance is passed, it will be wrapped in a `From`.
                If nothing is passed in then a from is not applied to the expression
            dialect: the dialect used to parse the input expression.
            copy: if `False`, modify this expression instance in-place.
            opts: other options to use to parse the input expressions.

        Returns:
            The modified Update expression.
        rl  FROMr  Nr.   )rU  r  r)  r  r.   r.   r/   from_B  s   
zUpdate.from_r   r1  r  r/  r  c           	      K  rG  )ae  
        Append to or set the common table expressions.

        Example:
            >>> Update().table("my_table").set_("x = 1").from_("baz").with_("baz", "SELECT id FROM foo").sql()
            'WITH baz AS (SELECT id FROM foo) UPDATE my_table SET x = 1 FROM baz'

        Args:
            alias: the SQL code string to parse as the table name.
                If an `Expression` instance is passed, this is used as-is.
            as_: the SQL code string to parse as the table expression.
                If an `Expression` instance is passed, it will be used as-is.
            recursive: set the RECURSIVE part of the expression. Defaults to `False`.
            materialized: set the MATERIALIZED part of the expression.
            append: if `True`, add to any existing expressions.
                Otherwise, this resets the expressions.
            dialect: the dialect used to parse the input expression.
            copy: if `False`, modify this expression instance in-place.
            opts: other options to use to parse the input expressions.

        Returns:
            The modified expression.
        rH  r  rI  r.   r.   r/   r  j  rJ  zUpdate.with_r  )r?   rO  r   r   r   rP   rO   r  )
rl   rO  r   rP   r   r   r   rP   rO   r  
rl   r  r   rP   r   r   r   rP   rO   r   r  )r?   r  r   r   r   rP   rO   r  rK  )r   rO  r1  rO  r  r/  r  r/  r   rP   r   r   r   rP   rO   r  )	r0   r1   r2   r  r8   r  r  r  r  r.   r.   r.   r/   r    s<    #(),r  c                   @  r  )ValuesTFrl   r   Nr  r.   r.   r.   r/   r    r  r  c                   @  r  )rq   Nr  r.   r.   r.   r/   rq     r  rq   c                   @  s   e Zd ZdZddddZdS )Versiona2  
    Time travel, iceberg, bigquery etc
    https://trino.io/docs/current/connector/iceberg.html?highlight=snapshot#using-snapshots
    https://www.databricks.com/blog/2019/02/04/introducing-delta-time-travel-for-large-scale-data-lakes.html
    https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax#for_system_time_as_of
    https://learn.microsoft.com/en-us/sql/relational-databases/tables/querying-data-in-a-system-versioned-temporal-table?view=sql-server-ver16
    this is either TIMESTAMP or VERSION
    kind is ("AS OF", "BETWEEN")
    TFrz  Nr0   r1   r2   r&   r  r.   r.   r.   r/   r    s    
r  c                   @  r  )SchemaFr=  Nr  r.   r.   r.   r/   r    r  r  c                   @  rH  )LockTF)r+  rl   waitNr  r.   r.   r.   r/   r    rK  r  c                	   @  sZ  e Zd ZdddddddddeZ	dEdFddZdddddGddZdddddGddZdddddGddZdddddGddZ	dddddGddZ
							dHdId#d$ZdddddGd%d&ZdddddGd'd(ZdddddGd)d*Zddd+dJd.d/Z			dKdLd4d5ZdMdNd7d8Zddd9dOd;d<ZedPd>d?ZedQd@dAZedRdCdDZdS )Sr   F)r  r%  rl   r>  r  r  rl  operation_modifiersNTr?   rO  r   r   r   rP   rO   c              
   K  s   t d|| dtd||d|S )a  
        Set the FROM expression.

        Example:
            >>> Select().from_("tbl").select("x").sql()
            'SELECT x FROM tbl'

        Args:
            expression : the SQL code strings to parse.
                If a `From` instance is passed, this is used as-is.
                If another `Expression` instance is passed, it will be wrapped in a `From`.
            dialect: the dialect used to parse the input expression.
            copy: if `False`, modify this expression instance in-place.
            opts: other options to use to parse the input expressions.

        Returns:
            The modified Select expression.
        rl  r  r  Nr.   )r  r)  r  r.   r.   r/   r    r  zSelect.from_r  rl   r  r   c             
   O  s2   |s
|s| S |   S t|| d||dt|d|S )a  
        Set the GROUP BY expression.

        Example:
            >>> Select().from_("tbl").select("x", "COUNT(1)").group_by("x").sql()
            'SELECT x, COUNT(1) FROM tbl GROUP BY x'

        Args:
            *expressions: the SQL code strings to parse.
                If a `Group` instance is passed, this is used as-is.
                If another `Expression` instance is passed, it will be wrapped in a `Group`.
                If nothing is passed in then a group by is not applied to the expression
            append: if `True`, add to any existing expressions.
                Otherwise, this flattens all the `Group` expression into a single expression.
            dialect: the dialect used to parse the input expression.
            copy: if `False`, modify this expression instance in-place.
            opts: other options to use to parse the input expressions.

        Returns:
            The modified Select expression.
        r  zGROUP BYr  )r   r  rj  r  r.   r.   r/   group_by  s   	zSelect.group_byc             
   O  r  )a_  
        Set the SORT BY expression.

        Example:
            >>> Select().from_("tbl").select("x").sort_by("x DESC").sql(dialect="hive")
            'SELECT x FROM tbl SORT BY x DESC'

        Args:
            *expressions: the SQL code strings to parse.
                If a `Group` instance is passed, this is used as-is.
                If another `Expression` instance is passed, it will be wrapped in a `SORT`.
            append: if `True`, add to any existing expressions.
                Otherwise, this flattens all the `Order` expression into a single expression.
            dialect: the dialect used to parse the input expression.
            copy: if `False`, modify this expression instance in-place.
            opts: other options to use to parse the input expressions.

        Returns:
            The modified Select expression.
        rt  zSORT BYr  )r  r  r  r.   r.   r/   sort_by  r  zSelect.sort_byc             
   O  r  )ak  
        Set the CLUSTER BY expression.

        Example:
            >>> Select().from_("tbl").select("x").cluster_by("x DESC").sql(dialect="hive")
            'SELECT x FROM tbl CLUSTER BY x DESC'

        Args:
            *expressions: the SQL code strings to parse.
                If a `Group` instance is passed, this is used as-is.
                If another `Expression` instance is passed, it will be wrapped in a `Cluster`.
            append: if `True`, add to any existing expressions.
                Otherwise, this flattens all the `Order` expression into a single expression.
            dialect: the dialect used to parse the input expression.
            copy: if `False`, modify this expression instance in-place.
            opts: other options to use to parse the input expressions.

        Returns:
            The modified Select expression.
        rC  z
CLUSTER BYr  )r  r  r  r.   r.   r/   
cluster_by:  r  zSelect.cluster_byc             	   O  s   t || d||t|d|S )Nrl   )r  r   r   r   r  r   r  r  r.   r.   r/   r  b     zSelect.selectc             
   O  r  )a  
        Append to or set the LATERAL expressions.

        Example:
            >>> Select().select("x").lateral("OUTER explode(y) tbl2 AS z").from_("tbl").sql()
            'SELECT x FROM tbl LATERAL VIEW OUTER EXPLODE(y) tbl2 AS z'

        Args:
            *expressions: the SQL code strings to parse.
                If an `Expression` instance is passed, it will be used as-is.
            append: if `True`, add to any existing expressions.
                Otherwise, this resets the expressions.
            dialect: the dialect used to parse the input expressions.
            copy: if `False`, modify this expression instance in-place.
            opts: other options to use to parse the input expressions.

        Returns:
            The modified Select expression.
        rn  zLATERAL VIEWr  )r  r  r  r.   r.   r/   lateralu  s   	zSelect.lateralr<  r|  -t.Optional[ExpOrStr | t.Collection[ExpOrStr]]	join_typer/  
join_aliast.Optional[Identifier | str]c	                 K  s\  d|i|	}
zt |ftdd|
}W n ty(   t |fdttfi|
}Y nw t|tr0|nt|d}t|jtrD|j|j  |rnt |fddi|
\}}}|r\|	d|j
 |re|	d|j
 |rn|	d	|j
 |rtt|||d
|	}|	d| |rtt||d||td|	}|r|	dt|j|dd t|f| d||d|	S )a7  
        Append to or set the JOIN expressions.

        Example:
            >>> Select().select("*").from_("tbl").join("tbl2", on="tbl1.y = tbl2.y").sql()
            'SELECT * FROM tbl JOIN tbl2 ON tbl1.y = tbl2.y'

            >>> Select().select("1").from_("a").join("b", using=["x", "y", "z"]).sql()
            'SELECT 1 FROM a JOIN b USING (x, y, z)'

            Use `join_type` to change the type of join:

            >>> Select().select("*").from_("tbl").join("tbl2", on="tbl1.y = tbl2.y", join_type="left outer").sql()
            'SELECT * FROM tbl LEFT OUTER JOIN tbl2 ON tbl1.y = tbl2.y'

        Args:
            expression: the SQL code string to parse.
                If an `Expression` instance is passed, it will be used as-is.
            on: optionally specify the join "on" criteria as a SQL string.
                If an `Expression` instance is passed, it will be used as-is.
            using: optionally specify the join "using" criteria as a SQL string.
                If an `Expression` instance is passed, it will be used as-is.
            append: if `True`, add to any existing expressions.
                Otherwise, this resets the expressions.
            join_type: if set, alter the parsed join type.
            join_alias: an optional alias for the joined source.
            dialect: the dialect used to parse the input expressions.
            copy: if `False`, modify this expression instance in-place.
            opts: other options to use to parse the input expressions.

        Returns:
            Select: the modified expression.
        r   JOIN)r  r  r  r  	JOIN_TYPEr  r  r%  r   r   r<  r|  )r  r   r   r   r  r4   Tr8   r  )r  r   r   r   )rL  r  r   r>   rn   r4   r   r	  rT  r   rv   r  r   r  ro   r0  )rL   r?   r<  r|  r   r  r  r   r   r   
parse_argsr   r  r  r%  r.   r.   r/   r     sV   -
zSelect.joinc             	   O  r  )ay  
        Append to or set the HAVING expressions.

        Example:
            >>> Select().select("x", "COUNT(y)").from_("tbl").group_by("x").having("COUNT(y) > 3").sql()
            'SELECT x, COUNT(y) FROM tbl GROUP BY x HAVING COUNT(y) > 3'

        Args:
            *expressions: the SQL code strings to parse.
                If an `Expression` instance is passed, it will be used as-is.
                Multiple expressions are combined with an AND operator.
            append: if `True`, AND the new expressions to any existing expression.
                Otherwise, this resets the expression.
            dialect: the dialect used to parse the input expressions.
            copy: if `False`, modify this expression instance in-place.
            opts: other options to use to parse the input expressions.

        Returns:
            The modified Select expression.
        rp  r  )r  r.  r  r.   r.   r/   rp    r  zSelect.havingc             	   O  r  )Nrr  r  )r  Windowr  r.   r.   r/   window%  r  zSelect.windowc             	   O  r  )Nrq  r  )r  rg  r  r.   r.   r/   rq  8  r  zSelect.qualify)r  r   onsr  c                  sN   t |  }|rt fdd|D dnd}|d|r"t|d |S d |S )a  
        Set the OFFSET expression.

        Example:
            >>> Select().from_("tbl").select("x").distinct().sql()
            'SELECT DISTINCT x FROM tbl'

        Args:
            ons: the expressions to distinct on
            distinct: whether the Select should be distinct
            copy: if `False`, modify this expression instance in-place.

        Returns:
            Select: the modified expression.
        c                   s   g | ]
}|rt | d qS rI  rL  )rX   r<  r   r.   r/   r   ^  s    z#Select.distinct.<locals>.<listcomp>rR  Nr  )r<  )rU  rl  r   Distinct)rL   r  r   r  r  r<  r.   r   r/   r  K  s   
 zSelect.distinctr8   r&  t.Optional[t.Dict]r$  c           	      K  sB   t | |}t|ft|d|}d}|rt|}t|d||dS )a  
        Convert this expression to a CREATE TABLE AS statement.

        Example:
            >>> Select().select("*").from_("tbl").ctas("x").sql()
            'CREATE TABLE x AS SELECT * FROM tbl'

        Args:
            table: the SQL code string to parse as the table name.
                If another `Expression` instance is passed, it will be used as-is.
            properties: an optional mapping of table properties
            dialect: the dialect used to parse the input table.
            copy: if `False`, modify this expression instance in-place.
            opts: other options to use to parse the input table.

        Returns:
            The new Create expression.
        r  r   NTABLE)r4   r%  r?   r&  )rU  rL  r  r@  re  r$  )	rL   r8   r&  r   r   r   r  table_expressionproperties_expressionr.   r.   r/   ctasb  s   

zSelect.ctasr+  c                 C  s"   t | |}|dt|dg |S )ap  
        Set the locking read mode for this expression.

        Examples:
            >>> Select().select("x").from_("tbl").where("x = 'a'").lock().sql("mysql")
            "SELECT x FROM tbl WHERE x = 'a' FOR UPDATE"

            >>> Select().select("x").from_("tbl").where("x = 'a'").lock(update=False).sql("mysql")
            "SELECT x FROM tbl WHERE x = 'a' FOR SHARE"

        Args:
            update: if `True`, the locking type will be `FOR UPDATE`, else it will be `FOR SHARE`.
            copy: if `False`, modify this expression instance in-place.

        Returns:
            The modified expression.
        ru  )r+  )rU  r   r  )rL   r+  r   instr.   r.   r/   lock  s   
zSelect.lockr  r~  c                  s0   t |  }|dt fdd|D d |S )a(  
        Set hints for this expression.

        Examples:
            >>> Select().select("x").from_("tbl").hint("BROADCAST(y)").sql(dialect="spark")
            'SELECT /*+ BROADCAST(y) */ x FROM tbl'

        Args:
            hints: The SQL code strings to parse as the hints.
                If an `Expression` instance is passed, it will be used as-is.
            dialect: The dialect used to parse the hints.
            copy: If `False`, modify this expression instance in-place.

        Returns:
            The modified expression.
        r>  c                   s   g | ]	}t | d qS r   r   r  )rX   hr  r.   r/   r         zSelect.hint.<locals>.<listcomp>rR  )rU  r   r/  )rL   r   r   r~  r  r.   r  r/   r>    s
   
zSelect.hintr   c                 C  r  )Nc                 S  s   g | ]}|j r|jqS r.   )r   r   r:  r.   r.   r/   r     r<  z(Select.named_selects.<locals>.<listcomp>rR  rb   r.   r.   r/   r    r  zSelect.named_selectsc                 C  s   t dd | jD S )Nc                 s      | ]}|j V  qd S rI   )r   rX   r?   r.   r.   r/   rZ         z!Select.is_star.<locals>.<genexpr>)r   rl   rb   r.   r.   r/   r     s   zSelect.is_starr  c                 C  r   rI   rR  rb   r.   r.   r/   r    r   zSelect.selectsr  )r?   rO  r   r   r   rP   rO   r   r  )NNTNNNT)r?   rO  r<  r  r|  r  r   rP   r  r/  r  r  r   r   r   rP   rO   r   )r  r  r  rP   r   rP   rO   r   r  )
r8   rO  r&  r  r   r   r   rP   rO   r$  )TT)r+  rP   r   rP   rO   r   )r~  rO  r   r   r   rP   rO   r   r  r  r  )r0   r1   r2   r  r  r  r  r  r  r  r  r   rp  r  rq  r  r  r  r>  r  r  r   r  r.   r.   r.   r/   r     s    	#/++*e*(r   c                   @  sl   e Zd ZddddeZdd ZdddZdd	dd
dddZedddZ	edddZ
edddZd	S )r   TF)r4   r   r  c                 C  s"   | }t |tr|j}t |ts|S )zReturns the first non subquery.)rn   r   r4   r   r.   r.   r/   r     s
   

zSubquery.unnestrO   c                 C  s.   | }|j r|jrtt|j}|j r|js|S rI   )r   
is_wrapperrM  rN  r   rA   r   r.   r.   r/   unwrap  s
   zSubquery.unwrapNr  rl   r  r   rP   r   r   r   c                O  s*   t | |}| j|||dd| |S r  )rU  r   r  r  r.   r.   r/   r    s   
zSubquery.selectc                 C  rV   )z
        Whether this Subquery acts as a simple wrapper around another expression.

        SELECT * FROM (((SELECT * FROM t)))
                      ^
                      This corresponds to a "wrapper" Subquery node
        c                 s  s$    | ]\}}|d kr|du V  qdS )r4   Nr.   r^   r.   r.   r/   rZ     s   " z&Subquery.is_wrapper.<locals>.<genexpr>)ro  r@   rJ   rb   r.   r.   r/   r    s   	zSubquery.is_wrapperc                 C  r*  rI   )r4   r   rb   r.   r.   r/   r     r,  zSubquery.is_starrm   c                 C  r   rI   r   rb   r.   r.   r/   r     r   zSubquery.output_name)rO   r   )
rl   r  r   rP   r   r   r   rP   rO   r   r  r  )r0   r1   r2   r  r  r   r  r  r  r  r   r   r.   r.   r.   r/   r     s&    
	
r   c                
   @  r  )TableSampleF)	rl   r  bucket_numeratorbucket_denominatorbucket_fieldrv  rw  r  seedNr  r.   r.   r.   r/   r    r  r  c                   @     e Zd ZdZddddZdS )TagzFTags are used for generating arbitrary sql like SELECT <span>x</span>.F)r4   r  postfixNr  r.   r.   r.   r/   r    s    
r  c                   @  sD   e Zd ZddddddddddddZedddZeddd	Zd
S )PivotF)r4   r   rl   r  unpivotr|  r  r   include_nullsdefault_on_nullr  rO   rP   c                 C  r  )Nr  r  rb   r.   r.   r/   r  '  r  zPivot.unpivotr  c                 C  s   | j dg S )Nr  rg   rb   r.   r.   r/   r  +  r  zPivot.fieldsNr  r  )r0   r1   r2   r  r  r  r  r.   r.   r.   r/   r    s"    r  c                   @  r  )UnpivotColumnsTr=  Nr  r.   r.   r.   r/   r  2  r  r  c                   @  s    e Zd ZddddddddZdS )r  TF)r4   r;  r  specr   overfirstNr  r.   r.   r.   r/   r  6  r?  r  c                   @  r3  )
WindowSpecF)r%  r<   
start_sider=   end_sideexcludeNr  r.   r.   r.   r/   r  B  rP  r  c                   @  r  )PreWhereNr  r.   r.   r.   r/   r  M  r  r  c                   @  r  )r  Nr  r.   r.   r.   r/   r  Q  r  r  c                   @  s4   e Zd ZddddZed
ddZed
ddZd	S )rr   F)exceptr	  renamerO   rm   c                 C  r   )N*r.   rb   r.   r.   r/   rt   X  r  z	Star.namec                 C  r   rI   r   rb   r.   r.   r/   r   \  r   zStar.output_nameNr  )r0   r1   r2   r  r  rt   r   r.   r.   r.   r/   rr   U  s    rr   c                   @  r  )	ParameterTFr2  Nr  r.   r.   r.   r/   r  a  r  r  c                   @  r  )SessionParameterTFrU  Nr  r.   r.   r.   r/   r  e  r  r  c                   @  s&   e Zd ZddddZedddZdS )	PlaceholderF)r4   r%  widgetrO   rm   c                 C  s
   | j pdS )N?r  rb   r.   r.   r/   rt   m  r   zPlaceholder.nameNr  r  r.   r.   r.   r/   r  j  r  r  c                   @  s2   e Zd ZU i Zded< edddZddd	Zd
S )rs   r   r  rO   rm   c                 C  r   )NNULLr.   rb   r.   r.   r/   rt   u  r  z	Null.name	Lit[None]c                 C  r  rI   r.   rb   r.   r.   r/   r|   y  r
  z
Null.to_pyNr  )rO   r  )r0   r1   r2   r  r  r  rt   r|   r.   r.   r.   r/   rs   r  s
   
 rs   c                   @  s   e Zd ZdddZdS )BooleanrO   rP   c                 C  r   rI   r  rb   r.   r.   r/   r|   ~  s   zBoolean.to_pyNr  )r0   r1   r2   r|   r.   r.   r.   r/   r  }  r  r  c                   @  r  )
DataTypeParamTFr2  rO   rm   c                 C  r*  rI   r+  rb   r.   r.   r/   rt     r,  zDataTypeParam.nameNr  r  r.   r.   r.   r/   r    r  r  c                   @  s  e Zd ZddddddddZG dd deZejejejej	hZ
ejejhZh e
eejZejejejejejejhZejejejejejejejhZejej ej!ej"ej#ej$ej%hZ&h ee&ej'Z(ej)ej*hZ+h e+ej,ej-ej.ej/ej0ej1ej2ej3ej4ej5Z6h e(e6Z7ej8ej9ej:ej;ej<ej=ej>ej?ej@ejAejBejCejDejEejFhZGeH			ddddZIdddddZJdS )r   TF)r4   rl   nestedr   r  r%  nullablec                   @  s  e Zd Ze Ze Ze Ze Ze Ze Z	e Z
e Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Z e Z!e Z"e Z#e Z$e Z%e Z&e Z'e Z(e Z)e Z*e Z+e Z,e Z-e Z.e Z/e Z0e Z1e Z2e Z3e Z4e Z5e Z6e Z7e Z8e Z9e Z:e Z;e Z<e Z=e Z>e Z?e Z@e ZAe ZBe ZCe ZDe ZEe ZFe ZGe ZHe ZIe ZJe ZKe ZLe ZMe ZNe ZOe ZPe ZQe ZRe ZSe ZTe ZUe ZVe ZWe ZXe ZYe ZZe Z[e Z\e Z]e Z^e Z_e Z`e Zae Zbe Zce Zde Zee Zfe Zge Zhe Zie Zje Zke Zle Zme Zne Zoe Zpe Zqe ZrdZse Zte Zue Zve Zwe Zxe Zye Zze Z{e Z|e Z}dS )zDataType.TypezUSER-DEFINEDN)~r0   r1   r2   r   ARRAYAGGREGATEFUNCTIONSIMPLEAGGREGATEFUNCTION
BIGDECIMALBIGINT	BIGSERIALBINARYBITBLOBBOOLEANBPCHARCHARDATEDATE32DATEMULTIRANGE	DATERANGEDATETIME	DATETIME2
DATETIME64DECIMAL	DECIMAL32	DECIMAL64
DECIMAL128
DECIMAL256DOUBLEDYNAMICENUMENUM8ENUM16FIXEDSTRINGFLOAT	GEOGRAPHYGEOMETRYPOINTRING
LINESTRINGMULTILINESTRINGPOLYGONMULTIPOLYGON	HLLSKETCHHSTOREIMAGEINETINTINT128INT256INT4MULTIRANGE	INT4RANGEINT8MULTIRANGE	INT8RANGEINTERVAL	IPADDRESSIPPREFIXIPV4IPV6JSONJSONBLISTLONGBLOBLONGTEXTLOWCARDINALITYMAP
MEDIUMBLOB	MEDIUMINT
MEDIUMTEXTMONEYNAMENCHARNESTEDNOTHINGr  NUMMULTIRANGENUMRANGENVARCHAROBJECTRANGE
ROWVERSIONSERIALSETSMALLDATETIMESMALLINT
SMALLMONEYSMALLSERIALSTRUCTSUPERTEXTTINYBLOBTINYTEXTTIMETIMETZ	TIMESTAMPTIMESTAMPNTZTIMESTAMPLTZTIMESTAMPTZTIMESTAMP_STIMESTAMP_MSTIMESTAMP_NSTINYINTTSMULTIRANGETSRANGETSTZMULTIRANGE	TSTZRANGEUBIGINTUINTUINT128UINT256
UMEDIUMINTUDECIMALUDOUBLEUNIONUNKNOWNUSERDEFINED	USMALLINTUTINYINTUUID	VARBINARYVARCHARVARIANTVECTORXMLYEARTDIGESTr.   r.   r.   r/   Type  s    
re  Nr   	DATA_TYPEr   r   udtrP   r   rO   c                 K  s  ddl m} t|tr@| dkrtddtjji|S z|||ttj	d}W nM t
y?   |r>tdtjj|d| Y S  w t|ttfrU|rUtdtjj|d|S t|tjrat|d}nt|trkt||S tdt| d	tdi i |j|S )a  
        Constructs a DataType object.

        Args:
            dtype: the data type of interest.
            dialect: the dialect to use for parsing `dtype`, in case it's a string.
            udt: when set to True, `dtype` will be used as-is if it can't be parsed into a
                DataType, thus creating a user-defined type.
            copy: whether to copy the data type.
            kwargs: additional arguments to pass in the constructor of DataType.

        Returns:
            The constructed DataType object.
        r   )	parse_onerY  r4   )readr  error_levelrU  r  zInvalid data type: z. Expected str or DataType.TypeNr.   )sqlglotrh  rn   rm   r3  r   re  rY  r
   IGNOREr   rZ  ro   r  rU  r{   rQ   r@   )r'   r   r   rg  r   r  rh  data_type_expr.   r.   r/   r   r  s*   




zDataType.build)check_nullabler   rn  c                G  s   | j d}|D ]7}tj|ddd}|j d}|js/|r!|s/|s/| jtjjks/|jtjjkr4| |k}n| j|jk}|r? dS qdS )aM  
        Checks whether this DataType matches one of the provided data types. Nested types or precision
        will be compared using "structural equivalence" semantics, so e.g. array<int> != array<float>.

        Args:
            dtypes: the data types to compare this DataType to.
            check_nullable: whether to take the NULLABLE type constructor into account for the comparison.
                If false, it means that NULLABLE<INT> is equivalent to INT.

        Returns:
            True, if and only if there is a type in `dtypes` which is equal to this DataType.
        r  FT)r   rg  )r@   rh   r   r   rl   r4   re  rZ  )rL   rn  r   self_is_nullabler   
other_typeother_is_nullablematchesr.   r.   r/   r     s(   
zDataType.is_type)NFT)
r   rf  r   r   rg  rP   r   rP   rO   r   )r   rf  rn  rP   rO   rP   )Kr0   r1   r2   r  r   re  r0  r5  r>  rX  STRUCT_TYPESr  r%  ARRAY_TYPESr)  NESTED_TYPESr  r/  r4  r@  r_  r.  
TEXT_TYPESr  r  r  r  r+  r;  rL  SIGNED_INTEGER_TYPESrQ  rR  rS  rT  rU  r[  r\  UNSIGNED_INTEGER_TYPESr  INTEGER_TYPESr  r
  FLOAT_TYPESr  r  r   r  r  r  r-  r<  rV  rW  
REAL_TYPESNUMERIC_TYPESr  r  r  r  r  r:  rC  rE  rF  rG  rH  rJ  rK  rI  rD  TEMPORAL_TYPESr  r   r   r.   r.   r.   r/   r     s    
}

	
/r   c                   @  rW  )
PseudoTyper4   TNr  r.   r.   r.   r/   r~    rY  r~  c                   @  rW  )ObjectIdentifierr4   TNr  r.   r.   r.   r/   r    rY  r  c                   @  r  )SubqueryPredicateNr  r.   r.   r.   r/   r    r  r  c                   @  r  )AllNr  r.   r.   r.   r/   r    r  r  c                   @  r  )AnyNr  r.   r.   r.   r/   r    r  r  c                   @  r  )CommandTFr2  Nr  r.   r.   r.   r/   r    r  r  c                   @  r]  )TransactionF)r4   modesmarkNr  r.   r.   r.   r/   r    rK  r  c                   @  r]  )CommitF)chainr4   
durabilityNr  r.   r.   r.   r/   r    rK  r  c                   @  r  )RollbackF)	savepointr4   Nr  r.   r.   r.   r/   r    r  r  c                	   @  s>   e Zd ZdddddddddZedddZedd	d
ZdS )AlterTF)r4   r%  actionsr  rB  r  rC  	not_validrO   r/  c                 C  r0  r1  r2  r4  r.   r.   r/   r%    r5  z
Alter.kindr  c                 C  rk   )Nr  rg   rb   r.   r.   r/   r    r  zAlter.actionsNr6  r  )r0   r1   r2   r  r  r%  r  r.   r.   r.   r/   r    s    r  c                   @  r8  )AnalyzeF)r%  r4   r  moderF  r?   r&  Nr  r.   r.   r.   r/   r    r?  r  c                   @  r  )AnalyzeStatisticsTF)r%  rE  r4   rl   Nr  r.   r.   r.   r/   r    r  r  c                   @  r  )AnalyzeHistogramTF)r4   rl   r?   update_optionsNr  r.   r.   r.   r/   r    r  r  c                   @  r  )AnalyzeSampleT)r%  r  Nr  r.   r.   r.   r/   r    r  r  c                   @  rW  )AnalyzeListChainedRowsr?   FNr  r.   r.   r.   r/   r  #  rY  r  c                   @  rW  )AnalyzeDeleter%  FNr  r.   r.   r.   r/   r  '  rY  r  c                   @  rW  )AnalyzeWithrl   TNr  r.   r.   r.   r/   r  +  rY  r  c                   @  rH  )AnalyzeValidateTF)r%  r4   r?   Nr  r.   r.   r.   r/   r  /  re  r  c                   @  r  )AnalyzeColumnsNr  r.   r.   r.   r/   r  7  r  r  c                   @  r  )	UsingDataNr  r.   r.   r.   r/   r  ;  r  r  c                   @  rW  )AddConstraintrl   TNr  r.   r.   r.   r/   r  ?  rY  r  c                   @  r  )AddPartitionTFr  Nr  r.   r.   r.   r/   r  C  r  r  c                   @  r  )AttachOptionTFr2  Nr  r.   r.   r.   r/   r  G  r  r  c                   @  r  )DropPartitionTF)rl   r  Nr  r.   r.   r.   r/   r  K  r  r  c                   @  r  )ReplacePartitionT)r?   rF  Nr  r.   r.   r.   r/   r  P  r  r  c                   @  2   e Zd ZdddZed
ddZed
ddZd	S )r5  Tr2  rO   r>   c                 C  r   rI   r  rb   r.   r.   r/   r  X  r   zBinary.leftc                 C  r   rI   r  rb   r.   r.   r/   r  \  r   zBinary.rightNr  )r0   r1   r2   r  r  r  r  r.   r.   r.   r/   r5  U  s    
r5  c                   @  r  )r~  Nr  r.   r.   r.   r/   r~  a  r  r~  c                   @  r  )	ConnectorNr  r.   r.   r.   r/   r  e  r  r  c                   @  r  )
BitwiseAndNr  r.   r.   r.   r/   r  i  r  r  c                   @  r  )BitwiseLeftShiftNr  r.   r.   r.   r/   r  m  r  r  c                   @  r  )	BitwiseOrNr  r.   r.   r.   r/   r  q  r  r  c                   @  r  )BitwiseRightShiftNr  r.   r.   r.   r/   r  u  r  r  c                   @  r  )
BitwiseXorNr  r.   r.   r.   r/   r  y  r  r  c                   @  r  )rm  TF)r4   r?   rk  rl  Nr  r.   r.   r.   r/   rm  }  r}  rm  c                   @  r  )OverlapsNr  r.   r.   r.   r/   r    r  r  c                   @  sR   e Zd ZedddZedddZeddd	ZedddZedddZ	dS )r  rO   rP   c                 C  r*  rI   )r?   r   rb   r.   r.   r/   r     r,  zDot.is_starrm   c                 C  r*  rI   )r?   rt   rb   r.   r.   r/   rt     r,  zDot.namec                 C  r   rI   r   rb   r.   r.   r/   r     r   zDot.output_namerl   t.Sequence[Expression]c                 C  s*   t |dk r
tdtttdd |S )z2Build a Dot object with a sequence of expressions.   zDot requires >= 2 expressions.c                 S  r#  )Nr2  )r  xyr.   r.   r/   r     s    zDot.build.<locals>.<lambda>)r   r{   rM  rN  r  r	   )rL   rl   r.   r.   r/   r     s   z	Dot.buildr  c                 C  sJ   |   ^}}|  tD ]}|j|}t|tr|| q|  |S )zAReturn the parts of a table / column in order catalog, db, table.)r   r   COLUMN_PARTSr@   rh   rn   r>   r   )rL   r4   r  r   r  r.   r.   r/   r    s   

z	Dot.partsNr  r  )rl   r  rO   r  r  )
r0   r1   r2   r  r   rt   r   r  r   r  r.   r.   r.   r/   r    s    r  c                   @  rZ  )DPipeTFr4   r?   rl  Nr  r.   r.   r.   r/   r    rK  r  c                   @  r  )re  Nr  r.   r.   r.   r/   re    r  re  c                   @  r  )
NullSafeEQNr  r.   r.   r.   r/   r    r  r  c                   @  r  )NullSafeNEQNr  r.   r.   r.   r/   r    r  r  c                   @  r  )
PropertyEQNr  r.   r.   r.   r/   r    r  r  c                   @  r  )DistanceNr  r.   r.   r.   r/   r    r  r  c                   @  r  )EscapeNr  r.   r.   r.   r/   r    r  r  c                   @  r  )GlobNr  r.   r.   r.   r/   r    r  r  c                   @  r  )rz  Nr  r.   r.   r.   r/   rz    r  rz  c                   @  r  )r|  Nr  r.   r.   r.   r/   r|    r  r|  c                   @  r  )rc  Nr  r.   r.   r.   r/   rc    r  rc  c                   @  r  )ILikeAnyNr  r.   r.   r.   r/   r    r  r  c                   @  r  )r  Nr  r.   r.   r.   r/   r    r  r  c                   @  r  )r]  Nr  r.   r.   r.   r/   r]    r  r]  c                   @  r  )Kwargz1Kwarg in special functions like func(kwarg => y).Nr  r.   r.   r.   r/   r    r  r  c                   @  r  )ra  Nr  r.   r.   r.   r/   ra    r  ra  c                   @  r  )LikeAnyNr  r.   r.   r.   r/   r    r  r  c                   @  r  )rv  Nr  r.   r.   r.   r/   rv    r  rv  c                   @  r  )rx  Nr  r.   r.   r.   r/   rx    r  rx  c                   @  r  )r  Nr  r.   r.   r.   r/   r    r  r  c                   @  r  )r  Nr  r.   r.   r.   r/   r    r  r  c                   @  r  )rg  Nr  r.   r.   r.   r/   rg    r  rg  c                   @  r]  )OperatorT)r4   operatorr?   Nr  r.   r.   r.   r/   r    rK  r  c                   @  r  )	SimilarToNr  r.   r.   r.   r/   r    r  r  c                   @  r  )SliceFr2  Nr  r.   r.   r.   r/   r    r  r  c                   @  r  )r  Nr  r.   r.   r.   r/   r    r  r  c                   @  r  )UnaryNr  r.   r.   r.   r/   r    r  r  c                   @  r  )
BitwiseNotNr  r.   r.   r.   r/   r    r  r  c                   @  r  )r  Nr  r.   r.   r.   r/   r  "  r  r  c                   @  r  )r   rO   rm   c                 C  r*  rI   r+  rb   r.   r.   r/   r   '  r,  zParen.output_nameNr  )r0   r1   r2   r  r   r.   r.   r.   r/   r   &  r  r   c                      s   e Zd Zd fddZ  ZS )ry   rO   int | Decimalc                   s   | j r
| j d S t  S )Nr   )rz   r4   r|   r"   rb   r,   r.   r/   r|   -  s   
z	Neg.to_py)rO   r  )r0   r1   r2   r|   r3   r.   r.   r,   r/   ry   ,  s    ry   c                   @  r  )
r   TFr  rO   rm   c                 C  r   rI   r  rb   r.   r.   r/   r   6  r   zAlias.output_nameNr  r0   r1   r2   r  r  r   r.   r.   r.   r/   r   3  r  r   c                   @  r  )
PivotAliasNr  r.   r.   r.   r/   r  =  r  r  c                   @  rW  )PivotAnyr4   FNr  r.   r.   r.   r/   r  C  rY  r  c                   @  r  )AliasesTr=  c                 C  r   rI   rR  rb   r.   r.   r/   aliasesJ  r   zAliases.aliasesN)r0   r1   r2   r  r  r  r.   r.   r.   r/   r  G  r  r  c                   @  r  )AtIndexTr2  Nr  r.   r.   r.   r/   r  P  r  r  c                   @  r  )
AtTimeZoneTr4   zoneNr  r.   r.   r.   r/   r  T  r  r  c                   @  r  )FromTimeZoneTr  Nr  r.   r.   r.   r/   r  X  r  r  c                   @  s   e Zd ZdZdddZdS )FormatPhrasezFormat override for a column in Teradata.
    Can be expanded to additional dialects as needed

    https://docs.teradata.com/r/Enterprise_IntelliFlex_VMware/SQL-Data-Types-and-Literals/Data-Type-Formats-and-Format-Phrases/FORMAT
    Tr4   rO  Nr  r.   r.   r.   r/   r  \  s    r  c                   @  r]  )rZ  Tr[  Nr  r.   r.   r.   r/   rZ  f  rK  rZ  c                      s2   e Zd ZddddddZed fddZ  ZS )	r8  TF)r4   rl   r  rl  returns_list_for_mapsrO   rm   c                   s"   t | jdkr| jd jS t jS )Nr   r   )r   rl   r   r"   rb   r,   r.   r/   r   t  s   zBracket.output_namer  )r0   r1   r2   r  r  r   r3   r.   r.   r,   r/   r8  j  s    r8  c                   @  r  )r  F)rl   r<  Nr  r.   r.   r.   r/   r  |  r  r  c                   @  rL  )rG  TF)r4   rl   rE  r   ru   	is_globalNr  r.   r.   r.   r/   rG    rP  rG  c                   @  r  )ForInTr2  Nr  r.   r.   r.   r/   r    r  r  c                      sZ   e Zd ZdZddiZdddddd	d
dddd
ZeeefZ	 fddZ
edddZ  ZS )TimeUnitz+Automatically converts unit arg into a var.unitFDAYHOURMINUTEMILLISECOND
NANOSECONDQUARTERSECONDMICROSECONDWEEKrc  )
DHMMSNSr   r   USWYc                   st   | d}t|| jrt| j |jp|j d|d< nt|tr/|dt|j	j d t
 jdi | d S )Nr  r  r4   r.   )rh   rn   VAR_LIKErq   UNABBREVIATED_UNIT_NAMErt   r3  Weekr   r4   r"   rN   )rL   r@   r  r,   r.   r/   rN     s   

zTimeUnit.__init__rO   t.Optional[Var | IntervalSpan]c                 C  rf   Nr  rg   rb   r.   r.   r/   r    r   zTimeUnit.unit)rO   r  )r0   r1   r2   r&   r  r  r~   rp   rq   r  rN   r  r  r3   r.   r.   r,   r/   r    s$    
r  c                   @  s   e Zd ZdddZdd ZdS )
IntervalOpFT)r  r?   c                 C  s&   t | j | jr| j dS d dS )Nr4   r  )Intervalr?   r   r  rb   r.   r.   r/   interval  s   zIntervalOp.intervalN)r0   r1   r2   r  r  r.   r.   r.   r/   r    s    
r  c                   @  r  )IntervalSpanTr2  Nr  r.   r.   r.   r/   r    r  r  c                   @  r  )r  Fr  Nr  r.   r.   r.   r/   r    r  r  c                   @  r  )IgnoreNullsNr  r.   r.   r.   r/   r    r  r  c                   @  r  )RespectNullsNr  r.   r.   r.   r/   r    r  r  c                   @  r]  )	HavingMaxT)r4   r?   r  Nr  r.   r.   r.   r/   r    rK  r  c                   @  sD   e Zd ZdZdZedd Zedd Zedd Zed	d
 Z	dS )r  a  
    The base class for all function expressions.

    Attributes:
        is_var_len_args (bool): if set to True the last argument defined in arg_types will be
            treated as a variable length argument and the argument's value will be stored as a list.
        _sql_names (list): the SQL name (1st item in the list) and aliases (subsequent items) for this
            function expression. These values are used to map this node to a name during parsing as
            well as to provide the function's name during SQL string generation. By default the SQL
            name is set to the expression's class name transformed to snake case.
    Fc                 C  s|   | j r,t| j}| j r|d d n|}t|}dd t||D }||d  ||d < ndd t|| jD }| di |S )Nr   c                 S  rV  r.   r.   rX   r   rB   r.   r.   r/   r)    rW  z&Func.from_arg_list.<locals>.<dictcomp>c                 S  rV  r.   r.   r  r.   r.   r/   r)    rW  r.   )r  r\   r  r   zip)r'   r@   all_arg_keysnon_var_len_arg_keysnum_non_var	args_dictr.   r.   r/   from_arg_list  s   
zFunc.from_arg_listc                 C  s.   | t u rtdd| jvrt| jg| _| jS )Nz?SQL name is only supported by concrete function implementations
_sql_names)r  r  __dict__r   r0   r  r'   r.   r.   r/   	sql_names  s   
zFunc.sql_namesc                 C  s   |   d S )Nr   r  r  r.   r.   r/   sql_name  r   zFunc.sql_namec                   s    fdd   D S )Nc                   s   i | ]}| j qS r.   )r  )rX   rt   r  r.   r/   r)    r   z0Func.default_parser_mappings.<locals>.<dictcomp>r  r  r.   r  r/   default_parser_mappings  s   zFunc.default_parser_mappingsN)
r0   r1   r2   r&   r  r  r  r  r  r  r.   r.   r.   r/   r    s    

	
r  c                   @  r  )TypeofNr  r.   r.   r.   r/   r    r  r  c                   @  r  )AggFuncNr  r.   r.   r.   r/   r    r  r  c                   @  r  )ArrayRemoveTr2  Nr  r.   r.   r.   r/   r    r  r  c                   @  r]  )ParameterizedAggTr4   rl   r  Nr  r.   r.   r.   r/   r     rK  r   c                   @  r  )AbsNr  r.   r.   r.   r/   r    r  r  c                   @      e Zd ZddddZg dZdS )ArgMaxTFr4   r?   rc  )ARG_MAXARGMAXMAX_BYNr0   r1   r2   r  r  r.   r.   r.   r/   r        r  c                   @  r  )ArgMinTFr  )ARG_MINARGMINMIN_BYNr	  r.   r.   r.   r/   r  !  r
  r  c                   @  rH  )
ApproxTopKTF)r4   r?   countersNr  r.   r.   r.   r/   r  &  rK  r  c                   @  r  )FlattenNr  r.   r.   r.   r/   r  *  r  r  c                   @  r  )	TransformTr2  Nr  r.   r.   r.   r/   r  /  r  r  c                   @  s(   e Zd ZdddZdZed	ddZdS )
	AnonymousTFr=  rO   rm   c                 C  s   t | jtr	| jS | jjS rI   )rn   r4   rm   rt   rb   r.   r.   r/   rt   7     zAnonymous.nameNr  )r0   r1   r2   r  r  r  rt   r.   r.   r.   r/   r  3  s
    
r  c                   @     e Zd ZdddZdZdS )AnonymousAggFuncTFr=  Nr0   r1   r2   r  r  r.   r.   r.   r/   r  <      
r  c                   @  r  )CombinedAggFuncTFr=  Nr  r.   r.   r.   r/   r  B  r  r  c                   @  r]  )CombinedParameterizedAggTr  Nr  r.   r.   r.   r/   r  F  rK  r  c                   @  r  )HllTFr=  Nr  r.   r.   r.   r/   r  L  r  r  c                   @     e Zd ZdddZddgZdS )ApproxDistinctTF)r4   accuracyAPPROX_DISTINCTAPPROX_COUNT_DISTINCTNr	  r.   r.   r.   r/   r  Q      
r  c                   @  r  )ApplyTr2  Nr  r.   r.   r.   r/   r"  V  r  r"  c                   @  s   e Zd ZdddZdZdS )ArrayF)rl   bracket_notationTNr  r.   r.   r.   r/   r#  Z  r  r#  c                   @  r  )ToArrayNr  r.   r.   r.   r/   r%  `  r  r%  c                   @     e Zd ZddiZdZdS )Listrl   FTNr  r.   r.   r.   r/   r'  e      r'  c                   @  s   e Zd ZdddddZdS )PadTF)r4   r?   fill_patternis_leftNr  r.   r.   r.   r/   r)  k  r}  r)  c                   @  rH  )ToCharTF)r4   rO  nlsparamNr  r.   r.   r.   r/   r,  q  rK  r,  c                   @  r  )ToNumberTF)r4   rO  r-  	precisionscaleNr  r.   r.   r.   r/   r.  w  rf  r.  c                   @  r  )ToDoubleTFr  Nr  r.   r.   r.   r/   r1    r  r1  c                   @  r  )ColumnsTF)r4   unpackNr  r.   r.   r.   r/   r2    r  r2  c                   @  rZ  )ConvertTF)r4   r?   rN  Nr  r.   r.   r.   r/   r4    rK  r4  c                   @  rZ  )ConvertToCharsetTF)r4   destrF  Nr  r.   r.   r.   r/   r5    rK  r5  c                   @  rH  )ConvertTimezoneFT)	source_tz	target_tz	timestampNr  r.   r.   r.   r/   r7    rK  r7  c                   @  r  )GenerateSeriesTF)r<   r=   r  is_end_exclusiveNr  r.   r.   r.   r/   r;    r}  r;  c                   @  r  )ExplodingGenerateSeriesNr  r.   r.   r.   r/   r=    r  r=  c                   @  r  )ArrayAggTF)r4   nulls_excludedNr  r.   r.   r.   r/   r>    r  r>  c                   @  r  )ArrayUniqueAggNr  r.   r.   r.   r/   r@    r  r@  c                   @  r  )ArrayAllTr2  Nr  r.   r.   r.   r/   rA    r  rA  c                   @  r  )ArrayAnyTr2  Nr  r.   r.   r.   r/   rB    r  rB  c                   @  s"   e Zd ZddgZdddZdZdS )ArrayConcatARRAY_CONCAT	ARRAY_CATTFr=  N)r0   r1   r2   r  r  r  r.   r.   r.   r/   rC    s    
rC  c                   @  r  )ArrayConcatAggNr  r.   r.   r.   r/   rF    r  rF  c                   @  s   e Zd ZddiZdZdS )ArrayConstructCompactrl   TNr  r.   r.   r.   r/   rG    r(  rG  c                   @     e Zd ZddgZdS )ArrayContainsARRAY_CONTAINS	ARRAY_HASNr0   r1   r2   r  r.   r.   r.   r/   rI    rY  rI  c                   @  rH  )ArrayContainsAllARRAY_CONTAINS_ALLARRAY_HAS_ALLNrL  r.   r.   r.   r/   rM    rY  rM  c                   @  s   e Zd ZdddZddgZdS )ArrayFilterTr2  FILTERARRAY_FILTERNr	  r.   r.   r.   r/   rP    r!  rP  c                   @  r  )
ArrayFirstNr  r.   r.   r.   r/   rS    r  rS  c                   @  r  )	ArrayLastNr  r.   r.   r.   r/   rT    r  rT  c                   @  r  )ArrayReverseNr  r.   r.   r.   r/   rU    r  rU  c                   @  r  )
ArraySliceTF)r4   r<   r=   r  Nr  r.   r.   r.   r/   rV    r}  rV  c                   @      e Zd ZddddZddgZdS )ArrayToStringTFr4   r?   rW  ARRAY_TO_STRING
ARRAY_JOINNr	  r.   r.   r.   r/   rX    r
  rX  c                   @  s    e Zd ZddiZdZddgZdS )ArrayIntersectrl   TARRAY_INTERSECTARRAY_INTERSECTIONNr0   r1   r2   r  r  r  r.   r.   r.   r/   r\    s    r\  c                   @  rW  )StPointTFrY  ST_POINTST_MAKEPOINTNr	  r.   r.   r.   r/   r`    r
  r`  c                   @  rZ  )
StDistanceTF)r4   r?   use_spheroidNr  r.   r.   r.   r/   rc    rK  rc  c                   @  r  )StringTFr  Nr  r.   r.   r.   r/   re    r  re  c                   @      e Zd ZddddZg dZdS )StringToArrayTFrY  )STRING_TO_ARRAYSPLIT_BY_STRINGSTRTOK_TO_ARRAYNr	  r.   r.   r.   r/   rg    r
  rg  c                   @  r  )ArrayOverlapsNr  r.   r.   r.   r/   rk    r  rk  c                   @  r  )	ArraySizeTFr2  
ARRAY_SIZEARRAY_LENGTHNr	  r.   r.   r.   r/   rl    r!  rl  c                   @  r  )	ArraySortTFr2  Nr  r.   r.   r.   r/   ro  
  r  ro  c                   @  r  )ArraySumTFr2  Nr  r.   r.   r.   r/   rp    r  rp  c                   @  r  )ArrayUnionAggNr  r.   r.   r.   r/   rq    r  rq  c                   @  r  )AvgNr  r.   r.   r.   r/   rr    r  rr  c                   @  r  )AnyValueNr  r.   r.   r.   r/   rs    r  rs  c                   @  rH  )LagTFr4   r  r\  Nr  r.   r.   r.   r/   rt    rK  rt  c                   @  rH  )LeadTFru  Nr  r.   r.   r.   r/   rv  "  rK  rv  c                   @  r  )FirstNr  r.   r.   r.   r/   rw  (  r  rw  c                   @  r  )LastNr  r.   r.   r.   r/   rx  ,  r  rx  c                   @  r  )
FirstValueNr  r.   r.   r.   r/   ry  0  r  ry  c                   @  r  )	LastValueNr  r.   r.   r.   r/   rz  4  r  rz  c                   @  r  )NthValueT)r4   r  Nr  r.   r.   r.   r/   r{  8  r  r{  c                   @  s0   e Zd ZddddZddd
dZddddZdS )CaseFT)r4   ifsr\  r  rO  thenr   rP   rO   c              	   K  sB   t | |}|dtt|fd|i|t|fd|i|d |S )Nr}  r   )r4   true)rU  r   IfrL  )rL   r  r~  r   r   r  r.   r.   r/   r  ?  s   
z	Case.whenc                 K  s*   t | |}|dt|fd|i| |S )Nr\  r   )rU  r   rL  )rL   r  r   r   r  r.   r.   r/   rM  J  s   
z
Case.else_Nr  )r  rO  r~  rO  r   rP   rO   r|  )r  rO  r   rP   rO   r|  )r0   r1   r2   r  r  rM  r.   r.   r.   r/   r|  <  s    r|  c                   @  sR   e Zd ZdddddddZedddZedd	d
ZedddZdddZdS )CastTF)r4   r  rO  rl  rQ  r\  rO   rm   c                 C  r*  rI   r+  rb   r.   r.   r/   rt   Z  r,  z	Cast.namer   c                 C  r  )Nr  r  rb   r.   r.   r/   r  ^  r   zCast.toc                 C  r   rI   r   rb   r.   r.   r/   r   b  r   zCast.output_namer   rf  rP   c                 G  s   | j j| S )a  
        Checks whether this Cast's DataType matches one of the provided data types. Nested types
        like arrays or structs will be compared using "structural equivalence" semantics, so e.g.
        array<int> != array<float>.

        Args:
            dtypes: the data types to compare this Cast's DataType to.

        Returns:
            True, if and only if there is a type in `dtypes` which is equal to this Cast's DataType.
        )r  r   r   r.   r.   r/   r   f  s   zCast.is_typeNr  rO   r   )r   rf  rO   rP   )	r0   r1   r2   r  r  rt   r  r   r   r.   r.   r.   r/   r  P  s    	r  c                   @  r  )TryCastNr  r.   r.   r.   r/   r  u  r  r  c                   @  r  )JSONCastNr  r.   r.   r.   r/   r  z  r  r  c                   @  r  )TryNr  r.   r.   r.   r/   r  ~  r  r  c                   @  r  )CastToStrTypeTr4   r  Nr  r.   r.   r.   r/   r    r  r  c                   @  rZ  )TranslateCharactersTF)r4   r?   
with_errorNr  r.   r.   r.   r/   r    rK  r  c                   @  r  )CollateNr  r.   r.   r.   r/   r    r  r  c                   @  s    e Zd ZddddZddgZdS )CeilTFr4   decimalsr  CEILCEILINGNr	  r.   r.   r.   r/   r    r
  r  c                   @  s&   e Zd ZdddddZdZg dZdS )CoalesceTF)r4   rl   is_nvlis_null)COALESCEIFNULLNVLNr_  r.   r.   r.   r/   r    s    r  c                   @  s"   e Zd ZdddZdZddgZdS )ChrTF)rl   charsetCHRr  Nr_  r.   r.   r.   r/   r    s    
r  c                   @  s   e Zd ZddddZdZdS )ConcatTF)rl   rl  coalesceNr  r.   r.   r.   r/   r        r  c                   @     e Zd ZdgZdS )ConcatWs	CONCAT_WSNrL  r.   r.   r.   r/   r        
r  c                   @  r  )ContainsTr2  Nr  r.   r.   r.   r/   r    r  r  c                   @  r  )ConnectByRootNr  r.   r.   r.   r/   r    r  r  c                   @     e Zd ZddddZdZdS )CountF)r4   rl   big_intTNr  r.   r.   r.   r/   r    r  r  c                   @  rH  )CountIfCOUNT_IFCOUNTIFNrL  r.   r.   r.   r/   r    rY  r  c                   @  r  )CbrtNr  r.   r.   r.   r/   r    r  r  c                   @  rW  )CurrentDater4   FNr  r.   r.   r.   r/   r    rY  r  c                   @  rW  )CurrentDatetimer4   FNr  r.   r.   r.   r/   r    rY  r  c                   @  rW  )CurrentTimer4   FNr  r.   r.   r.   r/   r    rY  r  c                   @  r  )CurrentTimestampF)r4   sysdateNr  r.   r.   r.   r/   r    r  r  c                   @  r  )CurrentTimestampLTZNr  r.   r.   r.   r/   r    r  r  c                   @  rW  )CurrentSchemar4   FNr  r.   r.   r.   r/   r    rY  r  c                   @  rW  )CurrentUserr4   FNr  r.   r.   r.   r/   r    rY  r  c                   @  rZ  )DateAddTFr4   r?   r  Nr  r.   r.   r.   r/   r    rK  r  c                   @  r  )DateBinTFr4   r?   r  r  Nr  r.   r.   r.   r/   r    r}  r  c                   @  rZ  )DateSubTFr  Nr  r.   r.   r.   r/   r    rK  r  c                   @  s"   e Zd ZddgZdddddZdS )DateDiffDATEDIFF	DATE_DIFFTFr  Nr0   r1   r2   r  r  r.   r.   r.   r/   r        r  c                      s6   e Zd ZddddZ fddZed
dd	Z  ZS )	DateTruncTF)r  r4   r  c                   sh   | dd}|d}t|tjr)|j }|r"|tjv r"tj| }t	||d< t
 jdi | d S )NunabbreviateTr  r.   )r   rh   rn   r  r  rt   r3  r  rp   r~  r"   rN   )rL   r@   r  r  	unit_namer,   r.   r/   rN     s   


zDateTrunc.__init__rO   r>   c                 C  r  r  r  rb   r.   r.   r/   r    r   zDateTrunc.unitr  )r0   r1   r2   r  rN   r  r  r3   r.   r.   r,   r/   r    s
    r  c                   @  r  )DatetimeTFr2  Nr  r.   r.   r.   r/   r    r  r  c                   @  rZ  )DatetimeAddTFr  Nr  r.   r.   r.   r/   r  
  rK  r  c                   @  rZ  )DatetimeSubTFr  Nr  r.   r.   r.   r/   r    rK  r  c                   @  rZ  )DatetimeDiffTFr  Nr  r.   r.   r.   r/   r    rK  r  c                   @  rZ  )DatetimeTruncTFr4   r  r  Nr  r.   r.   r.   r/   r    rK  r  c                   @  rH  )	DayOfWeekDAY_OF_WEEK	DAYOFWEEKNrL  r.   r.   r.   r/   r    rY  r  c                   @  rH  )DayOfWeekIsoDAYOFWEEK_ISOISODOWNrL  r.   r.   r.   r/   r     rY  r  c                   @  rH  )
DayOfMonthDAY_OF_MONTH
DAYOFMONTHNrL  r.   r.   r.   r/   r  $  rY  r  c                   @  rH  )	DayOfYearDAY_OF_YEAR	DAYOFYEARNrL  r.   r.   r.   r/   r  (  rY  r  c                   @  r  )ToDaysNr  r.   r.   r.   r/   r  ,  r  r  c                   @  rH  )
WeekOfYearWEEK_OF_YEAR
WEEKOFYEARNrL  r.   r.   r.   r/   r  0  rY  r  c                   @  rZ  )MonthsBetweenTF)r4   r?   roundoffNr  r.   r.   r.   r/   r  4  rK  r  c                   @  r3  )MakeIntervalF)yearmonthdayhourminutesecondNr  r.   r.   r.   r/   r  8  rP  r  c                   @  s   e Zd ZddgZdddZdS )LastDayLAST_DAYLAST_DAY_OF_MONTHTFr  Nr  r.   r.   r.   r/   r  C      r  c                   @  r  )ExtractTr2  Nr  r.   r.   r.   r/   r  H  r  r  c                   @  r  )ExistsTFr2  Nr  r.   r.   r.   r/   r  L  r  r  c                   @  r]  )	TimestampF)r4   r  with_tzNr  r.   r.   r.   r/   r  P  rK  r  c                   @  rZ  )TimestampAddTFr  Nr  r.   r.   r.   r/   r  T  rK  r  c                   @  rZ  )TimestampSubTFr  Nr  r.   r.   r.   r/   r  X  rK  r  c                   @  s    e Zd ZddgZddddZdS )TimestampDiffTIMESTAMPDIFFTIMESTAMP_DIFFTFr  Nr  r.   r.   r.   r/   r  \      r  c                   @  rZ  )TimestampTruncTFr  Nr  r.   r.   r.   r/   r  a  rK  r  c                   @  rZ  )TimeAddTFr  Nr  r.   r.   r.   r/   r  e  rK  r  c                   @  rZ  )TimeSubTFr  Nr  r.   r.   r.   r/   r  i  rK  r  c                   @  rZ  )TimeDiffTFr  Nr  r.   r.   r.   r/   r  m  rK  r  c                   @  rZ  )	TimeTruncTFr  Nr  r.   r.   r.   r/   r  q  rK  r  c                   @      e Zd ZddgZddddZdS )DateFromPartsDATE_FROM_PARTSDATEFROMPARTST)r  r  r  Nr  r.   r.   r.   r/   r  u  r  r  c                   @  s&   e Zd ZddgZdddddddZdS )TimeFromPartsTIME_FROM_PARTSTIMEFROMPARTSTF)r  r  secnano	fractionsr/  Nr  r.   r.   r.   r/   r  z  s    
r  c                   @  r  )DateStrToDateNr  r.   r.   r.   r/   r    r  r  c                   @  r  )DateToDateStrNr  r.   r.   r.   r/   r    r  r  c                   @  r  )DateToDiNr  r.   r.   r.   r/   r    r  r  c                   @  r  )DateF)r4   r  rl   TNr  r.   r.   r.   r/   r    r  r  c                   @  r  )DayNr  r.   r.   r.   r/   r    r  r  c                   @  rZ  )DecodeTF)r4   r  r	  Nr  r.   r.   r.   r/   r    rK  r  c                   @  s&   e Zd ZU g Zded< ddiZdZdS )
DecodeCaser   r  rl   TN)r0   r1   r2   r  r  r  r  r.   r.   r.   r/   r     s   
 r   c                   @  r  )DiToDateNr  r.   r.   r.   r/   r    r  r  c                   @  r  )EncodeT)r4   r  Nr  r.   r.   r.   r/   r    r  r  c                   @  r  )ExpNr  r.   r.   r.   r/   r    r  r  c                   @  r  )ExplodeTFr=  Nr  r.   r.   r.   r/   r    r  r  c                   @  r  )InlineNr  r.   r.   r.   r/   r    r  r  c                   @  r  )ExplodeOuterNr  r.   r.   r.   r/   r    r  r  c                   @  r  )
PosexplodeNr  r.   r.   r.   r/   r    r  r  c                   @  r  )PosexplodeOuterNr  r.   r.   r.   r/   r    r  r  c                      s0   e Zd ZdddddZed fddZ  ZS )	rV  TF)rl   r   r  explode_arrayrO   r  c                   s6   t  j}| jd}|r||du rtdn|g }|S )Nr  T)r"   r  r@   rh   r  )rL   r   r  r,   r.   r/   r    s
   zUnnest.selectsr  )r0   r1   r2   r  r  r  r3   r.   r.   r,   r/   rV    s    rV  c                   @  rH  )FloorTFr  Nr  r.   r.   r.   r/   r
    rK  r
  c                   @  r  )
FromBase64Nr  r.   r.   r.   r/   r    r  r  c                   @  r  )FeaturesAtTimeTF)r4   timenum_rowsignore_feature_nullsNr  r.   r.   r.   r/   r    r}  r  c                   @  r  )ToBase64Nr  r.   r.   r.   r/   r    r  r  c                   @  r  )FromISO8601TimestampFROM_ISO8601_TIMESTAMPNrL  r.   r.   r.   r/   r    r  r  c                   @  s    e Zd ZddddddddZdS )GapFillTF)r4   	ts_columnbucket_widthpartitioning_columnsvalue_columnsoriginignore_nullsNr  r.   r.   r.   r/   r    r?  r  c                   @  rZ  )GenerateDateArrayTFr<   r=   r  Nr  r.   r.   r.   r/   r    rK  r  c                   @  r]  )GenerateTimestampArrayTr  Nr  r.   r.   r.   r/   r    rK  r  c                   @  r  )GreatestTFr=  Nr  r.   r.   r.   r/   r    r  r  c                   @  r  )OverflowTruncateBehaviorFT)r4   
with_countNr  r.   r.   r.   r/   r    r  r  c                   @  rH  )GroupConcatTF)r4   	separatoron_overflowNr  r.   r.   r.   r/   r     rK  r   c                   @  r  )HexNr  r.   r.   r.   r/   r#    r  r#  c                   @  r  )LowerHexNr  r.   r.   r.   r/   r$    r  r$  c                   @  r  )r  Nr  r.   r.   r.   r/   r    r  r  c                   @  r  )r  Nr  r.   r.   r.   r/   r     r  r  c                   @  r]  )XorFr  Nr  r.   r.   r.   r/   r%  $  rK  r%  c                   @  rW  )r  TFr4   r  falseIFIIFNr	  r.   r.   r.   r/   r  (  r
  r  c                   @  r  )NullifTr2  Nr  r.   r.   r.   r/   r*  -  r  r*  c                   @  r  )InitcapTFr2  Nr  r.   r.   r.   r/   r+  1  r  r+  c                   @  r  )IsAsciiNr  r.   r.   r.   r/   r,  5  r  r,  c                   @  rH  )IsNanIS_NANISNANNrL  r.   r.   r.   r/   r-  9  rY  r-  c                   @  r  )Int64Nr  r.   r.   r.   r/   r0  >  r  r0  c                   @  rH  )IsInfIS_INFISINFNrL  r.   r.   r.   r/   r1  B  rY  r1  c                   @  r]  )r#  F)r4   r  r(  Nr  r.   r.   r.   r/   r#  G  rK  r#  c                   @  r  )
JSONPathTF)rl   r  rO   rm   c                 C  s   | j d j}t|tr|S dS )Nr   r!   )rl   r4   rn   rm   )rL   last_segmentr.   r.   r/   r   N  s   zJSONPath.output_nameNr  r  r.   r.   r.   r/   r4  K  r  r4  c                   @  r  )JSONPathPartNr  r.   r.   r.   r/   r6  T  r  r6  c                   @  rW  )JSONPathFilterr4   TNr  r.   r.   r.   r/   r7  X  rY  r7  c                   @  rW  )JSONPathKeyr4   TNr  r.   r.   r.   r/   r8  \  rY  r8  c                   @  rW  )JSONPathRecursiver4   FNr  r.   r.   r.   r/   r9  `  rY  r9  c                   @  r  )JSONPathRootNr  r.   r.   r.   r/   r:  d  r  r:  c                   @  rW  )JSONPathScriptr4   TNr  r.   r.   r.   r/   r;  h  rY  r;  c                   @  r]  )JSONPathSliceFr  Nr  r.   r.   r.   r/   r<  l  rK  r<  c                   @  rW  )JSONPathSelectorr4   TNr  r.   r.   r.   r/   r=  p  rY  r=  c                   @  rW  )JSONPathSubscriptr4   TNr  r.   r.   r.   r/   r>  t  rY  r>  c                   @  rW  )JSONPathUnionrl   TNr  r.   r.   r.   r/   r?  x  rY  r?  c                   @  r  )JSONPathWildcardNr  r.   r.   r.   r/   r@  |  r  r@  c                   @  r  )
FormatJsonNr  r.   r.   r.   r/   rA    r  rA  c                   @  r  )JSONKeyValueTr2  Nr  r.   r.   r.   r/   rB    r  rB  c                   @  rb  )
JSONObjectFrl   null_handlingunique_keysreturn_typeencodingNr  r.   r.   r.   r/   rC    rf  rC  c                   @  rb  )JSONObjectAggFrD  Nr  r.   r.   r.   r/   rI    rf  rI  c                   @  r  )JSONBObjectAggTr2  Nr  r.   r.   r.   r/   rJ    r  rJ  c                   @  r  )	JSONArrayTF)rl   rE  rG  strictNr  r.   r.   r.   r/   rK    r  rK  c                   @  r  )JSONArrayAggTF)r4   r  rE  rG  rL  Nr  r.   r.   r.   r/   rM    rf  rM  c                   @  r  )
JSONExistsTF)r4   pathpassingon_conditionNr  r.   r.   r.   r/   rN    r}  rN  c                   @  r  )JSONColumnDefF)r4   r%  rO  nested_schemaNr  r.   r.   r.   r/   rR    r}  rR  c                   @  rW  )
JSONSchemarl   TNr  r.   r.   r.   r/   rT    rY  rT  c                   @  r  )	JSONValueTF)r4   rO  r!  rQ  Nr  r.   r.   r.   r/   rU    r  rU  c                   @  r  )JSONValueArrayTFr2  Nr  r.   r.   r.   r/   rV    r  rV  c                   @  s   e Zd ZddddddZdS )	JSONTableTF)r4   r  rO  error_handlingempty_handlingNr  r.   r.   r.   r/   rW    rf  rW  c                   @  rz  )ObjectInsertTF)r4   r%   rM   update_flagNr  r.   r.   r.   r/   rZ    r  rZ  c                   @  r  )OpenJSONColumnDefTF)r4   r%  rO  as_jsonNr  r.   r.   r.   r/   r\    r}  r\  c                   @  rH  )OpenJSONTF)r4   rO  rl   Nr  r.   r.   r.   r/   r^    rK  r^  c                   @  r  )JSONBContainsJSONB_CONTAINSNrL  r.   r.   r.   r/   r_    r  r_  c                   @  s   e Zd ZdddZdgZdS )JSONBExistsT)r4   rO  JSONB_EXISTSNr	  r.   r.   r.   r/   ra        

ra  c                
   @  s<   e Zd Zdddddddddd	ZdgZdZed
ddZd	S )JSONExtractTF)	r4   r?   only_json_typesrl   variant_extract
json_queryrE  quoterQ  JSON_EXTRACTrO   rm   c                 C  s   | j s| jjS dS r    )rl   r?   r   rb   r.   r.   r/   r     rz  zJSONExtract.output_nameNr  r0   r1   r2   r  r  r  r  r   r.   r.   r.   r/   rd    s    rd  c                   @  r  )JSONExtractQuoteTF)rE  r  Nr  r.   r.   r.   r/   rk    r  rk  c                   @  s   e Zd ZdddZdgZdS )JSONExtractArrayTFr2  JSON_EXTRACT_ARRAYNr	  r.   r.   r.   r/   rl    rc  rl  c                   @  s2   e Zd ZdddddZdgZdZed
ddZd	S )JSONExtractScalarTF)r4   r?   re  rl   JSON_EXTRACT_SCALARrO   rm   c                 C  r*  rI   )r?   r   rb   r.   r.   r/   r     r,  zJSONExtractScalar.output_nameNr  rj  r.   r.   r.   r/   rn    s    rn  c                   @  r  )JSONBExtractJSONB_EXTRACTNrL  r.   r.   r.   r/   rp  #  r  rp  c                   @  r  )JSONBExtractScalarJSONB_EXTRACT_SCALARNrL  r.   r.   r.   r/   rr  '  r  rr  c                   @  s   e Zd ZddddZdgZdS )
JSONFormatF)r4   r  is_jsonJSON_FORMATNr	  r.   r.   r.   r/   rt  +  s    
rt  c                   @  r  )JSONArrayContainsJSON_ARRAY_CONTAINSNrL  r.   r.   r.   r/   rw  1  r  rw  c                   @      e Zd ZddgZddddZdS )	ParseJSON
PARSE_JSON
JSON_PARSETFr  Nr  r.   r.   r.   r/   rz  5  s    rz  c                   @  r  )LeastTFr=  Nr  r.   r.   r.   r/   r}  <  r  r}  c                   @  r  )LeftTr2  Nr  r.   r.   r.   r/   r~  A  r  r~  c                   @  r  )RightTr2  Nr  r.   r.   r.   r/   r  E  r  r  c                   @  rf  )LengthTF)r4   binaryrH  )LENGTHLENCHAR_LENGTHCHARACTER_LENGTHNr	  r.   r.   r.   r/   r  I  r
  r  c                   @  rL  )LevenshteinTF)r4   r?   ins_costdel_costsub_costmax_distNr  r.   r.   r.   r/   r  N  rP  r  c                   @  r  )LnNr  r.   r.   r.   r/   r  Y  r  r  c                   @  r  )LogTFr2  Nr  r.   r.   r.   r/   r  ]  r  r  c                   @     e Zd Zg dZdS )	LogicalOr)
LOGICAL_ORBOOL_OR
BOOLOR_AGGNrL  r.   r.   r.   r/   r  a  rY  r  c                   @  r  )
LogicalAnd)LOGICAL_ANDBOOL_ANDBOOLAND_AGGNrL  r.   r.   r.   r/   r  e  rY  r  c                   @  rH  )LowerLOWERLCASENrL  r.   r.   r.   r/   r  i  rY  r  c                   @  r  )MapFkeysr   rO   r  c                 C  r  Nr  r  )rL   r  r.   r.   r/   r  p  r  zMap.keysc                 C  r  Nr   r  )rL   r   r.   r.   r/   r   u  r  z
Map.valuesNr  )r0   r1   r2   r  r  r  r   r.   r.   r.   r/   r  m  s    
r  c                   @  r  )ToMapNr  r.   r.   r.   r/   r  |  r  r  c                   @  r  )MapFromEntriesNr  r.   r.   r.   r/   r    r  r  c                   @  r  )ScopeResolutionFTr2  Nr  r.   r.   r.   r/   r    r  r  c                   @  r  )StreamNr  r.   r.   r.   r/   r    r  r  c                   @  r  )StarMapNr  r.   r.   r.   r/   r    r  r  c                   @  s6   e Zd ZdddZdZed
ddZed
ddZd	S )VarMapTr  rO   r  c                 C     | j d jS r  r@   rl   rb   r.   r.   r/   r    r   zVarMap.keysc                 C  r  r  r  rb   r.   r.   r/   r     r   zVarMap.valuesNr  )r0   r1   r2   r  r  r  r  r   r.   r.   r.   r/   r    s    
r  c                   @  rZ  )MatchAgainstTF)r4   rl   modifierNr  r.   r.   r.   r/   r    rK  r  c                   @  r  )MaxTFr=  Nr  r.   r.   r.   r/   r    r  r  c                   @  s   e Zd Zd gZdS )MD5NrL  r.   r.   r.   r/   r    r  r  c                   @  r  )	MD5Digest
MD5_DIGESTNrL  r.   r.   r.   r/   r    r  r  c                   @  r  )MedianNr  r.   r.   r.   r/   r    r  r  c                   @  r  )MinTFr=  Nr  r.   r.   r.   r/   r    r  r  c                   @  r  )MonthNr  r.   r.   r.   r/   r    r  r  c                   @  r  )	AddMonthsTr2  Nr  r.   r.   r.   r/   r    r  r  c                   @  rZ  )Nvl2TFr&  Nr  r.   r.   r.   r/   r    rK  r  c                   @  r  )	NormalizeTF)r4   formNr  r.   r.   r.   r/   r    r  r  c                   @  rz  )OverlayTF)r4   r?   rl  forNr  r.   r.   r.   r/   r    r}  r  c                   @  rZ  )PredictTF)r4   r?   params_structNr  r.   r.   r.   r/   r    rK  r  c                   @  rH  )r  POWERPOWNrL  r.   r.   r.   r/   r    rY  r  c                   @  r  )PercentileContTFr2  Nr  r.   r.   r.   r/   r    r  r  c                   @  r  )PercentileDiscTFr2  Nr  r.   r.   r.   r/   r    r  r  c                   @  r  )QuantileT)r4   quantileNr  r.   r.   r.   r/   r    r  r  c                   @  r  )ApproxQuantileTF)r4   r  r  weightNr  r.   r.   r.   r/   r    r}  r  c                   @  r  )QuarterNr  r.   r.   r.   r/   r    r  r  c                   @  r  )RandRANDRANDOMF)r4   r$   r3  Nr  r.   r.   r.   r/   r    r  r  c                   @  rW  )Randnr4   FNr  r.   r.   r.   r/   r    rY  r  c                   @  rZ  )RangeNTF)r4   rl   eachNr  r.   r.   r.   r/   r    rK  r  c                   @  s    e Zd ZdgZdZdddZdS )ReadCSVREAD_CSVTFr=  N)r0   r1   r2   r  r  r  r.   r.   r.   r/   r    s    r  c                   @  rz  )ReduceTF)r4   initialmergefinishNr  r.   r.   r.   r/   r     r}  r  c                   @     e Zd ZdddddddZdS )RegexpExtractTFr4   r?   rs  
occurrence
parametersr  Nr  r.   r.   r.   r/   r    rP  r  c                   @  r  )RegexpExtractAllTFr  Nr  r.   r.   r.   r/   r    rP  r  c                   @  r  )RegexpReplaceTF)r4   r?   replacementrs  r  	modifiersNr  r.   r.   r.   r/   r    rP  r  c                   @  rZ  )ri  TFr4   r?   flagNr  r.   r.   r.   r/   ri  %  rK  ri  c                   @  rZ  )RegexpILikeTFr  Nr  r.   r.   r.   r/   r  )  rK  r  c                   @  rZ  )RegexpSplitTFr4   r?   r  Nr  r.   r.   r.   r/   r  /  rK  r  c                   @  r  )RepeatT)r4   timesNr  r.   r.   r.   r/   r  3  r  r  c                   @  rZ  )ReplaceTF)r4   r?   r  Nr  r.   r.   r.   r/   r  8  rK  r  c                   @  rH  )RoundTF)r4   r  truncateNr  r.   r.   r.   r/   r  >  rK  r  c                   @  rW  )	RowNumberr4   FNr  r.   r.   r.   r/   r  B  rY  r  c                   @  r  )
SafeDivideTr2  Nr  r.   r.   r.   r/   r  F  r  r  c                   @  s   e Zd Zd dgZdS )SHASHA1NrL  r.   r.   r.   r/   r  J  rY  r  c                   @  s   e Zd Zd gZdddZdS )SHA2TF)r4   lengthNr  r.   r.   r.   r/   r  N      r  c                   @  rH  )SignSIGNSIGNUMNrL  r.   r.   r.   r/   r  S  rY  r  c                   @  r  )	SortArrayTF)r4   rs  Nr  r.   r.   r.   r/   r  W  r  r  c                   @  rZ  )SplitTFr  Nr  r.   r.   r.   r/   r  [  rK  r  c                   @  r]  )	SplitPartT)r4   	delimiter
part_indexNr  r.   r.   r.   r/   r  `  rK  r  c                   @  ry  )	Substring	SUBSTRINGSUBSTRTF)r4   r<   r  Nr  r.   r.   r.   r/   r  f  r  r  c                   @  r  )SubstringIndexu   
    SUBSTRING_INDEX(str, delim, count)

    *count* > 0  → left slice before the *count*-th delimiter
    *count* < 0  → right slice after the |count|-th delimiter
    T)r4   r  rc  Nr  r.   r.   r.   r/   r  k  s    r  c                   @  r  )StandardHashTFr2  Nr  r.   r.   r.   r/   r  v  r  r  c                   @     e Zd ZddgZdddZdS )
StartsWithSTARTS_WITH
STARTSWITHTr2  Nr  r.   r.   r.   r/   r  z  r  r  c                   @  r  )EndsWith	ENDS_WITHENDSWITHTr2  Nr  r.   r.   r.   r/   r    r  r  c                   @  r  )StrPositionTF)r4   substrrs  r  Nr  r.   r.   r.   r/   r    r  r  c                   @  rH  )	StrToDateTFr4   rO  rl  Nr  r.   r.   r.   r/   r    rK  r  c                   @  r  )	StrToTimeTF)r4   rO  r  rl  Nr  r.   r.   r.   r/   r    r}  r  c                   @  r  )	StrToUnixFr  Nr  r.   r.   r.   r/   r    r  r  c                   @  r  )StrToMapTF)r4   
pair_delimkey_value_delimduplicate_resolution_callbackNr  r.   r.   r.   r/   r     r  r   c                   @  rZ  )NumberToStrTF)r4   rO  cultureNr  r.   r.   r.   r/   r    rK  r  c                   @  r  )FromBaseTr2  Nr  r.   r.   r.   r/   r    r  r  c                   @  r  )Spaceu>   
    SPACE(n) → string consisting of n blank characters
    Nr  r.   r.   r.   r/   r    s    r  c                   @  r&  )Structrl   FTNr  r.   r.   r.   r/   r    r(  r  c                   @  r  )StructExtractTr2  Nr  r.   r.   r.   r/   r	    r  r	  c                   @  s"   e Zd ZddgZdddddZdS )StuffSTUFFINSERTT)r4   r<   r  r?   Nr  r.   r.   r.   r/   r
    r  r
  c                   @  r  )SumNr  r.   r.   r.   r/   r    r  r  c                   @  r  )SqrtNr  r.   r.   r.   r/   r    r  r  c                   @  rH  )StddevSTDDEVSTDEVNrL  r.   r.   r.   r/   r    rY  r  c                   @  r  )	StddevPopNr  r.   r.   r.   r/   r    r  r  c                   @  r  )
StddevSampNr  r.   r.   r.   r/   r    r  r  c                   @  r  )TimeFr  Nr  r.   r.   r.   r/   r    r  r  c                   @  r  )	TimeToStrTF)r4   rO  r  r  Nr  r.   r.   r.   r/   r    r}  r  c                   @  r  )TimeToTimeStrNr  r.   r.   r.   r/   r    r  r  c                   @  r  )
TimeToUnixNr  r.   r.   r.   r/   r    r  r  c                   @  r  )TimeStrToDateNr  r.   r.   r.   r/   r    r  r  c                   @  r  )TimeStrToTimeTFr  Nr  r.   r.   r.   r/   r    r  r  c                   @  r  )TimeStrToUnixNr  r.   r.   r.   r/   r    r  r  c                   @  r  )TrimTF)r4   r?   rs  	collationNr  r.   r.   r.   r/   r    r  r  c                   @  s(   e Zd ZdddddZed	ddZdS )
	TsOrDsAddTF)r4   r?   r  rG  rO   r   c                 C  s   t | jdpt jjS )NrG  )r   r   r@   rh   re  r  rb   r.   r.   r/   rG    r  zTsOrDsAdd.return_typeNr  )r0   r1   r2   r  r  rG  r.   r.   r.   r/   r     s    r  c                   @  rZ  )
TsOrDsDiffTFr  Nr  r.   r.   r.   r/   r  	  rK  r  c                   @  r  )TsOrDsToDateStrNr  r.   r.   r.   r/   r    r  r  c                   @  rH  )TsOrDsToDateTFr  Nr  r.   r.   r.   r/   r     rK  r   c                   @  r  )TsOrDsToDatetimeNr  r.   r.   r.   r/   r!    r  r!  c                   @  rH  )TsOrDsToTimeTFr  Nr  r.   r.   r.   r/   r"    rK  r"  c                   @  r  )TsOrDsToTimestampNr  r.   r.   r.   r/   r#    r  r#  c                   @  r  )
TsOrDiToDiNr  r.   r.   r.   r/   r$  !  r  r$  c                   @  r  )UnhexTFr2  Nr  r.   r.   r.   r/   r%  %  r  r%  c                   @  r  )UnicodeNr  r.   r.   r.   r/   r&  )  r  r&  c                   @  r  )UnixDateNr  r.   r.   r.   r/   r'  .  r  r'  c                   @  r  )	UnixToStrTFr  Nr  r.   r.   r.   r/   r(  2  r  r(  c                   @  s   e Zd ZdddddddZedZedZedZedZ	edZ
ed	Zed
ZedZedZedZdS )
UnixToTimeTF)r4   r0  r  hoursminutesrO  r   r   r     r              	   N)r0   r1   r2   r  rp   r}  SECONDSDECISCENTISMILLIS
DECIMILLISCENTIMILLISMICROS
DECIMICROSCENTIMICROSNANOSr.   r.   r.   r/   r)  8  s$    
	







r)  c                   @  r  )UnixToTimeStrNr  r.   r.   r.   r/   r<  N  r  r<  c                   @  r  )UnixSecondsNr  r.   r.   r.   r/   r=  R  r  r=  c                   @  s   e Zd Zg dZdddZdS )Uuid)r]  GEN_RANDOM_UUIDGENERATE_UUIDUUID_STRINGFr+  Nr  r.   r.   r.   r/   r>  V  s    r>  c                
   @  s,   e Zd ZddgZdddddddddd	ZdS )TimestampFromPartsTIMESTAMP_FROM_PARTSTIMESTAMPFROMPARTSTF)	r  r  r  r  r  r  r  r  milliNr  r.   r.   r.   r/   rB  \  s    
rB  c                   @  rH  )UpperUPPERUCASENrL  r.   r.   r.   r/   rF  k  rY  rF  c                   @  r  )CorrNr  r.   r.   r.   r/   rI  o  r  rI  c                   @  r  )Variance)VARIANCEVARIANCE_SAMPVAR_SAMPNrL  r.   r.   r.   r/   rJ  s  rY  rJ  c                   @  rH  )VariancePopVARIANCE_POPVAR_POPNrL  r.   r.   r.   r/   rN  w  rY  rN  c                   @  r  )	CovarSampNr  r.   r.   r.   r/   rQ  {  r  rQ  c                   @  r  )CovarPopNr  r.   r.   r.   r/   rR    r  rR  c                   @  r  )r  TF)r4   r  Nr  r.   r.   r.   r/   r    r  r  c                   @  s   e Zd ZdgZdddZdS )
XMLElement
XMLELEMENTTFr=  Nr  r.   r.   r.   r/   rS    r  rS  c                   @  r  )XMLTableTF)r4   
namespacesrP  r   by_refNr  r.   r.   r.   r/   rU    rf  rU  c                   @  r  )XMLNamespaceNr  r.   r.   r.   r/   rX    r  rX  c                   @  r  )XMLKeyValueOptionTFr2  Nr  r.   r.   r.   r/   rY    r  rY  c                   @  r  )YearNr  r.   r.   r.   r/   rZ    r  rZ  c                   @  r]  )UseF)r4   rl   r%  Nr  r.   r.   r.   r/   r[    rK  r[  c                   @  s   e Zd ZdddddddZdS )MergeTF)r4   r|  r<  whensr  r!  Nr  r.   r.   r.   r/   r\    rP  r\  c                   @  s   e Zd ZdddddZdS )WhenTF)matchedrF  r  r~  Nr  r.   r.   r.   r/   r^    r}  r^  c                   @  s   e Zd ZdZddiZdS )Whensz:Wraps around one or more WHEN [NOT] MATCHED [...] clauses.rl   TNr  r.   r.   r.   r/   r`    s    r`  c                   @  r  )NextValueForTF)r4   r  Nr  r.   r.   r.   r/   ra    r  ra  c                   @  r  )	SemicolonNr  r.   r.   r.   r/   rb    r  rb  c                   @  r  )TableColumnNr  r.   r.   r.   r/   rc    r  rc  c                 C  s   t | tu r
|  S | S rI   )rQ   rm   r$   )r   r.   r.   r/   rW        rW   c                 C  s    i | ]}|  D ]}||qqS r.   r  )rX   funcrt   r.   r.   r/   r)    r  r)  )r   r  r   sql_or_expressionrO  r  r   r   r   r  r/  r   rP   rO   r   c                K  r  rI   r.   rf  r  r   r  r   r   r.   r.   r/   rL       	rL  )r  r   r  r   str | Et.Optional[IntoType]c                K  r  rI   r.   rg  r.   r.   r/   rL    rh  c                K  sd   t | tr|r|  S | S | du rtdddl}t| }|r&| d| }|j|f||d|S )aU  Gracefully handle a possible string or expression.

    Example:
        >>> maybe_parse("1")
        Literal(this=1, is_string=False)
        >>> maybe_parse(to_identifier("x"))
        Identifier(this=x, quoted=False)

    Args:
        sql_or_expression: the SQL code string or an expression
        into: the SQLGlot Expression to parse into
        dialect: the dialect used to parse the input expressions (in the case that an
            input expression is a SQL string).
        prefix: a string to prefix the sql with before it gets parsed
            (automatically includes a space)
        copy: whether to copy the expression.
        **opts: other options to use to parse the input expressions (again, in the case
            that an input expression is a SQL string).

    Returns:
        Expression: the parsed or given expression.
    NzSQL cannot be Noner    )ri  r  )rn   r>   r   r   rk  rm   rh  )rf  r  r   r  r   r   rk  r   r.   r.   r/   rL    s   
Tr  r   c                 C  r  rI   r.   r  r   r.   r.   r/   rU  #  r
  rU  c                 C  r  rI   r.   rl  r.   r.   r/   rU  '  r
  c                 C  s   |r| r|   S | S rI   r   rl  r.   r.   r/   rU  +  r  r   rH   r   levelrd   repr_strrm   c                   sT  dd d   }d| }t | trnfdd| j D }| js#r-t | ts-| j|d< | js2r7| j|d< r?t| |d	< |  rGd
}d}| j	pQt | t
oQ| j| fdd| D }| jj d| | dS t | tr| fdd| D }|r| | nd
}d| dS rt | trt| } |tt| d S )z7Generate a textual representation of an Expression tree
z  r   r   c                   s*   i | ]\}}|d ur|g ks r||qS rI   r.   r^   r   r.   r/   r)  5  s   * z_to_s.<locals>.<dictcomp>rE   	_comments_idr!   z, c              
     s.   g | ]\}}| d t | d d qS )r   r   )rn  r   r^   rm  rn  r   r.   r/   r   F  s   . z_to_s.<locals>.<listcomp>(r  c                 3  s     | ]}t | d  V  qdS )r   Nr   )rX   i)rm  r   r.   r/   rZ   K  s    z_to_s.<locals>.<genexpr>[])rn   r>   r@   rJ   rQ   r   rD   idr   rw   ro   r.  r   r-   r0   r\   rm   reprtextwrapdedentr   
splitlines)r   r   rm  rn  indentdelimr@   rJ   r.   rr  r/   r   /  s2   





r   c                 C  s   t | to
t | | S rI   )rn   r>   )r?   r  r.   r.   r/   _is_wrong_expressionW  r   r~  r4   c           	      K  sN   t | |r|di || i} t||}td| |||d|} |||  |S )N)rf  r  r  r   r.   )r~  rU  rL  r   )	r?   r  r   r   r  r  r   r  r   r.   r.   r/   r  [  s   

r  )r   r   r  r  r   r&  c                 O  s   t | |} g }
|d u ri n|}|D ]5}|d urFt||r"||gd}t|f|||d|	}|j D ]\}}|dkrA|
| q3|||< q3q| j|}|rV|rV|j|
 }
||
d}| D ]
\}}||| q_| || | S )NrR  r  r   r  rl   )	rU  r~  rL  r@   rJ   r  rh   rl   r   )r  r   r   r   r  r  r   r&  rl   r   parsedr?   r_   r`   existingchildr.   r.   r/   r  t  s:   




r  )r   r   r  r  r   c                   sN   t | |}	 fdd|D }|	j|}
|r|
r|
| }|	|| |	S )Nc              	     s,   g | ]}|d urt d| dqS )N)rf  r  r  r   r.   r  r  r   r  r   r  r.   r/   r     s    z'_apply_list_builder.<locals>.<listcomp>)rU  r@   rh   r   )r  r   r   r   r  r  r   rl   r   r  existing_expressionsr.   r  r/   r    s   
r  )r  r   r   r   c                 O  s   dd |D }|s| S t | |}|j|}	|r(|	d ur(|r!|	jn|	gt| }t|||d|}
|||r?||
d |S |
 |S )Nc                 S  s    g | ]}|d ur|dkr|qS r    r.   )rX   expr.   r.   r/   r     r  z._apply_conjunction_builder.<locals>.<listcomp>r  r  )rU  r@   rh   r4   r\   r  r   )r  r   r  r   r   r   rl   r   r  r  r   r.   r.   r/   r    s   

r  r   r1  r  r/  r  r   r  c	              	   K  sr   t |f|td|	}
t |f||d|	}|r"t|ts"t|d}t||
||d}t|| d||td|p5didS )	Nr   r  r  r  )r4   r   r  r  r  r  F)r  r   r   r   r  r&  )rL  r   rn   r   r  r  r~  )r  r   r1  r  r  r   r   r   r  r   alias_expressionas_expressioncter.   r.   r/   r    s   

r  rl    t.Sequence[t.Optional[ExpOrStr]]r  t.Type[Connector]r  c           
        sX    fdd| D }|^}}|r|rt |t}|D ]}	|||r%t |	tn|	d}q|S )Nc                   s*   g | ]}|d urt |f dqS )Nr  )r  r  r   r   r   r.   r/   r     s
    z_combine.<locals>.<listcomp>r2  )r4  r  )
rl   r  r   r   r  r   
conditionsr4   restr?   r.   r  r/   _combine  s   
r  r?   r%  t.Type[Expression]c                 C  r  rI   r.   r?   r%  r.   r.   r/   r4    r
  r4  	E | Parenc                 C  r  rI   r.   r  r.   r.   r/   r4    r
  r   t.Optional[E] | Parenc                 C  s   t | |r
t| dS | S r  )rn   r   r  r.   r.   r/   r4    rd  )r  r   r   set_operation	t.Type[S]r  c                   s(   t fdd fdd|D S )Nc                   s   d| | dS )N)r4   r?   r  r.   r.   r  )r  r   r  r.   r/   r   &  rW  z&_apply_set_operation.<locals>.<lambda>c                 3  s&    | ]}t |f d V  qdS )r  Nr  r:  r  r.   r/   rZ   '  s   $ z'_apply_set_operation.<locals>.<genexpr>r   )r  r  r   r   rl   r   r.   )r   r   r  r   r  r/   _apply_set_operation  s   r  c                 O  ,   t |dks
J dt|t| ||d|S )a  
    Initializes a syntax tree for the `UNION` operation.

    Example:
        >>> union("SELECT * FROM foo", "SELECT * FROM bla").sql()
        'SELECT * FROM foo UNION SELECT * FROM bla'

    Args:
        expressions: the SQL code strings, corresponding to the `UNION`'s operands.
            If `Expression` instances are passed, they will be used as-is.
        distinct: set the DISTINCT flag if and only if this is true.
        dialect: the dialect used to parse the input expression.
        copy: whether to copy the expression.
        opts: other options to use to parse the input expressions.

    Returns:
        The new Union instance.
    r  z1At least two expressions are required by `union`.r  r  r   r   )r   r  r   r  r   r   rl   r   r.   r.   r/   r  +     
r  c                 O  r  )a  
    Initializes a syntax tree for the `INTERSECT` operation.

    Example:
        >>> intersect("SELECT * FROM foo", "SELECT * FROM bla").sql()
        'SELECT * FROM foo INTERSECT SELECT * FROM bla'

    Args:
        expressions: the SQL code strings, corresponding to the `INTERSECT`'s operands.
            If `Expression` instances are passed, they will be used as-is.
        distinct: set the DISTINCT flag if and only if this is true.
        dialect: the dialect used to parse the input expression.
        copy: whether to copy the expression.
        opts: other options to use to parse the input expressions.

    Returns:
        The new Intersect instance.
    r  z5At least two expressions are required by `intersect`.r  )r   r  r  r  r.   r.   r/   r  J  r  r  c                 O  r  )a  
    Initializes a syntax tree for the `EXCEPT` operation.

    Example:
        >>> except_("SELECT * FROM foo", "SELECT * FROM bla").sql()
        'SELECT * FROM foo EXCEPT SELECT * FROM bla'

    Args:
        expressions: the SQL code strings, corresponding to the `EXCEPT`'s operands.
            If `Expression` instances are passed, they will be used as-is.
        distinct: set the DISTINCT flag if and only if this is true.
        dialect: the dialect used to parse the input expression.
        copy: whether to copy the expression.
        opts: other options to use to parse the input expressions.

    Returns:
        The new Except instance.
    r  z3At least two expressions are required by `except_`.r  )r   r  r  r  r.   r.   r/   r  i  r  r  r   c                 O  s   t  j|d| i|S )a  
    Initializes a syntax tree from one or multiple SELECT expressions.

    Example:
        >>> select("col1", "col2").from_("tbl").sql()
        'SELECT col1, col2 FROM tbl'

    Args:
        *expressions: the SQL code string to parse as the expressions of a
            SELECT statement. If an Expression instance is passed, this is used as-is.
        dialect: the dialect used to parse the input expressions (in the case that an
            input expression is a SQL string).
        **opts: other options to use to parse the input expressions (again, in the case
            that an input expression is a SQL string).

    Returns:
        Select: the syntax tree for the SELECT statement.
    r   )r   r  )r   rl   r   r.   r.   r/   r    s   r  c                 K  s   t  j| fd|i|S )a  
    Initializes a syntax tree from a FROM expression.

    Example:
        >>> from_("tbl").select("col1", "col2").sql()
        'SELECT col1, col2 FROM tbl'

    Args:
        *expression: the SQL code string to parse as the FROM expressions of a
            SELECT statement. If an Expression instance is passed, this is used as-is.
        dialect: the dialect used to parse the input expression (in the case that the
            input expression is a SQL string).
        **opts: other options to use to parse the input expressions (again, in the case
            that the input expression is a SQL string).

    Returns:
        Select: the syntax tree for the SELECT statement.
    r   )r   r  )r?   r   r   r.   r.   r/   r    s   r  r8   str | Tabler&  t.Optional[dict]r  r  !t.Optional[t.Dict[str, ExpOrStr]]c           	   	     s   t t| t dd}|r|d fdd| D  |r.|dt|ft dd t|tr8t|d}|rJ|d	t|ft d
d |ra fdd| D }|dt	|d |S )a  
    Creates an update statement.

    Example:
        >>> update("my_table", {"x": 1, "y": "2", "z": None}, from_="baz_cte", where="baz_cte.id > 1 and my_table.id = baz_cte.id", with_={"baz_cte": "SELECT id FROM foo"}).sql()
        "WITH baz_cte AS (SELECT id FROM foo) UPDATE my_table SET x = 1, y = '2', z = NULL FROM baz_cte WHERE baz_cte.id > 1 AND my_table.id = baz_cte.id"

    Args:
        properties: dictionary of properties to SET which are
            auto converted to sql objects eg None -> NULL
        where: sql conditional parsed into a WHERE statement
        from_: sql statement parsed into a FROM statement
        with_: dictionary of CTE aliases / select statements to include in a WITH clause.
        dialect: the dialect used to parse the input expressions.
        **opts: other options to use to parse the input expressions.

    Returns:
        Update: the syntax tree for the UPDATE statement.
    r  r  rl   c                   s0   g | ]\}}t t|fd  it|dqS )r   r2  )re  rL  r3  r^   r   r   r.   r/   r     s    zupdate.<locals>.<listcomp>rl  r  r  r  WHEREc                   s4   g | ]\}}t tt|fd  id|ddqS )r   r  Tr  )r0  r  rL  )rX   r   qryr  r.   r/   r     s    "r  rR  )
r  rL  r  r   rJ   r)  rn   r  r  r~  )	r8   r&  r  r  r  r   r   update_exprcte_listr.   r  r/   r+    s:   

r+  r!  c                 K  sV   t  j| f|dd|}|r|j|f|dd|}|r)|j|f|dd|}|S )a  
    Builds a delete statement.

    Example:
        >>> delete("my_table", where="id > 1").sql()
        'DELETE FROM my_table WHERE id > 1'

    Args:
        where: sql conditional parsed into a WHERE statement
        returning: sql conditional parsed into a RETURNING statement
        dialect: the dialect used to parse the input expressions.
        **opts: other options to use to parse the input expressions.

    Returns:
        Delete: the syntax tree for the DELETE statement.
    Fr  )r  r  r  r!  )r8   r  r!  r   r   delete_exprr.   r.   r/   r    s   r  r   (t.Optional[t.Sequence[str | Identifier]]r   c                   sz   t | f| d|}t |ft| d|}	|r&t|	 fdd|D d}	t|	||d}
|r;|
j|f|dd|}
|
S )a  
    Builds an INSERT statement.

    Example:
        >>> insert("VALUES (1, 2, 3)", "tbl").sql()
        'INSERT INTO tbl VALUES (1, 2, 3)'

    Args:
        expression: the sql string or expression of the INSERT statement
        into: the tbl to insert data to.
        columns: optionally the table's column names.
        overwrite: whether to INSERT OVERWRITE or not.
        returning: sql conditional parsed into a RETURNING statement
        dialect: the dialect used to parse the input expressions.
        copy: whether to copy the expression.
        **opts: other options to use to parse the input expressions.

    Returns:
        Insert: the syntax tree for the INSERT statement.
    r  r  r   r   c                   rH  rI  r  r   r   r.   r/   r   2  r<  zinsert.<locals>.<listcomp>r=  )r4   r?   r   F)rL  r  r  r=  r!  )r?   r  r   r   r!  r   r   r   r  r4   r   r.   r   r/   r     s   r   )r!  r   r   
when_exprsr|  r<  c                 O  s   g }|D ]}	t |	f||td|}
|t|
tr|
gn|
j qtt | f||d|t |f||d|t |f||d|t|dd}|rU|j|f|dd|}|S )aK  
    Builds a MERGE statement.

    Example:
        >>> merge("WHEN MATCHED THEN UPDATE SET col1 = source_table.col1",
        ...       "WHEN NOT MATCHED THEN INSERT (col1) VALUES (source_table.col1)",
        ...       into="my_table",
        ...       using="source_table",
        ...       on="my_table.id = source_table.id").sql()
        'MERGE INTO my_table USING source_table ON my_table.id = source_table.id WHEN MATCHED THEN UPDATE SET col1 = source_table.col1 WHEN NOT MATCHED THEN INSERT (col1) VALUES (source_table.col1)'

    Args:
        *when_exprs: The WHEN clauses specifying actions for matched and unmatched rows.
        into: The target table to merge data into.
        using: The source table to merge data from.
        on: The join condition for the merge.
        returning: The columns to return from the merge.
        dialect: The dialect used to parse the input expressions.
        copy: Whether to copy the expression.
        **opts: Other options to use to parse the input expressions.

    Returns:
        Merge: The syntax tree for the MERGE statement.
    )r   r   r  r  rR  )r4   r|  r<  r]  F)rL  r`  r  rn   r^  rl   r\  r!  )r  r|  r<  r!  r   r   r  r   rl   	when_exprr?   r  r.   r.   r/   r  <  s   "r  c                 K  s   t | ft||d|S )a  
    Initialize a logical condition expression.

    Example:
        >>> condition("x=1").sql()
        'x = 1'

        This is helpful for composing larger logical syntax trees:
        >>> where = condition("x=1")
        >>> where = where.and_("y=1")
        >>> Select().from_("tbl").select("*").where(where).sql()
        'SELECT * FROM tbl WHERE x = 1 AND y = 1'

    Args:
        *expression: the SQL code string to parse.
            If an Expression instance is passed, this is used as-is.
        dialect: the dialect used to parse the input expression (in the case that the
            input expression is a SQL string).
        copy: Whether to copy `expression` (only applies to expressions).
        **opts: other options to use to parse the input expressions (again, in the case
            that the input expression is a SQL string).

    Returns:
        The new Condition instance
    r  )rL  r  )r?   r   r   r   r.   r.   r/   r  o  s   r  r  c                 O  "   t tt|t| f||d|S )a  
    Combine multiple conditions with an AND logical operator.

    Example:
        >>> and_("x=1", and_("y=1", "z=1")).sql()
        'x = 1 AND (y = 1 AND z = 1)'

    Args:
        *expressions: the SQL code strings to parse.
            If an Expression instance is passed, this is used as-is.
        dialect: the dialect used to parse the input expression.
        copy: whether to copy `expressions` (only applies to Expressions).
        wrap: whether to wrap the operands in `Paren`s. This is true by default to avoid
            precedence issues, but can be turned off when the produced AST is too deep and
            causes recursion-related issues.
        **opts: other options to use to parse the input expressions.

    Returns:
        The new condition
    r   r  )rM  rN  r  r  r  r   r   r  rl   r   r.   r.   r/   r       "r  c                 O  r  )a  
    Combine multiple conditions with an OR logical operator.

    Example:
        >>> or_("x=1", or_("y=1", "z=1")).sql()
        'x = 1 OR (y = 1 OR z = 1)'

    Args:
        *expressions: the SQL code strings to parse.
            If an Expression instance is passed, this is used as-is.
        dialect: the dialect used to parse the input expression.
        copy: whether to copy `expressions` (only applies to Expressions).
        wrap: whether to wrap the operands in `Paren`s. This is true by default to avoid
            precedence issues, but can be turned off when the produced AST is too deep and
            causes recursion-related issues.
        **opts: other options to use to parse the input expressions.

    Returns:
        The new condition
    r  )rM  rN  r  r  r  r  r.   r.   r/   r"    r  r"  c                 O  r  )a  
    Combine multiple conditions with an XOR logical operator.

    Example:
        >>> xor("x=1", xor("y=1", "z=1")).sql()
        'x = 1 XOR (y = 1 XOR z = 1)'

    Args:
        *expressions: the SQL code strings to parse.
            If an Expression instance is passed, this is used as-is.
        dialect: the dialect used to parse the input expression.
        copy: whether to copy `expressions` (only applies to Expressions).
        wrap: whether to wrap the operands in `Paren`s. This is true by default to avoid
            precedence issues, but can be turned off when the produced AST is too deep and
            causes recursion-related issues.
        **opts: other options to use to parse the input expressions.

    Returns:
        The new condition
    r  )rM  rN  r  r  r%  r  r.   r.   r/   xor  r  r  c                 K  s&   t | f||d|}tt|tdS )a  
    Wrap a condition with a NOT operator.

    Example:
        >>> not_("this_suit='black'").sql()
        "NOT this_suit = 'black'"

    Args:
        expression: the SQL code string to parse.
            If an Expression instance is passed, this is used as-is.
        dialect: the dialect used to parse the input expression.
        copy: whether to copy the expression or not.
        **opts: other options to use to parse the input expressions.

    Returns:
        The new condition.
    r  r  )r  r  r4  r  )r?   r   r   r   r4   r.   r.   r/   r$    s   r$  c                 C  s   t t| |ddS )aR  
    Wrap an expression in parentheses.

    Example:
        >>> paren("5 + 3").sql()
        '(5 + 3)'

    Args:
        expression: the SQL code string to parse.
            If an Expression instance is passed, this is used as-is.
        copy: whether to copy the expression or not.

    Returns:
        The wrapped expression.
    r   r  )r   rL  )r?   r   r.   r.   r/   paren	  s   r  z^[_a-zA-Z][\w]*$zt.Pattern[str]SAFE_IDENTIFIER_RErt   r.  c                 C  r  rI   r.   rt   r.  r   r.   r.   r/   r    r
  r  r-  c                 C  r  rI   r.   r  r.   r.   r/   r  #  s   c                 C  sb   | du rdS t | trt| |}|S t | tr)t| |du r#t|  n|d}|S td| j )zBuilds an identifier.

    Args:
        name: The name to turn into an identifier.
        quoted: Whether to force quote the identifier.
        copy: Whether to copy name if it's an Identifier.

    Returns:
        The identifier ast node.
    Nr1  z1Name needs to be a string or an Identifier, got: )rn   ro   rU  rm   r  rm  r{   r-   )rt   r.  r   
identifierr.   r.   r/   r  )  s   


c              	   C  s6   z
t | |td}W |S  ttfy   t| }Y |S w )z
    Parses a given string into an identifier.

    Args:
        name: The name to parse into an identifier.
        dialect: The dialect to parse against.

    Returns:
        The identifier ast node.
    r  )rL  ro   r   r   r  )rt   r   r?   r.   r.   r/   parse_identifierD  s   
r  z+\s*(-?[0-9]+(?:\.[0-9]+)?)\s*([a-zA-Z]+)\s*r  str | Literalc                 C  s>   t | tr| jstd| j} td|  } t | tsJ | S )zGBuilds an interval expression from a string like '1 day' or '5 months'.zInvalid interval string.z	INTERVAL )rn   rp   rw   r{   r4   rL  r  )r  r.   r.   r/   to_intervalZ  s   
r  sql_pathc           
      K  s   t | trt| |dS z	t| t|d}W n ty0   t| dd\}}}|s' t|||d}Y nw | D ]
\}}	|||	 q5|S )a  
    Create a table expression from a `[catalog].[schema].[table]` sql path. Catalog and schema are optional.
    If a table is passed in then that table is returned.

    Args:
        sql_path: a `[catalog].[schema].[table]` string.
        dialect: the source dialect according to which the table name will be parsed.
        copy: Whether to copy a table if it is passed in.
        kwargs: the kwargs to instantiate the resulting `Table` expression with.

    Returns:
        A table expression.
    r   r  r  r,  )r5   r6   )	rn   r  rU  rL  r   r   table_rJ   r   )
r  r   r   r  r8   r6   r5   r4   r_   r`   r.   r.   r/   to_tableg  s   
r  str | Columnc           	      K  s   t | trt| |dS z	t| t|d}W n ty+   tt| dd|i| Y S w | D ]
\}}|	|| q0|rK|
tD ]}|	dd qB|S )a  
    Create a column from a `[table].[column]` sql path. Table is optional.
    If a column is passed in then that column is returned.

    Args:
        sql_path: a `[table].[column]` string.
        quoted: Whether or not to force quote identifiers.
        dialect: the source dialect according to which the column name will be parsed.
        copy: Whether to copy a column if it is passed in.
        kwargs: the kwargs to instantiate the resulting `Column` expression with.

    Returns:
        A column expression.
    r   r  r  r.  T)rn   r~   rU  rL  r   r  r   r   rJ   r   r   ro   )	r  r.  r   r   r  r;   r_   r`   rt  r.   r.   r/   r    s   
 r  t.Optional[str | Identifier]#bool | t.Sequence[str | Identifier]c           
      K  s   t | f||d|}t||d}|r4t|d}|d| t|ts2|D ]}	|dt|	|d q%|S d|jv rFt|tsF|d| |S t	||dS )a  Create an Alias expression.

    Example:
        >>> alias_('foo', 'bar').sql()
        'foo AS bar'

        >>> alias_('(select 1, 2)', 'bar', table=['a', 'b']).sql()
        '(SELECT 1, 2) AS bar(a, b)'

    Args:
        expression: the SQL code strings to parse.
            If an Expression instance is passed, this is used as-is.
        alias: the alias name to use. If the name has
            special characters it is quoted.
        table: Whether to create a table alias, can also be a list of columns.
        quoted: whether to quote the alias
        dialect: the dialect used to parse the input expression.
        copy: Whether to copy the expression.
        **opts: other options to use to parse the input expressions.

    Returns:
        Alias: the aliased expression
    r  r.  r  r   r   r  )
rL  r  r   r   rn   rP   r   r  r  r   )
r?   r   r8   r.  r   r   r   r  r   r  r.   r.   r/   r0    s    

r0  r  c                 K  s:   t | fd|i|j|fi |} t j| fd|i|S )aA  
    Build a subquery expression that's selected from.

    Example:
        >>> subquery('select x from tbl', 'bar').select('x').sql()
        'SELECT x FROM (SELECT x FROM tbl) AS bar'

    Args:
        expression: the SQL code strings to parse.
            If an Expression instance is passed, this is used as-is.
        alias: the alias name to use.
        dialect: the dialect used to parse the input expression.
        **opts: other options to use to parse the input expressions.

    Returns:
        A new Select instance with the subquery expression included.
    r   )rL  rT  r   r  )r?   r   r   r   r.   r.   r/   rT    s   "rT  r.  r   r;   r5   r6   r  &t.Collection[t.Union[str, Identifier]]c                C  r  rI   r.   r;   r8   r5   r6   r  r.  r   r.   r.   r/   r        r  )r  r.  r   str | Identifier | Starr  c                C  r  rI   r.   r  r.   r.   r/   r     r  c             	     sp   t | tst|  d} t| t| dt| dt| dd}|r6t|g fdd|D R }|S )am  
    Build a Column.

    Args:
        col: Column name.
        table: Table name.
        db: Database name.
        catalog: Catalog name.
        fields: Additional fields using dots.
        quoted: Whether to force quotes on the column's identifiers.
        copy: Whether to copy identifiers if passed in.

    Returns:
        The new Column instance.
    r  r7   c                 3  s    | ]
}t | d V  qdS )r  Nr  )rX   ru   r   r.  r.   r/   rZ   G   r   zcolumn.<locals>.<genexpr>)rn   rr   r  r~   r  r   )r;   r8   r5   r6   r  r.  r   r4   r.   r  r/   r  "   s   
r  rf  c                 K  s   t | f||d|}tj|f||d|}t|trIddlm} ||}|jj	}	|j
j}
|j}|	|
|
j|	||jk}||sG|rI|S t||d}||_|S )a/  Cast an expression to a data type.

    Example:
        >>> cast('x + 1', 'int').sql()
        'CAST(x + 1 AS INT)'

    Args:
        expression: The expression to cast.
        to: The datatype to cast to.
        copy: Whether to copy the supplied expressions.
        dialect: The target dialect. This is used to prevent a re-cast in the following scenario:
            - The expression to be cast is already a exp.Cast expression
            - The existing cast is to a type that is logically equivalent to new type

            For example, if :expression='CAST(x as DATETIME)' and :to=Type.TIMESTAMP,
            but in the target dialect DATETIME is mapped to TIMESTAMP, then we will NOT return `CAST(x (as DATETIME) as TIMESTAMP)`
            and instead just return the original expression `CAST(x as DATETIME)`.

            This is to prevent it being output as a double cast `CAST(x (as TIMESTAMP) as TIMESTAMP)` once the DATETIME -> TIMESTAMP
            mapping is applied in the target dialect generator.

    Returns:
        The new Cast instance.
    r  r   r   r  )rL  r   r   rn   r  sqlglot.dialects.dialectr   r   generator_classTYPE_MAPPINGr  r4   rh   rM   r   rQ   )r?   r  r   r   r   r  	data_typer   target_dialecttype_mappingexisting_cast_typenew_cast_typetypes_are_equivalentr.   r.   r/   rN  L   s$   

rN  Identifier | strc                 C  sV   t | r	t| |dnd|rt||dnd|rt||dnd|r'tt|ddS ddS )a  Build a Table.

    Args:
        table: Table name.
        db: Database name.
        catalog: Catalog name.
        quote: Whether to force quotes on the table's identifiers.
        alias: Table's alias.

    Returns:
        The new Table instance.
    r  Nr  )r4   r5   r6   r   )r  r  r   )r8   r5   r6   r.  r   r.   r.   r/   r     s   r  r   t.Iterable[t.Tuple[t.Any, ...]]3t.Optional[t.Iterable[str] | t.Dict[str, DataType]]c                 C  s^   |r|st dtdd | D |r tt|dd |D ddS |r+tt|ddS ddS )	a  Build VALUES statement.

    Example:
        >>> values([(1, '2')]).sql()
        "VALUES (1, '2')"

    Args:
        values: values statements that will be converted to SQL
        alias: optional alias
        columns: Optional list of ordered column names or ordered dictionary of column names to types.
         If either are provided then an alias is also required.

    Returns:
        Values: the Values expression object
    z(Alias is required when providing columnsc                 S     g | ]}t |qS r.   r9  )rX   tupr.   r.   r/   r      r   zvalues.<locals>.<listcomp>c                 S  r  r.   r  )rX   r  r.   r.   r/   r      r   r  r  Nr  )r{   r  r   r  )r   r   r   r.   r.   r/   r      s   c                 C  s&   | st dt| tr| j} t| dS )a)  Build a SQL variable.

    Example:
        >>> repr(var('x'))
        'Var(this=x)'

        >>> repr(var(column('x', table='y')))
        'Var(this=x)'

    Args:
        name: The name of the var or an expression who's name will become the var.

    Returns:
        The new variable node.
    z#Cannot convert empty name into var.r  )r{   rn   r>   rt   rq   r   r.   r.   r/   var   s
   

r  old_namenew_namec                 C  s.   t | |d}t ||d}t|dt|dgdS )zBuild ALTER TABLE... RENAME... expression

    Args:
        old_name: The old name of the table
        new_name: The new name of the table
        dialect: The dialect to parse the table.

    Returns:
        Alter table expression
    r  r  r  r4   r%  r  )r  r  r  )r  r  r   	old_table	new_tabler.   r.   r/   rename_table   s   r  
table_nameold_column_namenew_column_namer  c                 C  s>   t | |d}t||d}t||d}t|dt|||dgdS )a_  Build ALTER TABLE... RENAME COLUMN... expression

    Args:
        table_name: Name of the table
        old_column: The old name of the column
        new_column: The new name of the column
        exists: Whether to add the `IF EXISTS` clause
        dialect: The dialect to parse the table/column.

    Returns:
        Alter table expression
    r  r  r  r  )r  r  r  r  )r  r  r  r  r   r8   
old_column
new_columnr.   r.   r/   rename_column   s   r  rM   c                   s  t tr
t S t trtS t trtdS du s,t tr/t	
r/t S t tjr:tS t trFt dS t tjrhtjdd}d}jrbttj}t||dS t tjr{td}t|dS t trtdrt fdd	jD d
S t fdd	D d
S t trt fdd	D d
S t t rt!t fdd	D d
t fdd	" D d
dS tdrt fdd	j#$ D d
S t%d )a$  Convert a python value into an expression object.

    Raises an error if a conversion is not possible.

    Args:
        value: A python object.
        copy: Whether to copy `value` (only applies to Expressions and collections).

    Returns:
        The equivalent expression object.
    r  Nrk  )sepr  z%Y-%m-%d_fieldsc                   s*   g | ]}t t|tt| d dqS r   r2  )r  r  r3  getattrrX   r_   r   rM   r.   r/   r   5!  s    zconvert.<locals>.<listcomp>rR  c                   rH  rI  r9  r   r   r.   r/   r   <!  r<  c                   rH  rI  r9  r   r   r.   r/   r   >!  r<  c                   rH  rI  r9  r  r   r.   r/   r   A!  r<  c                   rH  rI  r9  r   r   r.   r/   r   B!  r<  r  r  c                   s(   g | ]\}}t t|t| d dqS r  )r  r  r3  r^   r   r.   r/   r   F!  s    zCannot convert )&rn   r>   rU  rm   rp   r~  rP   r  floatmathisnanrW  numbersNumberr}  bytesr  hexdatetime	isoformattzinfor  datestrftimer  r]   r   r  r  rl  r\   r#  dictr  r   r  rJ   r{   )rM   r   datetime_literaltzdate_literalr.   r  r/   r3  !  sV   














r3  r  r  c                 O  s   t | j D ]E\}}t|tu }|r|n|g}g }|D ]"}	t|	tr9t||	g|R i |D ]}
||
 q0q||	 q| 	||rF|nt
|d qdS )zZ
    Replace children of an expression with the result of a lambda fun(child) -> exp.
    r   N)r]   r@   rJ   rQ   r\   rn   r>   r   r   r   r   )r?   r  r@   r  r_   r`   is_list_argchild_nodesnew_child_nodescn
child_noder.   r.   r/   replace_childrenN!  s   
r  r   r   c                 C  sR   t | j|d}|r'| }||}||ur%|| t|tr%|| |s
|S )z
    Replace an entire tree with the result of function calls on each node.

    This will be traversed in reverse dfs, so leaves first.
    If new nodes are created as a result of function calls, they will also be traversed.
    r   )r\   r   r   r	  rn   r>   r   )r?   r  r   r   r   r  r.   r.   r/   replace_treeb!  s   



r  r!   r  
t.Set[str]c                   s"    fdddd |  tD D S )ap  
    Return all table names referenced through columns in an expression.

    Example:
        >>> import sqlglot
        >>> sorted(column_table_names(sqlglot.parse_one("a.b AND c.d AND c.e")))
        ['a', 'c']

    Args:
        expression: expression to find table names.
        exclude: a table name to exclude

    Returns:
        A list of unique names.
    c                   s   h | ]
}|r| kr|qS r.   r.   )rX   r8   r  r.   r/   	<setcomp>!  s    z%column_table_names.<locals>.<setcomp>c                 s  r  rI   r  )rX   r  r.   r.   r/   rZ   !  r  z%column_table_names.<locals>.<genexpr>)r   r~   )r?   r  r.   r  r/   column_table_names|!  s   
r  Table | stridentifyc                   s<   t | t d} | std|  d fdd| jD S )a9  Get the full name of a table as a string.

    Args:
        table: Table expression node or string.
        dialect: The dialect to generate the table name for.
        identify: Determines when an identifier should be quoted. Possible values are:
            False (default): Never quote, except in cases where it's mandatory by the dialect.
            True: Always quote.

    Examples:
        >>> from sqlglot import exp, parse_one
        >>> table_name(parse_one("select * from a.b.c").find(exp.Table))
        'a.b.c'

    Returns:
        The table name.
    r  zCannot parse r  c                 3  s8    | ]}st |js|j d dddn|jV  qdS )TF)r   r 	  r   rD   N)r  rm  rt   r   r  r   r 	  r.   r/   rZ   !  s    

ztable_name.<locals>.<genexpr>)rL  r  r{   r   r  )r8   r   r 	  r.   r	  r/   r  !  s   c              	   C  s4   ddl m} ddd |t| ||d|djD S )a3  Returns a case normalized table name without quotes.

    Args:
        table: the table to normalize
        dialect: the dialect to use for normalization rules
        copy: whether to copy the expression.

    Examples:
        >>> normalize_table_name("`A-B`.c", dialect="bigquery")
        'A-B.c'
    r   )normalize_identifiersr  c                 s  r  rI   r   )rX   pr.   r.   r/   rZ   !  s
    
z'normalize_table_name.<locals>.<genexpr>r  r  )'sqlglot.optimizer.normalize_identifiersr	  r   r  r  )r8   r   r   r	  r.   r.   r/   normalize_table_name!  s   
r	  mappingt.Dict[str, str]c                   s4    fdd  D d
 fdd}| j||dS )a  Replace all tables in expression according to the mapping.

    Args:
        expression: expression node to be transformed and replaced.
        mapping: mapping of table names.
        dialect: the dialect of the mapping table
        copy: whether to copy the expression.

    Examples:
        >>> from sqlglot import exp, parse_one
        >>> replace_tables(parse_one("select * from a.b"), {"a.b": "c"}).sql()
        'SELECT * FROM c /* a.b */'

    Returns:
        The mapped expression.
    c                      i | ]\}}t | d |qS r  r	  r^   r  r.   r/   r)  !  r*  z"replace_tables.<locals>.<dictcomp>r   r>   rO   c                   sp   t | tr6| jddur6t|  d}|}|r6t|fi dd | j D d i}||g |S | S )Nr	  Fr  c                 S  s   i | ]\}}|t vr||qS r.   )TABLE_PARTSr^   r.   r.   r/   r)  !  r*  z;replace_tables.<locals>._replace_tables.<locals>.<dictcomp>r   )	rn   r  r   rh   r	  r  r@   rJ   r   )r   originalr  r8   r   r	  r.   r/   _replace_tables!  s   
z'replace_tables.<locals>._replace_tablesr   Nr   r>   rO   r>   rJ   r  )r?   r	  r   r   r	  r.   r	  r/   replace_tables!  s   r	  c                 O  s"   ddd}| j |t|fi |S )a  Replace placeholders in an expression.

    Args:
        expression: expression node to be transformed and replaced.
        args: positional names that will substitute unnamed placeholders in the given order.
        kwargs: keyword arguments that will substitute named placeholders.

    Examples:
        >>> from sqlglot import exp, parse_one
        >>> replace_placeholders(
        ...     parse_one("select * from :tbl where ? = ?"),
        ...     exp.to_identifier("str_col"), "b", tbl=exp.to_identifier("foo")
        ... ).sql()
        "SELECT * FROM foo WHERE str_col = 'b'"

    Returns:
        The mapped expression.
    r   r>   rO   c                 [  sX   t | tr*| jr|| j}|d urt|S | S ztt|W S  ty)   Y | S w | S rI   )rn   r  r4   rh   r3  r   StopIteration)r   r@   r  r  r.   r.   r/   _replace_placeholders"  s   
z3replace_placeholders.<locals>._replace_placeholdersNr	  )r  rA  )r?   r@   r  r	  r.   r.   r/   replace_placeholders!  s   
r	  sources*t.Dict[str, Query | t.Callable[[], Query]]c                   s6   fdd|  D d	 fdd | j |dS )
ao  Transforms an expression by expanding all referenced sources into subqueries.

    Examples:
        >>> from sqlglot import parse_one
        >>> expand(parse_one("select * from x AS z"), {"x": parse_one("select * from y")}).sql()
        'SELECT * FROM (SELECT * FROM y) AS z /* source: x */'

        >>> expand(parse_one("select * from x AS z"), {"x": parse_one("select * from y"), "y": parse_one("select * from z")}).sql()
        'SELECT * FROM (SELECT * FROM (SELECT * FROM z) AS y /* source: y */) AS z /* source: x */'

    Args:
        expression: The expression to expand.
        sources: A dict of name to query or a callable that provides a query on demand.
        dialect: The dialect of the sources dict or the callable.
        copy: Whether to copy the expression during transformation. Defaults to True.

    Returns:
        The transformed expression.
    c                   r	  r		  r
	  r^   r  r.   r/   r)  0"  r*  zexpand.<locals>.<dictcomp>r   r>   c                   sf   t | tr1t| d}|}|r1t|r| n|}|| jp!|}d| g|_|j ddS | S )Nr  zsource: Fr   )	rn   r  r	  rh   callablerT  r   rD   r  )r   rt   rF  parsed_sourcerT  _expandr   normalized_sourcesr.   r/   r	  2"  s   

zexpand.<locals>._expandr   N)r   r>   r	  )r?   r	  r   r   r.   r	  r/   expand"  s   r	  r  c          
        s  |r|rt dddlm} | fdd|D } fdd| D }jj|  }|ro|rHd|j	j
v rC||d	}n;||}n6|jd
krV|jdi |}n(t|  }|rg|di |}nt d|  d|ptd|i}tdd| i|}||D ]}	t |	|S )a  
    Returns a Func expression.

    Examples:
        >>> func("abs", 5).sql()
        'ABS(5)'

        >>> func("cast", this=5, to=DataType.build("DOUBLE")).sql()
        'CAST(5 AS DOUBLE)'

    Args:
        name: the name of the function to build.
        args: the args used to instantiate the function of interest.
        copy: whether to copy the argument expressions.
        dialect: the source dialect.
        kwargs: the kwargs used to instantiate the function of interest.

    Note:
        The arguments `args` and `kwargs` are mutually exclusive.

    Returns:
        An instance of the function of interest, or an anonymous function, if `name` doesn't
        correspond to an existing `sqlglot.expressions.Func` class.
    z9Can't use both args and kwargs to instantiate a function.r   r   c                   s   g | ]	}t | d qS r  r  r   r  r.   r/   r   e"  r  zfunc.<locals>.<listcomp>c                   s    i | ]\}}|t | d qS r	  r  )rX   r%   rM   r  r.   r/   r)  f"  r  zfunc.<locals>.<dictcomp>r   r  r  zUnable to convert 'zd' into a Func. Either manually construct the Func expression of interest or parse the function call.rl   r4   Nr.   )r{   r  r   r   rJ   parser_class	FUNCTIONSrh   r3  __code__co_varnamesr0   __self__FUNCTION_BY_NAMEr  r  )
rt   r   r   r@   r  r   	convertedconstructorfunctionerror_messager.   r  r/   re  E"  s2   



re  c                 K  s*   | durt | fi |}nd}t|g dS )a  
    Initialize a CASE statement.

    Example:
        case().when("a = 1", "foo").else_("bar")

    Args:
        expression: Optionally, the input expression (not all dialects support this)
        **opts: Extra keyword arguments for parsing `expression`
    N)r4   r}  )rL  r|  )r?   r   r4   r.   r.   r/   case"  s   r(	  c                      t  fdd|D dS )av  
    Returns an array.

    Examples:
        >>> array(1, 'x').sql()
        'ARRAY(1, x)'

    Args:
        expressions: the expressions to add to the array.
        copy: whether to copy the argument expressions.
        dialect: the source dialect.
        kwargs: the kwargs used to instantiate the function of interest.

    Returns:
        An array expression.
    c                   "   g | ]}t |f d qS r  r  r  r   r   r  r.   r/   r   "      zarray.<locals>.<listcomp>rR  )r#  r   r   rl   r  r.   r+	  r/   array"  
   r.	  c                   r)	  )aq  
    Returns an tuple.

    Examples:
        >>> tuple_(1, 'x').sql()
        '(1, x)'

    Args:
        expressions: the expressions to add to the tuple.
        copy: whether to copy the argument expressions.
        dialect: the source dialect.
        kwargs: the kwargs used to instantiate the function of interest.

    Returns:
        A tuple expression.
    c                   r*	  r  r  r  r+	  r.   r/   r   "  r,	  ztuple_.<locals>.<listcomp>rR  )rl  r-	  r.   r+	  r/   tuple_"  r/	  r0	  c                   C  
   t ddS )z,
    Returns a true Boolean expression.
    Tr  r  r.   r.   r.   r/   r  "     
r  c                   C  r1	  )z-
    Returns a false Boolean expression.
    Fr  r2	  r.   r.   r.   r/   r'  "  r3	  r'  c                   C  s   t  S )z$
    Returns a Null expression.
    )rs   r.   r.   r.   r/   rW  "  s   rW  )rf  rO  r  r   r   r   r  r/  r   rP   rO   r   )rf  ri  r  rj  r   r   r  r/  r   rP   rO   r   )rf  rO  r  rj  r   r   r  r/  r   rP   rO   r>   r  )r  r   r   rP   rO   r   )r  r   r   rP   rO   r   )Fr   F)
r   rH   r   rP   rm  rd   rn  rP   rO   rm   )TNNNr4   r
  )r  r   r   rO  r1  rO  r  r/  r  r/  r   rP   r   r   r   rP   r  rP   rO   r   )NTT)rl   r  r  r  r   r   r   rP   r  rP   rO   r>   )r?   r   r%  r  rO   r   )r?   r   r%  r  rO   r  )r?   r   r%  r  rO   r  )rl   rO  r  r  r  rP   r   r   r   rP   rO   r   )
rl   rO  r  rP   r   r   r   rP   rO   r   )
rl   rO  r  rP   r   r   r   rP   rO   r  )
rl   rO  r  rP   r   r   r   rP   rO   r  )rl   rO  r   r   rO   r   rI   )r?   rO  r   r   rO   r   )NNNNN)r8   r  r&  r  r  r  r  r  r  r  r   r   rO   r  )NNN)
r8   rO  r  r  r!  r  r   r   rO   r  )NNNNT)r?   rO  r  rO  r   r  r   r/  r!  r  r   r   r   rP   rO   r=  )r  rO  r  rO  r|  rO  r<  rO  r!  r  r   r   r   rP   rO   r\  r  )r?   rO  r   r   r   rP   rO   r  r  )r?   rO  r   r   r   rP   rO   r  )r?   rO  r   rP   rO   r   )rt   r   r.  r/  r   rP   rO   r   )rt   r-  r.  r/  r   rP   rO   ro   )rt   r-  r   r   rO   ro   )r  r  rO   r  )r  r  r   r   r   rP   rO   r  r  )
r  r  r.  r/  r   r   r   rP   rO   r~   )FNNT)r?   rO  r   r  r8   r  r.  r/  r   r   r   rP   )NN)r?   rO  r   r  r   r   rO   r   )r;   r-  r8   r  r5   r  r6   r  r  r  r.  r/  r   rP   rO   r  )r;   r  r8   r  r5   r  r6   r  r  r  r.  r/  r   rP   rO   r~   r  )
r?   rO  r  rf  r   rP   r   r   rO   r  )NNNN)r8   r  r5   r  r6   r  r.  r/  r   r  rO   r  )r   r  r   r/  r   r  rO   r  )rt   r  rO   rq   )r  r  r  r  r   r   rO   r  )r  r  r  r  r  r  r  r/  r   r   rO   r  r  )rM   rH   r   rP   rO   r>   )r?   r>   r  r  rO   r   )r?   r>   r  r  r   r   rO   r>   )r!   )r?   r>   r  rm   rO   r  r  )r8   r  r   r   r 	  rP   rO   rm   )r8   r  r   r   r   rP   rO   rm   )
r?   r   r	  r	  r   r   r   rP   rO   r   )r?   r>   rO   r>   )
r?   r>   r	  r	  r   r   r   rP   rO   r>   )rt   rm   r   rP   r   r   rO   r  )r?   r  rO   r|  )rl   rO  r   rP   r   r   rO   r#  )rl   rO  r   rP   r   r   rO   rl  )rO   r  )rO   rs   (A  r&   
__future__r   r  r  r  rery  typingrM  collectionsr   r   r   decimalr   enumr   	functoolsr	   sqlglot.errorsr
   r   sqlglot.helperr   r   r   r   r   r   r   r   sqlglot.tokensr   r   TYPE_CHECKINGtyping_extensionsr   sqlglot._typingr   r   r  r   TypeVarr   r   rQ   r   r   SQLGLOT_ANONYMOUSr	  r  r(  r>   r   rm   re  
CollectionIntoTyperO  r  r  r  r   r  r  r  r  r  r  r$  r9  r@  rI  rM  rQ  rR  rS  rT  rV  rX  r[  r^  ra  rc  rg  rv  rx  r{  r~  r  r  r  r   r  r  r  r  r  r~   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r	  r  r  r  r  r  r  r  r  r  r"  r$  r%  r&  r)  r.  r/  r0  ro   r2  r4  r8  r=  rL  rN  rO  rT  r#  rX  rY  rZ  r]  r_  r`  ra  rf  rj  rp  rq  rr  rs  r  ru  rp   r  r  r  r  r  r  r  r  r  r  r  r  rp  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r	  r
  r  r  r  r  r  r  r  r  r   r!  r#  r$  r%  r&  r'  r(  r*  r+  r,  r-  r.  r/  r0  r1  r2  r3  r4  r5  r7  r8  r9  r;  r<  r=  r?  r@  rg  rh  rj  rk  rl  r  rv  rw  rx  ry  r{  r}  r  r   r  r  r  r  rq   r  r  r  r   UNWRAPPED_QUERIESr   r  r  r  r  r  r  r  r  rr   r  r  r  rs   r  r  r   r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r5  r~  r  r  r  r  r  r  rm  r  r  rf  r  re  r  r  r  r  r  r  rz  r|  rc  r  r  r]  r  ra  r  rv  rx  r  r  rg  r  r  r  r  r  r  r  r   ry   r   r  r  r  r  r  r  r  rZ  r8  r  rG  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r"  r#  r%  r'  r)  r,  r.  r1  r2  r4  r5  r7  r;  r=  r>  r@  rA  rB  rC  rF  rG  rI  rM  rP  rS  rT  rU  rV  rX  r\  r`  rc  re  rg  rk  rl  ro  rp  rq  rr  rs  rt  rv  rw  rx  ry  rz  r{  r|  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r  r  r  r  rV  r
  r  r  r  r  r  r  r  r  r  r   r#  r$  r  r  r%  r  r*  r+  r,  r-  r0  r1  r#  r4  r6  r7  r8  r9  r:  r;  r<  r=  r>  r?  r@  rA  rB  rC  rI  rJ  rK  rM  rN  rR  rT  rU  rV  rW  rZ  r\  r^  r_  ra  rd  rk  rl  rn  rp  rr  rt  rw  rz  r}  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  ri  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r	  r
  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r!  r"  r#  r$  r%  r&  r'  r(  r)  r<  r=  r>  rB  rF  rI  rJ  rN  rQ  rR  r  rS  rU  rX  rY  rZ  r[  r\  r^  r`  ra  rb  rc  rW   r0   ALL_FUNCTIONSr#	  JSON_PATH_PARTSPERCENTILESr  rL  rU  r   r~  r  r  r  r  r  r  r4  r  r  r  r  r  r  r+  r  r   r  r  r  r"  r  r$  r  compiler  r  r  r  INTERVAL_STRING_REr  r  r  r0  rT  r  rN  r  r   r  r  r  r3  r  r  r  r  r	  r	  r	  r	  re  r(	  r.	  r0	  r  r'  rW  NONNULL_CONSTANTS	CONSTANTSr.   r.   r.   r/   <module>   s   (
       X
  M	%
	)


U



D








C	
M9 P    5
  9		&
	
$1	%	


		
 				
0(2% !!?"14'  %*;+6!A"('.@
