o
    8Di2                     @  st   d dl mZ d dlZd dlmZ d dlmZmZ ej	r!d dl
mZ ejddddZejddddZdddZdS )    )annotationsN)exp)DialectDialectType)E
expressionr   dialectr   returnc                 C     d S N r   r   r   r   `/var/www/Datamplify/venv/lib/python3.10/site-packages/sqlglot/optimizer/normalize_identifiers.pynormalize_identifiers      r   strexp.Identifierc                 C  r
   r   r   r   r   r   r   r      r   c                 C  sR   t |}t| trtj| |d} | jdd dD ]}|jds&|	| q| S )a  
    Normalize identifiers by converting them to either lower or upper case,
    ensuring the semantics are preserved in each case (e.g. by respecting
    case-sensitivity).

    This transformation reflects how identifiers would be resolved by the engine corresponding
    to each SQL dialect, and plays a very important role in the standardization of the AST.

    It's possible to make this a no-op by adding a special comment next to the
    identifier of interest:

        SELECT a /* sqlglot.meta case_sensitive */ FROM table

    In this example, the identifier `a` will not be normalized.

    Note:
        Some dialects (e.g. DuckDB) treat all identifiers as case-insensitive even
        when they're quoted, so in these cases all identifiers are normalized.

    Example:
        >>> import sqlglot
        >>> expression = sqlglot.parse_one('SELECT Bar.A AS A FROM "Foo".Bar')
        >>> normalize_identifiers(expression).sql()
        'SELECT bar.a AS a FROM "Foo".bar'
        >>> normalize_identifiers("foo", dialect="snowflake").sql(dialect="snowflake")
        'FOO'

    Args:
        expression: The expression to transform.
        dialect: The dialect to use in order to decide how to normalize identifiers.

    Returns:
        The transformed expression.
    )r   c                 S  s   | j dS )Ncase_sensitive)metaget)nr   r   r   <lambda><   s    z'normalize_identifiers.<locals>.<lambda>)pruner   )
r   get_or_raise
isinstancer   r   parse_identifierwalkr   r   normalize_identifier)r   r   noder   r   r   r      s   
#

r   )r   r   r   r   r	   r   )r   r   r   r   r	   r   )
__future__r   typingtsqlglotr   sqlglot.dialects.dialectr   r   TYPE_CHECKINGsqlglot._typingr   overloadr   r   r   r   r   <module>   s    