Repository navigation
feat(spark): add SparkOptions config extension #98
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
andygrove
merged 23 commits into
apache:main
from
rizzabhdwaj:port-spark-options-config-extension
Nov 17, 2026
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
f67e3d5
SparkOptions port
rizzabhdwaj 19868f7
Merge branch 'main' into port-spark-options-config-extension
rizzabhdwaj 1465181
mapdedp reverted back to prev impl
rizzabhdwaj 3bef740
Merge branch 'main' of https://github.com/apache/datafusion-spark int…
rizzabhdwaj f418983
mapdedp reverted back to prev impl
rizzabhdwaj 91ab726
Merge branch 'port-spark-options-config-extension' of https://github.…
rizzabhdwaj 718703f
map_key_dedup.slt test changed
rizzabhdwaj d28450c
spark option insert check
rizzabhdwaj 0dadf0e
docs for making with_config survive
rizzabhdwaj aaafb9e
fix as per feedback
rizzabhdwaj 789cdc1
Merge branch 'main' into port-spark-options-config-extension
rizzabhdwaj 55b794f
fix as per feedback
rizzabhdwaj 437631a
Merge branch 'port-spark-options-config-extension' of https://github.…
rizzabhdwaj 6abf445
Merge branch 'main' into port-spark-options-config-extension
rizzabhdwaj 6decf32
Merge branch 'main' into port-spark-options-config-extension
rizzabhdwaj ad51835
Merge branch 'main' into port-spark-options-config-extension
rizzabhdwaj 7e23b4b
Merge branch 'main' into port-spark-options-config-extension
rizzabhdwaj f3b40a4
fix(spark): honor legacy map policy and address config review
rizzabhdwaj 0767ec6
Merge remote-tracking branch 'origin2/port-spark-options-config-exten…
rizzabhdwaj 68a6786
Merge branch 'main' into port-spark-options-config-extension
rizzabhdwaj 059876e
Merge branch 'main' into port-spark-options-config-extension
rizzabhdwaj 07d88f6
fix(spark): remove duplicate module declarations
rizzabhdwaj b9912b2
Merge branch 'main' into port-spark-options-config-extension
rizzabhdwaj 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-FileCopyrightText: See the NOTICE file distributed with this work for additional information regarding copyright ownership | ||
| // SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements | ||
|
|
||
| use std::fmt; | ||
| use std::str::FromStr; | ||
|
|
||
| use datafusion_common::config::{ConfigExtension, ConfigField, ConfigOptions, Visit}; | ||
| use datafusion_common::extensions_options; | ||
| use datafusion_common::{DataFusionError, Result}; | ||
|
|
||
| /// Policy for handling duplicate keys in Spark map functions. | ||
| #[derive(Debug, Default, Clone, Copy, PartialEq, Eq)] | ||
| pub enum MapKeyDedupPolicy { | ||
| #[default] | ||
| Exception, | ||
| LastWin, | ||
| } | ||
|
|
||
| impl FromStr for MapKeyDedupPolicy { | ||
| type Err = DataFusionError; | ||
|
|
||
| fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
| match s.to_ascii_uppercase().as_str() { | ||
| "EXCEPTION" => Ok(Self::Exception), | ||
| "LAST_WIN" => Ok(Self::LastWin), | ||
| other => Err(DataFusionError::Configuration(format!( | ||
| "Invalid MapKeyDedupPolicy: {other}. Expected one of: EXCEPTION, LAST_WIN" | ||
| ))), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl ConfigField for MapKeyDedupPolicy { | ||
| fn visit<V: Visit>(&self, v: &mut V, key: &str, description: &'static str) { | ||
| v.some(key, self, description) | ||
| } | ||
|
|
||
| fn set(&mut self, _: &str, value: &str) -> Result<()> { | ||
| *self = value.parse()?; | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| impl fmt::Display for MapKeyDedupPolicy { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| match self { | ||
| Self::Exception => write!(f, "EXCEPTION"), | ||
| Self::LastWin => write!(f, "LAST_WIN"), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| extensions_options! { | ||
| /// Spark-specific configuration options under the `spark` namespace. | ||
| pub struct SparkOptions { | ||
| /// How to handle duplicate map keys: EXCEPTION raises an error (default), | ||
| /// while LAST_WIN keeps the last value for each key. | ||
| pub map_key_dedup_policy: MapKeyDedupPolicy, default = MapKeyDedupPolicy::Exception | ||
| } | ||
| } | ||
|
|
||
| impl ConfigExtension for SparkOptions { | ||
| const PREFIX: &'static str = "spark"; | ||
| } | ||
|
|
||
| /// Returns whether Spark map functions should keep the last value for duplicate keys. | ||
| /// | ||
| /// The new key is `spark.map_key_dedup_policy`. For DataFusion 56 compatibility, | ||
| /// the legacy `datafusion.spark.map_key_dedup_policy` is also honored: LAST_WIN | ||
| /// on either key takes precedence over EXCEPTION on the other. | ||
| /// Remove the legacy lookup when upgrading to DataFusion 57. | ||
| pub fn map_last_value_wins(options: &ConfigOptions) -> bool { | ||
| options | ||
| .extensions | ||
| .get::<SparkOptions>() | ||
| .is_some_and(|options| options.map_key_dedup_policy == MapKeyDedupPolicy::LastWin) | ||
| || options.spark.map_key_dedup_policy | ||
| == datafusion_common::config::MapKeyDedupPolicy::LastWin | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use datafusion_common::config::ConfigOptions; | ||
|
|
||
| #[test] | ||
| fn spark_options_use_spark_prefix() { | ||
| let mut config = ConfigOptions::default(); | ||
| config.extensions.insert(SparkOptions::default()); | ||
|
|
||
| config | ||
| .set("spark.map_key_dedup_policy", "last_win") | ||
| .unwrap(); | ||
|
|
||
| assert_eq!( | ||
| config | ||
| .extensions | ||
| .get::<SparkOptions>() | ||
| .unwrap() | ||
| .map_key_dedup_policy, | ||
| MapKeyDedupPolicy::LastWin | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn spark_options_reject_invalid_policy() { | ||
| let mut config = ConfigOptions::default(); | ||
| config.extensions.insert(SparkOptions::default()); | ||
|
|
||
| let error = config | ||
| .set("spark.map_key_dedup_policy", "bogus") | ||
| .unwrap_err() | ||
| .to_string(); | ||
|
|
||
| assert!(error.contains("Invalid MapKeyDedupPolicy"), "{error}"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn missing_spark_options_use_exception_policy() { | ||
| assert!(!map_last_value_wins(&ConfigOptions::default())); | ||
| } | ||
|
|
||
| #[test] | ||
| fn configured_spark_options_enable_last_win() { | ||
| let mut config = ConfigOptions::default(); | ||
| config.extensions.insert(SparkOptions { | ||
| map_key_dedup_policy: MapKeyDedupPolicy::LastWin, | ||
| }); | ||
|
|
||
| assert!(map_last_value_wins(&config)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn legacy_and_extension_policy_combinations() { | ||
| for legacy in ["EXCEPTION", "LAST_WIN"] { | ||
| for extension in [None, Some("EXCEPTION"), Some("LAST_WIN")] { | ||
| let mut config = ConfigOptions::default(); | ||
| config | ||
| .set("datafusion.spark.map_key_dedup_policy", legacy) | ||
| .unwrap(); | ||
| if let Some(policy) = extension { | ||
| config.extensions.insert(SparkOptions::default()); | ||
| config.set("spark.map_key_dedup_policy", policy).unwrap(); | ||
| } | ||
|
|
||
| assert_eq!( | ||
| map_last_value_wins(&config), | ||
| legacy == "LAST_WIN" || extension == Some("LAST_WIN"), | ||
| "legacy={legacy}, extension={extension:?}" | ||
| ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn map_policy_has_description() { | ||
| let entries = datafusion_common::config::ExtensionOptions::entries( | ||
| &SparkOptions::default(), | ||
| ); | ||
| let entry = entries | ||
| .iter() | ||
| .find(|entry| entry.key == "map_key_dedup_policy") | ||
| .unwrap(); | ||
| assert!(entry.description.contains("EXCEPTION")); | ||
| assert!(entry.description.contains("LAST_WIN")); | ||
| } | ||
| } |
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.