jayzhan211 opened a new issue, #26466:
URL: https://github.com/apache/datafusion/issues/26466

   ### Describe the bug
   
   After an aggregate function is given extra names with 
`AggregateUDF::with_aliases`, `sum`, `min` and `max` can no longer be used in a 
window frame that does not start at `UNBOUNDED PRECEDING`, such as `ROWS 
BETWEEN 1 PRECEDING AND CURRENT ROW`. The query fails instead of computing the 
sliding result.
   
   The aliased wrapper forwards `create_sliding_accumulator` to the inner 
function's `accumulator` instead of its `create_sliding_accumulator` 
(`datafusion/expr/src/udaf.rs`, `AliasedAggregateUDFImpl`). The plain 
accumulators of `sum`, `min` and `max` cannot retract rows, so bounded frames 
are rejected. The original function name is affected too: registering the 
aliased UDAF replaces the built-in under its own name as well.
   
   ### To Reproduce
   
   ```rust
   use datafusion::prelude::*;
   use datafusion::arrow::array::Int32Array;
   use datafusion::arrow::record_batch::RecordBatch;
   use datafusion_functions_aggregate::sum::sum_udaf;
   use std::sync::Arc;
   
   let ctx = SessionContext::new();
   let batch = RecordBatch::try_from_iter(vec![(
       "i",
       Arc::new(Int32Array::from(vec![1, 2, 3, 4])) as _,
   )])?;
   ctx.register_batch("t", batch)?;
   ctx.register_udaf(sum_udaf().as_ref().clone().with_aliases(["my_sum"]));
   
   ctx.sql("SELECT my_sum(i) OVER (ORDER BY i ROWS BETWEEN 1 PRECEDING AND 
CURRENT ROW) FROM t")
       .await?
       .show()
       .await?;
   ```
   
   fails with:
   
   ```
   NotImplemented("Aggregate can not be used as a sliding accumulator because 
`retract_batch` is not implemented: sum(t.i) ORDER BY [t.i ASC NULLS LAST] ROWS 
BETWEEN 1 PRECEDING AND CURRENT ROW")
   ```
   
   Aliased `min` and `max` fail with the same error, and so does `sum(i)` 
itself once the aliased `sum` is registered.
   
   ### Expected behavior
   
   The aliased function behaves exactly like the original: `1, 3, 5, 7` for the 
query above (and `1, 1, 2, 3` / `1, 2, 3, 4` for `min` / `max`).
   
   ### Additional context
   
   The forwarding line dates from #12098, which set out to forward every method 
to the inner function, so this one looks like a slip. The 
`missing_trait_methods` lint on the wrapper can't catch it because the method 
exists.
   
   ### Willingness to contribute
   
   I plan to contribute a fix for this bug independently
   


-- 
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]

Reply via email to