Skip to content

Add protobuf support for lambdas - #22362

Merged
comphead merged 12 commits into
apache:mainfrom
gstvg:lambda_protobuf_new
Jul 10, 2026
Merged

Add protobuf support for lambdas#22362
comphead merged 12 commits into
apache:mainfrom
gstvg:lambda_protobuf_new

Conversation

@gstvg

@gstvggstvg commented May 19, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Part of #21172

Rationale for this change

Protobuf support wasn't implemented in main lambda PR to not make it even bigger

What changes are included in this PR?

Protobuf encoding and decoding (~1000 LOC in generated files, ~210 impl, ~400 tests)

Are these changes tested?

Unit tests, similar to the existing ones for scalar functions

Are there any user-facing changes?

Proto ExprType has new variants

@github-actionsgithub-actionsBot added the proto Related to proto crate label May 19, 2026
return Err(Error::General(
"Proto serialization error: Lambda not implemented".to_string(),
));
Expr::HigherOrderFunction(HigherOrderFunction { func, args }) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super nit: instead of appending this, can we move this next to the rest of functions? (Scalar, Aggregate etc)

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much easier to cross check the impls now 5688f3f thanks
(also did this to others similar matchs)

Comment on lines +434 to +436
HigherOrderUDFExprNode higher_order_udf_expr = 37;
Lambda lambda = 38;
LambdaVariable lambda_variable = 39;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super nit as well: Can we move this next to the other UDFs?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't better being ordered by field id? so the next one who add a node can spot the next available field id right away

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah makes sense

