Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve parquet partition_file output display #4467

Merged
merged 7 commits into from
Dec 4, 2022
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
104 changes: 52 additions & 52 deletions datafusion/core/src/physical_optimizer/enforcement.rs

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions datafusion/core/src/physical_optimizer/repartition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ mod tests {
"AggregateExec: mode=Final, gby=[], aggr=[]",
"AggregateExec: mode=Partial, gby=[], aggr=[]",
"RepartitionExec: partitioning=RoundRobinBatch(10)",
"ParquetExec: limit=None, partitions=[x], projection=[c1]",
"ParquetExec: limit=None, partitions={1 group: [[x]]}, projection=[c1]",
];

assert_optimized!(expected, plan);
Expand All @@ -402,7 +402,7 @@ mod tests {
"AggregateExec: mode=Partial, gby=[], aggr=[]",
"FilterExec: c1@0",
"RepartitionExec: partitioning=RoundRobinBatch(10)",
"ParquetExec: limit=None, partitions=[x], projection=[c1]",
"ParquetExec: limit=None, partitions={1 group: [[x]]}, projection=[c1]",
];

assert_optimized!(expected, plan);
Expand All @@ -419,7 +419,7 @@ mod tests {
"FilterExec: c1@0",
// nothing sorts the data, so the local limit doesn't require sorted data either
"RepartitionExec: partitioning=RoundRobinBatch(10)",
"ParquetExec: limit=None, partitions=[x], projection=[c1]",
"ParquetExec: limit=None, partitions={1 group: [[x]]}, projection=[c1]",
];

assert_optimized!(expected, plan);
Expand All @@ -436,7 +436,7 @@ mod tests {
"FilterExec: c1@0",
// nothing sorts the data, so the local limit doesn't require sorted data either
"RepartitionExec: partitioning=RoundRobinBatch(10)",
"ParquetExec: limit=None, partitions=[x], projection=[c1]",
"ParquetExec: limit=None, partitions={1 group: [[x]]}, projection=[c1]",
];

assert_optimized!(expected, plan);
Expand All @@ -452,7 +452,7 @@ mod tests {
"LocalLimitExec: fetch=100",
// data is sorted so can't repartition here
"SortExec: [c1@0 ASC]",
"ParquetExec: limit=None, partitions=[x], projection=[c1]",
"ParquetExec: limit=None, partitions={1 group: [[x]]}, projection=[c1]",
];

assert_optimized!(expected, plan);
Expand All @@ -470,7 +470,7 @@ mod tests {
// data is sorted so can't repartition here even though
// filter would benefit from parallelism, the answers might be wrong
"SortExec: [c1@0 ASC]",
"ParquetExec: limit=None, partitions=[x], projection=[c1]",
"ParquetExec: limit=None, partitions={1 group: [[x]]}, projection=[c1]",
];

assert_optimized!(expected, plan);
Expand All @@ -493,7 +493,7 @@ mod tests {
"GlobalLimitExec: skip=0, fetch=100",
"LocalLimitExec: fetch=100",
// Expect no repartition to happen for local limit
"ParquetExec: limit=None, partitions=[x], projection=[c1]",
"ParquetExec: limit=None, partitions={1 group: [[x]]}, projection=[c1]",
];

assert_optimized!(expected, plan);
Expand All @@ -518,7 +518,7 @@ mod tests {
"GlobalLimitExec: skip=0, fetch=100",
"LocalLimitExec: fetch=100",
// Expect no repartition to happen for local limit
"ParquetExec: limit=None, partitions=[x], projection=[c1]",
"ParquetExec: limit=None, partitions={1 group: [[x]]}, projection=[c1]",
];

