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
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.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ parquet = { version = "54.2.1", default-features = false, features = [
pbjson = { version = "0.7.0" }
pbjson-types = "0.7"
# Should match arrow-flight's version of prost.
insta = { version = "1.41.1", features = ["glob", "filters"] }
prost = "0.13.1"
rand = "0.8.5"
recursive = "0.1.1"
Expand Down
2 changes: 1 addition & 1 deletion datafusion-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ url = { workspace = true }
[dev-dependencies]
assert_cmd = "2.0"
ctor = { workspace = true }
insta = { version = "1.41.1", features = ["glob", "filters"] }
insta = { workspace = true }
insta-cmd = "0.6.0"
predicates = "3.0"
rstest = { workspace = true }
28 changes: 28 additions & 0 deletions datafusion/common/src/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

//! Utility functions to make testing DataFusion based crates easier

use crate::arrow::util::pretty::pretty_format_batches_with_options;
use crate::format::DEFAULT_FORMAT_OPTIONS;
use arrow::array::RecordBatch;
use std::{error::Error, path::PathBuf};

/// Compares formatted output of a record batch with an expected
Expand Down Expand Up @@ -73,6 +76,31 @@ macro_rules! assert_batches_eq {
};
}

pub fn batches_to_string(batches: &[RecordBatch]) -> String {
let actual = pretty_format_batches_with_options(batches, &DEFAULT_FORMAT_OPTIONS)
.unwrap()
.to_string();

actual.trim().to_string()
}

pub fn batches_to_sort_string(batches: &[RecordBatch]) -> String {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

there's alternative way: use https://docs.rs/insta/latest/insta/struct.Settings.html#method.sort_maps

this, however, will require switching to serializable format - which we dont want - so leaving as is

Copy link
Contributor

Choose a reason for hiding this comment

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

I think using strings for comparison works well - let's try this

let actual_lines =
pretty_format_batches_with_options(batches, &DEFAULT_FORMAT_OPTIONS)
.unwrap()
.to_string();

let mut actual_lines: Vec<&str> = actual_lines.trim().lines().collect();

// sort except for header + footer
let num_lines = actual_lines.len();
if num_lines > 3 {
actual_lines.as_mut_slice()[2..num_lines - 1].sort_unstable()
}

actual_lines.join("\n")
}

/// Compares formatted output of a record batch with an expected
/// vector of strings in a way that order does not matter.
/// This is a macro so errors appear on the correct line
Expand Down
1 change: 1 addition & 0 deletions datafusion/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ datafusion-functions-window-common = { workspace = true }
datafusion-physical-optimizer = { workspace = true }
doc-comment = { workspace = true }
env_logger = { workspace = true }
insta = { workspace = true }
paste = "^1.0"
rand = { workspace = true, features = ["small_rng"] }
rand_distr = "0.4.3"
Expand Down
Loading