Skip to content

Commit 57db62a

Browse files
authored
Fix: ignore/respect nulls generation edge case (#5117)
1 parent a330093 commit 57db62a

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

sqlglot/generator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4287,7 +4287,8 @@ def _embed_ignore_nulls(self, expression: exp.IgnoreNulls | exp.RespectNulls, te
42874287
agg_func = expression.find(exp.AggFunc)
42884288

42894289
if agg_func:
4290-
return self.sql(agg_func)[:-1] + f" {text})"
4290+
agg_func_sql = self.sql(agg_func, comment=False)[:-1] + f" {text})"
4291+
return self.maybe_comment(agg_func_sql, comments=agg_func.comments)
42914292

42924293
return f"{self.sql(expression, 'this')} {text}"
42934294

tests/dialects/test_bigquery.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ def test_bigquery(self):
177177
self.validate_identity(
178178
"CREATE OR REPLACE VIEW test (tenant_id OPTIONS (description='Test description on table creation')) AS SELECT 1 AS tenant_id, 1 AS customer_id",
179179
)
180+
self.validate_identity(
181+
"--c\nARRAY_AGG(v IGNORE NULLS)",
182+
"ARRAY_AGG(v IGNORE NULLS) /* c */",
183+
)
180184
self.validate_identity(
181185
'SELECT r"\\t"',
182186
"SELECT '\\\\t'",

0 commit comments

Comments
 (0)