o
    8Di                     @  s   d Z ddlm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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mZmZ edZejrlddl m!Z! ddl"m#Z# ddlm$Z$ 				ddddZ%dS ) z5
.. include:: ../../posts/python_sql_engine.md

----
    )annotationsN)exp)ExecuteError)PythonExecutor)Tableensure_tables)
dict_depth)optimize)annotate_types)Plan)ensure_schemaflatten_schema
nested_get
nested_setsqlglot)DialectType)
Expression)Schemasqlstr | Expressionschemat.Optional[t.Dict | Schema]readr   dialecttablest.Optional[t.Dict]returnr   c                 C  sT  |p|}t ||d}|sTi }t|jt|jd}|D ]9}t|jgt||R  }|dus.J |jD ]!}	|d |	 }
tt	|
|dj
pGt
|
j}t|g ||	| q1qt||d}|jrg|j|jkrgtdt }t| |dd|d}tdt |  td	|jdd
 t|}td| t }t|d|}tdt |  |S )aO  
    Run a sql query against data.

    Args:
        sql: a sql statement.
        schema: database schema.
            This can either be an instance of `Schema` or a mapping in one of the following forms:
            1. {table: {col: type}}
            2. {db: {table: {col: type}}}
            3. {catalog: {db: {table: {col: type}}}}
        read: the SQL dialect to apply during parsing (eg. "spark", "hive", "presto", "mysql").
        dialect: the SQL dialect (alias for read).
        tables: additional tables to register.

    Returns:
        Simple columnar data structure.
    )r   )depthNr   z1Tables must support the same table args as schemaT)leave_tables_isolatedinfer_csv_schemasr   zOptimization finished: %fzOptimized SQL: %s)prettyzLogical Plan: %s)r   zQuery finished: %f)r   r   mappingr   r   zipcolumnsr
   r   converttype__name__r   r   supported_table_argsr   timer	   loggerdebugr   r   r   execute)r   r   r   r   r   tables_flattened_tableskeystablecolumnvaluecolumn_typenow
expressionplanresult r7   R/var/www/Datamplify/venv/lib/python3.10/site-packages/sqlglot/executor/__init__.pyr+      s:   

r+   )NNNN)r   r   r   r   r   r   r   r   r   r   r   r   )&__doc__
__future__r   loggingr(   typingtr   r   sqlglot.errorsr   sqlglot.executor.pythonr   sqlglot.executor.tabler   r   sqlglot.helperr   sqlglot.optimizerr	    sqlglot.optimizer.annotate_typesr
   sqlglot.plannerr   sqlglot.schemar   r   r   r   	getLoggerr)   TYPE_CHECKINGsqlglot.dialects.dialectr   sqlglot.expressionsr   r   r+   r7   r7   r7   r8   <module>   s0    
