Skip to content

Commit df1ebaf

Browse files
committed
fix: sqlglot losses all CTE statements
1 parent b0f16e6 commit df1ebaf

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

bigframes/core/compile/sqlglot/sqlglot_ir.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def from_query_string(
174174
alias=cte_name,
175175
)
176176
select_expr = sge.Select().select(sge.Star()).from_(sge.Table(this=cte_name))
177-
select_expr.set("with", sge.With(expressions=[cte]))
177+
select_expr.set("with_", sge.With(expressions=[cte]))
178178
return cls(expr=select_expr, uid_gen=uid_gen)
179179

180180
@classmethod
@@ -197,7 +197,7 @@ def from_union(
197197
), f"All provided expressions must be of type sge.Select, but got {type(select)}"
198198

199199
select_expr = select.copy()
200-
existing_ctes = [*existing_ctes, *select_expr.args.pop("with", [])]
200+
existing_ctes = [*existing_ctes, *select_expr.args.pop("with_", [])]
201201

202202
new_cte_name = sge.to_identifier(
203203
next(uid_gen.get_uid_stream("bfcte_")), quoted=cls.quoted
@@ -229,7 +229,7 @@ def from_union(
229229
),
230230
)
231231
final_select_expr = sge.Select().select(sge.Star()).from_(union_expr.subquery())
232-
final_select_expr.set("with", sge.With(expressions=existing_ctes))
232+
final_select_expr.set("with_", sge.With(expressions=existing_ctes))
233233
return cls(expr=final_select_expr, uid_gen=uid_gen)
234234

235235
def select(
@@ -336,8 +336,8 @@ def join(
336336
left_select = _select_to_cte(self.expr, left_cte_name)
337337
right_select = _select_to_cte(right.expr, right_cte_name)
338338

339-
left_ctes = left_select.args.pop("with", [])
340-
right_ctes = right_select.args.pop("with", [])
339+
left_ctes = left_select.args.pop("with_", [])
340+
right_ctes = right_select.args.pop("with_", [])
341341
merged_ctes = [*left_ctes, *right_ctes]
342342

343343
join_on = _and(
@@ -353,7 +353,7 @@ def join(
353353
.from_(sge.Table(this=left_cte_name))
354354
.join(sge.Table(this=right_cte_name), on=join_on, join_type=join_type_str)
355355
)
356-
new_expr.set("with", sge.With(expressions=merged_ctes))
356+
new_expr.set("with_", sge.With(expressions=merged_ctes))
357357

358358
return SQLGlotIR(expr=new_expr, uid_gen=self.uid_gen)
359359

@@ -373,8 +373,8 @@ def isin_join(
373373
# Prefer subquery over CTE for the IN clause's right side to improve SQL readability.
374374
right_select = right.expr
375375

376-
left_ctes = left_select.args.pop("with", [])
377-
right_ctes = right_select.args.pop("with", [])
376+
left_ctes = left_select.args.pop("with_", [])
377+
right_ctes = right_select.args.pop("with_", [])
378378
merged_ctes = [*left_ctes, *right_ctes]
379379

380380
left_condition = typed_expr.TypedExpr(
@@ -415,7 +415,7 @@ def isin_join(
415415
.select(sge.Column(this=sge.Star(), table=left_cte_name), new_column)
416416
.from_(sge.Table(this=left_cte_name))
417417
)
418-
new_expr.set("with", sge.With(expressions=merged_ctes))
418+
new_expr.set("with_", sge.With(expressions=merged_ctes))
419419

420420
return SQLGlotIR(expr=new_expr, uid_gen=self.uid_gen)
421421

@@ -625,14 +625,14 @@ def _select_to_cte(expr: sge.Select, cte_name: sge.Identifier) -> sge.Select:
625625
into a new CTE and then generates a 'SELECT * FROM new_cte_name'
626626
for the new query."""
627627
select_expr = expr.copy()
628-
existing_ctes = select_expr.args.pop("with", [])
628+
existing_ctes = select_expr.args.pop("with_", [])
629629
new_cte = sge.CTE(
630630
this=select_expr,
631631
alias=cte_name,
632632
)
633633
new_with_clause = sge.With(expressions=[*existing_ctes, new_cte])
634634
new_select_expr = sge.Select().select(sge.Star()).from_(sge.Table(this=cte_name))
635-
new_select_expr.set("with", new_with_clause)
635+
new_select_expr.set("with_", new_with_clause)
636636
return new_select_expr
637637

638638

0 commit comments

Comments
 (0)