1
0
Fork 0

Merging upstream version 26.12.0.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-03-31 15:54:56 +02:00
parent d24d19e9ea
commit 69b6dd9501
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
70 changed files with 1134 additions and 340 deletions

View file

@ -129,8 +129,7 @@ def _mergeable(
inner_select = inner_scope.expression.unnest()
def _is_a_window_expression_in_unmergable_operation():
window_expressions = inner_select.find_all(exp.Window)
window_alias_names = {window.parent.alias_or_name for window in window_expressions}
window_aliases = {s.alias_or_name for s in inner_select.selects if s.find(exp.Window)}
inner_select_name = from_or_join.alias_or_name
unmergable_window_columns = [
column
@ -142,7 +141,7 @@ def _mergeable(
window_expressions_in_unmergable = [
column
for column in unmergable_window_columns
if column.table == inner_select_name and column.name in window_alias_names
if column.table == inner_select_name and column.name in window_aliases
]
return any(window_expressions_in_unmergable)

View file

@ -4,6 +4,7 @@ from sqlglot import alias, exp
from sqlglot.optimizer.qualify_columns import Resolver
from sqlglot.optimizer.scope import Scope, traverse_scope
from sqlglot.schema import ensure_schema
from sqlglot.errors import OptimizeError
# Sentinel value that means an outer query selecting ALL columns
SELECT_ALL = object()
@ -49,6 +50,10 @@ def pushdown_projections(expression, schema=None, remove_unused_selections=True)
if isinstance(scope.expression, exp.SetOperation):
left, right = scope.union_scopes
if len(left.expression.selects) != len(right.expression.selects):
scope_sql = scope.expression.sql()
raise OptimizeError(f"Invalid set operation due to column mismatch: {scope_sql}.")
referenced_columns[left] = parent_selections
if any(select.is_star for select in right.expression.selects):

View file

@ -272,7 +272,7 @@ def _expand_alias_refs(
"""
expression = scope.expression
if not isinstance(expression, exp.Select):
if not isinstance(expression, exp.Select) or dialect == "oracle":
return
alias_to_expression: t.Dict[str, t.Tuple[exp.Expression, int]] = {}