assert_optimized!(expected, plan);
Expand All @@ -534,11 +534,11 @@ mod tests {
let expected = &[
"UnionExec",
// Expect no repartition of ParquetExec
"ParquetExec: limit=None, partitions=[x], projection=[c1]",
"ParquetExec: limit=None, partitions=[x], projection=[c1]",
"ParquetExec: limit=None, partitions=[x], projection=[c1]",
"ParquetExec: limit=None, partitions=[x], projection=[c1]",
"ParquetExec: limit=None, partitions=[x], projection=[c1]",
"ParquetExec: limit=None, partitions={1 group: [[x]]}, projection=[c1]",
"ParquetExec: limit=None, partitions={1 group: [[x]]}, projection=[c1]",
"ParquetExec: limit=None, partitions={1 group: [[x]]}, projection=[c1]",
"ParquetExec: limit=None, partitions={1 group: [[x]]}, projection=[c1]",
"ParquetExec: limit=None, partitions={1 group: [[x]]}, projection=[c1]",
];

assert_optimized!(expected, plan);
Expand All @@ -552,7 +552,7 @@ mod tests {
let expected = &[
"SortPreservingMergeExec: [c1@0 ASC]",
// Expect no repartition of SortPreservingMergeExec
"ParquetExec: limit=None, partitions=[x], projection=[c1]",
"ParquetExec: limit=None, partitions={1 group: [[x]]}, projection=[c1]",
];

assert_optimized!(expected, plan);
Expand All @@ -568,7 +568,7 @@ mod tests {
// Expect no repartition of SortPreservingMergeExec
// even though there is a projection exec between it
"ProjectionExec: expr=[c1@0 as c1]",
"ParquetExec: limit=None, partitions=[x], projection=[c1]",
"ParquetExec: limit=None, partitions={1 group: [[x]]}, projection=[c1]",
];

assert_optimized!(expected, plan);
Expand All @@ -585,7 +585,7 @@ mod tests {
"SortExec: [c1@0 ASC]",
"ProjectionExec: expr=[c1@0 as c1]",
"RepartitionExec: partitioning=RoundRobinBatch(10)",
"ParquetExec: limit=None, partitions=[x], projection=[c1]",
"ParquetExec: limit=None, partitions={1 group: [[x]]}, projection=[c1]",
];

assert_optimized!(expected, plan);
Expand All @@ -602,7 +602,7 @@ mod tests {
"SortExec: [c1@0 ASC]",
"FilterExec: c1@0",
"RepartitionExec: partitioning=RoundRobinBatch(10)",
"ParquetExec: limit=None, partitions=[x], projection=[c1]",
"ParquetExec: limit=None, partitions={1 group: [[x]]}, projection=[c1]",
];

assert_optimized!(expected, plan);
Expand All @@ -623,7 +623,7 @@ mod tests {
"FilterExec: c1@0",
// repartition is lowest down
"RepartitionExec: partitioning=RoundRobinBatch(10)",
"ParquetExec: limit=None, partitions=[x], projection=[c1]",
"ParquetExec: limit=None, partitions={1 group: [[x]]}, projection=[c1]",
];

assert_optimized!(expected, plan);
Expand Down
83 changes: 72 additions & 11 deletions datafusion/core/src/physical_plan/file_format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,22 +178,39 @@ impl FileScanConfig {
}

/// A wrapper to customize partitioned file display
///
/// Prints in the format:
/// ```text
/// {NUM_GROUPS groups: [[file1, file2,...], [fileN, fileM, ...], ...]}
/// ```
#[derive(Debug)]
struct FileGroupsDisplay<'a>(&'a [Vec<PartitionedFile>]);

impl<'a> Display for FileGroupsDisplay<'a> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This implementation also avoids allocating strings and Vecs, which I don't think is a particularly important feature, but it is a nice benefit.

fn fmt(&self, f: &mut Formatter) -> FmtResult {
let parts: Vec<_> = self
.0
.iter()
.map(|pp| {
pp.iter()
.map(|pf| pf.object_meta.location.as_ref())
.collect::<Vec<_>>()
.join(", ")
})
.collect();
write!(f, "[{}]", parts.join(", "))
let mut first_group = true;
let groups = if self.0.len() == 1 { "group" } else { "groups" };
write!(f, "{{{} {}: [", self.0.len(), groups)?;
for group in self.0 {
if !first_group {
write!(f, ", ")?;
}
first_group = false;
write!(f, "[")?;

let mut first_file = true;
for pf in group {
if !first_file {
write!(f, ", ")?;
}
first_file = false;

write!(f, "{}", pf.object_meta.location.as_ref())?;
}
write!(f, "]")?;
}
write!(f, "]}}")?;
Ok(())
}
}

