
    g%                        d Z ddlmZ ddlmZmZmZmZ ddlm	Z	 dZ
dZ G d de      Z G d	 d
e      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d d e      Z G d! d"e      Z G d# d$e      Z G d% d&e      Z G d' d(e      Z G d) d*e      Z G d+ d,e      Z G d- d.e      Z G d/ d0e      Z  G d1 d2e      Z! G d3 d4e      Z" G d5 d6e      Z# G d7 d8e      Z$ G d9 d:e      Z% G d; d<e      Z& G d= d>e      Z' G d? d@e      Z( G dA dBe      Z) G dC dDe      Z* G dE dFe      Z+ G dG dHe      Z, G dI dJe      Z- G dK dLe      Z. G dM dNe      Z/ G dO dPe      Z0 G dQ dRe      Z1 G dS dTe      Z2 G dU dVe      Z3 G dW dXe      Z4 G dY dZe      Z5 G d[ d\e      Z6 G d] d^e      Z7 G d_ d`e      Z8 G da dbe      Z9 G dc dde      Z: G de dfe      Z; G dg dhe      Z< G di dje      Z= G dk dle      Z>ym)nz$
Package for SQL functions wrappers
    )SqlTypes)AggregateFunctionFunctionLiteralValueStar)builderzTimothy Heysztheys@kayak.comc                   8     e Zd Z fdZ fdZed        Z xZS )DistinctOptionFunctionc                 d    |j                  d      }t        t        |   |g|d|i d| _        y )NaliasF)getsuperr
   __init__	_distinct)selfnameargskwargsr   	__class__s        E/var/www/openai/venv/lib/python3.12/site-packages/pypika/functions.pyr   zDistinctOptionFunction.__init__   s2    

7#$d4TNDNN    c                     t        t        | 
  di |}t        | j                        dz   }| j
                  r|d | dz   ||d  z   S |S )N   z	DISTINCT  )r   r
   get_function_sqllenr   r   )r   r   snr   s       r   r   z'DistinctOptionFunction.get_function_sql   sR    ($@J6J		NQ>>Ra5;&12..r   c                     d| _         y )NT)r   )r   s    r   distinctzDistinctOptionFunction.distinct   s	    r   )__name__
__module____qualname__r   r   r   r    __classcell__r   s   @r   r
   r
      s!    
  r   r
   c                         e Zd Zd fd	Z xZS )Countc                 x    t        |t              xr d|k(  }t        t        |   d|r
