@@ -5,8 +5,7 @@ use datafusion::logical_expr::function::{
5
5
AccumulatorArgs , PartitionEvaluatorArgs , WindowUDFFieldArgs ,
6
6
} ;
7
7
use datafusion:: logical_expr:: {
8
- Accumulator , AggregateUDFImpl , ColumnarValue , PartitionEvaluator , ScalarUDFImpl ,
9
- Signature , TypeSignature , Volatility , WindowUDFImpl ,
8
+ Accumulator , AggregateUDFImpl , ColumnarValue , DocSection , Documentation , DocumentationBuilder , PartitionEvaluator , ScalarUDFImpl , Signature , TypeSignature , Volatility , WindowUDFImpl
10
9
} ;
11
10
use serde:: { Deserialize , Serialize } ;
12
11
use std:: any:: Any ;
@@ -46,7 +45,7 @@ impl FromStr for FunctionType {
46
45
type Err = String ;
47
46
48
47
fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
49
- match s {
48
+ match s. to_lowercase ( ) . as_str ( ) {
50
49
"scalar" => Ok ( FunctionType :: Scalar ) ,
51
50
"aggregate" => Ok ( FunctionType :: Aggregate ) ,
52
51
"window" => Ok ( FunctionType :: Window ) ,
@@ -63,17 +62,20 @@ pub struct ByPassScalarUDF {
63
62
name : String ,
64
63
return_type : DataType ,
65
64
signature : Signature ,
65
+ doc : Documentation ,
66
66
}
67
67
68
68
impl ByPassScalarUDF {
69
- pub fn new ( name : & str , return_type : DataType ) -> Self {
69
+ pub fn new ( name : & str , return_type : DataType , description : Option < String > ) -> Self {
70
+ let doc= DocumentationBuilder :: new_with_details ( DocSection :: default ( ) , description. unwrap_or ( "" . to_string ( ) ) , "" ) . build ( ) ;
70
71
Self {
71
72
name : name. to_string ( ) ,
72
73
return_type,
73
74
signature : Signature :: one_of (
74
75
vec ! [ TypeSignature :: VariadicAny , TypeSignature :: Nullary ] ,
75
76
Volatility :: Volatile ,
76
77
) ,
78
+ doc,
77
79
}
78
80
}
79
81
}
@@ -98,6 +100,10 @@ impl ScalarUDFImpl for ByPassScalarUDF {
98
100
fn invoke ( & self , _args : & [ ColumnarValue ] ) -> Result < ColumnarValue > {
99
101
internal_err ! ( "This function should not be called" )
100
102
}
103
+
104
+ fn documentation ( & self ) -> Option < & Documentation > {
105
+ Some ( & self . doc )
106
+ }
101
107
}
102
108
103
109
/// An aggregate UDF that will be bypassed when planning logical plan.
@@ -107,17 +113,20 @@ pub struct ByPassAggregateUDF {
107
113
name : String ,
108
114
return_type : DataType ,
109
115
signature : Signature ,
116
+ doc : Documentation ,
110
117
}
111
118
112
119
impl ByPassAggregateUDF {
113
- pub fn new ( name : & str , return_type : DataType ) -> Self {
120
+ pub fn new ( name : & str , return_type : DataType , description : Option < String > ) -> Self {
121
+ let doc= DocumentationBuilder :: new_with_details ( DocSection :: default ( ) , description. unwrap_or ( "" . to_string ( ) ) , "" ) . build ( ) ;
114
122
Self {
115
123
name : name. to_string ( ) ,
116
124
return_type,
117
125
signature : Signature :: one_of (
118
126
vec ! [ TypeSignature :: VariadicAny , TypeSignature :: Nullary ] ,
119
127
Volatility :: Volatile ,
120
128
) ,
129
+ doc,
121
130
}
122
131
}
123
132
}
@@ -142,6 +151,10 @@ impl AggregateUDFImpl for ByPassAggregateUDF {
142
151
fn accumulator ( & self , _acc_args : AccumulatorArgs ) -> Result < Box < dyn Accumulator > > {
143
152
internal_err ! ( "This function should not be called" )
144
153
}
154
+
155
+ fn documentation ( & self ) -> Option < & Documentation > {
156
+ Some ( & self . doc )
157
+ }
145
158
}
146
159
147
160
/// A window UDF that will be bypassed when planning logical plan.
@@ -151,17 +164,20 @@ pub struct ByPassWindowFunction {
151
164
name : String ,
152
165
return_type : DataType ,
153
166
signature : Signature ,
167
+ doc : Documentation ,
154
168
}
155
169
156
170
impl ByPassWindowFunction {
157
- pub fn new ( name : & str , return_type : DataType ) -> Self {
171
+ pub fn new ( name : & str , return_type : DataType , description : Option < String > ) -> Self {
172
+ let doc= DocumentationBuilder :: new_with_details ( DocSection :: default ( ) , description. unwrap_or ( "" . to_string ( ) ) , "" ) . build ( ) ;
158
173
Self {
159
174
name : name. to_string ( ) ,
160
175
return_type,
161
176
signature : Signature :: one_of (
162
177
vec ! [ TypeSignature :: VariadicAny , TypeSignature :: Nullary ] ,
163
178
Volatility :: Volatile ,
164
179
) ,
180
+ doc,
165
181
}
166
182
}
167
183
}
@@ -193,6 +209,10 @@ impl WindowUDFImpl for ByPassWindowFunction {
193
209
false ,
194
210
) )
195
211
}
212
+
213
+ fn documentation ( & self ) -> Option < & Documentation > {
214
+ Some ( & self . doc )
215
+ }
196
216
}
197
217
198
218
#[ cfg( test) ]
@@ -207,7 +227,7 @@ mod test {
207
227
208
228
#[ tokio:: test]
209
229
async fn test_by_pass_scalar_udf ( ) -> Result < ( ) > {
210
- let udf = ByPassScalarUDF :: new ( "date_diff" , DataType :: Int64 ) ;
230
+ let udf = ByPassScalarUDF :: new ( "date_diff" , DataType :: Int64 , None ) ;
211
231
let ctx = SessionContext :: new ( ) ;
212
232
ctx. register_udf ( ScalarUDF :: new_from_impl ( udf) ) ;
213
233
@@ -221,6 +241,7 @@ mod test {
221
241
ctx. register_udf ( ScalarUDF :: new_from_impl ( ByPassScalarUDF :: new (
222
242
"today" ,
223
243
DataType :: Utf8 ,
244
+ None ,
224
245
) ) ) ;
225
246
let plan_2 = ctx. sql ( "SELECT today()" ) . await ?. into_unoptimized_plan ( ) ;
226
247
assert_eq ! ( format!( "{plan_2}" ) , "Projection: today()\n EmptyRelation" ) ;
@@ -230,7 +251,7 @@ mod test {
230
251
231
252
#[ tokio:: test]
232
253
async fn test_by_pass_agg_udf ( ) -> Result < ( ) > {
233
- let udf = ByPassAggregateUDF :: new ( "count_self" , DataType :: Int64 ) ;
254
+ let udf = ByPassAggregateUDF :: new ( "count_self" , DataType :: Int64 , None ) ;
234
255
let ctx = SessionContext :: new ( ) ;
235
256
ctx. register_udaf ( AggregateUDF :: new_from_impl ( udf) ) ;
236
257
@@ -245,6 +266,7 @@ mod test {
245
266
ctx. register_udaf ( AggregateUDF :: new_from_impl ( ByPassAggregateUDF :: new (
246
267
"total_count" ,
247
268
DataType :: Int64 ,
269
+ None ,
248
270
) ) ) ;
249
271
let plan_2 = ctx
250
272
. sql ( "SELECT total_count() AS total_count FROM (VALUES (1), (2), (3)) AS val(x)" )
@@ -263,7 +285,7 @@ mod test {
263
285
264
286
#[ tokio:: test]
265
287
async fn test_by_pass_window_udf ( ) -> Result < ( ) > {
266
- let udf = ByPassWindowFunction :: new ( "custom_window" , DataType :: Int64 ) ;
288
+ let udf = ByPassWindowFunction :: new ( "custom_window" , DataType :: Int64 , None ) ;
267
289
let ctx = SessionContext :: new ( ) ;
268
290
ctx. register_udwf ( WindowUDF :: new_from_impl ( udf) ) ;
269
291
@@ -279,6 +301,7 @@ mod test {
279
301
ctx. register_udwf ( WindowUDF :: new_from_impl ( ByPassWindowFunction :: new (
280
302
"cume_dist" ,
281
303
DataType :: Int64 ,
304
+ None ,
282
305
) ) ) ;
283
306
let plan_2 = ctx
284
307
. sql ( "SELECT cume_dist() OVER ()" )
0 commit comments