feat: expose lambda and higher-order array functions#1561
Open
timsaucer wants to merge 5 commits into
Open
Conversation
Add a Pythonic API for DataFusion's higher-order array functions and the lambda expressions they consume. - Rust: lambda_, lambda_var, array_transform, and array_any_match pyfunctions, plus a ResolveLambdaVariables analyzer rule so expression-builder plans (which emit unresolved lambda variables) resolve before optimization. - Python: array_transform / array_any_match (with list_transform, any_match, list_any_match aliases) accept either a Python callable or an explicit lambda built with lambda_ / lambda_var. Callables are introspected so their parameter names become the lambda parameters. - Tests and docs (expressions guide + agent skill), noting v1 limits: lambda expressions are not serializable, and SQL arrow syntax needs the DuckDB dialect.
Combine the eight higher-order function result tests into a single parametrized test_higher_order_function_results, and the two to_lambda rejection tests into test_to_lambda_rejects_invalid_arg. Each case keeps a readable id via pytest.param. Co-Authored-By: Claude <noreply@anthropic.com>
Add array_filter, the remaining lambda-based higher-order array function in DataFusion (alongside the already-exposed array_transform and array_any_match). Includes the list_filter alias matching upstream, tests, and documentation in the expressions guide and skill. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Lead user-facing array-lambda docs with "lambda function" instead of "higher-order function," which is less recognizable to users. Drop the alias list, serialization caveat, and DuckDB-dialect note from the skill to keep it lean; those details already live in the docstrings. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
11 tasks
gstvg
reviewed
May 28, 2026
Comment on lines
+189
to
+191
| contains a lambda raises ``Lambda not implemented``. SQL lambda syntax | ||
| (``x -> x * 2``) is only parsed by dialects that support lambdas; set | ||
| ``datafusion.sql_parser.dialect`` to ``DuckDB`` to use it. The Python |
There was a problem hiding this comment.
DuckDB will remove this syntax in v2.1. Perhaps add other dialects that support this syntax (spark, databricks, clickhouse, snowflake), and/or add the new duckdb syntax (``lambda x: x *2`) ?
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.
Which issue does this PR close?
Closes #811
Rationale for this change
DataFusion gained lambda expressions and higher-order array functions (apache/datafusion#21172). The Python binding already had the read-only
Lambda,HigherOrderFunction, andLambdaVariablewrapper classes, but offered no way to construct a lambda or call the higher-order functions. This PR adds a Pythonic API for both.What changes are included in this PR?
Adds the following:
array_transformandarray_any_matchthat accept either a Python callable or an explicit lambda built withlambda_/lambda_varAre there any user-facing changes?
There are new APIs but they are all new additions.