t               n||       y )N*COUNTr   )
isinstancestrr   r'   r   r   )r   paramr   is_starr   s       r   r   zCount.__init__%   s5    UC(9SE\eT#GwTVEQV#Wr   Nr!   r"   r#   r   r$   r%   s   @r   r'   r'   $       X Xr   r'   c                         e Zd Zd fd	Z xZS )Sumc                 2    t         t        |   d||       y )NSUMr+   )r   r4   r   r   termr   r   s      r   r   zSum.__init__,       c4!%U!;r   r0   r1   r%   s   @r   r4   r4   +       < <r   r4   c                         e Zd Zd fd	Z xZS )Avgc                 2    t         t        |   d||       y )NAVGr+   )r   r<   r   r7   s      r   r   zAvg.__init__1   r9   r   r0   r1   r%   s   @r   r<   r<   0   r:   r   r<   c                         e Zd Zd fd	Z xZS )Minc                 2    t         t        |   d||       y )NMINr+   )r   r@   r   r7   s      r   r   zMin.__init__6   r9   r   r0   r1   r%   s   @r   r@   r@   5   r:   r   r@   c                         e Zd Zd fd	Z xZS )Maxc                 2    t         t        |   d||       y )NMAXr+   )r   rD   r   r7   s      r   r   zMax.__init__;   r9   r   r0   r1   r%   s   @r   rD   rD   :   r:   r   rD   c                         e Zd Zd fd	Z xZS )Stdc                 2    t         t        |   d||       y )NSTDr+   )r   rH   r   r7   s      r   r   zStd.__init__@   r9   r   r0   r1   r%   s   @r   rH   rH   ?   r:   r   rH   c                         e Zd Zd fd	Z xZS )StdDevc                 2    t         t        |   d||       y )NSTDDEVr+   )r   rL   r   r7   s      r   r   zStdDev.__init__E       fd$Xt5$Ar   r0   r1   r%   s   @r   rL   rL   D       B Br   rL   c                         e Zd Zd fd	Z xZS )Absc                 2    t         t        |   d||       y )NABSr+   )r   rR   r   r7   s      r   r   zAbs.__init__J   r9   r   r0   r1   r%   s   @r   rR   rR   I   r:   r   rR   c                         e Zd Zd fd	Z xZS )Firstc                 2    t         t        |   d||       y )NFIRSTr+   )r   rV   r   r7   s      r   r   zFirst.__init__O       eT#GT#?r   r0   r1   r%   s   @r   rV   rV   N       @ @r   rV   c                         e Zd Zd fd	Z xZS )Lastc                 2    t         t        |   d||       y )NLASTr+   )r   r\   r   r7   s      r   r   zLast.__init__T       dD"64u"=r   r0   r1   r%   s   @r   r\   r\   S       > >r   r\   c                         e Zd Zd fd	Z xZS )Sqrtc                 2    t         t        |   d||       y )NSQRTr+   )r   rb   r   r7   s      r   r   zSqrt.__init__Y   r_   r   r0   r1   r%   s   @r   rb   rb   X   r`   r   rb   c                         e Zd Zd fd	Z xZS )Floorc                 2    t         t        |   d||       y )NFLOORr+   )r   rf   r   r7   s      r   r   zFloor.__init__^   rY   r   r0   r1   r%   s   @r   rf   rf   ]   rZ   r   rf   c                   &     e Zd Zd fd	Zd Z xZS )ApproximatePercentilec                 R    t         t        |   d||       t        |      | _        y )NAPPROXIMATE_PERCENTILEr+   )r   rj   r   float
percentile)r   r8   rn   r   r   s       r   r   zApproximatePercentile.__init__c   s(    #T34LdZ_3`
+r   c                 :    dj                  | j                        S )Nz(USING PARAMETERS percentile={percentile})rn   )formatrn   r   r   s     r   get_special_params_sqlz,ApproximatePercentile.get_special_params_sqlg   s    9@@DOO@\\r   r0   r!   r"   r#   r   rr   r$   r%   s   @r   rj   rj   b   s    ,]r   rj   c                   &     e Zd Zd fd	Zd Z xZS )Castc                 @    t         t        |   d||       || _        y )NCASTr+   )r   ru   r   as_typer   r8   rx   r   r   s       r   r   zCast.__init__m   s     dD"64u"=r   c                     t        | j                  d      r | j                  j                  di |n"t        | j                        j	                         }dj                  |      S )Nget_sqlz	AS {type}typer   )hasattrrx   r{   r-   upperrp   )r   r   type_sqls      r   rr   zCast.get_special_params_sqlq   sU    5<T\\95U'4<<''1&1[^_c_k_k[l[r[r[t!!x!00r   r0   rs   r%   s   @r   ru   ru   l   s    1r   ru   c                   &     e Zd Zd fd	Zd Z xZS )Convertc                 @    t         t        |   d||       || _        y )NCONVERTr+   )r   r   r   encoding)r   r8   r   r   r   s       r   r   zConvert.__init__x   s     gt%iU%C r   c                 N    dj                  | j                  j                        S )NzUSING {type}r|   )rp   r   valuerq   s     r   rr   zConvert.get_special_params_sql|   s     $$$--*=*=$>>r   r0   rs   r%   s   @r   r   r   w   s    !?r   r   c                         e Zd Zd fd	Z xZS )ToCharc                 4    t         t        |   d|||       y )NTO_CHARr+   )r   r   r   ry   s       r   r   zToChar.__init__   s    fd$YgU$Kr   r0   r1   r%   s   @r   r   r      s    L Lr   r   c                         e Zd Zd fd	Z xZS )Signedc                 N    t         t        |   |t        j                  |       y Nr+   )r   r   r   r   SIGNEDr7   s      r   r   zSigned.__init__   s    fd$T8??%$Hr   r0   r1   r%   s   @r   r   r          I Ir   r   c                         e Zd Zd fd	Z xZS )Unsignedc                 N    t         t        |   |t        j                  |       y r   )r   r   r   r   UNSIGNEDr7   s      r   r   zUnsigned.__init__   s    h&tX->->e&Lr   r0   r1   r%   s   @r   r   r      s    M Mr   r   c                         e Zd Zd fd	Z xZS )Datec                 2    t         t        |   d||       y )NDATEr+   )r   r   r   r7   s      r   r   zDate.__init__   r_   r   r0   r1   r%   s   @r   r   r      r`   r   r   c                         e Zd Zd fd	Z xZS )DateDiffc                 6    t         t        |   d||||       y )NDATEDIFFr+   )r   r   r   )r   interval
start_dateend_dater   r   s        r   r   zDateDiff.__init__   s    h&z8ZY^&_r   r0   r1   r%   s   @r   r   r      s    ` `r   r   c                         e Zd Zd fd	Z xZS )TimeDiffc                 4    t         t        |   d|||       y )NTIMEDIFFr+   )r   r   r   )r   
start_timeend_timer   r   s       r   r   zTimeDiff.__init__   s    h&z:xu&Ur   r0   r1   r%   s   @r   r   r      s    V Vr   r   c                         e Zd Zd fd	Z xZS )DateAddc                 b    t        |d|      }t        t        |   dt	        |      |||       y )Nr   DATE_ADDr+   )getattrr   r   r   r   r   	date_partr   r8   r   r   s        r   r   zDateAdd.__init__   s2    Iw	:	gt%j,y2I8UYaf%gr   r0   r1   r%   s   @r   r   r      s    h hr   r   c                         e Zd Zd fd	Z xZS )ToDatec                 4    t         t        |   d|||       y )NTO_DATEr+   )r   r   r   )r   r   format_maskr   r   s       r   r   zToDate.__init__   s    fd$Y{%$Pr   r0   r1   r%   s   @r   r   r      s    Q Qr   r   c                         e Zd Zd fd	Z xZS )	Timestampc                 2    t         t        |   d||       y )N	TIMESTAMPr+   )r   r   r   r7   s      r   r   zTimestamp.__init__   s    i'T'Gr   r0   r1   r%   s   @r   r   r      s    H Hr   r   c                         e Zd Zd fd	Z xZS )TimestampAddc                 b    t        |d|      }t        t        |   dt	        |      |||       y )Nr   TIMESTAMPADDr+   )r   r   r   r   r   r   s        r   r   zTimestampAdd.__init__   s3    Iw	:	lD*><	;RT\^bjo*pr   r0   r1   r%   s   @r   r   r      s    q qr   r   c                         e Zd Zd fd	Z xZS )Asciic                 2    t         t        |   d||       y )NASCIIr+   )r   r   r   r7   s      r   r   zAscii.__init__   rY   r   r0   r1   r%   s   @r   r   r      rZ   r   r   c                        e Zd Z fdZ xZS )NullIfc                 2    t        t        | 
  d||fi | y )NNULLIF)r   r   r   )r   r8   	conditionr   r   s       r   r   zNullIf.__init__   s    fd$XtYI&Ir   r1   r%   s   @r   r   r          J Jr   r   c                         e Zd Zd fd	Z xZS )Binc                 2    t         t        |   d||       y )NBINr+   )r   r   r   r7   s      r   r   zBin.__init__   r9   r   r0   r1   r%   s   @r   r   r      r:   r   r   c                        e Zd Z fdZ xZS )Concatc                 4    t        t        | 
  dg|i | y )NCONCAT)r   r   r   )r   termsr   r   s      r   r   zConcat.__init__   s    fd$X@@@r   r1   r%   s   @r   r   r      s    A Ar   r   c                         e Zd Zd fd	Z xZS )Insertc                 t    ||||fD cg c]  }| c}\  }}}}t         t        |   d|||||       y c c}w )NINSERTr+   )r   r   r   )r   r8   startstopsubtermr   r   s         r   r   zInsert.__init__   sN    8<eT77S%T7Std7S%T"eT7fd$XtUD'QV$W &Us   	5r0   r1   r%   s   @r   r   r      r2   r   r   c                         e Zd Zd fd	Z xZS )Lengthc                 2    t         t        |   d||       y )NLENGTHr+   )r   r   r   r7   s      r   r   zLength.__init__   rO   r   r0   r1   r%   s   @r   r   r      rP   r   r   c                         e Zd Zd fd	Z xZS )Upperc                 2    t         t        |   d||       y )NUPPERr+   )r   r   r   r7   s      r   r   zUpper.__init__   rY   r   r0   r1   r%   s   @r   r   r      rZ   r   r   c                         e Zd Zd fd	Z xZS )Lowerc                 2    t         t        |   d||       y )NLOWERr+   )r   r   r   r7   s      r   r   zLower.__init__   rY   r   r0   r1   r%   s   @r   r   r      rZ   r   r   c                         e Zd Zd fd	Z xZS )	Substringc                 6    t         t        |   d||||       y )N	SUBSTRINGr+   )r   r   r   )r   r8   r   r   r   r   s        r   r   zSubstring.__init__   s    i'T5$e'Tr   r0   r1   r%   s   @r   r   r      s    U Ur   r   c                         e Zd Zd fd	Z xZS )Reversec                 2    t         t        |   d||       y )NREVERSEr+   )r   r   r   r7   s      r   r   zReverse.__init__   s    gt%iU%Cr   r0   r1   r%   s   @r   r   r      s    D Dr   r   c                         e Zd Zd fd	Z xZS )Trimc                 2    t         t        |   d||       y )NTRIMr+   )r   r   r   r7   s      r   r   zTrim.__init__   r_   r   r0   r1   r%   s   @r   r   r      r`   r   r   c                         e Zd Zd fd	Z xZS )	SplitPartc                 6    t         t        |   d||||       y )N
