Skip to content

Commit ef8834d

Browse files
authored
Fix: address staged file path edge case in snowflake parsing (#4233)
1 parent fbf5345 commit ef8834d

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

sqlmesh/core/dialect.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ def _parse_table_parts(
500500
self._curr
501501
and self._prev.token_type in (TokenType.L_PAREN, TokenType.R_PAREN)
502502
and self._curr.text.upper() not in ("FILE_FORMAT", "PATTERN")
503+
and not (table.args.get("format") or table.args.get("pattern"))
503504
)
504505
):
505506
self._retreat(index)

tests/core/test_model.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7463,6 +7463,23 @@ def test_staged_file_path():
74637463
query = model.render_query()
74647464
assert query.sql(dialect="snowflake") == "SELECT * FROM @a.b/c/d.csv (FILE_FORMAT => 'b.ff')"
74657465

7466+
expressions = d.parse(
7467+
"""
7468+
MODEL (name test, dialect snowflake);
7469+
7470+
SELECT
7471+
*
7472+
FROM @variable (FILE_FORMAT => 'foo'), @non_variable (FILE_FORMAT => 'bar')
7473+
LIMIT 100
7474+
"""
7475+
)
7476+
model = load_sql_based_model(expressions, variables={"variable": "some_path"})
7477+
query = model.render_query()
7478+
assert (
7479+
query.sql(dialect="snowflake")
7480+
== """SELECT * FROM 'some_path' (FILE_FORMAT => 'foo') AS "SOME_PATH", @non_variable (FILE_FORMAT => 'bar') LIMIT 100"""
7481+
)
7482+
74667483

74677484
def test_cache():
74687485
expressions = d.parse(

0 commit comments

Comments
 (0)