@@ -31,8 +31,8 @@ use datafusion_common::{
31
31
} ;
32
32
use datafusion_execution:: runtime_env:: { RuntimeConfig , RuntimeEnv } ;
33
33
use datafusion_expr:: {
34
- create_udaf, create_udf, Accumulator , ColumnarValue , CreateFunction , DropFunction ,
35
- ExprSchemable , LogicalPlanBuilder , ScalarUDF , ScalarUDFImpl , Signature , Volatility ,
34
+ create_udaf, create_udf, Accumulator , ColumnarValue , CreateFunction , ExprSchemable ,
35
+ LogicalPlanBuilder , ScalarUDF , ScalarUDFImpl , Signature , Volatility ,
36
36
} ;
37
37
use parking_lot:: Mutex ;
38
38
use rand:: { thread_rng, Rng } ;
@@ -693,28 +693,10 @@ impl FunctionFactory for MockFunctionFactory {
693
693
694
694
Ok ( RegisterFunction :: Scalar ( Arc :: new ( mock_udf) ) )
695
695
}
696
-
697
- async fn remove (
698
- & self ,
699
- _config : & SessionConfig ,
700
- _statement : DropFunction ,
701
- ) -> datafusion:: error:: Result < RegisterFunction > {
702
- // TODO: I don't like that remove returns RegisterFunction
703
- // we have to keep two states in FunctionFactory iml and
704
- // SessionState
705
- //
706
- // It would be better to return (function_name, function type) tuple
707
- //
708
- // at the moment state does not support unregister user defined functions
709
-
710
- Err ( datafusion_common:: DataFusionError :: NotImplemented (
711
- "remove function has not been implemented" . into ( ) ,
712
- ) )
713
- }
714
696
}
715
697
716
698
#[ tokio:: test]
717
- async fn create_scalar_function_from_sql_statement ( ) {
699
+ async fn create_scalar_function_from_sql_statement ( ) -> Result < ( ) > {
718
700
let function_factory = Arc :: new ( MockFunctionFactory :: default ( ) ) ;
719
701
let runtime_config = RuntimeConfig :: new ( ) ;
720
702
let runtime_environment = RuntimeEnv :: new ( runtime_config) . unwrap ( ) ;
@@ -732,23 +714,26 @@ async fn create_scalar_function_from_sql_statement() {
732
714
RETURNS DOUBLE
733
715
RETURN $1 + $2
734
716
"# ;
735
- let _ = ctx. sql ( sql) . await . unwrap ( ) ;
717
+ let _ = ctx. sql ( sql) . await ? ;
736
718
737
- ctx. sql ( "select better_add(2.0, 2.0)" )
738
- . await
739
- . unwrap ( )
740
- . show ( )
741
- . await
742
- . unwrap ( ) ;
719
+ ctx. sql ( "select better_add(2.0, 2.0)" ) . await ?. show ( ) . await ?;
743
720
744
721
// check if we sql expr has been converted to datafusion expr
745
722
let captured_expression = function_factory. captured_expr . lock ( ) . clone ( ) . unwrap ( ) ;
746
723
747
724
// is there some better way to test this
748
725
assert_eq ! ( "$1 + $2" , captured_expression. to_string( ) ) ;
749
726
750
- // no support at the moment
751
- // ctx.sql("drop function better_add").await.unwrap();
727
+ // statement drops function
728
+ assert ! ( ctx. sql( "drop function better_add" ) . await . is_ok( ) ) ;
729
+ // no function, it panics
730
+ assert ! ( ctx. sql( "drop function better_add" ) . await . is_err( ) ) ;
731
+ // no function, it dies not care
732
+ assert ! ( ctx. sql( "drop function if exists better_add" ) . await . is_ok( ) ) ;
733
+ // query should fail as there is no function
734
+ assert ! ( ctx. sql( "select better_add(2.0, 2.0)" ) . await . is_err( ) ) ;
735
+
736
+ Ok ( ( ) )
752
737
}
753
738
754
739
fn create_udf_context ( ) -> SessionContext {
0 commit comments