SPLIT_PARTr+   )r   r   r   )r   r8   	delimiterindexr   r   s        r   r   zSplitPart.__init__   s    i'dIuTY'Zr   r0   r1   r%   s   @r   r   r      s    [ [r   r   c                         e Zd Zd fd	Z xZS )RegexpMatchesc                 6    t         t        |   d||||       y )NREGEXP_MATCHESr+   )r   r   r   r   r8   pattern	modifiersr   r   s        r   r   zRegexpMatches.__init__   s    mT+,<dGY^c+dr   NNr1   r%   s   @r   r   r      s    e er   r   c                         e Zd Zd fd	Z xZS )
RegexpLikec                 6    t         t        |   d||||       y )NREGEXP_LIKEr+   )r   r   r   r   s        r   r   zRegexpLike.__init__   s    j$(gyX](^r   r   r1   r%   s   @r   r   r          _ _r   r   c                         e Zd Zd fd	Z xZS )Replacec                 6    t         t        |   d||||       y )NREPLACEr+   )r   r  r   )r   r8   find_stringreplace_withr   r   s        r   r   zReplace.__init__   s    gt%i{LX]%^r   r0   r1   r%   s   @r   r  r     r   r   r  c                         e Zd Zd fd	Z xZS )Nowc                 0    t         t        |   d|       y )NNOWr+   )r   r  r   r   r   r   s     r   r   zNow.__init__  s    c4!%u!5r   r0   r1   r%   s   @r   r  r    s    6 6r   r  c                         e Zd Zd fd	Z xZS )UtcTimestampc                 0    t         t        |   d|       y )NUTC_TIMESTAMPr+   )r   r  r   r
  s     r   r   zUtcTimestamp.__init__  s    lD*?%*Hr   r0   r1   r%   s   @r   r  r    r   r   r  c                   &     e Zd Zd fd	Zd Z xZS )CurTimestampc                 0    t         t        |   d|       y )NCURRENT_TIMESTAMPr+   )r   r  r   r
  s     r   r   zCurTimestamp.__init__  s    lD*+>e*Lr   c                      y)Nr  r   rq   s     r   r   zCurTimestamp.get_function_sql  s     #r   r0   )r!   r"   r#   r   r   r$   r%   s   @r   r  r    s    M#r   r  c                         e Zd Zd fd	Z xZS )CurDatec                 0    t         t        |   d|       y )NCURRENT_DATEr+   )r   r  r   r
  s     r   r   zCurDate.__init__      gt%nE%Br   r0   r1   r%   s   @r   r  r        C Cr   r  c                         e Zd Zd fd	Z xZS )CurTimec                 0    t         t        |   d|       y )NCURRENT_TIMEr+   )r   r  r   r
  s     r   r   zCurTime.__init__  r  r   r0   r1   r%   s   @r   r  r    r  r   r  c                   &     e Zd Zd fd	Zd Z xZS )Extractc                 l    t        |d|      }t        t        |   dt	        |      |       || _        y )Nr   EXTRACTr+   )r   r   r  r   r   field)r   r   r"  r   r   s       r   r   zExtract.__init__!  s4    Iw	:	gt%ii1HPU%V
