@@ -16,6 +16,7 @@ use common_expression::types::array::ArrayColumnBuilder;
1616use common_expression:: types:: AnyType ;
1717use common_expression:: types:: DataType ;
1818use common_expression:: Column ;
19+ use common_expression:: ColumnBuilder ;
1920use common_expression:: Function ;
2021use common_expression:: FunctionEval ;
2122use common_expression:: FunctionKind ;
@@ -39,6 +40,10 @@ pub fn register(registry: &mut FunctionRegistry) {
3940 ArrayColumnBuilder :: < AnyType > :: repeat ( & col, num_rows) . build ( )
4041 }
4142 Value :: Column ( Column :: Array ( col) ) => * col,
43+ Value :: Column ( Column :: Nullable ( box nullable_column) ) => match nullable_column. column {
44+ Column :: Array ( col) => * col,
45+ _ => unreachable ! ( ) ,
46+ } ,
4247 _ => unreachable ! ( ) ,
4348 } ;
4449 debug_assert_eq ! ( unnest_array. len( ) , num_rows) ;
@@ -63,6 +68,18 @@ pub fn register(registry: &mut FunctionRegistry) {
6368 ) ) ) ) ) ,
6469 ) ) ) ) ) ,
6570 ) ) ) ) ] ;
71+ registry. register_function ( Function {
72+ signature : FunctionSignature {
73+ name : "unnest" . to_string ( ) ,
74+ args_type : vec ! [ args_type[ 0 ] . wrap_nullable( ) ] ,
75+ return_type : DataType :: Tuple ( vec ! [ DataType :: Nullable ( Box :: new(
76+ DataType :: Generic ( 0 ) ,
77+ ) ) ] ) ,
78+ } ,
79+ eval : FunctionEval :: SRF {
80+ eval : Box :: new ( unnest_impl) ,
81+ } ,
82+ } ) ;
6683 registry. register_function ( Function {
6784 signature : FunctionSignature {
6885 name : "unnest" . to_string ( ) ,
@@ -88,6 +105,18 @@ pub fn register(registry: &mut FunctionRegistry) {
88105 ) ) ) ) ) ,
89106 ) ) ) ) ) ,
90107 ) ) ) ) ] ;
108+ registry. register_function ( Function {
109+ signature : FunctionSignature {
110+ name : "unnest" . to_string ( ) ,
111+ args_type : vec ! [ args_type[ 0 ] . wrap_nullable( ) ] ,
112+ return_type : DataType :: Tuple ( vec ! [ DataType :: Nullable ( Box :: new(
113+ DataType :: Generic ( 0 ) ,
114+ ) ) ] ) ,
115+ } ,
116+ eval : FunctionEval :: SRF {
117+ eval : Box :: new ( unnest_impl) ,
118+ } ,
119+ } ) ;
91120 registry. register_function ( Function {
92121 signature : FunctionSignature {
93122 name : "unnest" . to_string ( ) ,
@@ -111,6 +140,18 @@ pub fn register(registry: &mut FunctionRegistry) {
111140 ) ) ) ) ) ,
112141 ) ) ) ) ) ,
113142 ) ) ) ) ] ;
143+ registry. register_function ( Function {
144+ signature : FunctionSignature {
145+ name : "unnest" . to_string ( ) ,
146+ args_type : vec ! [ args_type[ 0 ] . wrap_nullable( ) ] ,
147+ return_type : DataType :: Tuple ( vec ! [ DataType :: Nullable ( Box :: new(
148+ DataType :: Generic ( 0 ) ,
149+ ) ) ] ) ,
150+ } ,
151+ eval : FunctionEval :: SRF {
152+ eval : Box :: new ( unnest_impl) ,
153+ } ,
154+ } ) ;
114155 registry. register_function ( Function {
115156 signature : FunctionSignature {
116157 name : "unnest" . to_string ( ) ,
@@ -134,6 +175,18 @@ pub fn register(registry: &mut FunctionRegistry) {
134175 ) ) ) ) ) ,
135176 ) ) ) ) ) ,
136177 ) ) ) ) ] ;
178+ registry. register_function ( Function {
179+ signature : FunctionSignature {
180+ name : "unnest" . to_string ( ) ,
181+ args_type : vec ! [ args_type[ 0 ] . wrap_nullable( ) ] ,
182+ return_type : DataType :: Tuple ( vec ! [ DataType :: Nullable ( Box :: new(
183+ DataType :: Generic ( 0 ) ,
184+ ) ) ] ) ,
185+ } ,
186+ eval : FunctionEval :: SRF {
187+ eval : Box :: new ( unnest_impl) ,
188+ } ,
189+ } ) ;
137190 registry. register_function ( Function {
138191 signature : FunctionSignature {
139192 name : "unnest" . to_string ( ) ,
@@ -157,6 +210,18 @@ pub fn register(registry: &mut FunctionRegistry) {
157210 ) ) ) ) ) ,
158211 ) ) ) ) ) ,
159212 ) ) ) ) ] ;
213+ registry. register_function ( Function {
214+ signature : FunctionSignature {
215+ name : "unnest" . to_string ( ) ,
216+ args_type : vec ! [ args_type[ 0 ] . wrap_nullable( ) ] ,
217+ return_type : DataType :: Tuple ( vec ! [ DataType :: Nullable ( Box :: new(
218+ DataType :: Generic ( 0 ) ,
219+ ) ) ] ) ,
220+ } ,
221+ eval : FunctionEval :: SRF {
222+ eval : Box :: new ( unnest_impl) ,
223+ } ,
224+ } ) ;
160225 registry. register_function ( Function {
161226 signature : FunctionSignature {
162227 name : "unnest" . to_string ( ) ,
@@ -178,6 +243,18 @@ pub fn register(registry: &mut FunctionRegistry) {
178243 Box :: new( DataType :: Nullable ( Box :: new( DataType :: Generic ( 0 ) ) ) ) ,
179244 ) ) ) ) ) ,
180245 ) ) ) ) ] ;
246+ registry. register_function ( Function {
247+ signature : FunctionSignature {
248+ name : "unnest" . to_string ( ) ,
249+ args_type : vec ! [ args_type[ 0 ] . wrap_nullable( ) ] ,
250+ return_type : DataType :: Tuple ( vec ! [ DataType :: Nullable ( Box :: new(
251+ DataType :: Generic ( 0 ) ,
252+ ) ) ] ) ,
253+ } ,
254+ eval : FunctionEval :: SRF {
255+ eval : Box :: new ( unnest_impl) ,
256+ } ,
257+ } ) ;
181258 registry. register_function ( Function {
182259 signature : FunctionSignature {
183260 name : "unnest" . to_string ( ) ,
@@ -199,6 +276,18 @@ pub fn register(registry: &mut FunctionRegistry) {
199276 Box :: new( DataType :: Generic ( 0 ) ) ,
200277 ) ) ) ) ) ,
201278 ) ) ) ) ] ;
279+ registry. register_function ( Function {
280+ signature : FunctionSignature {
281+ name : "unnest" . to_string ( ) ,
282+ args_type : vec ! [ args_type[ 0 ] . wrap_nullable( ) ] ,
283+ return_type : DataType :: Tuple ( vec ! [ DataType :: Nullable ( Box :: new(
284+ DataType :: Generic ( 0 ) ,
285+ ) ) ] ) ,
286+ } ,
287+ eval : FunctionEval :: SRF {
288+ eval : Box :: new ( unnest_impl) ,
289+ } ,
290+ } ) ;
202291 registry. register_function ( Function {
203292 signature : FunctionSignature {
204293 name : "unnest" . to_string ( ) ,
@@ -218,6 +307,18 @@ pub fn register(registry: &mut FunctionRegistry) {
218307 let args_type = vec ! [ DataType :: Array ( Box :: new( DataType :: Array ( Box :: new(
219308 DataType :: Array ( Box :: new( DataType :: Nullable ( Box :: new( DataType :: Generic ( 0 ) ) ) ) ) ,
220309 ) ) ) ) ] ;
310+ registry. register_function ( Function {
311+ signature : FunctionSignature {
312+ name : "unnest" . to_string ( ) ,
313+ args_type : vec ! [ args_type[ 0 ] . wrap_nullable( ) ] ,
314+ return_type : DataType :: Tuple ( vec ! [ DataType :: Nullable ( Box :: new(
315+ DataType :: Generic ( 0 ) ,
316+ ) ) ] ) ,
317+ } ,
318+ eval : FunctionEval :: SRF {
319+ eval : Box :: new ( unnest_impl) ,
320+ } ,
321+ } ) ;
221322 registry. register_function ( Function {
222323 signature : FunctionSignature {
223324 name : "unnest" . to_string ( ) ,
@@ -237,6 +338,18 @@ pub fn register(registry: &mut FunctionRegistry) {
237338 let args_type = vec ! [ DataType :: Array ( Box :: new( DataType :: Array ( Box :: new(
238339 DataType :: Nullable ( Box :: new( DataType :: Generic ( 0 ) ) ) ,
239340 ) ) ) ) ] ;
341+ registry. register_function ( Function {
342+ signature : FunctionSignature {
343+ name : "unnest" . to_string ( ) ,
344+ args_type : vec ! [ args_type[ 0 ] . wrap_nullable( ) ] ,
345+ return_type : DataType :: Tuple ( vec ! [ DataType :: Nullable ( Box :: new(
346+ DataType :: Generic ( 0 ) ,
347+ ) ) ] ) ,
348+ } ,
349+ eval : FunctionEval :: SRF {
350+ eval : Box :: new ( unnest_impl) ,
351+ } ,
352+ } ) ;
240353 registry. register_function ( Function {
241354 signature : FunctionSignature {
242355 name : "unnest" . to_string ( ) ,
@@ -256,6 +369,18 @@ pub fn register(registry: &mut FunctionRegistry) {
256369 let args_type = vec ! [ DataType :: Array ( Box :: new( DataType :: Nullable ( Box :: new(
257370 DataType :: Generic ( 0 ) ,
258371 ) ) ) ) ] ;
372+ registry. register_function ( Function {
373+ signature : FunctionSignature {
374+ name : "unnest" . to_string ( ) ,
375+ args_type : vec ! [ args_type[ 0 ] . wrap_nullable( ) ] ,
376+ return_type : DataType :: Tuple ( vec ! [ DataType :: Nullable ( Box :: new(
377+ DataType :: Generic ( 0 ) ,
378+ ) ) ] ) ,
379+ } ,
380+ eval : FunctionEval :: SRF {
381+ eval : Box :: new ( unnest_impl) ,
382+ } ,
383+ } ) ;
259384 registry. register_function ( Function {
260385 signature : FunctionSignature {
261386 name : "unnest" . to_string ( ) ,
@@ -269,4 +394,26 @@ pub fn register(registry: &mut FunctionRegistry) {
269394 } ,
270395 } ) ;
271396 }
397+
398+ {
399+ // Unnest NULL
400+ let args_type = vec ! [ DataType :: Null ] ;
401+ registry. register_function ( Function {
402+ signature : FunctionSignature {
403+ name : "unnest" . to_string ( ) ,
404+ args_type,
405+ return_type : DataType :: Tuple ( vec ! [ DataType :: Null ] ) ,
406+ } ,
407+ eval : FunctionEval :: SRF {
408+ eval : Box :: new ( |_, num_rows| {
409+ let mut columns = Vec :: with_capacity ( num_rows) ;
410+ ( 0 ..num_rows) . for_each ( |_| {
411+ let column = ColumnBuilder :: with_capacity ( & DataType :: Null , 0 ) . build ( ) ;
412+ columns. push ( ( Value :: Column ( Column :: Tuple ( vec ! [ column] ) ) , 0 ) ) ;
413+ } ) ;
414+ columns
415+ } ) ,
416+ } ,
417+ } ) ;
418+ }
272419}
0 commit comments