You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by "hakunamatata-sb (via GitHub)" <gi...@apache.org> on 2026/09/15 14:16:12 UTC
[PR] Prune Partition-Directory descent by filters during storage listing [hudi-rs]
hakunamatata-sb opened a new pull request, #784:
URL: https://github.com/apache/hudi-rs/pull/784
## Description
<!--- Describe your changes in detail -->
When the metadata table is unavailable, `FileLister::list_relevant_partition_paths` fell back to a full recursive listing of every partition directory (`get_leaf_dirs`), applying `PartitionPruner::should_include` only after every leaf partition path had already been discovered. A selective query therefore issued as many storage `list` calls as an unfiltered one, scaling cost and latency with total partition count rather than query selectivity.
This change:
- Threads a `should_descend` predicate through `get_leaf_dirs`, checked before recursing into each child directory.
- Adds `PartitionPruner::should_include_prefix`, a partial-path predicate used as that descent-time filter. It fails open (never wrongly prunes) whenever it can't positively prove a resolved segment violates a filter — no filters present, an opaque single-field partition schema (the case for timestamp-based-keygen tables, which already collapse to one `_hoodie_partition_path` field), a malformed hive-style segment, or a cast/comparison error.
- Keeps the existing full-path `should_include` filter unchanged as the final correctness backstop — descent pruning is purely an optimization.
<!--- If it fixes an open issue, please link to the issue here. -->
Fixes #779
<!--- Please link any related issues and PRs as well. -->
NA
## How are the changes test-covered
- [ ] N/A
- [x] Automated tests (unit and/or integration tests)
- [ ] Manual tests
- [ ] Details are described below
`cargo test -p hudi-core table::partition::tests` — 23/23 pass, including 6 new unit tests for `should_include_prefix` (hive-style, non-hive-style, url-encoded, malformed segment, no filters, single-field/timestamp-keygen schema).
`cargo test -p hudi-core table::listing::test` — new regression test `partition_filter_pruning_reduces_storage_list_calls` asserts exact storage `list` call counts against a `CountingObjectStore`: 7 calls unfiltered vs. 3 calls with a selective filter (`byteField = "10"`) on `V6ComplexkeygenHivestyle`, plus correctness of the returned partition paths.
`cargo test -p hudi-core storage::tests::use_storage_to_get_leaf_dirs*` still pass with the new predicate parameter.
`cargo clippy -p hudi-core --lib -- -D warnings` clean on the touched files.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Prune Partition-Directory descent by filters during storage listing [hudi-rs]
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #784:
URL: https://github.com/apache/hudi-rs/pull/784#issuecomment-5692076120
## [Codecov](https://app.codecov.io/gh/apache/hudi-rs/pull/784?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:x: Patch coverage is `87.09677%` with `4 lines` in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 79.51%. Comparing base ([`06f17bf`](https://app.codecov.io/gh/apache/hudi-rs/commit/06f17bf646ca7f8d76230d86f365f171814720cb?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`5409d92`](https://app.codecov.io/gh/apache/hudi-rs/commit/5409d927dac08df8a4b89984c5d690952524b1e7?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
:warning: Report is 2 commits behind head on main.
| [Files with missing lines](https://app.codecov.io/gh/apache/hudi-rs/pull/784?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [crates/core/src/table/partition.rs](https://app.codecov.io/gh/apache/hudi-rs/pull/784?src=pr&el=tree&filepath=crates%2Fcore%2Fsrc%2Ftable%2Fpartition.rs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Y3JhdGVzL2NvcmUvc3JjL3RhYmxlL3BhcnRpdGlvbi5ycw==) | 84.00% | [4 Missing :warning: ](https://app.codecov.io/gh/apache/hudi-rs/pull/784?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## main #784 +/- ##
==========================================
+ Coverage 79.50% 79.51% +0.01%
==========================================
Files 126 126
Lines 12371 12399 +28
==========================================
+ Hits 9835 9859 +24
- Misses 2536 2540 +4
```
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/hudi-rs/pull/784?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(core): Prune Partition-Directory descent by filters during storage listing [hudi-rs]
Posted by "hakunamatata-sb (via GitHub)" <gi...@apache.org>.
hakunamatata-sb commented on code in PR #784:
URL: https://github.com/apache/hudi-rs/pull/784#discussion_r4024045826
##########
crates/core/src/storage/mod.rs:
##########
@@ -409,8 +409,16 @@ impl Storage {
/// - /usr/hudi/table_name/dt=2025/month=02
///
/// the result is \[".hoodie", "dt=2024/mont=01/day=01", "dt=2025/month=02"\]
+///
+/// `should_descend` is checked before recursing into each child directory, so a
+/// directory a filter already rules out never incurs the storage `list` call
+/// its own children would otherwise need.
#[async_recursion]
-pub async fn get_leaf_dirs(storage: &Storage, subdir: Option<&str>) -> Result<Vec<String>> {
+pub async fn get_leaf_dirs(
Review Comment:
Added the breaking change description in the PR summary, PTAL.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Prune Partition-Directory descent by filters during storage listing [hudi-rs]
Posted by "codope (via GitHub)" <gi...@apache.org>.
codope commented on code in PR #784:
URL: https://github.com/apache/hudi-rs/pull/784#discussion_r4022722089
##########
crates/core/src/table/partition.rs:
##########
@@ -174,6 +174,71 @@ impl PartitionPruner {
})
}
+ /// Returns `true` if a partition directory prefix should be descended into.
+ ///
+ /// Unlike `should_include`, `partial_path` may resolve fewer segments than
+ /// the schema has fields (we're mid-descent, not at a leaf yet). Any segment
+ /// this can't safely reason about — not enough schema fields to compare
+ /// against, a single opaque path field (e.g. under a timestamp-based key
+ /// generator, where a segment carries no independently meaningful value),
+ /// a hive-style segment that doesn't parse as `key=value`, or a cast/compare
+ /// error — is treated as unconstrained, never as a reason to reject. Only a
+ /// segment that positively fails an already-resolved filter returns `false`.
+ pub fn should_include_prefix(&self, partial_path: &str) -> bool {
Review Comment:
I think this can drop a partition that actually matches. Take `region=us%2Feast/dt=2024-01-01` with a filter `region = 'us/east'`: the prefix check comes back false, but `should_include` on the full path comes back true. Values with a `/` in them are not that rare. Am I reading it right?
I suspect the main reason is that `parse_segments` decodes the whole path and then splits on `/`. Java goes the other way, splitting first and unescaping each fragment (`AbstractHoodieTableMetadata.extractPartitionValues`). Would it make sense to fix that ordering first? Looks like it would help `should_include` too.
Once segments decode independently, i would suggest gating this on `is_hive_style && is_url_encoded`? That is what Java requires (`FileSystemBackedTableMetadata.java:157`), and it seems to be the thing that makes the positional binding safe.
##########
crates/core/src/table/partition.rs:
##########
@@ -174,6 +174,71 @@ impl PartitionPruner {
})
}
+ /// Returns `true` if a partition directory prefix should be descended into.
+ ///
+ /// Unlike `should_include`, `partial_path` may resolve fewer segments than
+ /// the schema has fields (we're mid-descent, not at a leaf yet). Any segment
+ /// this can't safely reason about — not enough schema fields to compare
+ /// against, a single opaque path field (e.g. under a timestamp-based key
+ /// generator, where a segment carries no independently meaningful value),
+ /// a hive-style segment that doesn't parse as `key=value`, or a cast/compare
+ /// error — is treated as unconstrained, never as a reason to reject. Only a
+ /// segment that positively fails an already-resolved filter returns `false`.
+ pub fn should_include_prefix(&self, partial_path: &str) -> bool {
+ if self.and_filters.is_empty() || self.schema.fields().len() <= 1 {
+ return true;
+ }
+
+ let decoded;
Review Comment:
minor: `let decoded; ... &decoded` reads a bit awkwardly. `Cow<str>` would do this directly.
##########
crates/core/src/table/partition.rs:
##########
@@ -401,6 +466,113 @@ mod tests {
assert!(!pruner.should_include("date=2023-02-01/category=B/count=10"));
}
+ #[test]
+ fn test_partition_pruner_should_include_prefix() {
+ let schema = create_test_schema();
+ let configs = create_hudi_configs(true, false);
+
+ let filter_gt_date = Filter::try_from(("date", ">", "2023-01-01")).unwrap();
+ let filter_eq_a = Filter::try_from(("category", "=", "A")).unwrap();
+ let filter_lte_100 = Filter::try_from(("count", "<=", "100")).unwrap();
+
+ let pruner = PartitionPruner::new(
+ &[filter_gt_date, filter_eq_a, filter_lte_100],
+ &schema,
+ &configs,
+ )
+ .unwrap();
+
+ // A resolved segment that already violates its filter is rejected
+ // without needing to resolve the rest of the path.
+ assert!(!pruner.should_include_prefix("date=2022-12-31"));
+ assert!(!pruner.should_include_prefix("date=2023-02-01/category=B"));
+
+ // A resolved segment that satisfies its filter, with later fields not
+ // yet resolved, is not rejected.
+ assert!(pruner.should_include_prefix("date=2023-02-01"));
+ assert!(pruner.should_include_prefix("date=2023-02-01/category=A"));
+ assert!(pruner.should_include_prefix("date=2023-02-01/category=A/count=10"));
+ }
+
+ #[test]
+ fn test_partition_pruner_should_include_prefix_no_filters() {
+ let pruner = PartitionPruner::empty();
+ assert!(pruner.should_include_prefix("date=2022-12-31"));
+ assert!(pruner.should_include_prefix(""));
+ }
+
+ #[test]
+ fn test_partition_pruner_should_include_prefix_malformed_segment_fails_open() {
+ let schema = create_test_schema();
+ let configs = create_hudi_configs(true, false);
+ let filter_eq_a = Filter::try_from(("category", "=", "A")).unwrap();
+ let pruner = PartitionPruner::new(&[filter_eq_a], &schema, &configs).unwrap();
+
+ // A segment that doesn't parse as `key=value` under hive-style
+ // partitioning can't be safely compared, so it must not be rejected.
+ assert!(pruner.should_include_prefix("not-a-kv-pair"));
+ }
+
+ #[test]
+ fn test_partition_pruner_should_include_prefix_non_hive_style() {
+ let schema = create_test_schema();
+ let configs = create_hudi_configs(false, false);
+ let filter_gt_date = Filter::try_from(("date", ">", "2023-01-01")).unwrap();
+ let pruner = PartitionPruner::new(&[filter_gt_date], &schema, &configs).unwrap();
+
+ assert!(!pruner.should_include_prefix("2022-12-31"));
+ assert!(pruner.should_include_prefix("2023-02-01"));
+ }
+
+ #[test]
+ fn test_partition_pruner_should_include_prefix_url_encoded() {
+ let schema = create_test_schema();
+ let configs = create_hudi_configs(true, true);
+ let filter_eq_a = Filter::try_from(("category", "=", "A")).unwrap();
+ let pruner = PartitionPruner::new(&[filter_eq_a], &schema, &configs).unwrap();
+
+ assert!(!pruner.should_include_prefix("date%3D2023-02-01%2Fcategory%3DB"));
Review Comment:
I don't think Hudi writes paths like this. It escapes values but leaves `=` and `/` alone. Something like `category=A%2FB` would be closer, and it would cover the slash case too.
##########
crates/core/src/table/listing.rs:
##########
@@ -185,9 +185,14 @@ impl FileLister {
.filter(|dir| !LAKE_FORMAT_METADATA_DIRS.contains(&dir.as_str()))
.collect();
+ let should_descend = |prefix: &str| self.partition_pruner.should_include_prefix(prefix);
+
let mut partition_paths = Vec::new();
for dir in top_level_dirs {
- partition_paths.extend(get_leaf_dirs(&self.storage, Some(&dir)).await?);
+ if !should_descend(&dir) {
Review Comment:
Could this fold into the `top_level_dirs` filter chain next to the `LAKE_FORMAT_METADATA_DIRS` one, rather than a separate `continue`?
##########
crates/core/src/table/partition.rs:
##########
@@ -174,6 +174,71 @@ impl PartitionPruner {
})
}
+ /// Returns `true` if a partition directory prefix should be descended into.
+ ///
+ /// Unlike `should_include`, `partial_path` may resolve fewer segments than
+ /// the schema has fields (we're mid-descent, not at a leaf yet). Any segment
+ /// this can't safely reason about — not enough schema fields to compare
+ /// against, a single opaque path field (e.g. under a timestamp-based key
+ /// generator, where a segment carries no independently meaningful value),
+ /// a hive-style segment that doesn't parse as `key=value`, or a cast/compare
+ /// error — is treated as unconstrained, never as a reason to reject. Only a
+ /// segment that positively fails an already-resolved filter returns `false`.
+ pub fn should_include_prefix(&self, partial_path: &str) -> bool {
+ if self.and_filters.is_empty() || self.schema.fields().len() <= 1 {
Review Comment:
This also switches the optimization off for single-column `dt=...` tables, which is probably the most common layout out there. I tried it on `V6SimplekeygenHivestyleNoMetafields` and got 4 list calls either way. Keying on the `_hoodie_partition_path` field instead of the field count got it down to 2, with the suite still green. Worth a try?
##########
crates/core/src/table/listing.rs:
##########
@@ -311,6 +316,61 @@ mod test {
)
}
+ /// Regression test for descent-time partition pruning: a selective filter
+ /// must skip the storage `list` calls under directories it already rules
+ /// out, not merely filter the leaf paths after every directory is listed.
+ ///
+ /// For `V6ComplexkeygenHivestyle` (3 leaf partitions under two hive-style
+ /// levels, `byteField`/`shortField`), an unfiltered run issues 7 `list`
+ /// calls: 1 for the top-level `byteField=*` dirs, then for each of the 3,
+ /// 1 to find its `shortField=*` child and 1 more on that leaf to confirm
+ /// it has no children. A filter matching only `byteField=10` issues 3:
+ /// the same unavoidable top-level call, then only `byteField=10`'s two
+ /// levels are ever listed — `byteField=20`/`byteField=30` are pruned
+ /// before incurring any `list` call under them.
+ #[tokio::test]
+ async fn partition_filter_pruning_reduces_storage_list_calls() {
+ use crate::storage::counting::CountingObjectStore;
+ use object_store::local::LocalFileSystem;
+
+ let base_url = SampleTable::V6ComplexkeygenHivestyle.url_to_cow();
+ let hudi_table = Table::new(base_url.path()).await.unwrap();
+ let hudi_configs = hudi_table.hudi_configs.clone();
+ let partition_schema = hudi_table.get_partition_schema().await.unwrap();
+
+ let list_calls_for = |pruner: PartitionPruner| {
+ let base_url = base_url.clone();
+ let hudi_configs = hudi_configs.clone();
+ async move {
+ let (object_store, counts) =
+ CountingObjectStore::new(Arc::new(LocalFileSystem::new()));
+ let storage =
+ Storage::new_with_object_store(base_url, object_store, hudi_configs);
+ let lister = FileLister::new(storage.hudi_configs.clone(), storage, pruner);
+ let partition_paths = lister.list_relevant_partition_paths().await.unwrap();
+ (partition_paths.len(), counts.lists())
+ }
+ };
+
+ let (unfiltered_partitions, unfiltered_lists) =
+ list_calls_for(PartitionPruner::empty()).await;
+ assert_eq!(unfiltered_partitions, 3);
+ assert_eq!(unfiltered_lists, 7);
+
+ let filter_eq_10 = crate::expr::filter::Filter::try_from(("byteField", "=", "10")).unwrap();
+ let selective_pruner =
+ PartitionPruner::new(&[filter_eq_10], &partition_schema, &hudi_configs).unwrap();
+ let (filtered_partitions, filtered_lists) = list_calls_for(selective_pruner).await;
+ assert_eq!(filtered_partitions, 1);
+ assert_eq!(filtered_lists, 3);
+
+ assert!(
Review Comment:
minor: this cannot fail once the two exact counts above are asserted.
##########
crates/core/src/storage/mod.rs:
##########
@@ -409,8 +409,16 @@ impl Storage {
/// - /usr/hudi/table_name/dt=2025/month=02
///
/// the result is \[".hoodie", "dt=2024/mont=01/day=01", "dt=2025/month=02"\]
+///
+/// `should_descend` is checked before recursing into each child directory, so a
+/// directory a filter already rules out never incurs the storage `list` call
+/// its own children would otherwise need.
#[async_recursion]
-pub async fn get_leaf_dirs(storage: &Storage, subdir: Option<&str>) -> Result<Vec<String>> {
+pub async fn get_leaf_dirs(
Review Comment:
Just noting this is `pub`, so the added parameter is a signature break. Nothing outside the crate calls it, so probably fine. Maybe worth a line in the description?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(core): Prune Partition-Directory descent by filters during storage listing [hudi-rs]
Posted by "hakunamatata-sb (via GitHub)" <gi...@apache.org>.
hakunamatata-sb commented on code in PR #784:
URL: https://github.com/apache/hudi-rs/pull/784#discussion_r4024084715
##########
crates/core/src/table/listing.rs:
##########
@@ -185,9 +185,14 @@ impl FileLister {
.filter(|dir| !LAKE_FORMAT_METADATA_DIRS.contains(&dir.as_str()))
.collect();
+ let should_descend = |prefix: &str| self.partition_pruner.should_include_prefix(prefix);
+
let mut partition_paths = Vec::new();
for dir in top_level_dirs {
- partition_paths.extend(get_leaf_dirs(&self.storage, Some(&dir)).await?);
+ if !should_descend(&dir) {
Review Comment:
fixed.
##########
crates/core/src/table/listing.rs:
##########
@@ -311,6 +316,61 @@ mod test {
)
}
+ /// Regression test for descent-time partition pruning: a selective filter
+ /// must skip the storage `list` calls under directories it already rules
+ /// out, not merely filter the leaf paths after every directory is listed.
+ ///
+ /// For `V6ComplexkeygenHivestyle` (3 leaf partitions under two hive-style
+ /// levels, `byteField`/`shortField`), an unfiltered run issues 7 `list`
+ /// calls: 1 for the top-level `byteField=*` dirs, then for each of the 3,
+ /// 1 to find its `shortField=*` child and 1 more on that leaf to confirm
+ /// it has no children. A filter matching only `byteField=10` issues 3:
+ /// the same unavoidable top-level call, then only `byteField=10`'s two
+ /// levels are ever listed — `byteField=20`/`byteField=30` are pruned
+ /// before incurring any `list` call under them.
+ #[tokio::test]
+ async fn partition_filter_pruning_reduces_storage_list_calls() {
+ use crate::storage::counting::CountingObjectStore;
+ use object_store::local::LocalFileSystem;
+
+ let base_url = SampleTable::V6ComplexkeygenHivestyle.url_to_cow();
+ let hudi_table = Table::new(base_url.path()).await.unwrap();
+ let hudi_configs = hudi_table.hudi_configs.clone();
+ let partition_schema = hudi_table.get_partition_schema().await.unwrap();
+
+ let list_calls_for = |pruner: PartitionPruner| {
+ let base_url = base_url.clone();
+ let hudi_configs = hudi_configs.clone();
+ async move {
+ let (object_store, counts) =
+ CountingObjectStore::new(Arc::new(LocalFileSystem::new()));
+ let storage =
+ Storage::new_with_object_store(base_url, object_store, hudi_configs);
+ let lister = FileLister::new(storage.hudi_configs.clone(), storage, pruner);
+ let partition_paths = lister.list_relevant_partition_paths().await.unwrap();
+ (partition_paths.len(), counts.lists())
+ }
+ };
+
+ let (unfiltered_partitions, unfiltered_lists) =
+ list_calls_for(PartitionPruner::empty()).await;
+ assert_eq!(unfiltered_partitions, 3);
+ assert_eq!(unfiltered_lists, 7);
+
+ let filter_eq_10 = crate::expr::filter::Filter::try_from(("byteField", "=", "10")).unwrap();
+ let selective_pruner =
+ PartitionPruner::new(&[filter_eq_10], &partition_schema, &hudi_configs).unwrap();
+ let (filtered_partitions, filtered_lists) = list_calls_for(selective_pruner).await;
+ assert_eq!(filtered_partitions, 1);
+ assert_eq!(filtered_lists, 3);
+
+ assert!(
Review Comment:
fixed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(core): Prune Partition-Directory descent by filters during storage listing [hudi-rs]
Posted by "hakunamatata-sb (via GitHub)" <gi...@apache.org>.
hakunamatata-sb commented on PR #784:
URL: https://github.com/apache/hudi-rs/pull/784#issuecomment-5695959507
@codope @xushiyan requesting re-review.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(core): Prune Partition-Directory descent by filters during storage listing [hudi-rs]
Posted by "hakunamatata-sb (via GitHub)" <gi...@apache.org>.
hakunamatata-sb commented on code in PR #784:
URL: https://github.com/apache/hudi-rs/pull/784#discussion_r4024063731
##########
crates/core/src/table/partition.rs:
##########
@@ -174,6 +174,71 @@ impl PartitionPruner {
})
}
+ /// Returns `true` if a partition directory prefix should be descended into.
+ ///
+ /// Unlike `should_include`, `partial_path` may resolve fewer segments than
+ /// the schema has fields (we're mid-descent, not at a leaf yet). Any segment
+ /// this can't safely reason about — not enough schema fields to compare
+ /// against, a single opaque path field (e.g. under a timestamp-based key
+ /// generator, where a segment carries no independently meaningful value),
+ /// a hive-style segment that doesn't parse as `key=value`, or a cast/compare
+ /// error — is treated as unconstrained, never as a reason to reject. Only a
+ /// segment that positively fails an already-resolved filter returns `false`.
+ pub fn should_include_prefix(&self, partial_path: &str) -> bool {
Review Comment:
fixed the single partition issue now that as well get pruned, added a safety check for MetaField:PartitionPath in that case when we would have multiple segments for the single partitions.
Along with hive-style partition and is_url_encoded to be always ensured.
The bug related to encoding and splits have been reordered, have done so in the the split_segments and reused that parse_segments so they don't diverge.
Thanks for pointing this out.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(core): Prune Partition-Directory descent by filters during storage listing [hudi-rs]
Posted by "hakunamatata-sb (via GitHub)" <gi...@apache.org>.
hakunamatata-sb commented on code in PR #784:
URL: https://github.com/apache/hudi-rs/pull/784#discussion_r4024082488
##########
crates/core/src/table/partition.rs:
##########
@@ -174,6 +174,71 @@ impl PartitionPruner {
})
}
+ /// Returns `true` if a partition directory prefix should be descended into.
+ ///
+ /// Unlike `should_include`, `partial_path` may resolve fewer segments than
+ /// the schema has fields (we're mid-descent, not at a leaf yet). Any segment
+ /// this can't safely reason about — not enough schema fields to compare
+ /// against, a single opaque path field (e.g. under a timestamp-based key
+ /// generator, where a segment carries no independently meaningful value),
+ /// a hive-style segment that doesn't parse as `key=value`, or a cast/compare
+ /// error — is treated as unconstrained, never as a reason to reject. Only a
+ /// segment that positively fails an already-resolved filter returns `false`.
+ pub fn should_include_prefix(&self, partial_path: &str) -> bool {
+ if self.and_filters.is_empty() || self.schema.fields().len() <= 1 {
Review Comment:
fixed.
##########
crates/core/src/table/partition.rs:
##########
@@ -174,6 +174,71 @@ impl PartitionPruner {
})
}
+ /// Returns `true` if a partition directory prefix should be descended into.
+ ///
+ /// Unlike `should_include`, `partial_path` may resolve fewer segments than
+ /// the schema has fields (we're mid-descent, not at a leaf yet). Any segment
+ /// this can't safely reason about — not enough schema fields to compare
+ /// against, a single opaque path field (e.g. under a timestamp-based key
+ /// generator, where a segment carries no independently meaningful value),
+ /// a hive-style segment that doesn't parse as `key=value`, or a cast/compare
+ /// error — is treated as unconstrained, never as a reason to reject. Only a
+ /// segment that positively fails an already-resolved filter returns `false`.
+ pub fn should_include_prefix(&self, partial_path: &str) -> bool {
+ if self.and_filters.is_empty() || self.schema.fields().len() <= 1 {
+ return true;
+ }
+
+ let decoded;
Review Comment:
fixed
##########
crates/core/src/table/partition.rs:
##########
@@ -401,6 +466,113 @@ mod tests {
assert!(!pruner.should_include("date=2023-02-01/category=B/count=10"));
}
+ #[test]
+ fn test_partition_pruner_should_include_prefix() {
+ let schema = create_test_schema();
+ let configs = create_hudi_configs(true, false);
+
+ let filter_gt_date = Filter::try_from(("date", ">", "2023-01-01")).unwrap();
+ let filter_eq_a = Filter::try_from(("category", "=", "A")).unwrap();
+ let filter_lte_100 = Filter::try_from(("count", "<=", "100")).unwrap();
+
+ let pruner = PartitionPruner::new(
+ &[filter_gt_date, filter_eq_a, filter_lte_100],
+ &schema,
+ &configs,
+ )
+ .unwrap();
+
+ // A resolved segment that already violates its filter is rejected
+ // without needing to resolve the rest of the path.
+ assert!(!pruner.should_include_prefix("date=2022-12-31"));
+ assert!(!pruner.should_include_prefix("date=2023-02-01/category=B"));
+
+ // A resolved segment that satisfies its filter, with later fields not
+ // yet resolved, is not rejected.
+ assert!(pruner.should_include_prefix("date=2023-02-01"));
+ assert!(pruner.should_include_prefix("date=2023-02-01/category=A"));
+ assert!(pruner.should_include_prefix("date=2023-02-01/category=A/count=10"));
+ }
+
+ #[test]
+ fn test_partition_pruner_should_include_prefix_no_filters() {
+ let pruner = PartitionPruner::empty();
+ assert!(pruner.should_include_prefix("date=2022-12-31"));
+ assert!(pruner.should_include_prefix(""));
+ }
+
+ #[test]
+ fn test_partition_pruner_should_include_prefix_malformed_segment_fails_open() {
+ let schema = create_test_schema();
+ let configs = create_hudi_configs(true, false);
+ let filter_eq_a = Filter::try_from(("category", "=", "A")).unwrap();
+ let pruner = PartitionPruner::new(&[filter_eq_a], &schema, &configs).unwrap();
+
+ // A segment that doesn't parse as `key=value` under hive-style
+ // partitioning can't be safely compared, so it must not be rejected.
+ assert!(pruner.should_include_prefix("not-a-kv-pair"));
+ }
+
+ #[test]
+ fn test_partition_pruner_should_include_prefix_non_hive_style() {
+ let schema = create_test_schema();
+ let configs = create_hudi_configs(false, false);
+ let filter_gt_date = Filter::try_from(("date", ">", "2023-01-01")).unwrap();
+ let pruner = PartitionPruner::new(&[filter_gt_date], &schema, &configs).unwrap();
+
+ assert!(!pruner.should_include_prefix("2022-12-31"));
+ assert!(pruner.should_include_prefix("2023-02-01"));
+ }
+
+ #[test]
+ fn test_partition_pruner_should_include_prefix_url_encoded() {
+ let schema = create_test_schema();
+ let configs = create_hudi_configs(true, true);
+ let filter_eq_a = Filter::try_from(("category", "=", "A")).unwrap();
+ let pruner = PartitionPruner::new(&[filter_eq_a], &schema, &configs).unwrap();
+
+ assert!(!pruner.should_include_prefix("date%3D2023-02-01%2Fcategory%3DB"));
Review Comment:
fixed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(core): Prune Partition-Directory descent by filters during storage listing [hudi-rs]
Posted by "yihua (via GitHub)" <gi...@apache.org>.
yihua commented on code in PR #784:
URL: https://github.com/apache/hudi-rs/pull/784#discussion_r4396347052
##########
crates/core/src/table/partition.rs:
##########
@@ -174,6 +174,83 @@ impl PartitionPruner {
})
}
+ /// Returns `true` if a partition directory prefix should be descended into.
+ ///
+ /// Unlike `should_include`, `partial_path` may resolve fewer segments than
+ /// the schema has fields (we're mid-descent, not at a leaf yet). Any segment
+ /// this can't safely reason about — not enough schema fields to compare
+ /// against, an opaque single-field `_hoodie_partition_path` schema (e.g.
+ /// under a timestamp-based key generator, where that one field's value
+ /// spans multiple physical path segments, so no individual segment carries
+ /// independently meaningful value), a hive-style segment that doesn't parse
+ /// as `key=value`, or a cast/compare error — is treated as unconstrained,
+ /// never as a reason to reject. Only a segment that positively fails an
+ /// already-resolved filter returns `false`.
+ ///
+ /// `is_hive_style && is_url_encoded` is required unconditionally, matching
+ /// Java's `FileSystemBackedTableMetadata` (line 157) — regardless of field
+ /// count. `is_hive_style` is needed because without `key=value` labels
+ /// there's no independent way to verify a split segment lines up with its
+ /// schema field at all. `is_url_encoded` is needed even for a single
+ /// field: without it, a value containing a literal `/` splits across an
+ /// extra physical directory level (e.g. `region=b/c` on disk for a value
+ /// `"b/c"`), and a mid-descent prefix that has only resolved the first
+ /// level (`region=b`) has no way to tell that genuinely-short value apart
+ /// from one truncated by such a stray `/` — the `parts.len()` check below
+ /// can't catch it either, since at that depth there simply aren't more
+ /// parts yet to exceed the field count. Comparing the truncated value
+ /// against a filter for the full value would then wrongly reject a prefix
+ /// that should have been descended into.
+ pub fn should_include_prefix(&self, partial_path: &str) -> bool {
+ // A single-field schema is only unsafe to reason about per-segment when
+ // that field is the opaque `_hoodie_partition_path` metafield, whose one
+ // value spans multiple physical segments. A genuine single partition
+ // field (e.g. `SimpleKeyGenerator`) has no such gap: its one segment
+ // *is* its full value when `is_hive_style && is_url_encoded` hold, so
+ // it can be compared like any other field.
+ let is_opaque_single_field = self.schema.fields().len() == 1
+ && self.schema.field(0).name() == MetaField::PartitionPath.as_ref();
+ if self.and_filters.is_empty() || is_opaque_single_field {
+ return true;
+ }
+ if !(self.is_hive_style && self.is_url_encoded) {
Review Comment:
non-blocking: with the gate as written, a hive-style table without url-encoding (Spark SQL's default) gets no descent pruning, which is the case #779 describes, and `partition_filter_pruning_fails_open_without_url_encoding_single_field` pins that at 4 calls either way. The slash ambiguity only exists for string-typed columns, so would it be safe to evaluate a segment whenever every partition field up to and including it has a non-string type? Fine as a follow-up if you'd rather keep this PR to the encoded case.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org