@@ -34,7 +34,7 @@ use arrow::{
34
34
datatypes:: { DataType , Field , Schema , SchemaRef } ,
35
35
record_batch:: RecordBatch ,
36
36
} ;
37
- use arrow_array:: builder:: BooleanBuilder ;
37
+ use arrow_array:: builder:: { BooleanBuilder , UInt8Builder } ;
38
38
use async_trait:: async_trait;
39
39
use datafusion_common:: error:: Result ;
40
40
use datafusion_common:: DataFusionError ;
@@ -247,6 +247,7 @@ impl InformationSchemaConfig {
247
247
return_type,
248
248
"SCALAR" ,
249
249
udf. documentation ( ) . map ( |d| d. description . to_string ( ) ) ,
250
+ udf. documentation ( ) . map ( |d| d. syntax_example . to_string ( ) ) ,
250
251
)
251
252
}
252
253
}
@@ -266,6 +267,7 @@ impl InformationSchemaConfig {
266
267
return_type,
267
268
"AGGREGATE" ,
268
269
udaf. documentation ( ) . map ( |d| d. description . to_string ( ) ) ,
270
+ udaf. documentation ( ) . map ( |d| d. syntax_example . to_string ( ) ) ,
269
271
)
270
272
}
271
273
}
@@ -285,6 +287,7 @@ impl InformationSchemaConfig {
285
287
return_type,
286
288
"WINDOW" ,
287
289
udwf. documentation ( ) . map ( |d| d. description . to_string ( ) ) ,
290
+ udwf. documentation ( ) . map ( |d| d. syntax_example . to_string ( ) ) ,
288
291
)
289
292
}
290
293
}
@@ -308,7 +311,8 @@ impl InformationSchemaConfig {
308
311
args : Option < & Vec < ( String , String ) > > ,
309
312
arg_types : Vec < String > ,
310
313
return_type : Option < String > ,
311
- is_variadic : bool | {
314
+ is_variadic : bool ,
315
+ rid : u8 | {
312
316
for ( position, type_name) in arg_types. iter ( ) . enumerate ( ) {
313
317
let param_name =
314
318
args. and_then ( |a| a. get ( position) . map ( |arg| arg. 0 . as_str ( ) ) ) ;
@@ -322,6 +326,7 @@ impl InformationSchemaConfig {
322
326
type_name,
323
327
None :: < & str > ,
324
328
is_variadic,
329
+ rid,
325
330
) ;
326
331
}
327
332
if let Some ( return_type) = return_type {
@@ -335,48 +340,52 @@ impl InformationSchemaConfig {
335
340
return_type. as_str ( ) ,
336
341
None :: < & str > ,
337
342
false ,
343
+ rid,
338
344
) ;
339
345
}
340
346
} ;
341
347
342
348
for ( func_name, udf) in udfs {
343
349
let args = udf. documentation ( ) . and_then ( |d| d. arguments . clone ( ) ) ;
344
350
let combinations = get_udf_args_and_return_types ( udf) ?;
345
- for ( arg_types, return_type) in combinations {
351
+ for ( rid , ( arg_types, return_type) ) in combinations. into_iter ( ) . enumerate ( ) {
346
352
add_parameters (
347
353
func_name,
348
354
args. as_ref ( ) ,
349
355
arg_types,
350
356
return_type,
351
357
Self :: is_variadic ( udf. signature ( ) ) ,
358
+ rid as u8 ,
352
359
) ;
353
360
}
354
361
}
355
362
356
363
for ( func_name, udaf) in udafs {
357
364
let args = udaf. documentation ( ) . and_then ( |d| d. arguments . clone ( ) ) ;
358
365
let combinations = get_udaf_args_and_return_types ( udaf) ?;
359
- for ( arg_types, return_type) in combinations {
366
+ for ( rid , ( arg_types, return_type) ) in combinations. into_iter ( ) . enumerate ( ) {
360
367
add_parameters (
361
368
func_name,
362
369
args. as_ref ( ) ,
363
370
arg_types,
364
371
return_type,
365
372
Self :: is_variadic ( udaf. signature ( ) ) ,
373
+ rid as u8 ,
366
374
) ;
367
375
}
368
376
}
369
377
370
378
for ( func_name, udwf) in udwfs {
371
379
let args = udwf. documentation ( ) . and_then ( |d| d. arguments . clone ( ) ) ;
372
380
let combinations = get_udwf_args_and_return_types ( udwf) ?;
373
- for ( arg_types, return_type) in combinations {
381
+ for ( rid , ( arg_types, return_type) ) in combinations. into_iter ( ) . enumerate ( ) {
374
382
add_parameters (
375
383
func_name,
376
384
args. as_ref ( ) ,
377
385
arg_types,
378
386
return_type,
379
387
Self :: is_variadic ( udwf. signature ( ) ) ,
388
+ rid as u8 ,
380
389
) ;
381
390
}
382
391
}
@@ -1095,6 +1104,7 @@ impl InformationSchemaRoutines {
1095
1104
Field :: new( "data_type" , DataType :: Utf8 , true ) ,
1096
1105
Field :: new( "function_type" , DataType :: Utf8 , true ) ,
1097
1106
Field :: new( "description" , DataType :: Utf8 , true ) ,
1107
+ Field :: new( "syntax_example" , DataType :: Utf8 , true ) ,
1098
1108
] ) ) ;
1099
1109
1100
1110
Self { schema, config }
@@ -1114,6 +1124,7 @@ impl InformationSchemaRoutines {
1114
1124
data_type : StringBuilder :: new ( ) ,
1115
1125
function_type : StringBuilder :: new ( ) ,
1116
1126
description : StringBuilder :: new ( ) ,
1127
+ syntax_example : StringBuilder :: new ( ) ,
1117
1128
}
1118
1129
}
1119
1130
}
@@ -1131,6 +1142,7 @@ struct InformationSchemaRoutinesBuilder {
1131
1142
data_type : StringBuilder ,
1132
1143
function_type : StringBuilder ,
1133
1144
description : StringBuilder ,
1145
+ syntax_example : StringBuilder ,
1134
1146
}
1135
1147
1136
1148
impl InformationSchemaRoutinesBuilder {
@@ -1145,6 +1157,7 @@ impl InformationSchemaRoutinesBuilder {
1145
1157
data_type : Option < impl AsRef < str > > ,
1146
1158
function_type : impl AsRef < str > ,
1147
1159
description : Option < impl AsRef < str > > ,
1160
+ syntax_example : Option < impl AsRef < str > > ,
1148
1161
) {
1149
1162
self . specific_catalog . append_value ( catalog_name. as_ref ( ) ) ;
1150
1163
self . specific_schema . append_value ( schema_name. as_ref ( ) ) ;
@@ -1157,6 +1170,7 @@ impl InformationSchemaRoutinesBuilder {
1157
1170
self . data_type . append_option ( data_type. as_ref ( ) ) ;
1158
1171
self . function_type . append_value ( function_type. as_ref ( ) ) ;
1159
1172
self . description . append_option ( description) ;
1173
+ self . syntax_example . append_option ( syntax_example) ;
1160
1174
}
1161
1175
1162
1176
fn finish ( & mut self ) -> RecordBatch {
@@ -1174,6 +1188,7 @@ impl InformationSchemaRoutinesBuilder {
1174
1188
Arc :: new( self . data_type. finish( ) ) ,
1175
1189
Arc :: new( self . function_type. finish( ) ) ,
1176
1190
Arc :: new( self . description. finish( ) ) ,
1191
+ Arc :: new( self . syntax_example. finish( ) ) ,
1177
1192
] ,
1178
1193
)
1179
1194
. unwrap ( )
@@ -1222,6 +1237,12 @@ impl InformationSchemaParameters {
1222
1237
Field :: new( "data_type" , DataType :: Utf8 , false ) ,
1223
1238
Field :: new( "parameter_default" , DataType :: Utf8 , true ) ,
1224
1239
Field :: new( "is_variadic" , DataType :: Boolean , false ) ,
1240
+ // `rid` (short for `routine id`) is used to differentiate parameters from different signatures
1241
+ // (It serves as the group-by key when generating the `SHOW FUNCTIONS` query).
1242
+ // For example, the following signatures have different `rid` values:
1243
+ // - `datetrunc(Utf8, Timestamp(Microsecond, Some("+TZ"))) -> Timestamp(Microsecond, Some("+TZ"))`
1244
+ // - `datetrunc(Utf8View, Timestamp(Nanosecond, None)) -> Timestamp(Nanosecond, None)`
1245
+ Field :: new( "rid" , DataType :: UInt8 , false ) ,
1225
1246
] ) ) ;
1226
1247
1227
1248
Self { schema, config }
@@ -1239,7 +1260,7 @@ impl InformationSchemaParameters {
1239
1260
data_type : StringBuilder :: new ( ) ,
1240
1261
parameter_default : StringBuilder :: new ( ) ,
1241
1262
is_variadic : BooleanBuilder :: new ( ) ,
1242
- inserted : HashSet :: new ( ) ,
1263
+ rid : UInt8Builder :: new ( ) ,
1243
1264
}
1244
1265
}
1245
1266
}
@@ -1255,8 +1276,7 @@ struct InformationSchemaParametersBuilder {
1255
1276
data_type : StringBuilder ,
1256
1277
parameter_default : StringBuilder ,
1257
1278
is_variadic : BooleanBuilder ,
1258
- // use HashSet to avoid duplicate rows. The key is (specific_name, ordinal_position, parameter_mode, data_type)
1259
- inserted : HashSet < ( String , u64 , String , String ) > ,
1279
+ rid : UInt8Builder ,
1260
1280
}
1261
1281
1262
1282
impl InformationSchemaParametersBuilder {
@@ -1272,25 +1292,19 @@ impl InformationSchemaParametersBuilder {
1272
1292
data_type : impl AsRef < str > ,
1273
1293
parameter_default : Option < impl AsRef < str > > ,
1274
1294
is_variadic : bool ,
1295
+ rid : u8 ,
1275
1296
) {
1276
- let key = (
1277
- specific_name. as_ref ( ) . to_string ( ) ,
1278
- ordinal_position,
1279
- parameter_mode. as_ref ( ) . to_string ( ) ,
1280
- data_type. as_ref ( ) . to_string ( ) ,
1281
- ) ;
1282
- if self . inserted . insert ( key) {
1283
- self . specific_catalog
1284
- . append_value ( specific_catalog. as_ref ( ) ) ;
1285
- self . specific_schema . append_value ( specific_schema. as_ref ( ) ) ;
1286
- self . specific_name . append_value ( specific_name. as_ref ( ) ) ;
1287
- self . ordinal_position . append_value ( ordinal_position) ;
1288
- self . parameter_mode . append_value ( parameter_mode. as_ref ( ) ) ;
1289
- self . parameter_name . append_option ( parameter_name. as_ref ( ) ) ;
1290
- self . data_type . append_value ( data_type. as_ref ( ) ) ;
1291
- self . parameter_default . append_option ( parameter_default) ;
1292
- self . is_variadic . append_value ( is_variadic) ;
1293
- }
1297
+ self . specific_catalog
1298
+ . append_value ( specific_catalog. as_ref ( ) ) ;
1299
+ self . specific_schema . append_value ( specific_schema. as_ref ( ) ) ;
1300
+ self . specific_name . append_value ( specific_name. as_ref ( ) ) ;
1301
+ self . ordinal_position . append_value ( ordinal_position) ;
1302
+ self . parameter_mode . append_value ( parameter_mode. as_ref ( ) ) ;
1303
+ self . parameter_name . append_option ( parameter_name. as_ref ( ) ) ;
1304
+ self . data_type . append_value ( data_type. as_ref ( ) ) ;
1305
+ self . parameter_default . append_option ( parameter_default) ;
1306
+ self . is_variadic . append_value ( is_variadic) ;
1307
+ self . rid . append_value ( rid) ;
1294
1308
}
1295
1309
1296
1310
fn finish ( & mut self ) -> RecordBatch {
@@ -1306,6 +1320,7 @@ impl InformationSchemaParametersBuilder {
1306
1320
Arc :: new( self . data_type. finish( ) ) ,
1307
1321
Arc :: new( self . parameter_default. finish( ) ) ,
1308
1322
Arc :: new( self . is_variadic. finish( ) ) ,
1323
+ Arc :: new( self . rid. finish( ) ) ,
1309
1324
] ,
1310
1325
)
1311
1326
. unwrap ( )
0 commit comments