Skip to content

Commit 11842f8

Browse files
committed
Normalize lambda variables as well
1 parent a96de8b commit 11842f8

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

sqlmesh/core/macros.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ def substitute(
645645
) -> exp.Expression | t.List[exp.Expression] | None:
646646
if isinstance(node, (exp.Identifier, exp.Var)):
647647
if not isinstance(node.parent, exp.Column):
648-
name = node.name
648+
name = node.name.lower()
649649
if name in args:
650650
return args[name].copy()
651651
if name in evaluator.locals:
@@ -678,7 +678,7 @@ def substitute(
678678
return expressions, lambda args: func.this.transform(
679679
substitute,
680680
{
681-
expression.name: arg
681+
expression.name.lower(): arg
682682
for expression, arg in zip(
683683
func.expressions, args.expressions if isinstance(args, exp.Tuple) else [args]
684684
)

tests/core/test_macros.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,16 @@ def test_ast_correctness(macro_evaluator):
292292
"SELECT 'a' + a_z + 'c' + c_a, 'b' + b_z + 'c' + c_b",
293293
{"y": "c"},
294294
),
295+
(
296+
"""select @each(['a'], x -> @X)""",
297+
"SELECT 'a'",
298+
{},
299+
),
300+
(
301+
"""select @each(['a'], X -> @x)""",
302+
"SELECT 'a'",
303+
{},
304+
),
295305
(
296306
'"is_@{x}"',
297307
'"is_b"',

0 commit comments

Comments
 (0)