Merging upstream version 10.6.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
fe1b1057f7
commit
2153103f81
36 changed files with 1007 additions and 270 deletions
|
@ -2,6 +2,14 @@ from sqlglot import exp
|
|||
|
||||
|
||||
def expand_multi_table_selects(expression):
|
||||
"""
|
||||
Replace multiple FROM expressions with JOINs.
|
||||
|
||||
Example:
|
||||
>>> from sqlglot import parse_one
|
||||
>>> expand_multi_table_selects(parse_one("SELECT * FROM x, y")).sql()
|
||||
'SELECT * FROM x CROSS JOIN y'
|
||||
"""
|
||||
for from_ in expression.find_all(exp.From):
|
||||
parent = from_.parent
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ def isolate_table_selects(expression, schema=None):
|
|||
if len(scope.selected_sources) == 1:
|
||||
continue
|
||||
|
||||
for (_, source) in scope.selected_sources.values():
|
||||
for _, source in scope.selected_sources.values():
|
||||
if not isinstance(source, exp.Table) or not schema.column_names(source):
|
||||
continue
|
||||
|
||||
|
|
|
@ -6,6 +6,11 @@ from sqlglot.optimizer.simplify import simplify
|
|||
def optimize_joins(expression):
|
||||
"""
|
||||
Removes cross joins if possible and reorder joins based on predicate dependencies.
|
||||
|
||||
Example:
|
||||
>>> from sqlglot import parse_one
|
||||
>>> optimize_joins(parse_one("SELECT * FROM x CROSS JOIN y JOIN z ON x.a = z.a AND y.a = z.a")).sql()
|
||||
'SELECT * FROM x JOIN z ON x.a = z.a AND TRUE JOIN y ON y.a = z.a'
|
||||
"""
|
||||
for select in expression.find_all(exp.Select):
|
||||
references = {}
|
||||
|
|
|
@ -64,7 +64,6 @@ def optimize(expression, schema=None, db=None, catalog=None, rules=RULES, **kwar
|
|||
possible_kwargs = {"db": db, "catalog": catalog, "schema": schema, **kwargs}
|
||||
expression = expression.copy()
|
||||
for rule in rules:
|
||||
|
||||
# Find any additional rule parameters, beyond `expression`
|
||||
rule_params = rule.__code__.co_varnames
|
||||
rule_kwargs = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue