Skip to content

Add support for lambda/higher order functions #14205

Closed

Description

@gstvg

Is your feature request related to a problem or challenge?

Some engines, like DuckDB and Clickhouse, supports lambda functions, like:

SELECT list_filter(numbers, x -> x > 40) as greater_than_40s FROM relation

There's already support for the syntax in sqlparser-rs

From #12206 (comment) by @jayzhan211

Activity

  1. rkrishn7 commented on Jan 27, 2025

    @rkrishn7
    Contributor

    Hello! I'm interested in working on this.

    Agreed that tweaking the existing ScalarUDF code would be ideal as it would be least breaking. However, after poking around a bit, I have some concerns:

    • How do implementers define a signature for a UDF that takes one or more lambdas? Do we just skip type checking of lambda arguments? How does this affect the ordering?
    • How should one map lambda function arguments to concrete values in the body? If the function only operates on a list, this becomes easier to express.

    A more prohibitive interface certainly seems like it would help implementation here, albeit at the expense of consumer flexibility.

    Any thoughts/feedback would be much appreciated. Thanks!

  2. gstvg commented on Jan 29, 2025

    @gstvg
    ContributorAuthor

    Hi @rkrishn7, have you already started any work?

    Since creating this issue, I’ve been working on a PoC to refine the proposal, and I managed to get it working. I’d like to continue with it if you’re OK with that—I probably should have assigned the issue to myself earlier, my bad 🤦🏻‍♂️! Anyway, many thanks for your interest and for your questionings, and I would really appreciate your input in futures questions (I expect many to arise!)

    How do implementers define a signature for a UDF that takes one or more lambdas? Do we just skip type checking of lambda arguments? How does this affect the ordering?

    I added a new ScalarUDF method invoke_with_lambda_args that receives ScalarFunctionArgs instead of ScalarFunctionArgs, and has a default implementation calling invoke_with_args, returning an error if any arg is a lambda
    This should preserve ordering of any arg.
    But maybe we could add an lambda_arguments to ScalarFunctionArgs similtar to here, what do you think ?

    How should one map lambda function arguments to concrete values in the body? If the function only operates on a list, this becomes easier to express.

    The lambda implementation should build a RecordBatch, likely using some other concrete argument, and pass it to the lambda PhysicalExpr evaluate method

    That said, if you have any thoughts on the current interface, I’d love to hear your feedback. It's a list_map([1,2], x -> x*2) udf, you can see the executed output here. Thanks! 🙏

  3. gstvg commented on Jan 29, 2025

    @gstvg
    ContributorAuthor

    Lambda syntax only works with databricks dialect, proposed fix here apache/datafusion-sqlparser-rs#1686

  4. rkrishn7 commented on Jan 30, 2025

    @rkrishn7
    Contributor

    Hi @gstvg! No worries at all, please continue working on it since you've started!

    Happy to take a look at the work you've done already and give feedback where it makes sense 👍🏾

  5. gstvg commented on Feb 8, 2025

    @gstvg
    ContributorAuthor

    take

  6. alexanderbianchi commented on Oct 9, 2025

    @alexanderbianchi
    Contributor

    @gstvg Is there an update on the status here?

  7. gstvg commented on Oct 11, 2025

    @gstvg
    ContributorAuthor

    Hi @alexanderbianchi. The code is already functional, mostly finished, but it ended up being a bigger change than I expected, ~3k LOC, some of it in core parts of DF. After I got stuck documenting and splitting it into smaller PRs, I stopped for a while.. but it's already been 6 months (!!). I'll start working on it again this weekend and hopefully we can make it into the 51.0 release 🙏

  8. ahmed-mez commented on Nov 12, 2025

    @ahmed-mez
    Contributor

    Hi @gstvg, thanks a lot for working on this! Is there an update on the progress so far? I'm also interested in this feature.

  9. gstvg commented on Nov 12, 2025

    @gstvg
    ContributorAuthor

    Hi @ahmed-mez, I'm finishing the text that explains and justifies the path I took, as well as showing alternative approaches. I found out today that it cant make into the 51 release anymore, sorry about that. Last week I found a flaw in my code that would break existing code but I already fixed it, so now all that's left is the text

  10. gstvg commented on Nov 25, 2025

    @gstvg
    ContributorAuthor

    Hi @rkrishn7, my bad for taking too long. Based on your questions, I assume you thought a bit about the implementation details of this. What's your opinion on my approach and/or the alternatives? Thanks

    @ahmed-mez @alexanderbianchi I opened a draft in #18921, if any of you have an opinion on it, if please leave a comment, thanks

  11. derrley commented on Feb 10, 2026

    @derrley

    Looking forward to this!

  12. LiaCastaneda commented on Mar 19, 2026

    @LiaCastaneda
    Contributor

    @gstvg since we don't have the Proposal doc in the original PR anymore, do you think it's worth moving it here? so it doesn't get lost and others can review as well.

  13. gstvg commented on Mar 26, 2026

    @gstvg
    ContributorAuthor

    @LiaCastaneda I set it as the PR description there. I think that's better than here because it's very specific to that particular implementation, and greatly differs from other lambda support attempts, for example. WDYT?
    But your suggestion made me note that the proposal here is very outdated, so at least I removed that part. Thanks

  14. LiaCastaneda commented on Mar 26, 2026

    @LiaCastaneda
    Contributor

    Ah, I was not aware it was in the PR description (while reviewing I guided myself mostly on the doc but PR description makes sense as well) thanks!

  15. gstvg commented on Apr 29, 2026

    @gstvg
    ContributorAuthor

    I'm closing this as #21679 got merged. Many thanks for everyone who showed interest on the feature ❤️

  16. ahmed-mez commented on Apr 29, 2026

    @ahmed-mez
    Contributor

    Congrats & kudos to @gstvg and @LiaCastaneda for the massive work you've done to get this shipped !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions