Skip to content

Commit

Permalink
Reapply "fix: only limit the root node since bigquery can't handle to… (
Browse files Browse the repository at this point in the history
  • Loading branch information
tobymao authored and izeigerman committed Sep 23, 2024
1 parent 537cc67 commit 3e89017
Showing 1 changed file with 1 addition and 16 deletions.
17 changes: 1 addition & 16 deletions sqlmesh/core/model/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,26 +513,11 @@ def ctas_query(self, **render_kwarg: t.Any) -> exp.Query:
Return:
The mocked out ctas query.
"""
query = self.render_query_or_raise(**render_kwarg).copy()
query = self.render_query_or_raise(**render_kwarg).limit(0)

for select_or_set_op in query.find_all(exp.Select, exp.SetOperation):
skip_limit = False
ancestor = select_or_set_op.parent
while ancestor and not skip_limit:
if isinstance(ancestor, exp.With) and ancestor.recursive:
skip_limit = True
ancestor = ancestor.parent

if isinstance(select_or_set_op, exp.Select) and select_or_set_op.args.get("from"):
select_or_set_op.where(exp.false(), copy=False)
if not skip_limit and not isinstance(select_or_set_op.parent, exp.SetOperation):
select_or_set_op.limit(0, copy=False)
elif (
not skip_limit
and isinstance(select_or_set_op, exp.SetOperation)
and not isinstance(select_or_set_op.parent, exp.SetOperation)
):
select_or_set_op.set("limit", exp.Limit(expression=exp.Literal.number(0)))

if self.managed_columns:
query.select(
Expand Down

0 comments on commit 3e89017

Please sign in to comment.