| 259 | } |
| 260 | |
| 261 | fn partition_evaluator( |
| 262 | &self, |
| 263 | partition_evaluator_args: PartitionEvaluatorArgs, |
| 264 | ) -> Result<Box<dyn PartitionEvaluator>> { |
| 265 | let state = NthValueState { |
| 266 | finalized_result: None, |
| 267 | kind: self.kind, |
| 268 | }; |
| 269 | |
| 270 | if self.kind != NthValueKind::Nth { |
| 271 | return Ok(Box::new(NthValueEvaluator { |
| 272 | state, |
| 273 | ignore_nulls: partition_evaluator_args.ignore_nulls(), |
| 274 | n: 0, |
| 275 | })); |
| 276 | } |
| 277 | |
| 278 | let n = match get_scalar_value_from_args( |
| 279 | partition_evaluator_args.input_exprs(), |
| 280 | 1, |
| 281 | ) |
| 282 | .map_err(|_e| { |
| 283 | exec_datafusion_err!( |
| 284 | "Expected a signed integer literal for the second argument of nth_value" |
| 285 | ) |
| 286 | })? |
| 287 | .map(|v| get_signed_integer(&v)) |
| 288 | { |
| 289 | Some(Ok(n)) => { |
| 290 | if partition_evaluator_args.is_reversed() { |
| 291 | -n |
| 292 | } else { |
| 293 | n |
| 294 | } |
| 295 | } |
| 296 | _ => { |
| 297 | return exec_err!( |
| 298 | "Expected a signed integer literal for the second argument of nth_value" |
| 299 | ); |
| 300 | } |
| 301 | }; |
| 302 | |
| 303 | Ok(Box::new(NthValueEvaluator { |
| 304 | state, |
| 305 | ignore_nulls: partition_evaluator_args.ignore_nulls(), |
| 306 | n, |
| 307 | })) |
| 308 | } |
| 309 | |
| 310 | fn field(&self, field_args: WindowUDFFieldArgs) -> Result<FieldRef> { |
| 311 | let input_field = |