edmondop opened a new pull request, #8447: URL: https://github.com/apache/arrow-datafusion/pull/8447
Addresses #8157 Implement an AnalyzerRules that rewrites Expr::ScalarFunction replacing `ScalarFunctionDefinition::Name` into `ScalarFunctionDefinition::BuiltIn` or `ScalarFunctionDefinition:ScalarUDF` at plan time. Unclear how to pass the FunctionRegistry down to the analyzer rule. ### Option 1: When creating the analyzer Using this approach means giving up the Default implementation, as well as doing some refactoring in https://github.com/apache/arrow-datafusion/blob/c8e1c84e6b4f1292afa6f5517bc6978b55758723/datafusion/core/src/execution/context/mod.rs#L1348, since the analyzer needs a FunctionRegistry and the SessionState implements that trait ### Option 2: When invoking the analyzer Using this approach means changing the `pub trait Analyzer` adding a fourth parameter. ```rust pub trait AnalyzerRule { /// Rewrite `plan` fn analyze(&self, plan: LogicalPlan, config: &ConfigOptions, registry: impl FunctionRegistry + Send + Sync) -> Result<LogicalPlan>; /// A human readable name for this analyzer rule fn name(&self) -> &str; } ``` However this creates on its own a problem ``` the trait `AnalyzerRule` cannot be made into an object consider moving `analyze` to another traitrustc[Click for full compiler diagnostic](rust-analyzer-diagnostics-view:/diagnostic%20message%20%5B2%5D?2#file%3A%2F%2F%2Fworkspace%2Farrow-datafusion%2Fdatafusion%2Foptimizer%2Fsrc%2Fanalyzer%2Fmod.rs) mod.rs(55, 8): for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> the trait `analyzer::AnalyzerRule` cannot be made into an object consider moving `analyze` to another traitrustc[Click for full compiler diagnostic](rust-analyzer-diagnostics-view:/diagnostic%20message%20%5B5%5D?5#file%3A%2F%2F%2Fworkspace%2Farrow-datafusion%2Fdatafusion%2Foptimizer%2Fsrc%2Fanalyzer%2Fmod.rs) mod.rs(55, 8): for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> No quick fixes available ``` Maybe the best solution is to create an intermediate struct that contains the various HashMaps of SessionState, an pass that struct to the Analyzer, as well as the SessionState constructor? Suggestions are welcome :) -- 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]
