Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions datafusion/core/tests/sql/aggregates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2373,3 +2373,24 @@ async fn array_agg_one() -> Result<()> {
assert_batches_eq!(expected, &actual);
Ok(())
}

#[tokio::test]
async fn test_approx_percentile_cont_decimal_support() -> Result<()> {
let ctx = SessionContext::new();
register_aggregate_csv(&ctx).await?;
let sql = "SELECT c1, approx_percentile_cont(c2, cast(0.85 as decimal(10,2))) apc FROM aggregate_test_100 GROUP BY 1 ORDER BY 1";
let actual = execute_to_batches(&ctx, sql).await;
let expected = vec![
"+----+-----+",
"| c1 | apc |",
"+----+-----+",
"| a | 4 |",
"| b | 5 |",
"| c | 4 |",
"| d | 4 |",
"| e | 4 |",
"+----+-----+",
];
assert_batches_eq!(expected, &actual);
Ok(())
}
19 changes: 12 additions & 7 deletions datafusion/expr/src/type_coercion/aggregates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ use std::ops::Deref;

use crate::{AggregateFunction, Signature, TypeSignature};

use super::functions::can_coerce_from;

pub static STRINGS: &[DataType] = &[DataType::Utf8, DataType::LargeUtf8];

pub static NUMERICS: &[DataType] = &[
Expand Down Expand Up @@ -166,19 +168,22 @@ pub fn coerce_types(
agg_fun, input_types[0]
)));
}
if !matches!(input_types[1], DataType::Float64) {
return Err(DataFusionError::Plan(format!(
"The percentile argument for {:?} must be Float64, not {:?}.",
agg_fun, input_types[1]
)));
}
if input_types.len() == 3 && !is_integer_arg_type(&input_types[2]) {
return Err(DataFusionError::Plan(format!(
"The percentile sample points count for {:?} must be integer, not {:?}.",
agg_fun, input_types[2]
)));
}
Ok(input_types.to_vec())
let mut result = input_types.to_vec();
if can_coerce_from(&DataType::Float64, &input_types[1]) {
result[1] = DataType::Float64;
} else {
return Err(DataFusionError::Plan(format!(
"Could not coerce the percent argument for {:?} to Float64. Was {:?}.",
agg_fun, input_types[1]
)));
}
Ok(result)
}
AggregateFunction::ApproxPercentileContWithWeight => {
if !is_approx_percentile_cont_supported_arg_type(&input_types[0]) {
Expand Down
1 change: 0 additions & 1 deletion datafusion/physical-expr/src/aggregate/tdigest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ impl TDigest {
}

pub(crate) fn merge_sorted_f64(&self, sorted_values: &[f64]) -> TDigest {
dbg!(&sorted_values);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

#[cfg(debug_assertions)]
debug_assert!(is_sorted(sorted_values), "unsorted input to TDigest");

Expand Down