Repository navigation
DuckDB: support list comprehensions - #2798
Merged
manticore-projects merged 2 commits intoOct 13, 2026
Merged
Conversation
guizmaii
marked this pull request as ready for review
October 13, 2026 08:57
27 tasks
guizmaii
force-pushed
the
duckdb-list-comprehension
branch
3 times, most recently
from
October 13, 2026 21:48
327524b to
bb13af8
Compare
`[x * 2 FOR x IN l IF x > 1]` and `[x + i FOR x, i IN l]` parse as the new `ListComprehension`. A `[` opens one when a `FOR` follows at its top level; any other `[` is still an array. `visit(ListComprehension)` is a default method that visits the element, list and condition, so existing `ExpressionVisitor` implementations keep compiling.
`isListComprehensionAhead()` called `getToken(i)` for each token, which walks from the current token every time: parsing a 10,000-element array took seconds. It now follows the token chain.
guizmaii
force-pushed
the
duckdb-list-comprehension
branch
from
October 13, 2026 21:57
bb13af8 to
75371f7
Compare
Contributor
|
Thank you 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.
For DuckDB's list comprehensions (docs):
ListComprehensionexpression: element expression, one or two variables (element, 1-based index), list expression, optionalIFcondition.[opens a comprehension only whenFORfollows at its top level (isListComprehensionAhead(), one pass over the token chain; a 20,000-element array parses as fast as on master); every other[is still anArrayConstructor.[... FOR ...]was a syntax error in every dialect, so nothing that parsed before changes. SQL Server's[name]quoting is lexed before this and unaffected.ExpressionVisitor.visit(ListComprehension)is a default method visiting the element, list and condition, so existing visitors keep compiling. The deparser, adapter, validator andTablesNamesFinderimplement it (tables in a sub-select list are found).checkGrammarAmbiguity: no conflicts../gradlew check: 10,120 tests, 0 failures.test/sql, 70,729 statements): 91 more parse, none less.