Skip to content

Commit baf192d

Browse files
authored
Fix!: enable loading of Snowflake models that use staged file paths (#2973)
1 parent b9f9f49 commit baf192d

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

sqlmesh/core/dialect.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,11 @@ def output_name(self) -> str:
101101
return self.this.name
102102

103103

104-
class StagedFilePath(exp.Table):
104+
class StagedFilePath(exp.Expression):
105105
"""Represents paths to "staged files" in Snowflake."""
106106

107+
arg_types = exp.Table.arg_types.copy()
108+
107109

108110
def _parse_statement(self: Parser) -> t.Optional[exp.Expression]:
109111
if self._curr is None:
@@ -409,7 +411,7 @@ def _parse_types(
409411
# See: https://docs.snowflake.com/en/user-guide/querying-stage
410412
def _parse_table_parts(
411413
self: Parser, schema: bool = False, is_db_reference: bool = False
412-
) -> exp.Table:
414+
) -> exp.Table | StagedFilePath:
413415
index = self._index
414416
table = self.__parse_table_parts(schema=schema, is_db_reference=is_db_reference) # type: ignore
415417

tests/core/test_model.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5371,3 +5371,16 @@ def test_trailing_comments():
53715371
model = load_sql_based_model(expressions, path=Path("./examples/sushi/models/test_model.sql"))
53725372
assert not model.render_pre_statements()
53735373
assert not model.render_post_statements()
5374+
5375+
5376+
def test_staged_file_path():
5377+
expressions = d.parse(
5378+
"""
5379+
MODEL (name test, dialect snowflake);
5380+
5381+
SELECT * FROM @a.b/c/d.csv(FILE_FORMAT => 'b.ff')
5382+
"""
5383+
)
5384+
model = load_sql_based_model(expressions)
5385+
query = model.render_query()
5386+
assert query.sql(dialect="snowflake") == "SELECT * FROM @a.b/c/d.csv (FILE_FORMAT => 'b.ff')"

0 commit comments

Comments
 (0)