o
    8Di                     @  s   d dl m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 d dlmZmZmZmZ d dlmZ d d	lmZmZ 					
	
			
		
	
	
	d$d%d"d#ZdS )&    )annotationsN)exp)DialectDialectType)isolate_table_selects)normalize_identifiers)pushdown_cte_alias_columnsqualify_columnsquote_identifiersvalidate_qualify_columns)qualify_tables)Schemaensure_schemaTF
expressionexp.Expressiondialectr   dbt.Optional[str]catalogschemat.Optional[dict | Schema]expand_alias_refsboolexpand_starsinfer_schemat.Optional[bool]isolate_tablesr	   allow_partial_qualificationr   r
   identifyinfer_csv_schemasreturnc                 C  s   t ||d}t| |||||d} t| |d} |rt| |d} t|jr(t| } |	r4t| |||||
d} |r=t	| ||d} |rCt
|  | S )a|  
    Rewrite sqlglot AST to have normalized and qualified tables and columns.

    This step is necessary for all further SQLGlot optimizations.

    Example:
        >>> import sqlglot
        >>> schema = {"tbl": {"col": "INT"}}
        >>> expression = sqlglot.parse_one("SELECT col FROM tbl")
        >>> qualify(expression, schema=schema).sql()
        'SELECT "tbl"."col" AS "col" FROM "tbl" AS "tbl"'

    Args:
        expression: Expression to qualify.
        db: Default database name for tables.
        catalog: Default catalog name for tables.
        schema: Schema to infer column names and types.
        expand_alias_refs: Whether to expand references to aliases.
        expand_stars: Whether to expand star queries. This is a necessary step
            for most of the optimizer's rules to work; do not set to False unless you
            know what you're doing!
        infer_schema: Whether to infer the schema if missing.
        isolate_tables: Whether to isolate table selects.
        qualify_columns: Whether to qualify columns.
        allow_partial_qualification: Whether to allow partial qualification.
        validate_qualify_columns: Whether to validate columns.
        quote_identifiers: Whether to run the quote_identifiers step.
            This step is necessary to ensure correctness for case sensitive queries.
            But this flag is provided in case this step is performed at a later time.
        identify: If True, quote all identifiers, else only necessary ones.
        infer_csv_schemas: Whether to scan READ_CSV calls in order to infer the CSVs' schemas.

    Returns:
        The qualified expression.
    )r   )r   r   r   r   r   )r   )r   r   r   r   )r   r   )r   r   r   r   r   get_or_raisePREFER_CTE_ALIAS_COLUMNpushdown_cte_alias_columns_funcqualify_columns_funcquote_identifiers_funcvalidate_qualify_columns_func)r   r   r   r   r   r   r   r   r   r	   r   r   r
   r   r    r'   R/var/www/Datamplify/venv/lib/python3.10/site-packages/sqlglot/optimizer/qualify.pyqualify   s8   4	r)   )NNNNTTNFTFTTTF) 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   )
__future__r   typingtsqlglotr   sqlglot.dialects.dialectr   r   'sqlglot.optimizer.isolate_table_selectsr   'sqlglot.optimizer.normalize_identifiersr   !sqlglot.optimizer.qualify_columnsr   r#   r	   r$   r
   r%   r   r&    sqlglot.optimizer.qualify_tablesr   sqlglot.schemar   r   r)   r'   r'   r'   r(   <module>   s0    