r   c                 Z    dj                   | j                  j                  di |      S )NzFROM {field})r"  r   )rp   r"  r{   rq   s     r   rr   zExtract.get_special_params_sql&  s+    $$+=4::+=+=+G+G$HHr   r0   rs   r%   s   @r   r  r     s    
Ir   r  c                         e Zd Zd fd	Z xZS )IsNullc                 2    t         t        |   d||       y )NISNULLr+   )r   r%  r   r7   s      r   r   zIsNull.__init__,  rO   r   r0   r1   r%   s   @r   r%  r%  +  rP   r   r%  c                        e Zd Z fdZ xZS )Coalescec                 6    t        t        | 
  d|g|i | y )NCOALESCE)r   r)  r   )r   r8   default_valuesr   r   s       r   r   zCoalesce.__init__1  s    h&z4S.SFSr   r1   r%   s   @r   r)  r)  0  s    T Tr   r)  c                        e Zd Z fdZ xZS )IfNullc                 2    t        t        | 
  d||fi | y )NIFNULL)r   r.  r   )r   r   r8   r   r   s       r   r   zIfNull.__init__6  s    fd$Xy$I&Ir   r1   r%   s   @r   r.  r.  5  r   r   r.  c                         e Zd Zd fd	Z xZS )NVLc                 4    t         t        |   d|||       y )Nr2  r+   )r   r2  r   )r   r   r8   r   r   s       r   r   zNVL.__init__;  s    c4!%D!Fr   r0   r1   r%   s   @r   r2  r2  :  s    G Gr   r2  N)?__doc__pypika.enumsr   pypika.termsr   r   r   r   pypika.utilsr   
__author__	__email__r
   r'   r4   r<   r@   rD   rH   rL   rR   rV   r\   rb   rf   rj   ru   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.  r2  r   r   r   <module>r:     s   "  !
	. &X" X<
  <
<
 <
<
 <
<
 <
<
 <
B B
<
 <
@ @
> >
>8 >
@H @
]- ]18 1?h ?LX L
IT I
Mt M
>8 >
`x `
Vx V
hh hQX Q
H H
q8 q@H @
JX J
<( <
AX A
XX XBX B
@H @
@H @
U U
Dh D
>8 >
[ [
eH e
_ _
_h _6( 6
I8 I
#8 #Ch C
Ch C
Ih IBX B
Tx T
JX J
G( Gr   