diff options
Diffstat (limited to 'sqlglot/planner.py')
-rw-r--r-- | sqlglot/planner.py | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/sqlglot/planner.py b/sqlglot/planner.py index 5fd96ef..eccad35 100644 --- a/sqlglot/planner.py +++ b/sqlglot/planner.py @@ -1,11 +1,10 @@ from __future__ import annotations -import itertools import math import typing as t from sqlglot import alias, exp -from sqlglot.errors import UnsupportedError +from sqlglot.helper import name_sequence from sqlglot.optimizer.eliminate_joins import join_condition @@ -105,13 +104,7 @@ class Step: from_ = expression.args.get("from") if isinstance(expression, exp.Select) and from_: - from_ = from_.expressions - if len(from_) > 1: - raise UnsupportedError( - "Multi-from statements are unsupported. Run it through the optimizer" - ) - - step = Scan.from_expression(from_[0], ctes) + step = Scan.from_expression(from_.this, ctes) elif isinstance(expression, exp.Union): step = SetOperation.from_expression(expression, ctes) else: @@ -128,7 +121,7 @@ class Step: projections = [] # final selects in this chain of steps representing a select operands = {} # intermediate computations of agg funcs eg x + 1 in SUM(x + 1) aggregations = [] - sequence = itertools.count() + next_operand_name = name_sequence("_a_") def extract_agg_operands(expression): for agg in expression.find_all(exp.AggFunc): @@ -136,7 +129,7 @@ class Step: if isinstance(operand, exp.Column): continue if operand not in operands: - operands[operand] = f"_a_{next(sequence)}" + operands[operand] = next_operand_name() operand.replace(exp.column(operands[operand], quoted=True)) for e in expression.expressions: @@ -310,7 +303,7 @@ class Join(Step): for join in joins: source_key, join_key, condition = join_condition(join) step.joins[join.this.alias_or_name] = { - "side": join.side, + "side": join.side, # type: ignore "join_key": join_key, "source_key": source_key, "condition": condition, |