Skip to content
Open
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
6 changes: 5 additions & 1 deletion datafusion/functions-aggregate/src/approx_median.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::sync::Arc;

use datafusion_common::{Result, not_impl_err};
use datafusion_expr::function::{AccumulatorArgs, StateFieldsArgs};
use datafusion_expr::utils::format_state_name;
use datafusion_expr::utils::{AggregateOrderSensitivity, format_state_name};
use datafusion_expr::{
Accumulator, AggregateUDFImpl, Coercion, Documentation, Signature, TypeSignature,
TypeSignatureClass, Volatility,
Expand Down Expand Up @@ -137,6 +137,10 @@ impl AggregateUDFImpl for ApproxMedian {
}
}

fn order_sensitivity(&self) -> AggregateOrderSensitivity {
AggregateOrderSensitivity::Insensitive
}

fn documentation(&self) -> Option<&Documentation> {
self.doc()
}
Expand Down
8 changes: 8 additions & 0 deletions datafusion/sqllogictest/test_files/aggregate.slt
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,14 @@ SELECT approx_median(c12) FROM aggregate_test_100
statement error
SELECT approx_median(c1) FROM aggregate_test_100

# APPROX_MEDIAN ignores aggregate ORDER BY keys. They must not be interpreted

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does it make sense to support ORDER BY that is just ignored?
What do other systems (postgres?) do?

I think it would be better to reject this query with a more specific message

# as percentile arguments by the shared accumulator.
query R
SELECT approx_median(x ORDER BY k)
FROM (VALUES (1.0, 3), (2.0, 1), (3.0, 2)) t(x, k)
----
2

# csv_query_median_1
query R
SELECT median(c2) FROM aggregate_test_100
Expand Down
Loading