diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-03-19 10:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-03-19 10:22:09 +0000 |
commit | 66af5c6fc22f6f11e9ea807b274e011a6f64efb7 (patch) | |
tree | 08ceed3b311b7b343935c1e55941b9d15e6f56d8 /sqlglot/optimizer/pushdown_projections.py | |
parent | Releasing debian version 11.3.6-1. (diff) | |
download | sqlglot-66af5c6fc22f6f11e9ea807b274e011a6f64efb7.tar.xz sqlglot-66af5c6fc22f6f11e9ea807b274e011a6f64efb7.zip |
Merging upstream version 11.4.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sqlglot/optimizer/pushdown_projections.py')
-rw-r--r-- | sqlglot/optimizer/pushdown_projections.py | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/sqlglot/optimizer/pushdown_projections.py b/sqlglot/optimizer/pushdown_projections.py index 07a1b70..2e51117 100644 --- a/sqlglot/optimizer/pushdown_projections.py +++ b/sqlglot/optimizer/pushdown_projections.py @@ -1,7 +1,6 @@ from collections import defaultdict from sqlglot import alias, exp -from sqlglot.helper import flatten from sqlglot.optimizer.qualify_columns import Resolver from sqlglot.optimizer.scope import Scope, traverse_scope from sqlglot.schema import ensure_schema @@ -86,14 +85,15 @@ def _remove_unused_selections(scope, parent_selections, schema): else: order_refs = set() - new_selections = defaultdict(list) + new_selections = [] removed = False star = False + for selection in scope.selects: name = selection.alias_or_name if SELECT_ALL in parent_selections or name in parent_selections or name in order_refs: - new_selections[name].append(selection) + new_selections.append(selection) else: if selection.is_star: star = True @@ -101,18 +101,17 @@ def _remove_unused_selections(scope, parent_selections, schema): if star: resolver = Resolver(scope, schema) + names = {s.alias_or_name for s in new_selections} for name in sorted(parent_selections): - if name not in new_selections: - new_selections[name].append( - alias(exp.column(name, table=resolver.get_table(name)), name) - ) + if name not in names: + new_selections.append(alias(exp.column(name, table=resolver.get_table(name)), name)) # If there are no remaining selections, just select a single constant if not new_selections: - new_selections[""].append(DEFAULT_SELECTION()) + new_selections.append(DEFAULT_SELECTION()) - scope.expression.select(*flatten(new_selections.values()), append=False, copy=False) + scope.expression.select(*new_selections, append=False, copy=False) if removed: scope.clear_cache() |