Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb committed May 21, 2024
1 parent d64ecf6 commit 45d4813
Showing 1 changed file with 37 additions and 25 deletions.
62 changes: 37 additions & 25 deletions datafusion/core/src/datasource/physical_plan/parquet/row_groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,42 @@ mod tests {
NonePruned,
}

impl ExpectedPruning {
/// asserts that the pruned row group match this expectation
fn assert(&self, row_groups: &RowGroupSet) {
let num_row_groups = row_groups.len();
assert!(num_row_groups > 0);
let num_pruned = (0..num_row_groups)
.filter_map(|i| {
if row_groups.should_scan(i) {
None
} else {
Some(1)
}
})
.sum::<usize>();

match self {
Self::AllPruned => {
assert_eq!(
num_row_groups, num_pruned,
"Expected all row groups to be pruned, but got {row_groups:?}"
);
}
ExpectedPruning::NonePruned => {
assert_eq!(
num_pruned, 0,
"Expected no row groups to be pruned, but got {row_groups:?}"
);
}
ExpectedPruning::SomePruned(expected) => {
let actual = row_groups.indexes();
assert_eq!(expected, &actual, "Unexpected row groups pruned. Expected {expected:?}, got {actual:?}");
}
}
}
}

struct BloomFilterTest {
file_name: String,
schema: Schema,
Expand Down Expand Up @@ -1370,30 +1406,7 @@ mod tests {
.await
.unwrap();

let num_row_groups = pruned_row_groups.len();
assert!(num_row_groups > 0);
let num_pruned = (0..num_row_groups)
.filter_map(|i| {
if pruned_row_groups.should_scan(i) {
None
} else {
Some(1)
}
})
.sum::<usize>();

match post_pruning_row_groups {
ExpectedPruning::AllPruned => {
assert_eq!(num_row_groups, num_pruned, "Expected all row groups to be pruned, but got {pruned_row_groups:?}");
}
ExpectedPruning::NonePruned => {
assert_eq!(num_pruned, 0, "Expected no row groups to be pruned, but got {pruned_row_groups:?}");
}
ExpectedPruning::SomePruned(expected) => {
let actual = pruned_row_groups.indexes();
assert_eq!(expected, actual, "Unexpected row groups pruned. Expected {expected:?}, got {actual:?}");
}
}
post_pruning_row_groups.assert(&pruned_row_groups);
}
}

Expand Down Expand Up @@ -1427,7 +1440,6 @@ mod tests {
};
let mut builder = ParquetRecordBatchStreamBuilder::new(reader).await.unwrap();

let metadata = builder.metadata().clone();
let pruned_row_group = prune_row_groups_by_bloom_filters(
pruning_predicate.schema(),
&mut builder,
Expand Down

0 comments on commit 45d4813

Please sign in to comment.