milenkovicm commented on code in PR #2637:
URL:
https://github.com/apache/datafusion-ballista/pull/2637#discussion_r4432986761
##########
python/python/ballista/extension.py:
##########
@@ -318,44 +319,349 @@ def _config_value_to_str(value: ConfigValue) -> str:
return str(value)
-def _normalize_cluster_config(
- cluster_config: Optional[Dict[str, ConfigValue]],
-) -> Optional[Dict[str, str]]:
- if cluster_config is None:
- return None
- return {str(k): _config_value_to_str(v) for k, v in cluster_config.items()}
-
-
-def _produce_valid_config(
- config: Optional[Union[SessionConfig, Dict[str, str]]] = None,
- cluster_config: Optional[Dict[str, ConfigValue]] = None,
-) -> SessionConfig:
- cluster_config = _normalize_cluster_config(cluster_config)
-
- ballista_settings = {
- k: v for k, v in (cluster_config or {}).items() if
k.startswith("ballista.")
- }
-
- # options explicitly set by the user, only known when config is a dict
- user_options = config if isinstance(config, dict) else {}
-
- if config is None:
- config = SessionConfig()
- elif isinstance(config, dict):
- config = SessionConfig(config)
-
- for key, value in ballista_datafusion_config_defaults().items():
- if (
- key.startswith("datafusion.")
- and key in _BALLISTA_RESTRICTED_DATAFUSION_OPTIONS
- ):
- restricted = _BALLISTA_RESTRICTED_DATAFUSION_OPTIONS[key]
- # keep user value for options which are not restricted
- if not restricted and key in user_options:
- continue
+class BallistaSessionConfig:
+ """
+ Builder for a Ballista-ready DataFusion ``SessionConfig``.
+
+ Mirrors Rust ``BallistaConfig``: typed ``with_*`` setters for Ballista
+ options, plus ``set`` for any ``datafusion.*`` or ``ballista.*`` option.
+ ``build`` produces a ``SessionConfig`` with Ballista defaults applied and
+ ``BallistaConfigExtension`` registered.
+
+ DataFusion options which Ballista overrides are set to Ballista defaults:
+ restricted options are always overridden, non-restricted options are kept
+ only when set with ``set`` or a dict.
+ Options inside a passed ``SessionConfig`` can not be inspected, so all of
+ them are overridden with Ballista defaults.
+
+ For example ``datafusion.execution.target_partitions`` defaults to ``16``,
+ change it with ``with_target_partitions``, ``set`` or a dict, not with
+ ``SessionConfig.with_target_partitions``.
+
+ Args:
+ config: Initial configuration, either a ``SessionConfig`` or a
dictionary
+ of ``datafusion.*`` and ``ballista.*`` options.
+
+ Examples:
+ >>> from ballista import BallistaSessionConfig
+ >>> config = (
+ ... BallistaSessionConfig({"datafusion.execution.batch_size":
8192})
+ ... .with_target_partitions(32)
+ ... .with_job_name("daily report")
+ ... .with_adaptive_query_planner(True)
+ ... .set("ballista.shuffle.compression.codec", "zstd")
+ ... .build()
+ ... )
+ """
+
+ def __init__(
+ self,
+ config: Optional[Union[SessionConfig, Dict[str, ConfigValue]]] = None,
Review Comment:
I don't quite understand this comment
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]