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