feat: add array_exists with lambda expression support#3611
Open
andygrove wants to merge 3 commits intoapache:mainfrom
Open
feat: add array_exists with lambda expression support#3611andygrove wants to merge 3 commits intoapache:mainfrom
andygrove wants to merge 3 commits intoapache:mainfrom
Conversation
Add native support for `array_exists(arr, x -> predicate(x))` in SQL and DataFrame API. This is the first general-purpose lambda expression infrastructure, which can later be extended to support `array_filter`, `array_transform`, and `array_forall`. The lambda body is serialized as a regular expression tree where `NamedLambdaVariable` leaf nodes are serialized as `LambdaVariable` proto messages. On the Rust side, `ArrayExistsExpr` evaluates the lambda body vectorized over all elements in a single pass: it flattens list values, expands the batch with repeat indices, appends elements as a `__comet_lambda_var` column, evaluates once, and reduces per row with SQL three-valued logic semantics. Unsupported lambda bodies (e.g. containing UDFs) fall back to Spark. Closes apache#3149
- Remove unused element_type proto field from ArrayExists - Add LargeListArray support via decompose_list helper - Use column index instead of name for lambda variable lookup - Add TimestampNTZType to supported element types - Restore CometNamedLambdaVariable as standalone serde object - Remove SQL-based Scala tests (covered by SQL file tests) - Add DataFrame tests for decimal and date element types - Add negative test for unsupported element type fallback - Add multi-column batch Rust unit test
gstvg
reviewed
Mar 2, 2026
Comment on lines
+159
to
+163
| for (i, col) in batch.columns().iter().enumerate() { | ||
| let expanded = take(col.as_ref(), &repeat_indices_array, None)?; | ||
| expanded_columns.push(expanded); | ||
| expanded_fields.push(Arc::new(batch.schema().field(i).clone())); | ||
| } |
Contributor
There was a problem hiding this comment.
non-blocking: I believe this will also expand uncaptured columns (those not referenced in the lambda body)
To avoid that costly expansion, is possible to:
- Use a NullArray as it's creation is O(1) regardless of length,
- Only includes on the batch the captured columns and the lambda variable, and rewrite the lambda body adjusting columns indices, as done in http://github.com/apache/datafusion/pull/18329/changes#diff-ac23ff0fe78acd71875341026dd5907736e3e3f49e2c398a69e6b33cb6394ae8R92-R139
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.
Closes #3149
Summary
array_exists(arr, x -> predicate(x))in SQL and DataFrame APIarray_filter,array_transform,array_forall