Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
cleanup
  • Loading branch information
2010YOUY01 committed Nov 1, 2026
commit 5d9ccacda7abc18e842b49fe27ed7ad9139df64a
38 changes: 24 additions & 14 deletions datafusion/core/tests/fuzz_cases/sort_query_fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use std::sync::Arc;

use arrow::array::RecordBatch;
use arrow::compute::concat_batches;
use arrow::util::pretty::pretty_format_batches;
use arrow_schema::SchemaRef;
use datafusion::datasource::MemTable;
use datafusion::prelude::{SessionConfig, SessionContext};
use datafusion_common::test_util::batches_to_string;
use datafusion_common::{Result, human_readable_size, instant::Instant};
use datafusion_execution::disk_manager::DiskManagerBuilder;
use datafusion_execution::memory_pool::{MemoryPool, UnboundedMemoryPool};
Expand Down Expand Up @@ -211,14 +211,7 @@ impl SortQueryFuzzer {
if expected_results.is_none() {
expected_results = Some(results);
} else if let Some(ref expected) = expected_results {
// Check logical equivalence.
// `assert_eq!` directly on `RecordBatch` may report false
// failures when logically equivalent batches have different
// physical encodings, so here it compares formatted batches.
assert_eq!(
batches_to_string(std::slice::from_ref(expected)),
batches_to_string(std::slice::from_ref(&results))
);
assert_batches_equal_in_order(expected, &results, "");
} else {
unreachable!();
}
Expand Down Expand Up @@ -602,10 +595,10 @@ impl SortFuzzerTestGenerator {
let ctx =
self.generate_random_config(config_seed, false, Some(threshold))?;
let actual = ctx.sql(&query_str).await?.collect().await?;
assert_eq!(
batches_to_string(std::slice::from_ref(&results)),
batches_to_string(&[concat_batches(&schema, &actual)?]),
"sort_in_place_threshold_bytes={threshold}"
assert_batches_equal_in_order(
&results,
&concat_batches(&schema, &actual)?,
&format!("sort_in_place_threshold_bytes={threshold}"),
);
}
}
Expand All @@ -614,6 +607,23 @@ impl SortFuzzerTestGenerator {
}
}

/// Compares rows in order by their displayed values, so logically equal
/// batches with different physical encodings (e.g. dictionaries) still match.
#[track_caller]
fn assert_batches_equal_in_order(
expected: &RecordBatch,
actual: &RecordBatch,
msg: &str,
) {
let expected = pretty_format_batches(std::slice::from_ref(expected))
.unwrap()
.to_string();
let actual = pretty_format_batches(std::slice::from_ref(actual))
.unwrap()
.to_string();
assert_eq!(expected, actual, "{msg}");
}

#[cfg(test)]
mod test {
use super::*;
Expand Down Expand Up @@ -664,6 +674,6 @@ mod test {

let res1 = test_generator.fuzzer_run(1, 2, 3, false).await.unwrap();
let res2 = test_generator.fuzzer_run(1, 2, 3, false).await.unwrap();
assert_eq!(batches_to_string(&[res1]), batches_to_string(&[res2]));
assert_batches_equal_in_order(&res1, &res2, "");
}
}
Loading