diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-08 08:11:53 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-08 08:12:02 +0000 |
commit | 8d36f5966675e23bee7026ba37ae0647fbf47300 (patch) | |
tree | df4227bbb3b07cb70df87237bcff03c8efd7822d /sqlglot/executor/__init__.py | |
parent | Releasing debian version 22.2.0-1. (diff) | |
download | sqlglot-8d36f5966675e23bee7026ba37ae0647fbf47300.tar.xz sqlglot-8d36f5966675e23bee7026ba37ae0647fbf47300.zip |
Merging upstream version 23.7.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sqlglot/executor/__init__.py')
-rw-r--r-- | sqlglot/executor/__init__.py | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/sqlglot/executor/__init__.py b/sqlglot/executor/__init__.py index c8f9148..29c0e68 100644 --- a/sqlglot/executor/__init__.py +++ b/sqlglot/executor/__init__.py @@ -10,11 +10,13 @@ import logging import time import typing as t +from sqlglot import exp from sqlglot.errors import ExecuteError from sqlglot.executor.python import PythonExecutor from sqlglot.executor.table import Table, ensure_tables from sqlglot.helper import dict_depth from sqlglot.optimizer import optimize +from sqlglot.optimizer.annotate_types import annotate_types from sqlglot.planner import Plan from sqlglot.schema import ensure_schema, flatten_schema, nested_get, nested_set @@ -26,15 +28,11 @@ if t.TYPE_CHECKING: from sqlglot.schema import Schema -PYTHON_TYPE_TO_SQLGLOT = { - "dict": "MAP", -} - - def execute( sql: str | Expression, schema: t.Optional[t.Dict | Schema] = None, read: DialectType = None, + dialect: DialectType = None, tables: t.Optional[t.Dict] = None, ) -> Table: """ @@ -48,11 +46,13 @@ def execute( 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. """ + read = read or dialect tables_ = ensure_tables(tables, dialect=read) if not schema: @@ -64,8 +64,9 @@ def execute( assert table is not None for column in table.columns: - py_type = type(table[0][column]).__name__ - nested_set(schema, [*keys, column], PYTHON_TYPE_TO_SQLGLOT.get(py_type) or py_type) + value = table[0][column] + column_type = annotate_types(exp.convert(value)).type or type(value).__name__ + nested_set(schema, [*keys, column], column_type) schema = ensure_schema(schema, dialect=read) |