diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-06-02 23:59:40 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-06-02 23:59:46 +0000 |
commit | 20739a12c39121a9e7ad3c9a2469ec5a6876199d (patch) | |
tree | c000de91c59fd29b2d9beecf9f93b84e69727f37 /sqlglot/executor/__init__.py | |
parent | Releasing debian version 12.2.0-1. (diff) | |
download | sqlglot-20739a12c39121a9e7ad3c9a2469ec5a6876199d.tar.xz sqlglot-20739a12c39121a9e7ad3c9a2469ec5a6876199d.zip |
Merging upstream version 15.0.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 | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/sqlglot/executor/__init__.py b/sqlglot/executor/__init__.py index a67c155..017d5bc 100644 --- a/sqlglot/executor/__init__.py +++ b/sqlglot/executor/__init__.py @@ -14,9 +14,10 @@ from sqlglot import maybe_parse 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.planner import Plan -from sqlglot.schema import ensure_schema +from sqlglot.schema import ensure_schema, flatten_schema, nested_get, nested_set logger = logging.getLogger("sqlglot") @@ -52,10 +53,15 @@ def execute( tables_ = ensure_tables(tables) if not schema: - schema = { - name: {column: type(table[0][column]).__name__ for column in table.columns} - for name, table in tables_.mapping.items() - } + schema = {} + flattened_tables = flatten_schema(tables_.mapping, depth=dict_depth(tables_.mapping)) + + for keys in flattened_tables: + table = nested_get(tables_.mapping, *zip(keys, keys)) + assert table is not None + + for column in table.columns: + nested_set(schema, [*keys, column], type(table[0][column]).__name__) schema = ensure_schema(schema, dialect=read) |