Skip to content

Run filter lambdas natively with DataFusion's array_filter #7321

Open

Description

@andygrove

What is the problem the feature request solves?

filter(arr, x -> ...) runs natively only when the lambda is x IS NOT NULL (what array_compact expands to). Every other lambda goes through the JVM codegen dispatcher: each batch is exported over FFI and Spark's interpreter evaluates the lambda one element at a time. That is the same per-element work Spark does, plus the transfer, so such a query runs at about Spark's speed, and a user reported it slower than Spark.

The user's workaround was to rewrite filter(arr, x -> nvl(x, '') != '') to array_remove(array_compact(arr), ''), which is native and much faster. Release build, Spark 4.1, 1M rows of ten-element string arrays:

Query Spark Comet
filter(strs, x -> nvl(x, '') != '') 616 ms 547 ms
array_remove(array_compact(strs), '') 587 ms 252 ms

Describe the potential solution

DataFusion 55 ships higher-order functions (array_filter, array_transform, array_any_match, array_first) that evaluate a lambda once over all the elements of a batch. Comet can serialize the lambda body as ordinary native expressions and plan it into DataFusion's array_filter, falling back to the dispatcher for bodies it cannot evaluate natively.

array_transform, exists and forall could follow. Spark's three-valued logic in exists needs checking first.

Related: the native AND, OR and IN do not short-circuit data-dependent errors under ANSI mode, so the first version has to keep such bodies on the dispatcher (see the comment on #6006).

Part of the effort tracked in #7300.

Activity

  1. tlfua commented on Nov 3, 2026

    @tlfua

    take

  2. tlfua commented on Nov 7, 2026

    @tlfua

    untake

  3. tlfua commented on Nov 7, 2026

    @tlfua

    #7322 already covers this, so I'm stepping back.

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