@@ -29,9 +29,10 @@ use arrow::datatypes::{
2929use datafusion_common:: cast:: {
3030 as_fixed_size_list_array, as_generic_list_array, as_int64_array,
3131} ;
32- use datafusion_common:: { exec_err, plan_err , Result } ;
32+ use datafusion_common:: { exec_err, Result } ;
3333use datafusion_expr:: {
34- ColumnarValue , Documentation , ScalarUDFImpl , Signature , Volatility ,
34+ ArrayFunctionArgument , ArrayFunctionSignature , ColumnarValue , Documentation ,
35+ ScalarUDFImpl , Signature , TypeSignature , Volatility ,
3536} ;
3637use datafusion_functions:: downcast_arg;
3738use datafusion_macros:: user_doc;
@@ -79,7 +80,22 @@ impl Default for ArrayLength {
7980impl ArrayLength {
8081 pub fn new ( ) -> Self {
8182 Self {
82- signature : Signature :: variadic_any ( Volatility :: Immutable ) ,
83+ signature : Signature :: one_of (
84+ vec ! [
85+ TypeSignature :: ArraySignature ( ArrayFunctionSignature :: Array {
86+ arguments: vec![ ArrayFunctionArgument :: Array ] ,
87+ array_coercion: None ,
88+ } ) ,
89+ TypeSignature :: ArraySignature ( ArrayFunctionSignature :: Array {
90+ arguments: vec![
91+ ArrayFunctionArgument :: Array ,
92+ ArrayFunctionArgument :: Index ,
93+ ] ,
94+ array_coercion: None ,
95+ } ) ,
96+ ] ,
97+ Volatility :: Immutable ,
98+ ) ,
8399 aliases : vec ! [ String :: from( "list_length" ) ] ,
84100 }
85101 }
@@ -97,13 +113,8 @@ impl ScalarUDFImpl for ArrayLength {
97113 & self . signature
98114 }
99115
100- fn return_type ( & self , arg_types : & [ DataType ] ) -> Result < DataType > {
101- Ok ( match arg_types[ 0 ] {
102- List ( _) | LargeList ( _) | FixedSizeList ( _, _) => UInt64 ,
103- _ => {
104- return plan_err ! ( "The array_length function can only accept List/LargeList/FixedSizeList." ) ;
105- }
106- } )
116+ fn return_type ( & self , _arg_types : & [ DataType ] ) -> Result < DataType > {
117+ Ok ( UInt64 )
107118 }
108119
109120 fn invoke_with_args (
0 commit comments