o
    8Di                     @  s  d Z ddlmZ ddlZddlZddlmZ ddl	m
Z
mZ ddlmZ ddlmZmZmZmZ ddlmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z)m*Z*m+Z+m,Z,m-Z- dd	l.m/Z/ dd
l0m1Z1 ddl2m3Z3m4Z4 ddl5m6Z6m7Z7m8Z8 ej9rddl:m;Z; ddl	m<Z< e=dZ>z
ddl?m@Z@mAZA W n eBy   e>Cd Y nw dZD	 d1d2ddZE	d1d3ddZFejGd4d"d#ZHejGd5d%d#ZH			d6d7d'd#ZH			(	d8d9d/d0ZIdS ):z!
.. include:: ../README.md

----
    )annotationsN)expressions)DialectDialects)diff)
ErrorLevel
ParseError
TokenErrorUnsupportedError)
Expressionalias_and_casecastcolumn	conditiondeleteexcept_from_funcinsert	intersectmaybe_parsemergenot_or_selectsubquerytable_	to_columnto_identifierto_tableunion)	Generator)Parser)MappingSchemaSchema)Token	Tokenizer	TokenType)E)DialectTypesqlglot)__version____version_tuple__zUUnable to set __version__, run `pip install -e .` or `python setup.py develop` first.Fsqlstrreadr+   dialectreturnt.List[Token]c                 C  s   t |p|| S )a,  
    Tokenizes the given SQL string.

    Args:
        sql: the SQL code string to tokenize.
        read: the SQL dialect to apply during tokenizing (eg. "spark", "hive", "presto", "mysql").
        dialect: the SQL dialect (alias for read).

    Returns:
        The resulting list of tokens.
    )r   get_or_raisetokenize)r/   r1   r2    r7   I/var/www/Datamplify/venv/lib/python3.10/site-packages/sqlglot/__init__.pyr6   H   s   r6   t.List[t.Optional[Expression]]c                 K  s   t |p|j| fi |S )a  
    Parses the given SQL string into a collection of syntax trees, one per parsed SQL statement.

    Args:
        sql: the SQL code string to parse.
        read: the SQL dialect to apply during parsing (eg. "spark", "hive", "presto", "mysql").
        dialect: the SQL dialect (alias for read).
        **opts: other `sqlglot.parser.Parser` options.

    Returns:
        The resulting syntax tree collection.
    r   r5   parse)r/   r1   r2   optsr7   r7   r8   r;   W   s   r;   into	t.Type[E]r*   c                K     d S Nr7   )r/   r=   r<   r7   r7   r8   	parse_onei      rA   r   c                 K  r?   r@   r7   )r/   r<   r7   r7   r8   rA   m   rB   t.Optional[exp.IntoType]c                 K  sn   t |p|}|r|j|| fi |}n	|j| fi |}|D ]}|s+td|  d|  S td|  d)a  
    Parses the given SQL string and returns a syntax tree for the first parsed SQL statement.

    Args:
        sql: the SQL code string to parse.
        read: the SQL dialect to apply during parsing (eg. "spark", "hive", "presto", "mysql").
        dialect: the SQL dialect (alias for read)
        into: the SQLGlot Expression to parse into.
        **opts: other `sqlglot.parser.Parser` options.

    Returns:
        The syntax tree for the first parsed statement.
    zNo expression was parsed from '')r   r5   
parse_intor;   r   )r/   r1   r2   r=   r<   result
expressionr7   r7   r8   rA   q   s   Twriteidentityboolerror_levelt.Optional[ErrorLevel]t.List[str]c                   s@   |r
du r|nnt  fddt| ||dD S )af  
    Parses the given SQL string in accordance with the source dialect and returns a list of SQL strings transformed
    to conform to the target dialect. Each string in the returned list represents a single transformed SQL statement.

    Args:
        sql: the SQL code string to transpile.
        read: the source dialect used to parse the input string (eg. "spark", "hive", "presto", "mysql").
        write: the target dialect into which the input should be transformed (eg. "spark", "hive", "presto", "mysql").
        identity: if set to `True` and if the target dialect is not specified the source dialect will be used as both:
            the source and the target dialect.
        error_level: the desired error level of the parser.
        **opts: other `sqlglot.generator.Generator` options.

    Returns:
        The list of transpiled SQL statements.
    Nc                   s*   g | ]}|rj |fd di ndqS )copyF )generate).0rG   r<   rH   r7   r8   
<listcomp>   s    ztranspile.<locals>.<listcomp>)rK   r:   )r/   r1   rH   rI   rK   r<   r7   rR   r8   	transpile   s
   
rT   )NN)r/   r0   r1   r+   r2   r+   r3   r4   )r/   r0   r1   r+   r2   r+   r3   r9   )r/   r0   r=   r>   r3   r*   )r/   r0   r3   r   )NNN)
r/   r0   r1   r+   r2   r+   r=   rC   r3   r   )NNTN)r/   r0   r1   r+   rH   r+   rI   rJ   rK   rL   r3   rM   )J__doc__
__future__r   loggingtypingtr,   r   expsqlglot.dialects.dialectr   r   sqlglot.diffr   sqlglot.errorsr   r   r	   r
   sqlglot.expressionsr   r   aliasr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   tabler   r    r!   r"   sqlglot.generatorr#   sqlglot.parserr$   sqlglot.schemar%   r&   sqlglot.tokensr'   r(   r)   TYPE_CHECKINGsqlglot._typingr*   r+   	getLoggerloggersqlglot._versionr-   r.   ImportErrorerrorprettyr6   r;   overloadrA   rT   r7   r7   r7   r8   <module>   sT   h
&