PreetiToppo opened a new pull request, #26556:
URL: https://github.com/apache/datafusion/pull/26556

   ## Which issue does this PR close?
   
   Closes #26497.
   
   ## Rationale for this change
   
   `nth_value` and `approx_percentile_cont` are tagged 
`DistinctHandling::Unsupported`, but their accumulators never read 
`is_distinct`, so `f(DISTINCT x)` silently returned the same result as `f(x)`. 
   
   Instead of adding a check to every affected accumulator (as #26484 did for 
`corr` and `covar_*`), this adds a single planning-time check in 
`AggregateExprBuilder::build`, so any current or future aggregate tagged 
`Unsupported` is rejected automatically. The check runs after the logical 
optimizer, so `SingleDistinctToGroupBy` can still rewrite cases like 
`corr(DISTINCT x, x)`. The default `DistinctHandling` is `Sensitive`, so UDFs 
that don't opt in are unaffected.
   
   ## What changes are included in this PR?
   
   - `datafusion/physical-expr/src/aggregate.rs`: Return `not_impl_err!` from 
`AggregateExprBuilder::build` when `is_distinct` is set and the function 
reports `DistinctHandling::Unsupported`.
   - New 
`datafusion/sqllogictest/test_files/aggregate_distinct_unsupported.slt` 
covering `nth_value(DISTINCT ...)`, both `approx_percentile_cont(DISTINCT ...)` 
forms, and a positive case (`count(DISTINCT x)` still works).
   
   ## What is the testing strategy for this PR?
   
   Yes, this is tested via the new `sqllogictest` file added in this PR.
   
   ## Are there any user-facing changes?
   
   Yes: queries that previously silently ignored `DISTINCT` on these functions 
now fail at planning time with `This feature is not implemented: <fn> does not 
support DISTINCT`.


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