1616// under the License.
1717
1818use crate :: serde:: protobuf:: {
19- ScalarUdfDocumentation , ScalarUdfInfo , ScalarUdfTypeSignature ,
19+ ScalarUdfDocumentation , ScalarUdfDocumentationArgument , ScalarUdfInfo ,
20+ ScalarUdfTypeSignature ,
2021} ;
21- use arrow:: datatypes:: DataType ;
2222use datafusion:: execution:: FunctionRegistry ;
2323use datafusion:: functions:: all_default_functions;
24- use datafusion:: logical_expr:: { ScalarUDF , UserDefinedLogicalNode } ;
2524use datafusion:: prelude:: SessionContext ;
2625use datafusion_proto_common:: ArrowType ;
2726use std:: collections:: HashSet ;
2827
2928/// Used to serialize function shapes to ship to Ballista clients
30- pub trait FunctionSerializeExt {
29+ pub trait RemoteFunctionSerializeExt {
3130 fn serialize_udfs ( & self ) -> Vec < ScalarUdfInfo > ;
3231}
3332
34- fn try_derive_return_type ( udf : & ScalarUDF , types : & [ DataType ] ) -> Option < DataType > {
35- if let Ok ( return_type) = udf. return_type ( & types) {
36- return Some ( return_type) ;
37- }
38-
39- // TODO: try to serialize these with dummy values
40- // let fields = types.iter().enumerate().map(|(i, t)| Arc::new(Field::new(
41- // format!("Field{}", i),
42- // t.clone(),
43- // true
44- // ))).collect::<Vec<_>>();
45- //
46- // let return_type = f.return_field_from_args(ReturnFieldArgs {
47- // arg_fields: &fields,
48- // scalar_arguments: &vec![None; fields.len()],
49- // }).expect("Must have return type");
50-
51- None
52- }
53-
54- impl FunctionSerializeExt for SessionContext {
33+ impl RemoteFunctionSerializeExt for SessionContext {
5534 fn serialize_udfs ( & self ) -> Vec < ScalarUdfInfo > {
5635 let mut udfs = vec ! [ ] ;
5736
@@ -78,26 +57,34 @@ impl FunctionSerializeExt for SessionContext {
7857 . collect :: < Result < Vec < ArrowType > , _ > > ( )
7958 . expect ( "Must serialize data types" ) ;
8059
81- if let Some ( ref return_type) = try_derive_return_type ( f. as_ref ( ) , & t)
82- {
83- Some ( ScalarUdfTypeSignature {
60+ // TODO: some functions use `ScalarUDF::return_field_from_args`, which this does not support
61+ f. return_type ( & t)
62+ . ok ( )
63+ . and_then ( |ref return_type| return_type. try_into ( ) . ok ( ) )
64+ . map ( |arrow_return_type| ScalarUdfTypeSignature {
8465 arity,
85- return_type : Some (
86- return_type
87- . try_into ( )
88- . expect ( "Must serialize return type" ) ,
89- ) ,
66+ return_type : Some ( arrow_return_type) ,
9067 } )
91- } else {
92- None
93- }
9468 } )
9569 . collect :: < Vec < _ > > ( ) ;
9670
97- let docs = f. documentation ( ) . map ( |d| ScalarUdfDocumentation {
98- description : d. description . clone ( ) ,
99- syntax_example : d. syntax_example . clone ( ) ,
100- sql_example : d. sql_example . clone ( ) ,
71+ let docs = f. documentation ( ) . map ( |d| {
72+ let arguments = d
73+ . arguments
74+ . iter ( )
75+ . flatten ( )
76+ . map ( |( arg, desc) | ScalarUdfDocumentationArgument {
77+ argument : arg. clone ( ) ,
78+ description : desc. clone ( ) ,
79+ } )
80+ . collect :: < Vec < _ > > ( ) ;
81+
82+ ScalarUdfDocumentation {
83+ description : d. description . clone ( ) ,
84+ syntax_example : d. syntax_example . clone ( ) ,
85+ sql_example : d. sql_example . clone ( ) ,
86+ arguments,
87+ }
10188 } ) ;
10289
10390 udfs. push ( ScalarUdfInfo {
0 commit comments