@@ -23,7 +23,7 @@ use std::str::FromStr;
23
23
use std:: sync:: OnceLock ;
24
24
25
25
use crate :: type_coercion:: functions:: data_types;
26
- use crate :: { FuncMonotonicity , Signature , TypeSignature , Volatility } ;
26
+ use crate :: { FuncMonotonicity , Signature , Volatility } ;
27
27
28
28
use arrow:: datatypes:: DataType ;
29
29
use datafusion_common:: { plan_err, DataFusionError , Result } ;
@@ -39,15 +39,6 @@ pub enum BuiltinScalarFunction {
39
39
// math functions
40
40
/// coalesce
41
41
Coalesce ,
42
- // string functions
43
- /// concat
44
- Concat ,
45
- /// concat_ws
46
- ConcatWithSeparator ,
47
- /// ends_with
48
- EndsWith ,
49
- /// initcap
50
- InitCap ,
51
42
}
52
43
53
44
/// Maps the sql function name to `BuiltinScalarFunction`
@@ -101,10 +92,6 @@ impl BuiltinScalarFunction {
101
92
match self {
102
93
// Immutable scalar builtins
103
94
BuiltinScalarFunction :: Coalesce => Volatility :: Immutable ,
104
- BuiltinScalarFunction :: Concat => Volatility :: Immutable ,
105
- BuiltinScalarFunction :: ConcatWithSeparator => Volatility :: Immutable ,
106
- BuiltinScalarFunction :: EndsWith => Volatility :: Immutable ,
107
- BuiltinScalarFunction :: InitCap => Volatility :: Immutable ,
108
95
}
109
96
}
110
97
@@ -117,8 +104,6 @@ impl BuiltinScalarFunction {
117
104
/// 1. Perform additional checks on `input_expr_types` that are beyond the scope of `TypeSignature` validation.
118
105
/// 2. Deduce the output `DataType` based on the provided `input_expr_types`.
119
106
pub fn return_type ( self , input_expr_types : & [ DataType ] ) -> Result < DataType > {
120
- use DataType :: * ;
121
-
122
107
// Note that this function *must* return the same type that the respective physical expression returns
123
108
// or the execution panics.
124
109
@@ -130,43 +115,18 @@ impl BuiltinScalarFunction {
130
115
let coerced_types = data_types ( input_expr_types, & self . signature ( ) ) ;
131
116
coerced_types. map ( |types| types[ 0 ] . clone ( ) )
132
117
}
133
- BuiltinScalarFunction :: Concat => Ok ( Utf8 ) ,
134
- BuiltinScalarFunction :: ConcatWithSeparator => Ok ( Utf8 ) ,
135
- BuiltinScalarFunction :: InitCap => {
136
- utf8_to_str_type ( & input_expr_types[ 0 ] , "initcap" )
137
- }
138
- BuiltinScalarFunction :: EndsWith => Ok ( Boolean ) ,
139
118
}
140
119
}
141
120
142
121
/// Return the argument [`Signature`] supported by this function
143
122
pub fn signature ( & self ) -> Signature {
144
- use DataType :: * ;
145
- use TypeSignature :: * ;
146
123
// note: the physical expression must accept the type returned by this function or the execution panics.
147
124
148
125
// for now, the list is small, as we do not have many built-in functions.
149
126
match self {
150
- BuiltinScalarFunction :: Concat
151
- | BuiltinScalarFunction :: ConcatWithSeparator => {
152
- Signature :: variadic ( vec ! [ Utf8 ] , self . volatility ( ) )
153
- }
154
127
BuiltinScalarFunction :: Coalesce => {
155
128
Signature :: variadic_equal ( self . volatility ( ) )
156
129
}
157
- BuiltinScalarFunction :: InitCap => {
158
- Signature :: uniform ( 1 , vec ! [ Utf8 , LargeUtf8 ] , self . volatility ( ) )
159
- }
160
-
161
- BuiltinScalarFunction :: EndsWith => Signature :: one_of (
162
- vec ! [
163
- Exact ( vec![ Utf8 , Utf8 ] ) ,
164
- Exact ( vec![ Utf8 , LargeUtf8 ] ) ,
165
- Exact ( vec![ LargeUtf8 , Utf8 ] ) ,
166
- Exact ( vec![ LargeUtf8 , LargeUtf8 ] ) ,
167
- ] ,
168
- self . volatility ( ) ,
169
- ) ,
170
130
}
171
131
}
172
132
@@ -182,11 +142,6 @@ impl BuiltinScalarFunction {
182
142
match self {
183
143
// conditional functions
184
144
BuiltinScalarFunction :: Coalesce => & [ "coalesce" ] ,
185
-
186
- BuiltinScalarFunction :: Concat => & [ "concat" ] ,
187
- BuiltinScalarFunction :: ConcatWithSeparator => & [ "concat_ws" ] ,
188
- BuiltinScalarFunction :: EndsWith => & [ "ends_with" ] ,
189
- BuiltinScalarFunction :: InitCap => & [ "initcap" ] ,
190
145
}
191
146
}
192
147
}
@@ -208,49 +163,6 @@ impl FromStr for BuiltinScalarFunction {
208
163
}
209
164
}
210
165
211
- /// Creates a function to identify the optimal return type of a string function given
212
- /// the type of its first argument.
213
- ///
214
- /// If the input type is `LargeUtf8` or `LargeBinary` the return type is
215
- /// `$largeUtf8Type`,
216
- ///
217
- /// If the input type is `Utf8` or `Binary` the return type is `$utf8Type`,
218
- macro_rules! get_optimal_return_type {
219
- ( $FUNC: ident, $largeUtf8Type: expr, $utf8Type: expr) => {
220
- fn $FUNC( arg_type: & DataType , name: & str ) -> Result <DataType > {
221
- Ok ( match arg_type {
222
- // LargeBinary inputs are automatically coerced to Utf8
223
- DataType :: LargeUtf8 | DataType :: LargeBinary => $largeUtf8Type,
224
- // Binary inputs are automatically coerced to Utf8
225
- DataType :: Utf8 | DataType :: Binary => $utf8Type,
226
- DataType :: Null => DataType :: Null ,
227
- DataType :: Dictionary ( _, value_type) => match * * value_type {
228
- DataType :: LargeUtf8 | DataType :: LargeBinary => $largeUtf8Type,
229
- DataType :: Utf8 | DataType :: Binary => $utf8Type,
230
- DataType :: Null => DataType :: Null ,
231
- _ => {
232
- return plan_err!(
233
- "The {} function can only accept strings, but got {:?}." ,
234
- name. to_uppercase( ) ,
235
- * * value_type
236
- ) ;
237
- }
238
- } ,
239
- data_type => {
240
- return plan_err!(
241
- "The {} function can only accept strings, but got {:?}." ,
242
- name. to_uppercase( ) ,
243
- data_type
244
- ) ;
245
- }
246
- } )
247
- }
248
- } ;
249
- }
250
-
251
- // `utf8_to_str_type`: returns either a Utf8 or LargeUtf8 based on the input type size.
252
- get_optimal_return_type ! ( utf8_to_str_type, DataType :: LargeUtf8 , DataType :: Utf8 ) ;
253
-
254
166
#[ cfg( test) ]
255
167
mod tests {
256
168
use super :: * ;
0 commit comments