gabotechs commented on code in PR #18739:
URL: https://github.com/apache/datafusion/pull/18739#discussion_r2554895458


##########
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()
+    }
+}
+
+/// `PhysicalOptimizerRule` transforms one [`ExecutionPlan`] into another which
 /// computes the same results, but in a potentially more efficient way.
 ///
 /// Use [`SessionState::add_physical_optimizer_rule`] to register additional
 /// `PhysicalOptimizerRule`s.
 ///
 /// [`SessionState::add_physical_optimizer_rule`]: 
https://docs.rs/datafusion/latest/datafusion/execution/session_state/struct.SessionState.html#method.add_physical_optimizer_rule
 pub trait PhysicalOptimizerRule: Debug {
+    /// Rewrite `plan` to an optimized form with additional context
+    ///
+    /// This is the preferred method for implementing optimization rules as it
+    /// provides access to the full optimizer context including session 
configuration.
+    ///
+    /// The default implementation delegates to 
[`PhysicalOptimizerRule::optimize`] for
+    /// backwards compatibility with existing implementations.
+    ///
+    /// New implementations should override this method instead of 
`optimize()`.
+    ///
+    /// Once [`PhysicalOptimizerRule::optimize`] is deprecated and removed, 
this
+    /// default implementation will be removed and all implementations will be
+    /// required to implement this method.
+    fn optimize_plan(
+        &self,
+        plan: Arc<dyn ExecutionPlan>,
+        context: &OptimizerContext,
+    ) -> Result<Arc<dyn ExecutionPlan>> {
+        // Default implementation: delegate to the old method for backwards 
compatibility
+        #[allow(deprecated)]
+        self.optimize(plan, context.options())
+    }
+
     /// Rewrite `plan` to an optimized form
+    ///
+    /// This method is kept for backwards compatibility. New implementations
+    /// should implement [`optimize_plan`](Self::optimize_plan) instead, which
+    /// provides access to additional context.
+    ///
+    /// The default implementation returns an error indicating that neither
+    /// `optimize` nor `optimize_plan` was properly implemented. At least one
+    /// of these methods must be overridden.
+    #[deprecated(
+        since = "53.0.0",

Review Comment:
   If we are now on 51.0.0, I imagine this should say 52.0.0 right?



-- 
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]

Reply via email to