@@ -40,7 +40,6 @@ use datafusion_common::{
40
40
exec_err, not_impl_err, plan_datafusion_err, plan_err,
41
41
tree_node:: { TreeNode , TreeNodeVisitor , VisitRecursion } ,
42
42
} ;
43
- pub use datafusion_execution:: registry:: MutableFunctionRegistry ;
44
43
use datafusion_execution:: registry:: SerializerRegistry ;
45
44
use datafusion_expr:: {
46
45
logical_plan:: { DdlStatement , Statement } ,
@@ -796,6 +795,48 @@ impl SessionContext {
796
795
. add_var_provider ( variable_type, provider) ;
797
796
}
798
797
798
+ /// Registers a scalar UDF within this context.
799
+ ///
800
+ /// Note in SQL queries, function names are looked up using
801
+ /// lowercase unless the query uses quotes. For example,
802
+ ///
803
+ /// - `SELECT MY_FUNC(x)...` will look for a function named `"my_func"`
804
+ /// - `SELECT "my_FUNC"(x)` will look for a function named `"my_FUNC"`
805
+ pub fn register_udf ( & self , f : ScalarUDF ) {
806
+ self . state
807
+ . write ( )
808
+ . scalar_functions
809
+ . insert ( f. name ( ) . to_string ( ) , Arc :: new ( f) ) ;
810
+ }
811
+
812
+ /// Registers an aggregate UDF within this context.
813
+ ///
814
+ /// Note in SQL queries, aggregate names are looked up using
815
+ /// lowercase unless the query uses quotes. For example,
816
+ ///
817
+ /// - `SELECT MY_UDAF(x)...` will look for an aggregate named `"my_udaf"`
818
+ /// - `SELECT "my_UDAF"(x)` will look for an aggregate named `"my_UDAF"`
819
+ pub fn register_udaf ( & self , f : AggregateUDF ) {
820
+ self . state
821
+ . write ( )
822
+ . aggregate_functions
823
+ . insert ( f. name . clone ( ) , Arc :: new ( f) ) ;
824
+ }
825
+
826
+ /// Registers a window UDF within this context.
827
+ ///
828
+ /// Note in SQL queries, window function names are looked up using
829
+ /// lowercase unless the query uses quotes. For example,
830
+ ///
831
+ /// - `SELECT MY_UDWF(x)...` will look for a window function named `"my_udwf"`
832
+ /// - `SELECT "my_UDWF"(x)` will look for a window function named `"my_UDWF"`
833
+ pub fn register_udwf ( & self , f : WindowUDF ) {
834
+ self . state
835
+ . write ( )
836
+ . window_functions
837
+ . insert ( f. name . clone ( ) , Arc :: new ( f) ) ;
838
+ }
839
+
799
840
/// Creates a [`DataFrame`] for reading a data source.
800
841
///
801
842
/// For more control such as reading multiple files, you can use
@@ -1117,50 +1158,6 @@ impl FunctionRegistry for SessionContext {
1117
1158
}
1118
1159
}
1119
1160
1120
- impl MutableFunctionRegistry for SessionContext {
1121
- /// Registers a scalar UDF within this context.
1122
- ///
1123
- /// Note in SQL queries, function names are looked up using
1124
- /// lowercase unless the query uses quotes. For example,
1125
- ///
1126
- /// - `SELECT MY_FUNC(x)...` will look for a function named `"my_func"`
1127
- /// - `SELECT "my_FUNC"(x)` will look for a function named `"my_FUNC"`
1128
- fn register_udf ( & self , f : ScalarUDF ) {
1129
- self . state
1130
- . write ( )
1131
- . scalar_functions
1132
- . insert ( f. name ( ) . to_string ( ) , Arc :: new ( f) ) ;
1133
- }
1134
-
1135
- /// Registers an aggregate UDF within this context.
1136
- ///
1137
- /// Note in SQL queries, aggregate names are looked up using
1138
- /// lowercase unless the query uses quotes. For example,
1139
- ///
1140
- /// - `SELECT MY_UDAF(x)...` will look for an aggregate named `"my_udaf"`
1141
- /// - `SELECT "my_UDAF"(x)` will look for an aggregate named `"my_UDAF"`
1142
- fn register_udaf ( & self , f : AggregateUDF ) {
1143
- self . state
1144
- . write ( )
1145
- . aggregate_functions
1146
- . insert ( f. name . clone ( ) , Arc :: new ( f) ) ;
1147
- }
1148
-
1149
- /// Registers a window UDF within this context.
1150
- ///
1151
- /// Note in SQL queries, window function names are looked up using
1152
- /// lowercase unless the query uses quotes. For example,
1153
- ///
1154
- /// - `SELECT MY_UDWF(x)...` will look for a window function named `"my_udwf"`
1155
- /// - `SELECT "my_UDWF"(x)` will look for a window function named `"my_UDWF"`
1156
- fn register_udwf ( & self , f : WindowUDF ) {
1157
- self . state
1158
- . write ( )
1159
- . window_functions
1160
- . insert ( f. name . clone ( ) , Arc :: new ( f) ) ;
1161
- }
1162
- }
1163
-
1164
1161
/// A planner used to add extensions to DataFusion logical and physical plans.
1165
1162
#[ async_trait]
1166
1163
pub trait QueryPlanner {
@@ -1301,14 +1298,18 @@ impl SessionState {
1301
1298
) ;
1302
1299
}
1303
1300
1301
+ // register built in functions
1302
+ let mut scalar_functions = HashMap :: new ( ) ;
1303
+ datafusion_functions:: register_all ( & mut scalar_functions) ;
1304
+
1304
1305
SessionState {
1305
1306
session_id,
1306
1307
analyzer : Analyzer :: new ( ) ,
1307
1308
optimizer : Optimizer :: new ( ) ,
1308
1309
physical_optimizers : PhysicalOptimizer :: new ( ) ,
1309
1310
query_planner : Arc :: new ( DefaultQueryPlanner { } ) ,
1310
1311
catalog_list,
1311
- scalar_functions : HashMap :: new ( ) ,
1312
+ scalar_functions,
1312
1313
aggregate_functions : HashMap :: new ( ) ,
1313
1314
window_functions : HashMap :: new ( ) ,
1314
1315
serializer_registry : Arc :: new ( EmptySerializerRegistry ) ,
@@ -1318,19 +1319,7 @@ impl SessionState {
1318
1319
table_factories,
1319
1320
}
1320
1321
}
1321
- /// Returns new [`SessionState`] using the provided
1322
- /// [`SessionConfig`] and [`RuntimeEnv`].
1323
- #[ deprecated(
1324
- since = "32.0.0" ,
1325
- note = "Use SessionState::new_with_config_rt_and_catalog_list"
1326
- ) ]
1327
- pub fn with_config_rt_and_catalog_list (
1328
- config : SessionConfig ,
1329
- runtime : Arc < RuntimeEnv > ,
1330
- catalog_list : Arc < dyn CatalogList > ,
1331
- ) -> Self {
1332
- Self :: new_with_config_rt_and_catalog_list ( config, runtime, catalog_list)
1333
- }
1322
+
1334
1323
fn register_default_schema (
1335
1324
config : & SessionConfig ,
1336
1325
table_factories : & HashMap < String , Arc < dyn TableProviderFactory > > ,
0 commit comments