@@ -143,49 +143,64 @@ impl FromStr for BuiltInWindowFunction {
143143
144144/// Returns the datatype of the window function
145145pub fn return_type ( fun : & WindowFunction , arg_types : & [ DataType ] ) -> Result < DataType > {
146+ match fun {
147+ WindowFunction :: AggregateFunction ( fun) => aggregates:: return_type ( fun, arg_types) ,
148+ WindowFunction :: BuiltInWindowFunction ( fun) => {
149+ return_type_for_built_in ( fun, arg_types)
150+ }
151+ }
152+ }
153+
154+ /// Returns the datatype of the built-in window function
155+ pub ( super ) fn return_type_for_built_in (
156+ fun : & BuiltInWindowFunction ,
157+ arg_types : & [ DataType ] ,
158+ ) -> Result < DataType > {
146159 // Note that this function *must* return the same type that the respective physical expression returns
147160 // or the execution panics.
148161
149162 // verify that this is a valid set of data types for this function
150- data_types ( arg_types, & signature ( fun) ) ?;
163+ data_types ( arg_types, & signature_for_built_in ( fun) ) ?;
151164
152165 match fun {
153- WindowFunction :: AggregateFunction ( fun) => aggregates:: return_type ( fun, arg_types) ,
154- WindowFunction :: BuiltInWindowFunction ( fun) => match fun {
155- BuiltInWindowFunction :: RowNumber
156- | BuiltInWindowFunction :: Rank
157- | BuiltInWindowFunction :: DenseRank => Ok ( DataType :: UInt64 ) ,
158- BuiltInWindowFunction :: PercentRank | BuiltInWindowFunction :: CumeDist => {
159- Ok ( DataType :: Float64 )
160- }
161- BuiltInWindowFunction :: Ntile => Ok ( DataType :: UInt32 ) ,
162- BuiltInWindowFunction :: Lag
163- | BuiltInWindowFunction :: Lead
164- | BuiltInWindowFunction :: FirstValue
165- | BuiltInWindowFunction :: LastValue
166- | BuiltInWindowFunction :: NthValue => Ok ( arg_types[ 0 ] . clone ( ) ) ,
167- } ,
166+ BuiltInWindowFunction :: RowNumber
167+ | BuiltInWindowFunction :: Rank
168+ | BuiltInWindowFunction :: DenseRank => Ok ( DataType :: UInt64 ) ,
169+ BuiltInWindowFunction :: PercentRank | BuiltInWindowFunction :: CumeDist => {
170+ Ok ( DataType :: Float64 )
171+ }
172+ BuiltInWindowFunction :: Ntile => Ok ( DataType :: UInt32 ) ,
173+ BuiltInWindowFunction :: Lag
174+ | BuiltInWindowFunction :: Lead
175+ | BuiltInWindowFunction :: FirstValue
176+ | BuiltInWindowFunction :: LastValue
177+ | BuiltInWindowFunction :: NthValue => Ok ( arg_types[ 0 ] . clone ( ) ) ,
168178 }
169179}
170180
171181/// the signatures supported by the function `fun`.
172- fn signature ( fun : & WindowFunction ) -> Signature {
173- // note: the physical expression must accept the type returned by this function or the execution panics.
182+ pub fn signature ( fun : & WindowFunction ) -> Signature {
174183 match fun {
175184 WindowFunction :: AggregateFunction ( fun) => aggregates:: signature ( fun) ,
176- WindowFunction :: BuiltInWindowFunction ( fun) => match fun {
177- BuiltInWindowFunction :: RowNumber
178- | BuiltInWindowFunction :: Rank
179- | BuiltInWindowFunction :: DenseRank
180- | BuiltInWindowFunction :: PercentRank
181- | BuiltInWindowFunction :: CumeDist => Signature :: Any ( 0 ) ,
182- BuiltInWindowFunction :: Lag
183- | BuiltInWindowFunction :: Lead
184- | BuiltInWindowFunction :: FirstValue
185- | BuiltInWindowFunction :: LastValue => Signature :: Any ( 1 ) ,
186- BuiltInWindowFunction :: Ntile => Signature :: Exact ( vec ! [ DataType :: UInt64 ] ) ,
187- BuiltInWindowFunction :: NthValue => Signature :: Any ( 2 ) ,
188- } ,
185+ WindowFunction :: BuiltInWindowFunction ( fun) => signature_for_built_in ( fun) ,
186+ }
187+ }
188+
189+ /// the signatures supported by the built-in window function `fun`.
190+ pub ( super ) fn signature_for_built_in ( fun : & BuiltInWindowFunction ) -> Signature {
191+ // note: the physical expression must accept the type returned by this function or the execution panics.
192+ match fun {
193+ BuiltInWindowFunction :: RowNumber
194+ | BuiltInWindowFunction :: Rank
195+ | BuiltInWindowFunction :: DenseRank
196+ | BuiltInWindowFunction :: PercentRank
197+ | BuiltInWindowFunction :: CumeDist => Signature :: Any ( 0 ) ,
198+ BuiltInWindowFunction :: Lag
199+ | BuiltInWindowFunction :: Lead
200+ | BuiltInWindowFunction :: FirstValue
201+ | BuiltInWindowFunction :: LastValue => Signature :: Any ( 1 ) ,
202+ BuiltInWindowFunction :: Ntile => Signature :: Exact ( vec ! [ DataType :: UInt64 ] ) ,
203+ BuiltInWindowFunction :: NthValue => Signature :: Any ( 2 ) ,
189204 }
190205}
191206
0 commit comments