Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(parser): none check on parent_predicate #2

Merged
merged 2 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions sqlglot/optimizer/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,9 @@ def traverse(self):
scope.subquery_scopes,
)
)
if len(result) > MAX_SCOPE_DEPTH:
raise OptimizeError("Scope depth limit exceeded")
actual_depth = len(result)
if actual_depth > MAX_SCOPE_DEPTH:
raise OptimizeError(f"Scope depth limit({actual_depth}) exceeded max depth limit({MAX_SCOPE_DEPTH})")

yield from reversed(result)

Expand Down
19 changes: 11 additions & 8 deletions sqlglot/optimizer/unnest_subqueries.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,16 +261,19 @@ def remove_aggs(node):
if key in group_by:
key.replace(nested)
elif isinstance(predicate, exp.EQ):
parent_predicate = _replace(
parent_predicate,
f"({parent_predicate} AND ARRAY_CONTAINS({nested}, {column}))",
)
if parent_predicate:
parent_predicate = _replace(
parent_predicate,
f"({parent_predicate} AND ARRAY_CONTAINS({nested}, {column}))",
)
else:
key.replace(exp.to_identifier("_x"))
parent_predicate = _replace(
parent_predicate,
f"({parent_predicate} AND ARRAY_ANY({nested}, _x -> {predicate}))",
)

if parent_predicate:
parent_predicate = _replace(
parent_predicate,
f"({parent_predicate} AND ARRAY_ANY({nested}, _x -> {predicate}))",
)

parent_select.join(
select.group_by(*group_by, copy=False),
Expand Down
Loading