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
116 changes: 59 additions & 57 deletions datafusion/physical-plan/src/sorts/partial_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,12 @@ mod tests {
use arrow::array::*;
use arrow::compute::SortOptions;
use arrow::datatypes::*;
use datafusion_common::test_util::batches_to_string;
use futures::FutureExt;
use insta::allow_duplicates;
use insta::assert_snapshot;
use itertools::Itertools;

use datafusion_common::assert_batches_eq;

use crate::collect;
use crate::expressions::col;
use crate::expressions::PhysicalSortExpr;
Expand Down Expand Up @@ -522,20 +523,21 @@ mod tests {

let result = collect(partial_sort_exec, Arc::clone(&task_ctx)).await?;

let expected_after_sort = [
"+---+---+---+",
"| a | b | c |",
"+---+---+---+",
"| 0 | 1 | 0 |",
"| 0 | 1 | 1 |",
"| 0 | 2 | 5 |",
"| 1 | 2 | 4 |",
"| 1 | 3 | 2 |",
"| 1 | 3 | 3 |",
"+---+---+---+",
];
assert_eq!(2, result.len());
assert_batches_eq!(expected_after_sort, &result);
allow_duplicates! {
assert_snapshot!(batches_to_string(&result), @r#"
+---+---+---+
| a | b | c |
+---+---+---+
| 0 | 1 | 0 |
| 0 | 1 | 1 |
| 0 | 2 | 5 |
| 1 | 2 | 4 |
| 1 | 3 | 2 |
| 1 | 3 | 3 |
+---+---+---+
"#);
}
assert_eq!(
task_ctx.runtime_env().memory_pool.reserved(),
0,
Expand Down Expand Up @@ -588,18 +590,19 @@ mod tests {

let result = collect(partial_sort_exec, Arc::clone(&task_ctx)).await?;

let expected_after_sort = [
"+---+---+---+",
"| a | b | c |",
"+---+---+---+",
"| 0 | 1 | 4 |",
"| 0 | 2 | 3 |",
"| 1 | 2 | 2 |",
"| 1 | 3 | 0 |",
"+---+---+---+",
];
assert_eq!(2, result.len());
assert_batches_eq!(expected_after_sort, &result);
allow_duplicates! {
assert_snapshot!(batches_to_string(&result), @r#"
+---+---+---+
| a | b | c |
+---+---+---+
| 0 | 1 | 4 |
| 0 | 2 | 3 |
| 1 | 2 | 2 |
| 1 | 3 | 0 |
+---+---+---+
"#);
}
assert_eq!(
task_ctx.runtime_env().memory_pool.reserved(),
0,
Expand Down Expand Up @@ -663,21 +666,22 @@ mod tests {
0,
"The sort should have returned all memory used back to the memory manager"
);
let expected = [
"+---+---+---+",
"| a | b | c |",
"+---+---+---+",
"| 0 | 1 | 6 |",
"| 0 | 1 | 7 |",
"| 0 | 3 | 4 |",
"| 0 | 3 | 5 |",
"| 1 | 2 | 0 |",
"| 1 | 2 | 1 |",
"| 1 | 4 | 2 |",
"| 1 | 4 | 3 |",
"+---+---+---+",
];
assert_batches_eq!(expected, &result);
allow_duplicates! {
assert_snapshot!(batches_to_string(&result), @r#"
+---+---+---+
| a | b | c |
+---+---+---+
| 0 | 1 | 6 |
| 0 | 1 | 7 |
| 0 | 3 | 4 |
| 0 | 3 | 5 |
| 1 | 2 | 0 |
| 1 | 2 | 1 |
| 1 | 4 | 2 |
| 1 | 4 | 3 |
+---+---+---+
"#);
}
}
Ok(())
}
Expand Down Expand Up @@ -1000,21 +1004,6 @@ mod tests {
2,
));

let expected = [
"+-----+------+-------+",
"| a | b | c |",
"+-----+------+-------+",
"| 1.0 | 20.0 | 20.0 |",
"| 1.0 | 20.0 | 10.0 |",
"| 1.0 | 40.0 | 10.0 |",
"| 2.0 | 40.0 | 100.0 |",
"| 2.0 | NaN | NaN |",
"| 3.0 | | |",
"| 3.0 | | 100.0 |",
"| 3.0 | NaN | NaN |",
"+-----+------+-------+",
];

assert_eq!(
DataType::Float32,
*partial_sort_exec.schema().field(0).data_type()
Expand All @@ -1033,7 +1022,20 @@ mod tests {
task_ctx,
)
.await?;
assert_batches_eq!(expected, &result);
assert_snapshot!(batches_to_string(&result), @r#"
+-----+------+-------+
| a | b | c |
+-----+------+-------+
| 1.0 | 20.0 | 20.0 |
| 1.0 | 20.0 | 10.0 |
| 1.0 | 40.0 | 10.0 |
| 2.0 | 40.0 | 100.0 |
| 2.0 | NaN | NaN |
| 3.0 | | |
| 3.0 | | 100.0 |
| 3.0 | NaN | NaN |
+-----+------+-------+
"#);
assert_eq!(result.len(), 2);
let metrics = partial_sort_exec.metrics().unwrap();
assert!(metrics.elapsed_compute().unwrap() > 0);
Expand Down
35 changes: 18 additions & 17 deletions datafusion/physical-plan/src/sorts/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1244,14 +1244,16 @@ mod tests {
use arrow::compute::SortOptions;
use arrow::datatypes::*;
use datafusion_common::cast::as_primitive_array;
use datafusion_common::{assert_batches_eq, Result, ScalarValue};
use datafusion_common::test_util::batches_to_string;
use datafusion_common::{Result, ScalarValue};
use datafusion_execution::config::SessionConfig;
use datafusion_execution::runtime_env::RuntimeEnvBuilder;
use datafusion_execution::RecordBatchStream;
use datafusion_physical_expr::expressions::{Column, Literal};
use datafusion_physical_expr::EquivalenceProperties;

use futures::{FutureExt, Stream};
use insta::assert_snapshot;

#[derive(Debug, Clone)]
pub struct SortedUnboundedExec {
Expand Down Expand Up @@ -1913,22 +1915,21 @@ mod tests {
plan = plan.with_fetch(Some(9));

let batches = collect(Arc::new(plan), task_ctx).await?;
#[rustfmt::skip]
let expected = [
"+----+",
"| c1 |",
"+----+",
"| 0 |",
"| 1 |",
"| 2 |",
"| 3 |",
"| 4 |",
"| 5 |",
"| 6 |",
"| 7 |",
"| 8 |",
"+----+",];
assert_batches_eq!(expected, &batches);
assert_snapshot!(batches_to_string(&batches), @r#"
+----+
| c1 |
+----+
| 0 |
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
| 7 |
| 8 |
+----+
"#);
Ok(())
}
}
Loading