Skip to content

Commit

Permalink
Fix: yet another edge case related to snowflake staged file syntax (T…
Browse files Browse the repository at this point in the history
  • Loading branch information
georgesittas authored May 31, 2024
1 parent 17f0090 commit f3139c5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sqlmesh/core/dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def _parse_table_parts(

if isinstance(table_arg, exp.Var) and table_arg.name.startswith(SQLMESH_MACRO_PREFIX):
# Macro functions do not clash with the staged file syntax, so we can safely parse them
if "(" in table_arg.name:
if self._prev.token_type == TokenType.STRING or "(" in table_arg.name:
self._retreat(index)
return Parser._parse_table_parts(self, schema=schema, is_db_reference=is_db_reference)

Expand Down
8 changes: 8 additions & 0 deletions tests/core/test_macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ def test_macro_var(macro_evaluator):
assert e.find(exp.Parameter) is e.selects[0]
assert e.sql(dialect="snowflake") == "SELECT $1 FROM @path (FILE_FORMAT => bla.foo)"

macro_evaluator.locals = {"x": 1}
macro_evaluator.dialect = "snowflake"
e = parse_one("COPY INTO @'s3://example/foo_@{x}.csv' FROM a.b.c", read="snowflake")
assert (
macro_evaluator.transform(e).sql(dialect="snowflake")
== "COPY INTO 's3://example/foo_1.csv' FROM a.b.c"
)


def test_macro_str_replace(macro_evaluator):
expression = parse_one("""@'@val1, @val2'""")
Expand Down

0 comments on commit f3139c5

Please sign in to comment.