Skip to content

Commit 9c67234

Browse files
authored
Fix: update snowflake staged file code to match sqlglot (#1507)
* Fix: update snowflake staged file code to match sqlglot * Bump sqlglot to v18.11.0
1 parent b402722 commit 9c67234

3 files changed

Lines changed: 7 additions & 4 deletions

File tree

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"requests",
4747
"rich",
4848
"ruamel.yaml",
49-
"sqlglot~=18.10.1",
49+
"sqlglot~=18.11.0",
5050
],
5151
extras_require={
5252
"bigquery": [

sqlmesh/core/dialect.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ def _parse_table_parts(self: Parser, schema: bool = False) -> exp.Table:
336336
table_arg = table.this
337337

338338
if isinstance(table_arg, exp.Var) and table_arg.name.startswith(SQLMESH_MACRO_PREFIX):
339-
return StagedFilePath(this=MacroVar(this=table_arg.name[1:]))
339+
table_arg.replace(MacroVar(this=table_arg.name[1:]))
340+
return StagedFilePath(**table.args)
340341

341342
return table
342343

tests/core/test_macros.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pytest
66
from sqlglot import exp, parse_one
77

8-
from sqlmesh.core.dialect import MacroVar, StagedFilePath
8+
from sqlmesh.core.dialect import StagedFilePath
99
from sqlmesh.core.macros import MacroEvaluator, macro
1010
from sqlmesh.utils.errors import SQLMeshError
1111
from sqlmesh.utils.metaprogramming import Executable, ExecutableKind
@@ -94,7 +94,9 @@ def test_macro_var(macro_evaluator):
9494
assert "Macro variable 'y' is undefined." in str(ex.value)
9595

9696
# Parsing a "parameter" like Snowflake's $1 should not produce a MacroVar expression
97-
assert parse_one("select $1", read="snowflake").find(MacroVar) is None
97+
e = parse_one("select $1 from @path (file_format => bla.foo)", read="snowflake")
98+
assert e.find(exp.Parameter) is e.selects[0]
99+
assert e.sql(dialect="snowflake") == "SELECT $1 FROM @path (FILE_FORMAT => bla.foo)"
98100

99101

100102
def test_macro_str_replace(macro_evaluator):

0 commit comments

Comments
 (0)