jayzhan211 commented on code in PR #11845:
URL: https://github.com/apache/datafusion/pull/11845#discussion_r1706238384
##########
datafusion/functions-aggregate/src/nth_value.rs:
##########
@@ -87,27 +85,37 @@ impl AggregateUDFImpl for NthValueAgg {
}
fn accumulator(&self, acc_args: AccumulatorArgs) -> Result<Box<dyn
Accumulator>> {
- let n = match acc_args.input_exprs[1] {
- Expr::Literal(ScalarValue::Int64(Some(value))) => {
- if acc_args.is_reversed {
- Ok(-value)
- } else {
- Ok(value)
+ let n = match acc_args.physical_exprs[1]
+ .as_any()
+ .downcast_ref::<Literal>()
+ {
+ Some(lit) => match lit.value() {
+ ScalarValue::Int64(Some(value)) => {
+ if acc_args.is_reversed {
+ -*value
+ } else {
+ *value
+ }
+ }
+ _ => {
+ return not_impl_err!(
+ "{} not supported for n: {}",
+ self.name(),
+ &acc_args.physical_exprs[1]
+ );
}
+ },
+ None => {
+ return not_impl_err!(
+ "{} not supported for n: {}",
+ self.name(),
+ &acc_args.physical_exprs[1]
+ );
Review Comment:
I come out another way that is slightly more readable
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]