@@ -57,10 +57,8 @@ use datafusion_expr::planner::ExprPlanner;
5757#[ cfg( feature = "sql" ) ]
5858use datafusion_expr:: planner:: { RelationPlanner , TypePlanner } ;
5959use datafusion_expr:: registry:: { FunctionRegistry , SerializerRegistry } ;
60- use datafusion_expr:: simplify:: SimplifyInfo ;
61- use datafusion_expr:: {
62- AggregateUDF , Explain , Expr , ExprSchemable , LogicalPlan , ScalarUDF , WindowUDF ,
63- } ;
60+ use datafusion_expr:: simplify:: SimplifyContext ;
61+ use datafusion_expr:: { AggregateUDF , Explain , Expr , LogicalPlan , ScalarUDF , WindowUDF } ;
6462use datafusion_optimizer:: simplify_expressions:: ExprSimplifier ;
6563use datafusion_optimizer:: {
6664 Analyzer , AnalyzerRule , Optimizer , OptimizerConfig , OptimizerRule ,
@@ -744,13 +742,18 @@ impl SessionState {
744742 expr : Expr ,
745743 df_schema : & DFSchema ,
746744 ) -> datafusion_common:: Result < Arc < dyn PhysicalExpr > > {
747- let simplifier =
748- ExprSimplifier :: new ( SessionSimplifyProvider :: new ( self , df_schema) ) ;
745+ let config_options = self . config_options ( ) ;
746+ let simplify_context = SimplifyContext :: default ( )
747+ . with_schema ( Arc :: new ( df_schema. clone ( ) ) )
748+ . with_config_options ( Arc :: clone ( config_options) )
749+ . with_query_execution_start_time (
750+ self . execution_props ( ) . query_execution_start_time ,
751+ ) ;
752+ let simplifier = ExprSimplifier :: new ( simplify_context) ;
749753 // apply type coercion here to ensure types match
750754 let mut expr = simplifier. coerce ( expr, df_schema) ?;
751755
752756 // rewrite Exprs to functions if necessary
753- let config_options = self . config_options ( ) ;
754757 for rewrite in self . analyzer . function_rewrites ( ) {
755758 expr = expr
756759 . transform_up ( |expr| rewrite. rewrite ( expr, df_schema, config_options) ) ?
@@ -1834,9 +1837,12 @@ impl ContextProvider for SessionContextProvider<'_> {
18341837 . get ( name)
18351838 . cloned ( )
18361839 . ok_or_else ( || plan_datafusion_err ! ( "table function '{name}' not found" ) ) ?;
1837- let dummy_schema = DFSchema :: empty ( ) ;
1838- let simplifier =
1839- ExprSimplifier :: new ( SessionSimplifyProvider :: new ( self . state , & dummy_schema) ) ;
1840+ let simplify_context = SimplifyContext :: default ( )
1841+ . with_config_options ( Arc :: clone ( self . state . config_options ( ) ) )
1842+ . with_query_execution_start_time (
1843+ self . state . execution_props ( ) . query_execution_start_time ,
1844+ ) ;
1845+ let simplifier = ExprSimplifier :: new ( simplify_context) ;
18401846 let args = args
18411847 . into_iter ( )
18421848 . map ( |arg| simplifier. simplify ( arg) )
@@ -2115,39 +2121,6 @@ impl QueryPlanner for DefaultQueryPlanner {
21152121 }
21162122}
21172123
2118- struct SessionSimplifyProvider < ' a > {
2119- state : & ' a SessionState ,
2120- df_schema : & ' a DFSchema ,
2121- }
2122-
2123- impl < ' a > SessionSimplifyProvider < ' a > {
2124- fn new ( state : & ' a SessionState , df_schema : & ' a DFSchema ) -> Self {
2125- Self { state, df_schema }
2126- }
2127- }
2128-
2129- impl SimplifyInfo for SessionSimplifyProvider < ' _ > {
2130- fn is_boolean_type ( & self , expr : & Expr ) -> datafusion_common:: Result < bool > {
2131- Ok ( expr. get_type ( self . df_schema ) ? == DataType :: Boolean )
2132- }
2133-
2134- fn nullable ( & self , expr : & Expr ) -> datafusion_common:: Result < bool > {
2135- expr. nullable ( self . df_schema )
2136- }
2137-
2138- fn get_data_type ( & self , expr : & Expr ) -> datafusion_common:: Result < DataType > {
2139- expr. get_type ( self . df_schema )
2140- }
2141-
2142- fn query_execution_start_time ( & self ) -> Option < DateTime < Utc > > {
2143- self . state . execution_props ( ) . query_execution_start_time
2144- }
2145-
2146- fn config_options ( & self ) -> Option < & Arc < ConfigOptions > > {
2147- self . state . execution_props ( ) . config_options . as_ref ( )
2148- }
2149- }
2150-
21512124#[ derive( Debug ) ]
21522125pub ( crate ) struct PreparedPlan {
21532126 /// Data types of the parameters
0 commit comments