expr_id,
expr_type: Some(protobuf::physical_expr_node::ExprType::LambdaVariable(
PhysicalLambdaVariableExprNode {
index: var.index() as u32,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for now we don't use this so it is always 0 no?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used now after lambda capture got merged. The variable below has index 1, for example:

01)ProjectionExec: expr=[array_transform(make_array(number@0), (v) -> CAST(v@1 AS Float64) + 3) as array_transform(make_array(t.number),(v) -> v + Float64(3))]

Comment on lines +586 to +590
protobuf::PhysicalHigherOrderUdfNode {
name: expr.name().to_string(),
args: serialize_physical_exprs(expr.args(), codec, proto_converter)?,
fun_definition: (!buf.is_empty()).then_some(buf),
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we encode the return_field instead of resolving it from the schema when decoding (like ScalarUDF)?
Not really sure what would be the exact disadvantage of keeping it at is, but wondering if it would be cleaner to make the return type explicit.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the HigherOrderFunctionExpr::new, the only constructor that receives return_field as arg, from the lambda PR, due to possible type mismatch, so it could be discussed on it's own PR when needed. See #21679 (review) and

FYI, the return field might not match the function output after the new arguments, but you don't have the schema here so you cant check that and I see ScalarFunctionExpr have the same problem

from https://github.com/apache/datafusion/pull/21679/changes#r3109735988 (quoting directly since the github link anchor doesn't work well)

let serialize_name = extract_function_name(&expr);
let deserialize_name = extract_function_name(&deserialize);

assert_eq!(serialize_name, deserialize_name);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we assert directly on expr and deserialize instead? since the Hofs implement PartialEq I think it should work
assert_eq!(expr, deserialized_expr);

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, 9a3f30c thanks
This was based on test_expression_serialization_roundtrip which checks only names but asserting directly on expr is definitively better

@LiaCastaneda

Copy link
Copy Markdown
Contributor

Not sure why I thought this PR was already merged, not sure who to ping -- @comphead@alamb, are you able to take a look whenever you have time? 🙇 Half of the diff is the pbjson/prost generated files.

@comphead

Copy link
Copy Markdown
Contributor

Not sure why I thought this PR was already merged, not sure who to ping -- @comphead@alamb, are you able to take a look whenever you have time? 🙇 Half of the diff is the pbjson/prost generated files.

Thanks @LiaCastaneda

@gstvg if you have anytime to resolve the conflicts

@github-actions

github-actionsBot commented Jul 10, 2026

Copy link
Copy Markdown

Thank you for opening this pull request!

Reviewer note: cargo-semver-checks reported the current version number is not SemVer-compatible with the changes in this pull request (compared against the base branch).

Details
 Cloning apache/main
Building datafusion-physical-expr v54.0.0 (current)
Built [ 29.106s] (current)
Parsing datafusion-physical-expr v54.0.0 (current)
Parsed [ 0.046s] (current)
Building datafusion-physical-expr v54.0.0 (baseline)
Built [ 28.385s] (baseline)
Parsing datafusion-physical-expr v54.0.0 (baseline)
Parsed [ 0.046s] (baseline)
Checking datafusion-physical-expr v54.0.0 -> v54.0.0 (no change; assume patch)
Checked [ 0.395s] 223 checks: 223 pass, 30 skip
Summary no semver update required
Finished [ 58.988s] datafusion-physical-expr
Building datafusion-proto v54.0.0 (current)
Built [ 58.633s] (current)
Parsing datafusion-proto v54.0.0 (current)
Parsed [ 0.021s] (current)
Building datafusion-proto v54.0.0 (baseline)
Built [ 57.335s] (baseline)
Parsing datafusion-proto v54.0.0 (baseline)
Parsed [ 0.019s] (baseline)
Checking datafusion-proto v54.0.0 -> v54.0.0 (no change; assume patch)
Checked [ 0.248s] 223 checks: 223 pass, 30 skip
Summary no semver update required
Finished [ 118.667s] datafusion-proto
Building datafusion-proto-models v54.0.0 (current)
Built [ 23.477s] (current)
Parsing datafusion-proto-models v54.0.0 (current)
Parsed [ 0.127s] (current)
Building datafusion-proto-models v54.0.0 (baseline)
Built [ 23.326s] (baseline)
Parsing datafusion-proto-models v54.0.0 (baseline)
Parsed [ 0.124s] (baseline)
Checking datafusion-proto-models v54.0.0 -> v54.0.0 (no change; assume patch)
Checked [ 1.677s] 223 checks: 222 pass, 1 fail, 0 warn, 30 skip
--- failure enum_variant_added: enum variant added on exhaustive enum ---
Description:
A publicly-visible enum without #[non_exhaustive] has a new variant.
ref: https://doc.rust-lang.org/cargo/reference/semver.html#enum-variant-new
impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.48.0/src/lints/enum_variant_added.ron
Failed in:
variant ExprType:HigherOrderUdfExpr in /home/runner/work/datafusion/datafusion/datafusion/proto-models/src/generated/prost.rs:806
variant ExprType:Lambda in /home/runner/work/datafusion/datafusion/datafusion/proto-models/src/generated/prost.rs:808
variant ExprType:LambdaVariable in /home/runner/work/datafusion/datafusion/datafusion/proto-models/src/generated/prost.rs:810
variant ExprType:HigherOrderUdfExpr in /home/runner/work/datafusion/datafusion/datafusion/proto-models/src/generated/prost.rs:806
variant ExprType:Lambda in /home/runner/work/datafusion/datafusion/datafusion/proto-models/src/generated/prost.rs:808
variant ExprType:LambdaVariable in /home/runner/work/datafusion/datafusion/datafusion/proto-models/src/generated/prost.rs:810
variant ExprType:HigherOrderUdf in /home/runner/work/datafusion/datafusion/datafusion/proto-models/src/generated/prost.rs:1565
variant ExprType:Lambda in /home/runner/work/datafusion/datafusion/datafusion/proto-models/src/generated/prost.rs:1567
variant ExprType:LambdaVariable in /home/runner/work/datafusion/datafusion/datafusion/proto-models/src/generated/prost.rs:1569
variant ExprType:HigherOrderUdf in /home/runner/work/datafusion/datafusion/datafusion/proto-models/src/generated/prost.rs:1565
variant ExprType:Lambda in /home/runner/work/datafusion/datafusion/datafusion/proto-models/src/generated/prost.rs:1567
variant ExprType:LambdaVariable in /home/runner/work/datafusion/datafusion/datafusion/proto-models/src/generated/prost.rs:1569
Summary semver requires new major version: 1 major and 0 minor checks failed
Finished [ 50.080s] datafusion-proto-models

@github-actionsgithub-actionsBot added the auto detected api change Auto detected API change label Jul 10, 2026
@gstvg
gstvgforce-pushed the lambda_protobuf_new branch from 574ef1e to 17ad991CompareJuly 10, 2026 05:41
@gstvg
gstvgforce-pushed the lambda_protobuf_new branch from 17ad991 to 27769b9CompareJuly 10, 2026 05:44
@github-actionsgithub-actionsBot added the physical-expr Changes to the physical-expr crates label Jul 10, 2026
@gstvg

Copy link
Copy Markdown
ContributorAuthor

Thanks @LiaCastaneda@comphead, conflicts are resolved

@compheadcomphead left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @gstvg

@comphead
comphead added this pull request to the merge queueJul 10, 2026
Merged via the queue into apache:main with commit 7ac784fJul 10, 2026
40 checks passed
Tristan1900 pushed a commit to Tristan1900/datafusion-apache that referenced this pull request Jul 23, 2026
## Which issue does this PR close?
Part of apache#21172
## Rationale for this change
Protobuf support wasn't implemented in main lambda PR to not make it
even bigger
## What changes are included in this PR?
Protobuf encoding and decoding (~1000 LOC in generated files, ~210 impl,
~400 tests)
## Are these changes tested?
Unit tests, similar to the existing ones for scalar functions
## Are there any user-facing changes?
Proto `ExprType` has new variants
Tristan1900 pushed a commit to Tristan1900/datafusion-apache that referenced this pull request Jul 24, 2026
## Which issue does this PR close?
Part of apache#21172
## Rationale for this change
Protobuf support wasn't implemented in main lambda PR to not make it
even bigger
## What changes are included in this PR?
Protobuf encoding and decoding (~1000 LOC in generated files, ~210 impl,
~400 tests)
## Are these changes tested?
Unit tests, similar to the existing ones for scalar functions
## Are there any user-facing changes?
Proto `ExprType` has new variants
gabotechs pushed a commit to DataDog/datafusion that referenced this pull request Jul 27, 2026
## Which issue does this PR close?
Part of apache#21172
## Rationale for this change
Protobuf support wasn't implemented in main lambda PR to not make it
even bigger
## What changes are included in this PR?
Protobuf encoding and decoding (~1000 LOC in generated files, ~210 impl,
~400 tests)
## Are these changes tested?
Unit tests, similar to the existing ones for scalar functions
## Are there any user-facing changes?
Proto `ExprType` has new variants
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto detected api changeAuto detected API changephysical-exprChanges to the physical-expr cratesprotoRelated to proto crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@gstvg@LiaCastaneda@comphead