gabotechs commented on code in PR #18739:
URL: https://github.com/apache/datafusion/pull/18739#discussion_r2558705726
##########
datafusion/physical-optimizer/src/optimizer.rs:
##########
@@ -38,23 +38,103 @@ use crate::update_aggr_exprs::OptimizeAggregateOrder;
use crate::limit_pushdown_past_window::LimitPushPastWindows;
use datafusion_common::config::ConfigOptions;
-use datafusion_common::Result;
+use datafusion_common::{internal_err, Result};
+use datafusion_execution::config::{Extensions, SessionConfig};
use datafusion_physical_plan::ExecutionPlan;
-/// `PhysicalOptimizerRule` transforms one ['ExecutionPlan'] into another which
+/// Context for optimizing physical plans.
+///
+/// This context provides access to session configuration and optimizer
extensions.
+///
+/// Similar to [`TaskContext`] which provides context during execution,
+/// `OptimizerContext` provides context during optimization.
+///
+/// [`TaskContext`]:
https://docs.rs/datafusion/latest/datafusion/execution/struct.TaskContext.html
+#[derive(Debug, Clone)]
+pub struct OptimizerContext {
+ /// Session configuration
+ session_config: SessionConfig,
+}
+
+impl OptimizerContext {
+ /// Create a new OptimizerContext
+ pub fn new(session_config: SessionConfig) -> Self {
+ Self { session_config }
+ }
+
+ /// Return a reference to the session configuration
+ pub fn session_config(&self) -> &SessionConfig {
+ &self.session_config
+ }
+
+ /// Return a reference to the configuration options
+ ///
+ /// This is a convenience method that returns the [`ConfigOptions`]
+ /// from the [`SessionConfig`].
+ pub fn options(&self) -> &Arc<ConfigOptions> {
+ self.session_config.options()
+ }
+
+ /// Return a reference to the extensions
+ pub fn extensions(&self) -> &Arc<Extensions> {
+ self.session_config.extensions()
+ }
+}
Review Comment:
> Personally I would have kept the SessionConfig hidden until someone asks
for it to minimize the dependency on such a large object
✋ asking here, I specifically could use both `session_config.extensions` and
`session_config.options.extensions`, so just having something like what we have
in `TaskContext` is enough:
```rust
/// Return the SessionConfig associated with this [OptimizerContext]
pub fn session_config(&self) -> &SessionConfig {
&self.session_config
}
```
--
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]