-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add lambda substrait support #21193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gstvg
wants to merge
16
commits into
apache:main
Choose a base branch
from
gstvg:lambda_substrait
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add lambda substrait support #21193
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
df1b740
feat: add substrait lambda support
gstvg 809d5db
Merge branch 'main' into lambda_substrait
rluvaton feace02
add some comments
gstvg 35e3bcf
Merge branch 'main' of https://github.com/apache/datafusion into lamb…
gstvg 9b6a8e1
address pr review
gstvg a153093
improve roundtrip tests
gstvg 1fc0f05
add consumer test
gstvg 6cdfc05
add producer test
gstvg 2c23439
add default impl to new lambda methods
gstvg 3d83fb4
Apply suggestion from @benbellick
gstvg 83e261f
improve serialize test readability
gstvg c019769
add lambda field reference tests
gstvg 93f17e4
add lambda tests
gstvg 347bf12
check invalid lambda
gstvg 59fb308
add comment to collect_lambda_ref test helper
gstvg e9a9441
Merge branch 'main' of https://github.com/gstvg/arrow-datafusion into…
gstvg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
103 changes: 103 additions & 0 deletions
103
datafusion/substrait/src/logical_plan/consumer/expr/lambda.rs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| use datafusion::{ | ||
| common::{DFSchema, substrait_err}, | ||
| prelude::{Expr, lambda}, | ||
| }; | ||
| use substrait::proto; | ||
|
|
||
| use crate::logical_plan::consumer::SubstraitConsumer; | ||
|
|
||
| pub async fn from_lambda( | ||
| consumer: &impl SubstraitConsumer, | ||
| expr: &proto::expression::Lambda, | ||
| input_schema: &DFSchema, | ||
| ) -> datafusion::common::Result<Expr> { | ||
| let Some(parameters) = expr.parameters.as_ref() else { | ||
| return substrait_err!("Lambda expression without parameters is not allowed"); | ||
| }; | ||
|
|
||
| let (names, consumer_with_parameters) = | ||
| consumer.with_lambda_parameters(¶meters.types, input_schema)?; | ||
|
|
||
| let Some(body) = expr.body.as_ref() else { | ||
| return substrait_err!("Lambda expression without body is not allowed"); | ||
| }; | ||
|
|
||
| let body = consumer_with_parameters | ||
| .consume_expression(body, input_schema) | ||
| .await?; | ||
|
|
||
| Ok(lambda(names, body)) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use datafusion::{ | ||
| common::{DFSchema, assert_contains}, | ||
| prelude::SessionContext, | ||
| }; | ||
| use substrait::proto::{self, Expression, r#type::Struct}; | ||
|
|
||
| use crate::{ | ||
| extensions::Extensions, | ||
| logical_plan::consumer::{DefaultSubstraitConsumer, from_lambda}, | ||
| }; | ||
|
|
||
| #[tokio::test] | ||
| async fn test_lambda_without_body() { | ||
| let lambda = proto::expression::Lambda { | ||
| parameters: Some(Struct::default()), | ||
| body: None, | ||
| }; | ||
|
|
||
| let extensions = Extensions::default(); | ||
| let session_state = SessionContext::new().state(); | ||
| let consumer = DefaultSubstraitConsumer::new(&extensions, &session_state); | ||
|
|
||
| let err = from_lambda(&consumer, &lambda, DFSchema::empty_ref()) | ||
| .await | ||
| .unwrap_err(); | ||
|
|
||
| assert_contains!( | ||
| err.to_string(), | ||
| "Lambda expression without body is not allowed" | ||
| ); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_lambda_without_parameters() { | ||
| let lambda = proto::expression::Lambda { | ||
| parameters: None, | ||
| body: Some(Box::new(Expression::default())), | ||
| }; | ||
|
|
||
| let extensions = Extensions::default(); | ||
| let session_state = SessionContext::new().state(); | ||
| let consumer = DefaultSubstraitConsumer::new(&extensions, &session_state); | ||
|
|
||
| let err = from_lambda(&consumer, &lambda, DFSchema::empty_ref()) | ||
| .await | ||
| .unwrap_err(); | ||
|
|
||
| assert_contains!( | ||
| err.to_string(), | ||
| "Lambda expression without parameters is not allowed" | ||
| ); | ||
| } | ||
| } |
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
|
gstvg marked this conversation as resolved.
|
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we include tests here to check that the following two things result in an error?
Or somewhere else if you think it would be more appropriate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, added tests for all 4 error at 93f17e4 and c019769, thanks