Merging upstream version 21.1.2.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
d59261cf1f
commit
472d4a62ba
103 changed files with 18237 additions and 17794 deletions
|
@ -76,7 +76,7 @@ def normalized(expression: exp.Expression, dnf: bool = False) -> bool:
|
|||
|
||||
Args:
|
||||
expression: The expression to check if it's normalized.
|
||||
dnf: Whether or not to check if the expression is in Disjunctive Normal Form (DNF).
|
||||
dnf: Whether to check if the expression is in Disjunctive Normal Form (DNF).
|
||||
Default: False, i.e. we check if it's in Conjunctive Normal Form (CNF).
|
||||
"""
|
||||
ancestor, root = (exp.And, exp.Or) if dnf else (exp.Or, exp.And)
|
||||
|
@ -99,7 +99,7 @@ def normalization_distance(expression: exp.Expression, dnf: bool = False) -> int
|
|||
|
||||
Args:
|
||||
expression: The expression to compute the normalization distance for.
|
||||
dnf: Whether or not to check if the expression is in Disjunctive Normal Form (DNF).
|
||||
dnf: Whether to check if the expression is in Disjunctive Normal Form (DNF).
|
||||
Default: False, i.e. we check if it's in Conjunctive Normal Form (CNF).
|
||||
|
||||
Returns:
|
||||
|
|
|
@ -48,15 +48,15 @@ def qualify(
|
|||
db: Default database name for tables.
|
||||
catalog: Default catalog name for tables.
|
||||
schema: Schema to infer column names and types.
|
||||
expand_alias_refs: Whether or not to expand references to aliases.
|
||||
expand_stars: Whether or not to expand star queries. This is a necessary step
|
||||
expand_alias_refs: Whether to expand references to aliases.
|
||||
expand_stars: Whether to expand star queries. This is a necessary step
|
||||
for most of the optimizer's rules to work; do not set to False unless you
|
||||
know what you're doing!
|
||||
infer_schema: Whether or not to infer the schema if missing.
|
||||
isolate_tables: Whether or not to isolate table selects.
|
||||
qualify_columns: Whether or not to qualify columns.
|
||||
validate_qualify_columns: Whether or not to validate columns.
|
||||
quote_identifiers: Whether or not to run the quote_identifiers step.
|
||||
infer_schema: Whether to infer the schema if missing.
|
||||
isolate_tables: Whether to isolate table selects.
|
||||
qualify_columns: Whether to qualify columns.
|
||||
validate_qualify_columns: Whether to validate columns.
|
||||
quote_identifiers: Whether to run the quote_identifiers step.
|
||||
This step is necessary to ensure correctness for case sensitive queries.
|
||||
But this flag is provided in case this step is performed at a later time.
|
||||
identify: If True, quote all identifiers, else only necessary ones.
|
||||
|
|
|
@ -35,11 +35,11 @@ def qualify_columns(
|
|||
Args:
|
||||
expression: Expression to qualify.
|
||||
schema: Database schema.
|
||||
expand_alias_refs: Whether or not to expand references to aliases.
|
||||
expand_stars: Whether or not to expand star queries. This is a necessary step
|
||||
expand_alias_refs: Whether to expand references to aliases.
|
||||
expand_stars: Whether to expand star queries. This is a necessary step
|
||||
for most of the optimizer's rules to work; do not set to False unless you
|
||||
know what you're doing!
|
||||
infer_schema: Whether or not to infer the schema if missing.
|
||||
infer_schema: Whether to infer the schema if missing.
|
||||
|
||||
Returns:
|
||||
The qualified expression.
|
||||
|
@ -164,12 +164,7 @@ def _expand_using(scope: Scope, resolver: Resolver) -> t.Dict[str, t.Any]:
|
|||
|
||||
table = table or source_table
|
||||
conditions.append(
|
||||
exp.condition(
|
||||
exp.EQ(
|
||||
this=exp.column(identifier, table=table),
|
||||
expression=exp.column(identifier, table=join_table),
|
||||
)
|
||||
)
|
||||
exp.column(identifier, table=table).eq(exp.column(identifier, table=join_table))
|
||||
)
|
||||
|
||||
# Set all values in the dict to None, because we only care about the key ordering
|
||||
|
@ -449,10 +444,9 @@ def _expand_stars(
|
|||
continue
|
||||
|
||||
for name in columns:
|
||||
if name in columns_to_exclude or name in coalesced_columns:
|
||||
continue
|
||||
if name in using_column_tables and table in using_column_tables[name]:
|
||||
if name in coalesced_columns:
|
||||
continue
|
||||
|
||||
coalesced_columns.add(name)
|
||||
tables = using_column_tables[name]
|
||||
coalesce = [exp.column(name, table=table) for table in tables]
|
||||
|
@ -464,7 +458,7 @@ def _expand_stars(
|
|||
copy=False,
|
||||
)
|
||||
)
|
||||
elif name not in columns_to_exclude:
|
||||
else:
|
||||
alias_ = replace_columns.get(table_id, {}).get(name, name)
|
||||
column = exp.column(name, table=table)
|
||||
new_selections.append(
|
||||
|
|
|
@ -254,7 +254,7 @@ class Scope:
|
|||
self._columns = []
|
||||
for column in columns + external_columns:
|
||||
ancestor = column.find_ancestor(
|
||||
exp.Select, exp.Qualify, exp.Order, exp.Having, exp.Hint, exp.Table
|
||||
exp.Select, exp.Qualify, exp.Order, exp.Having, exp.Hint, exp.Table, exp.Star
|
||||
)
|
||||
if (
|
||||
not ancestor
|
||||
|
|
|
@ -41,7 +41,7 @@ def simplify(
|
|||
|
||||
Args:
|
||||
expression (sqlglot.Expression): expression to simplify
|
||||
constant_propagation: whether or not the constant propagation rule should be used
|
||||
constant_propagation: whether the constant propagation rule should be used
|
||||
|
||||
Returns:
|
||||
sqlglot.Expression: simplified expression
|
||||
|
|
|
@ -248,7 +248,7 @@ def decorrelate(select, parent_select, external_columns, next_alias_name):
|
|||
key.replace(exp.to_identifier("_x"))
|
||||
parent_predicate = _replace(
|
||||
parent_predicate,
|
||||
f'({parent_predicate} AND ARRAY_ANY({nested}, "_x" -> {predicate}))',
|
||||
f"({parent_predicate} AND ARRAY_ANY({nested}, _x -> {predicate}))",
|
||||
)
|
||||
|
||||
parent_select.join(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue