@@ -72,7 +72,7 @@ impl BuiltInWindowFunctionExpr for FirstValue {
7272}
7373
7474// sql values start with 1, so we can use 0 to indicate the special last value behavior
75- const SPECIAL_USIZE_VALUE_FOR_LAST : usize = 0 ;
75+ const SPECIAL_SIZE_VALUE_FOR_LAST : u32 = 0 ;
7676
7777/// last_value expression
7878#[ derive( Debug ) ]
@@ -114,7 +114,7 @@ impl BuiltInWindowFunctionExpr for LastValue {
114114
115115 fn create_accumulator ( & self ) -> Result < Box < dyn WindowAccumulator > > {
116116 Ok ( Box :: new ( NthValueAccumulator :: try_new (
117- SPECIAL_USIZE_VALUE_FOR_LAST ,
117+ SPECIAL_SIZE_VALUE_FOR_LAST ,
118118 self . data_type . clone ( ) ,
119119 ) ?) )
120120 }
@@ -124,7 +124,7 @@ impl BuiltInWindowFunctionExpr for LastValue {
124124#[ derive( Debug ) ]
125125pub struct NthValue {
126126 name : String ,
127- n : usize ,
127+ n : u32 ,
128128 data_type : DataType ,
129129 expr : Arc < dyn PhysicalExpr > ,
130130}
@@ -134,10 +134,10 @@ impl NthValue {
134134 pub fn try_new (
135135 expr : Arc < dyn PhysicalExpr > ,
136136 name : String ,
137- n : usize ,
137+ n : u32 ,
138138 data_type : DataType ,
139139 ) -> Result < Self > {
140- if n == SPECIAL_USIZE_VALUE_FOR_LAST {
140+ if n == SPECIAL_SIZE_VALUE_FOR_LAST {
141141 Err ( DataFusionError :: Execution (
142142 "nth_value expect n to be > 0" . to_owned ( ) ,
143143 ) )
@@ -184,14 +184,14 @@ struct NthValueAccumulator {
184184 // n the target nth_value, however we'll reuse it for last_value acc, so when n == 0 it specifically
185185 // means last; also note that it is totally valid for n to be larger than the number of rows input
186186 // in which case all the values shall be null
187- n : usize ,
188- offset : usize ,
187+ n : u32 ,
188+ offset : u32 ,
189189 value : ScalarValue ,
190190}
191191
192192impl NthValueAccumulator {
193193 /// new count accumulator
194- pub fn try_new ( n : usize , data_type : DataType ) -> Result < Self > {
194+ pub fn try_new ( n : u32 , data_type : DataType ) -> Result < Self > {
195195 Ok ( Self {
196196 n,
197197 offset : 0 ,
@@ -203,7 +203,7 @@ impl NthValueAccumulator {
203203
204204impl WindowAccumulator for NthValueAccumulator {
205205 fn scan ( & mut self , values : & [ ScalarValue ] ) -> Result < Option < ScalarValue > > {
206- if self . n == SPECIAL_USIZE_VALUE_FOR_LAST {
206+ if self . n == SPECIAL_SIZE_VALUE_FOR_LAST {
207207 // for last_value function
208208 self . value = values[ 0 ] . clone ( ) ;
209209 } else if self . offset < self . n {
@@ -212,10 +212,10 @@ impl WindowAccumulator for NthValueAccumulator {
212212 self . value = values[ 0 ] . clone ( ) ;
213213 }
214214 }
215- Ok ( Some ( self . value . clone ( ) ) )
215+ Ok ( None )
216216 }
217217
218218 fn evaluate ( & self ) -> Result < Option < ScalarValue > > {
219- Ok ( None )
219+ Ok ( Some ( self . value . clone ( ) ) )
220220 }
221221}
0 commit comments