Expand Down Expand Up @@ -521,6 +538,8 @@ pub(crate) fn get_output_ordering(

#[cfg(test)]
mod tests {
use chrono::Utc;

use crate::{
test::{build_table_i32, columns},
test_util::aggr_test_schema,
Expand Down Expand Up @@ -796,4 +815,46 @@ mod tests {
output_ordering: None,
}
}

#[test]
fn file_groups_display_empty() {
let expected = "{0 groups: []}";
assert_eq!(&FileGroupsDisplay(&[]).to_string(), expected);
}

#[test]
fn file_groups_display_one() {
let files = [vec![partitioned_file("foo"), partitioned_file("bar")]];

let expected = "{1 group: [[foo, bar]]}";
assert_eq!(&FileGroupsDisplay(&files).to_string(), expected);
}

#[test]
fn file_groups_display_many() {
let files = [
vec![partitioned_file("foo"), partitioned_file("bar")],
vec![partitioned_file("baz")],
vec![],
];

let expected = "{3 groups: [[foo, bar], [baz], []]}";
assert_eq!(&FileGroupsDisplay(&files).to_string(), expected);
}

/// create a PartitionedFile for testing
fn partitioned_file(path: &str) -> PartitionedFile {
let object_meta = ObjectMeta {
location: object_store::path::Path::parse(path).unwrap(),
last_modified: Utc::now(),
size: 42,
};

PartitionedFile {
object_meta,
partition_values: vec![],
range: None,
extensions: None,
}
}
}
2 changes: 1 addition & 1 deletion datafusion/core/src/physical_plan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ pub fn with_new_children_if_necessary(
/// \n CoalesceBatchesExec: target_batch_size=4096\
/// \n FilterExec: a@0 < 5\
/// \n RepartitionExec: partitioning=RoundRobinBatch(3)\
/// \n CsvExec: files=[WORKING_DIR/tests/example.csv], has_header=true, limit=None, projection=[a]",
/// \n CsvExec: files={1 group: [[WORKING_DIR/tests/example.csv]]}, has_header=true, limit=None, projection=[a]",
/// plan_string.trim());
///
/// let one_line = format!("{}", displayable_plan.one_line());
Expand Down
2 changes: 1 addition & 1 deletion datafusion/core/tests/sql/avro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ async fn avro_explain() {
\n CoalescePartitionsExec\
\n AggregateExec: mode=Partial, gby=[], aggr=[COUNT(UInt8(1))]\
\n RepartitionExec: partitioning=RoundRobinBatch(NUM_CORES)\
\n AvroExec: files=[ARROW_TEST_DATA/avro/alltypes_plain.avro], limit=None\
\n AvroExec: files={1 group: [[ARROW_TEST_DATA/avro/alltypes_plain.avro]]}, limit=None\
\n",
],
];
Expand Down
8 changes: 4 additions & 4 deletions datafusion/core/tests/sql/explain_analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ async fn test_physical_plan_display_indent() {
" CoalesceBatchesExec: target_batch_size=4096",
" FilterExec: c12@1 < 10",
" RepartitionExec: partitioning=RoundRobinBatch(9000)",
" CsvExec: files=[ARROW_TEST_DATA/csv/aggregate_test_100.csv], has_header=true, limit=None, projection=[c1, c12]",
" CsvExec: files={1 group: [[ARROW_TEST_DATA/csv/aggregate_test_100.csv]]}, has_header=true, limit=None, projection=[c1, c12]",
];

let normalizer = ExplainNormalizer::new();
Expand Down Expand Up @@ -739,12 +739,12 @@ async fn test_physical_plan_display_indent_multi_children() {
" RepartitionExec: partitioning=Hash([Column { name: \"c1\", index: 0 }], 9000)",
" ProjectionExec: expr=[c1@0 as c1]",
" RepartitionExec: partitioning=RoundRobinBatch(9000)",
" CsvExec: files=[ARROW_TEST_DATA/csv/aggregate_test_100.csv], has_header=true, limit=None, projection=[c1]",
" CsvExec: files={1 group: [[ARROW_TEST_DATA/csv/aggregate_test_100.csv]]}, has_header=true, limit=None, projection=[c1]",
" CoalesceBatchesExec: target_batch_size=4096",
" RepartitionExec: partitioning=Hash([Column { name: \"c2\", index: 0 }], 9000)",
" ProjectionExec: expr=[c1@0 as c2]",
" RepartitionExec: partitioning=RoundRobinBatch(9000)",
" CsvExec: files=[ARROW_TEST_DATA/csv/aggregate_test_100.csv], has_header=true, limit=None, projection=[c1, c2]",
" CsvExec: files={1 group: [[ARROW_TEST_DATA/csv/aggregate_test_100.csv]]}, has_header=true, limit=None, projection=[c1, c2]",
];

let normalizer = ExplainNormalizer::new();
Expand Down Expand Up @@ -787,7 +787,7 @@ async fn csv_explain() {
\n CoalesceBatchesExec: target_batch_size=4096\
\n FilterExec: c2@1 > 10\
\n RepartitionExec: partitioning=RoundRobinBatch(NUM_CORES)\
\n CsvExec: files=[ARROW_TEST_DATA/csv/aggregate_test_100.csv], has_header=true, limit=None, projection=[c1, c2]\
\n CsvExec: files={1 group: [[ARROW_TEST_DATA/csv/aggregate_test_100.csv]]}, has_header=true, limit=None, projection=[c1, c2]\
\n",
]];
assert_eq!(expected, actual);
Expand Down
2 changes: 1 addition & 1 deletion datafusion/core/tests/sql/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async fn json_explain() {
\n CoalescePartitionsExec\
\n AggregateExec: mode=Partial, gby=[], aggr=[COUNT(UInt8(1))]\
\n RepartitionExec: partitioning=RoundRobinBatch(NUM_CORES)\
\n JsonExec: limit=None, files=[WORKING_DIR/tests/jsons/2.json]\n",
\n JsonExec: limit=None, files={1 group: [[WORKING_DIR/tests/jsons/2.json]]}\n",
],
];
assert_eq!(expected, actual);
Expand Down