Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sqlmesh/core/macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ def filter_(evaluator: MacroEvaluator, *args: t.Any) -> t.List[t.Any]:
"""
*items, func = args
items, func = _norm_var_arg_lambda(evaluator, func, *items) # type: ignore
return list(filter(lambda arg: evaluator.eval_expression(func(arg)), items))
return list(filter(lambda arg: evaluator.eval_expression(func(arg)), ensure_collection(items)))


def _optional_expression(
Expand Down
12 changes: 12 additions & 0 deletions tests/core/test_macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,18 @@ def test_ast_correctness(macro_evaluator):
"700",
{},
),
# @FILTER documents "The first argument can be an Array or var args can be
# used", like @EACH and @REDUCE, so a lone item must work too.
(
"""@SQL(@REDUCE(@FILTER(300, x -> x > 250), (x,y) -> x + y))""",
"300",
{},
),
(
"""select @FILTER(a, x -> x > 1)""",
"SELECT a",
{},
),
(
"""select @EACH([a, b, c], x -> x and @SQL('@y'))""",
"SELECT a AND z, b AND z, c AND z",
Expand Down