Skip to content

Commit 2519ee0

Browse files
authored
Fix: fix tests due to sqlglot upgrade (#1549)
1 parent 9204459 commit 2519ee0

2 files changed

Lines changed: 22 additions & 16 deletions

File tree

sqlmesh/core/renderer.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,13 @@ def _optimize_query(self, query: exp.Subqueryable) -> exp.Subqueryable:
417417
"*",
418418
"",
419419
):
420-
select.replace(exp.alias_(select, select.output_name))
420+
alias = exp.alias_(select, select.output_name)
421+
comments = alias.this.comments
422+
if comments:
423+
alias.add_comments(comments)
424+
comments.clear()
425+
426+
select.replace(alias)
421427

422428
return annotate_types(query, schema=schema)
423429

tests/core/test_model.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -112,22 +112,22 @@ def test_load(assert_exp_eq):
112112
d.parse_one("DROP TABLE x"),
113113
]
114114
assert model.depends_on == {"db.other_table"}
115-
assert_exp_eq(
116-
model.render_query(),
117-
"""
118-
SELECT
119-
TRY_CAST(1 AS INT) AS "a",
120-
TRY_CAST(2 AS DOUBLE) AS "b",
121-
TRY_CAST("c" AS BOOLEAN) AS "c",
122-
TRY_CAST(1 AS INT) AS "d", /* d */
123-
TRY_CAST(2 AS DOUBLE) AS "e", /* e */
124-
TRY_CAST("f" AS BOOLEAN) AS "f", /* f */
125-
TRY_CAST(1 + 1 AS INT) AS "g",
126-
FROM "db"."other_table" AS "t1"
127-
LEFT JOIN "db"."table" AS "t2"
128-
ON "t1"."a" = "t2"."a"
129-
""",
115+
116+
assert (
117+
model.render_query().sql(pretty=True, dialect="spark")
118+
== """SELECT
119+
CAST(1 AS INT) AS `a`,
120+
CAST(2 AS DOUBLE) AS `b`,
121+
CAST(`c` AS BOOLEAN) AS `c`,
122+
CAST(1 AS INT) AS `d`, /* d */
123+
CAST(2 AS DOUBLE) AS `e`, /* e */
124+
CAST(`f` AS BOOLEAN) AS `f`, /* f */
125+
CAST(1 + 1 AS INT) AS `g`
126+
FROM `db`.`other_table` AS `t1`
127+
LEFT JOIN `db`.`table` AS `t2`
128+
ON `t1`.`a` = `t2`.`a`"""
130129
)
130+
131131
assert model.tags == ["tag_foo", "tag_bar"]
132132
assert [r.dict() for r in model.all_references] == [
133133
{"model_name": "db.table", "expression": d.parse_one("[a, b]"), "unique": True},

0 commit comments

Comments
 (0)