apache / apache/datafusion

Support date types in `percentile_cont` aggregate function

Open
#18,601 2 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Rust
Stars
9.3k
Forks
2.4k
Avg merge
3d 7h
Merged PRs (30d)
344

Description

### Is your feature request related to a problem or challenge?

https://github.com/apache/datafusion/pull/17988 has added support for `percentile_cont`, and this function can support more date-related data types.

Data is generated with https://github.com/clflushopt/tpchgen-rs/tree/main/tpchgen-cli
```
DataFusion CLI v51.0.0
> select percentile_cont(0.01) within group (order by l_shipdate)
from '/Users/yongting/data/tpch_sf1/lineitem.parquet';
Error during planning: Failed to coerce arguments to satisfy a call to 'percentile_cont' function: coercion from Date32, Float64 to the signature OneOf([Exact([Int8, Float64]), Exact([Int16, Float64]), Exact([Int32, Float64]), Exact([Int64, Float64]), Exact([UInt8, Float64]), Exact([UInt16, Float64]), Exact([UInt32, Float64]), Exact([UInt64, Float64]), Exact([Float32, Float64]), Exact([Float64, Float64])]) failed No function matches the given name and argument types 'percentile_cont(Date32, Float64)'. You might need to add explicit type casts.
Candidate functions:
percentile_cont(expr: Int8, percentile: Float64)
percentile_cont(expr: Int16, percentile: Float64)
percentile_cont(expr: Int32, percentile: Float64)
percentile_cont(expr: Int64, percentile: Float64)
percentile_cont(expr: UInt8, percentile: Float64)
percentile_cont(expr: UInt16, percentile: Float64)
percentile_cont(expr: UInt32, percentile: Float64)
percentile_cont(expr: UInt64, percentile: Float64)
percentile_cont(expr: Float32, percentile: Float64)
percentile_cont(expr: Float64, percentile: Float64)
```

### Describe the solution you'd like

_No response_

### Describe alternatives you've considered

_No response_

### Additional context

_No response_

Contributor guide

Open the contributing guide

Research direction

Start at the percentile_cont aggregate-function implementation and its argument type-signature or coercion handling. Reproduce the shown DataFusion CLI query with the TPCH lineitem data, then add coverage for Date32 and the date-related types supported by the implementation. Done means percentile_cont accepts the reported date input and returns the expected percentile result.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, sql
Domain
databases
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.