Fix(macros): @FILTER with a single non-array argument#5902
Open
chuenchen309 wants to merge 1 commit into
Open
Conversation
@filter's docstring says "The first argument can be an Array or var args can be used", the same contract @each and @reduce state. All three route their arguments through _norm_var_arg_lambda, whose single-item branch returns a bare expression rather than a list: expressions = ( item.expressions if isinstance(item, (exp.Array, exp.Tuple)) else [item.this] if isinstance(item, exp.Paren) else item # <- bare expression ) @each and @reduce absorb that with ensure_collection(); @filter iterates it directly, so a lone argument raises: @each(a, x -> x + 1) -> SELECT a + 1 @reduce(a, (x, y) -> x+y) -> SELECT a @filter(a, x -> x > 1) -> MacroEvalError: 'Column' object is not iterable Wrap the items in ensure_collection() so @filter matches its siblings. An explicit array was already working and is unaffected. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: chuenchen309 <48723787+chuenchen309@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
@FILTER's docstring says "The first argument can be an Array or var args can be used" — the same contract@EACHand@REDUCEstate. All three route their arguments through_norm_var_arg_lambda, whose single-item branch returns a bare expression rather than a list:@EACH(macros.py:714) and@REDUCE(:764) absorb that withensure_collection().@FILTER(:792) iterates it directly, so a lone argument raises:An explicit array already worked for all three, so this only affects the lone-argument shape the docstring advertises.
Test Plan
Added two cases to
test_macro_functions, next to the existing array-based@FILTERcase so the two shapes sit together:@SQL(@REDUCE(@FILTER(300, x -> x > 250), (x,y) -> x + y))→300(mirrors the existing[100, 200, 300, 400]→700case)select @FILTER(a, x -> x > 1)→SELECT aBoth fail on
mainand pass with this change.tests/core/test_macros.pyis 140 passed with the fix, 138 passed / 2 failed without it.tests/core/test_macros.py tests/core/test_dialect.pytogether: 296 passed.Checklist
make styleand fixed any issuesmake fast-test)git commit -s) per the DCOOn
make fast-test: I ranruff,ruff-formatand the migrations hook (all pass) plus the test files above, but not the full suite.mypyreports onlyCannot find implementation or library stub for module named "sqlmesh._version"in four unrelated files — that's the setuptools-scm generated module missing from my worktree (it's gitignored), not something this diff touches.Disclosure: written with Claude Code, which I see this repo already uses. I verified the reproduction, the sibling comparison, and the test red/green myself.