Repository navigation
Support DuckDB's lambda x, y : expr syntax - #2782
Merged
manticore-projects merged 2 commits intoOct 13, 2026
Merged
Conversation
DuckDB's recommended lambda syntax, `lambda x, y : expr`, had no rule: `lambda x : x + 1` only parsed by accident, as a column named `lambda` followed by a JSON path, and a condition body (`lambda x : x > 0`, `lambda x : x IS NOT NULL`) or several parameters (`lambda acc, x : acc + x`) were rejected. These are the common forms in `list_filter` and `list_reduce`. `DuckDBLambdaExpression()` parses it into a `LambdaExpression` flagged with `isLambdaKeyword()`, which deparses it as written. `LAMBDA` is a non-reserved keyword, so it remains usable as a name.
As a keyword token, LAMBDA stopped parsing where only plain identifiers are accepted: `CAST(a AS lambda)`, `COLLATE lambda`, `CREATE TABLE t (a lambda)`, `ALTER TABLE t DROP COLUMN lambda`, `ALTER TABLE t RENAME lambda TO x`. `isDuckDBLambdaAhead()` recognises `lambda name [, name ...] :` contextually, as `isKeywordAhead()` does for other words, so no token is needed.
Contributor
|
Thank you very much! |
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.
Purpose
Support DuckDB's recommended lambda syntax,
lambda x, y : expr(DuckDB docs).Current behaviour
There is no rule for it.
list_transform(l, lambda x : x + 1)only parses by accident, as a parameterlambdafollowed by a keyword argumentx : x + 1, which deparses aslist_transform(l, lambda)once aFILTERorOVERfollows. The common forms are rejected:list_filter(l, lambda x : x > 0),lambda x : x IS NOT NULLlist_reduce(l, lambda acc, x : acc + x)Change
DuckDBLambdaExpression()parseslambda x [, y ...] : exprinto aLambdaExpression, reached fromPrimaryExpressionbeforeColumn(), behindisDuckDBLambdaAhead():lambdafollowed by names separated by commas and a:.LambdaExpression#isLambdaKeyword()records the syntax, so it deparses as written.lambdastays a plain identifier (no new token, like the otherisKeywordAhead()words): as a column, alias, table, type (CAST(a AS lambda),CREATE TABLE t (a lambda)), collation or inALTER TABLE, andSELECT lambda x, y FROM t(a column aliasedx) parses as before.Validation
check: 10,045 tests, zero failures/errors; Spotless, Checkstyle, PMD and SpotBugs pass.DuckDBTest: comparison and boolean bodies, two parameters, nested lambdas, an array literal with a parenthesized element as the first argument, a lambda followed by more arguments, AST shape, andlambdaas a name in queries, types, collations and DDL.