@@ -23,7 +23,8 @@ use arrow::datatypes::{ArrowNativeType, DataType, Int32Type, Int64Type};
23
23
24
24
use crate :: string:: common:: StringArrayType ;
25
25
use crate :: utils:: { make_scalar_function, utf8_to_int_type} ;
26
- use datafusion_common:: { exec_err, plan_err, Result } ;
26
+ use datafusion_common:: { exec_err, Result } ;
27
+ use datafusion_expr:: TypeSignature :: Exact ;
27
28
use datafusion_expr:: { ColumnarValue , ScalarUDFImpl , Signature , Volatility } ;
28
29
29
30
#[ derive( Debug ) ]
@@ -40,8 +41,20 @@ impl Default for StrposFunc {
40
41
41
42
impl StrposFunc {
42
43
pub fn new ( ) -> Self {
44
+ use DataType :: * ;
43
45
Self {
44
- signature : Signature :: user_defined ( Volatility :: Immutable ) ,
46
+ signature : Signature :: one_of (
47
+ vec ! [
48
+ Exact ( vec![ Utf8 , Utf8 ] ) ,
49
+ Exact ( vec![ Utf8 , LargeUtf8 ] ) ,
50
+ Exact ( vec![ LargeUtf8 , Utf8 ] ) ,
51
+ Exact ( vec![ LargeUtf8 , LargeUtf8 ] ) ,
52
+ Exact ( vec![ Utf8View , Utf8View ] ) ,
53
+ Exact ( vec![ Utf8View , Utf8 ] ) ,
54
+ Exact ( vec![ Utf8View , LargeUtf8 ] ) ,
55
+ ] ,
56
+ Volatility :: Immutable ,
57
+ ) ,
45
58
aliases : vec ! [ String :: from( "instr" ) , String :: from( "position" ) ] ,
46
59
}
47
60
}
@@ -71,25 +84,6 @@ impl ScalarUDFImpl for StrposFunc {
71
84
fn aliases ( & self ) -> & [ String ] {
72
85
& self . aliases
73
86
}
74
-
75
- fn coerce_types ( & self , arg_types : & [ DataType ] ) -> Result < Vec < DataType > > {
76
- match arg_types {
77
- [ first, second ] => {
78
- match ( first, second) {
79
- ( DataType :: LargeUtf8 | DataType :: Utf8View | DataType :: Utf8 , DataType :: LargeUtf8 | DataType :: Utf8View | DataType :: Utf8 ) => Ok ( arg_types. to_vec ( ) ) ,
80
- ( DataType :: Null , DataType :: Null ) => Ok ( vec ! [ DataType :: Utf8 , DataType :: Utf8 ] ) ,
81
- ( DataType :: Null , _) => Ok ( vec ! [ DataType :: Utf8 , second. to_owned( ) ] ) ,
82
- ( _, DataType :: Null ) => Ok ( vec ! [ first. to_owned( ) , DataType :: Utf8 ] ) ,
83
- ( DataType :: Dictionary ( _, value_type) , DataType :: LargeUtf8 | DataType :: Utf8View | DataType :: Utf8 ) => match * * value_type {
84
- DataType :: LargeUtf8 | DataType :: Utf8View | DataType :: Utf8 | DataType :: Null | DataType :: Binary => Ok ( vec ! [ * value_type. clone( ) , second. to_owned( ) ] ) ,
85
- _ => plan_err ! ( "The STRPOS/INSTR/POSITION function can only accept strings, but got {:?}." , * * value_type) ,
86
- } ,
87
- _ => plan_err ! ( "The STRPOS/INSTR/POSITION function can only accept strings, but got {:?}." , arg_types)
88
- }
89
- } ,
90
- _ => plan_err ! ( "The STRPOS/INSTR/POSITION function can only accept strings, but got {:?}" , arg_types)
91
- }
92
- }
93
87
}
94
88
95
89
fn strpos ( args : & [ ArrayRef ] ) -> Result < ArrayRef > {
0 commit comments