Skip to content

Commit

Permalink
fix(parser): none check on parent_predicate (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsheth2 authored Aug 2, 2024
1 parent 0e5553a commit 012d086
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
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

0 comments on commit 012d086

Please sign in to comment.