@@ -84,15 +84,21 @@ pub async fn handle_create_function(
84
84
Kind :: Scalar ( ScalarFunction { } )
85
85
}
86
86
Some ( CreateFunctionReturns :: Table ( columns) ) => {
87
- let datatypes = columns
88
- . iter ( )
89
- . map ( |c| bind_data_type ( & c. data_type ) )
90
- . collect :: < Result < Vec < _ > > > ( ) ?;
91
- let names = columns
92
- . iter ( )
93
- . map ( |c| c. name . real_value ( ) )
94
- . collect :: < Vec < _ > > ( ) ;
95
- return_type = DataType :: new_struct ( datatypes, names) ;
87
+ if columns. len ( ) == 1 {
88
+ // return type is the original type for single column
89
+ return_type = bind_data_type ( & columns[ 0 ] . data_type ) ?;
90
+ } else {
91
+ // return type is a struct for multiple columns
92
+ let datatypes = columns
93
+ . iter ( )
94
+ . map ( |c| bind_data_type ( & c. data_type ) )
95
+ . collect :: < Result < Vec < _ > > > ( ) ?;
96
+ let names = columns
97
+ . iter ( )
98
+ . map ( |c| c. name . real_value ( ) )
99
+ . collect :: < Vec < _ > > ( ) ;
100
+ return_type = DataType :: new_struct ( datatypes, names) ;
101
+ }
96
102
Kind :: Table ( TableFunction { } )
97
103
}
98
104
None => {
@@ -137,11 +143,24 @@ pub async fn handle_create_function(
137
143
. map ( |t| arrow_schema:: Field :: new ( "" , t. into ( ) , true ) )
138
144
. collect ( ) ,
139
145
) ;
140
- let returns = arrow_schema:: Schema :: new ( vec ! [ arrow_schema:: Field :: new(
141
- "" ,
142
- return_type. clone( ) . into( ) ,
143
- true ,
144
- ) ] ) ;
146
+ let returns = match kind {
147
+ Kind :: Scalar ( _) => arrow_schema:: Schema :: new ( vec ! [ arrow_schema:: Field :: new(
148
+ "" ,
149
+ return_type. clone( ) . into( ) ,
150
+ true ,
151
+ ) ] ) ,
152
+ Kind :: Table ( _) => arrow_schema:: Schema :: new ( match & return_type {
153
+ DataType :: Struct ( s) => ( s. fields . iter ( ) )
154
+ . map ( |t| arrow_schema:: Field :: new ( "" , t. clone ( ) . into ( ) , true ) )
155
+ . collect ( ) ,
156
+ _ => vec ! [ arrow_schema:: Field :: new(
157
+ "" ,
158
+ return_type. clone( ) . into( ) ,
159
+ true ,
160
+ ) ] ,
161
+ } ) ,
162
+ _ => unreachable ! ( ) ,
163
+ } ;
145
164
client
146
165
. check ( & identifier, & args, & returns)
147
166
. await
0 commit comments