Skip to content

Commit e65dafe

Browse files
authored
minor: Fix parquet pruning metrics display order (#18379)
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> - Closes #. ## Rationale for this change <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> It's better to let pruning metrics in parquet displayed in an order that is the same as the actual pruning order: ``` metrics=...files_ranges_pruned_statistics=21 total → 3 matched, row_groups_pruned_statistics=1 total → 1 matched, row_groups_pruned_bloom_filter=1 total → 1 matched, page_index_rows_pruned=748901 total → 19813 matched... ``` Now it's ordered alphabetically. See #18321 (comment) for reproducing. ## What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> Update the sort key API in `MetricValue`, to let the parquet pruning metrics display in the expected order. ## Are these changes tested? UT <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> ## Are there any user-facing changes? No <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> <!-- If there are any breaking changes to public APIs, please add the `api change` label. -->
1 parent a216aa5 commit e65dafe

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

datafusion/core/tests/sql/explain_analyze.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,21 @@ async fn parquet_explain_analyze() {
860860
&formatted,
861861
"row_groups_pruned_statistics=1 total \u{2192} 1 matched"
862862
);
863+
864+
// The order of metrics is expected to be the same as the actual pruning order
865+
// (file-> row-group -> page)
866+
let i_file = formatted.find("files_ranges_pruned_statistics").unwrap();
867+
let i_rowgroup_stat = formatted.find("row_groups_pruned_statistics").unwrap();
868+
let i_rowgroup_bloomfilter =
869+
formatted.find("row_groups_pruned_bloom_filter").unwrap();
870+
let i_page = formatted.find("page_index_rows_pruned").unwrap();
871+
872+
assert!(
873+
(i_file < i_rowgroup_stat)
874+
&& (i_rowgroup_stat < i_rowgroup_bloomfilter)
875+
&& (i_rowgroup_bloomfilter < i_page),
876+
"The parquet pruning metrics should be displayed in an order of: file range -> row group statistics -> row group bloom filter -> page index."
877+
);
863878
}
864879

865880
// This test reproduces the behavior described in

datafusion/physical-plan/src/metrics/value.rs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -749,17 +749,30 @@ impl MetricValue {
749749
Self::ElapsedCompute(_) => 1,
750750
Self::OutputBytes(_) => 2,
751751
// Other metrics
752-
Self::PruningMetrics { .. } => 3,
753-
Self::SpillCount(_) => 4,
754-
Self::SpilledBytes(_) => 5,
755-
Self::SpilledRows(_) => 6,
756-
Self::CurrentMemoryUsage(_) => 7,
757-
Self::Count { .. } => 8,
758-
Self::Gauge { .. } => 9,
759-
Self::Time { .. } => 10,
760-
Self::StartTimestamp(_) => 11, // show timestamps last
761-
Self::EndTimestamp(_) => 12,
762-
Self::Custom { .. } => 13,
752+
Self::PruningMetrics { name, .. } => match name.as_ref() {
753+
// The following metrics belong to `DataSourceExec` with a Parquet data source.
754+
// They are displayed in a specific order that reflects the actual pruning process,
755+
// from coarse-grained to fine-grained pruning levels.
756+
//
757+
// You may update these metrics as long as their relative order remains unchanged.
758+
//
759+
// Reference PR: <https://github.com/apache/datafusion/pull/18379>
760+
"files_ranges_pruned_statistics" => 3,
761+
"row_groups_pruned_statistics" => 4,
762+
"row_groups_pruned_bloom_filter" => 5,
763+
"page_index_rows_pruned" => 6,
764+
_ => 7,
765+
},
766+
Self::SpillCount(_) => 8,
767+
Self::SpilledBytes(_) => 9,
768+
Self::SpilledRows(_) => 10,
769+
Self::CurrentMemoryUsage(_) => 11,
770+
Self::Count { .. } => 12,
771+
Self::Gauge { .. } => 13,
772+
Self::Time { .. } => 14,
773+
Self::StartTimestamp(_) => 15, // show timestamps last
774+
Self::EndTimestamp(_) => 16,
775+
Self::Custom { .. } => 17,
763776
}
764777
}
765778

0 commit comments

Comments
 (0)