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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 25 additions & 1 deletion datafusion/core/tests/dataframe/dataframe_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ use datafusion_common::test_util::batches_to_string;
use datafusion_common::{DFSchema, ScalarValue};
use datafusion_expr::expr::Alias;
use datafusion_expr::{ExprSchemable, LogicalPlanBuilder, table_scan};
use datafusion_functions_aggregate::expr_fn::{approx_median, approx_percentile_cont};
use datafusion_functions_aggregate::expr_fn::{
approx_median, approx_percentile_cont, approx_top_k,
};
use datafusion_functions_nested::map::map;
use insta::assert_snapshot;

Expand Down Expand Up @@ -409,6 +411,28 @@ async fn test_fn_approx_median() -> Result<()> {
Ok(())
}

#[tokio::test]
async fn test_fn_approx_top_k() -> Result<()> {
// Column b has values [1, 10, 10, 100] -- 10 appears twice, others once.
// Use k=1 to avoid non-deterministic ordering among tied items.
let expr = approx_top_k(vec![col("b"), lit(1)]);

let df = create_test_table().await?;
let batches = df.aggregate(vec![], vec![expr]).unwrap().collect().await?;

assert_snapshot!(
batches_to_string(&batches),
@r"
+-------------------------------+
| approx_top_k(test.b,Int32(1)) |
+-------------------------------+
| [{value: 10, count: 2}] |
+-------------------------------+
");

Ok(())
}

#[tokio::test]
async fn test_fn_approx_percentile_cont() -> Result<()> {
let expr = approx_percentile_cont(col("b").sort(true, false), lit(0.5), None);
Expand Down
1 change: 1 addition & 0 deletions datafusion/functions-aggregate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ datafusion-physical-expr = { workspace = true }
datafusion-physical-expr-common = { workspace = true }
foldhash = "0.2"
half = { workspace = true }
hashbrown = { workspace = true }
log = { workspace = true }
num-traits = { workspace = true }

Expand Down
Loading
Loading