-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat(spark): Add SessionStateBuilderSpark to datafusion-spark
#19865
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e2a2861
feat: Add with_spark_features to SessionStateBuilder
cht42 c45f8fa
test: Add unit test for SessionState with Spark features
cht42 be3cc4a
feat: Add Spark feature checks to CI workflow
cht42 168747a
feat: Refactor Spark feature integration and update dependencies
cht42 a07eab4
feat: Remove datafusion-spark core feature check from CI workflow
cht42 6a96254
f
cht42 5e44faf
refactor: Remove unnecessary documentation for SessionStateBuilderSpark
cht42 078a1bf
fix: Update documentation for SessionStateBuilderSpark usage example
cht42 90faba8
fix: Correct code block syntax in documentation for SessionStateBuild…
cht42 5f89e47
fix: Update documentation for SessionStateBuilderSpark example and usage
cht42 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,96 @@ | ||
| // 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 std::collections::HashMap; | ||
| use std::sync::Arc; | ||
|
|
||
| use datafusion::execution::session_state::SessionStateBuilder; | ||
|
|
||
| use crate::planner::SparkFunctionPlanner; | ||
| use crate::{ | ||
| all_default_aggregate_functions, all_default_scalar_functions, | ||
| all_default_table_functions, all_default_window_functions, | ||
| }; | ||
|
|
||
| /// Extension trait for adding Apache Spark features to [`SessionStateBuilder`]. | ||
| /// | ||
| /// This trait provides a convenient way to register all Apache Spark-compatible | ||
| /// functions and planners with a DataFusion session. | ||
| pub trait SessionStateBuilderSpark { | ||
| /// Adds all expr_planners, scalar, aggregate, window and table functions | ||
| /// compatible with Apache Spark. | ||
| /// | ||
| /// Note: This overwrites any previously registered items with the same name. | ||
| fn with_spark_features(self) -> Self; | ||
| } | ||
|
|
||
| impl SessionStateBuilderSpark for SessionStateBuilder { | ||
| fn with_spark_features(mut self) -> Self { | ||
| self.expr_planners() | ||
| .get_or_insert_with(Vec::new) | ||
| // planners are evaluated in order of insertion. Push Apache Spark function planner to the front | ||
| // to take precedence over others | ||
| .insert(0, Arc::new(SparkFunctionPlanner)); | ||
|
|
||
| self.scalar_functions() | ||
| .get_or_insert_with(Vec::new) | ||
| .extend(all_default_scalar_functions()); | ||
|
|
||
| self.aggregate_functions() | ||
| .get_or_insert_with(Vec::new) | ||
| .extend(all_default_aggregate_functions()); | ||
|
|
||
| self.window_functions() | ||
| .get_or_insert_with(Vec::new) | ||
| .extend(all_default_window_functions()); | ||
|
|
||
| self.table_functions() | ||
| .get_or_insert_with(HashMap::new) | ||
| .extend( | ||
| all_default_table_functions() | ||
| .into_iter() | ||
| .map(|f| (f.name().to_string(), f)), | ||
| ); | ||
|
|
||
| self | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn test_session_state_with_spark_features() { | ||
| let state = SessionStateBuilder::new().with_spark_features().build(); | ||
|
|
||
| assert!( | ||
| state.scalar_functions().contains_key("sha2"), | ||
| "Apache Spark scalar function 'sha2' should be registered" | ||
| ); | ||
|
|
||
| assert!( | ||
| state.aggregate_functions().contains_key("try_sum"), | ||
| "Apache Spark aggregate function 'try_sum' should be registered" | ||
| ); | ||
|
|
||
| assert!( | ||
| !state.expr_planners().is_empty(), | ||
| "Apache Spark expr planners should be registered" | ||
| ); | ||
| } | ||
| } |
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
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.
Would prefer to avoid
ignorehere if possibleThere 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.
fixed it