Re: [PR] fix(spark): avoid full partition listing in incremental reads [hudi]
yihua merged PR #19898: URL: https://github.com/apache/hudi/pull/19898 -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
Re: [PR] fix(spark): avoid full partition listing in incremental reads [hudi]
yihua commented on PR #19898: URL: https://github.com/apache/hudi/pull/19898#issuecomment-6028425765 > One more ask: a guard test for the listing itself. `TestIncrementalReadWithPartitionFilter` asserts row counts only, so the full listing could come back without any test failing. I pushed a commit to enhance the test based on the suggestion. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
Re: [PR] fix(spark): avoid full partition listing in incremental reads [hudi]
prashantwason commented on PR #19898: URL: https://github.com/apache/hudi/pull/19898#issuecomment-6024201953 Thanks @yihua, I traced it against `BaseHoodieTableFileIndex.listPartitionPaths` and your analysis is right. The "always" in the description was wrong. - **Latency claim:** the "minutes of latency" number was not measured in a specific scenario, so I've removed it. The description now names the two cases where `listFileSplits()` lists the whole table: (1) the start is `earliest` or older than the active timeline, and (2) a partition predicate with no bound leading prefix on a hive-style, URL-encoded table. It also says the gain is small when the start is inside the active timeline. The prune-rule skip is described as saving redundant work in every case, and as a full-table cost only in those two cases. - **Scaladoc:** in 7863548, `listMatchingPartitionPaths` now spells out when it lists the table, using the cases above. It points callers that already hold candidate partitions to `filterPartitionPaths`. I also reworded its "listing full table" log line, since the no-predicate path doesn't always do that. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
Re: [PR] fix(spark): avoid full partition listing in incremental reads [hudi]
yihua commented on PR #19898: URL: https://github.com/apache/hudi/pull/19898#issuecomment-6024342396 Thanks for the description and scaladoc updates, both look right. One more ask: a guard test for the listing itself. `TestIncrementalReadWithPartitionFilter` asserts row counts only, so the full listing could come back without any test failing. I ran a probe on master with and without this diff (4 partitions, one commit each, COW and MOR). With a start before the first commit and the metadata table disabled for the read, master lists the table root twice and every partition directory once. With the diff there is no `listStatus` outside `.hoodie`, and the row counts match master in every case. That gives a simple guard, which could go in the same test class: - After the writes, `RecordingLocalFileSystem.register(spark.sparkContext.hadoopConfiguration)` and `reset()`, with `unregister` in teardown. The class is in the `hudi-hadoop-common` tests since #20080, so this needs a rebase. - Run the incremental read with `hoodie.metadata.enable=false` and a start of `000` (as the test already uses) or `earliest` plus an end commit. That is the case where master lists the whole table. - Assert that an `open` of a data file was recorded, so the recorder is known to be live, then assert there is no `listStatus` call outside `.hoodie`. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
Re: [PR] fix(spark): avoid full partition listing in incremental reads [hudi]
yihua commented on PR #19898: URL: https://github.com/apache/hudi/pull/19898#issuecomment-6023717374 I traced when `listMatchingPartitionPaths` actually enumerates the table, since the description says a plain incremental pull always lists every partition. From reading master (not measured), the full listing is narrower than that. **No partition predicate** (`getAllQueryPartitionPaths` -> `BaseHoodieTableFileIndex.listPartitionPaths`): - Incremental query whose start is not `earliest` and is inside the active timeline: partitions come from the commit metadata of the instants in range (`TimelineUtils.getWrittenPartitions`, added in #10098). No table listing. The relation's `fileIndex` is built from `optParams`, so it takes this branch. - Start is `earliest` or older than the active timeline: every partition is listed. **With partition predicates** (prefix analysis is on by default): - Equality on all partition columns: one `exists` call, no listing. - Equality on the leading partition columns: listing under that prefix only. - No usable prefix: hive-style, URL-encoded tables call `getPartitionPathWithPathPrefixUsingFilterExpression` from the table root, which has no incremental shortcut. Other tables fall back to `getAllQueryPartitionPaths`, so the two cases above apply. So for `listFileSplits()`, the full-table listing this PR removes happens when: 1. the start is `earliest` or older than the active timeline, or 2. there is a partition predicate with no bound leading prefix on a hive-style, URL-encoded table. When the start is inside the active timeline and there is no such predicate, master already lists only the partitions written in the range, so the gain from the `listFileSplits()` change is small there. The prune rule goes through the same partition listing and then also loads the file slices of those partitions, so skipping it saves redundant work in every case, but it is only a full-table cost in the two cases above. Two asks: - @prashantwason which scenario were the "minutes of latency" measured in? Could the description say which cases list the full table instead of "always"? - Since this PR splits `listMatchingPartitionPaths` and adds `filterPartitionPaths` next to it, could the scaladoc of `listMatchingPartitionPaths` state when it lists the table (the cases above) and point callers that already hold candidate paths to `filterPartitionPaths`? Today it only says "Prune the partition by the filter". -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
Re: [PR] fix(spark): avoid full partition listing in incremental reads [hudi]
hudi-bot commented on PR #19898: URL: https://github.com/apache/hudi/pull/19898#issuecomment-6000239612 ## CI report: * 4d6368179f9102b74dd1416ebf5a184e0f13b038 Azure: [SUCCESS](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17452) Bot commands @hudi-bot supports the following commands: - `@hudi-bot run azure` re-run the last Azure build -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
Re: [PR] fix(spark): avoid full partition listing in incremental reads [hudi]
prashantwason commented on PR #19898: URL: https://github.com/apache/hudi/pull/19898#issuecomment-5998198145 Thanks @yihua for reproducing this, and sorry about the missing import — the branch was missing `import org.apache.hudi.core.read.BaseHoodieTableFileIndex`. Addressed in 4d63681: - Fixed the build (missing import). - Partition filters are evaluated again, against `modifiedPartitions` only: I extracted the predicate evaluation from `listMatchingPartitionPaths` into a shared helper and added `SparkHoodieTableFileIndex.filterPartitionPaths(paths, predicates)`, used by `listFileSplits` in V1 and V2. This keeps the O(modified partitions) listing without changing results. - `filterFileSlices` override now keeps the base contract (returns the `PartitionPath`, keeps `isPartitionPruneOnly`). The index also overrides `hasPredicatesPushedDown` instead of setting the flag in the constructor, since `refresh()` resets it. - `sizeInBytes`: handled by the companion #19912 (they should land together), noted in the description. - Added `TestIncrementalReadWithPartitionFilter`: a range touching two partitions, filtering on each, for COW and MOR. - Moved the description into the PR template so `validate-pr` passes. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
Re: [PR] fix(spark): avoid full partition listing in incremental reads [hudi]
hudi-bot commented on PR #19898: URL: https://github.com/apache/hudi/pull/19898#issuecomment-5998322401 ## CI report: * 00cbbaa6622c56b3c8ce892c107d6be34260a0e4 Azure: [FAILURE](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=16997) * 4d6368179f9102b74dd1416ebf5a184e0f13b038 UNKNOWN Bot commands @hudi-bot supports the following commands: - `@hudi-bot run azure` re-run the last Azure build -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
Re: [PR] fix(spark): avoid full partition listing in incremental reads [hudi]
hudi-bot commented on PR #19898: URL: https://github.com/apache/hudi/pull/19898#issuecomment-5998448113 ## CI report: * 00cbbaa6622c56b3c8ce892c107d6be34260a0e4 Azure: [FAILURE](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=16997) * 4d6368179f9102b74dd1416ebf5a184e0f13b038 Azure: [PENDING](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17452) Bot commands @hudi-bot supports the following commands: - `@hudi-bot run azure` re-run the last Azure build -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
Re: [PR] fix(spark): avoid full partition listing in incremental reads [hudi]
yihua commented on code in PR #19898:
URL: https://github.com/apache/hudi/pull/19898#discussion_r4077686634
##
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/MergeOnReadIncrementalRelationV2.scala:
##
@@ -124,11 +124,9 @@ case class MergeOnReadIncrementalRelationV2(override val
sqlContext: SQLContext,
val fsView = new HoodieTableFileSystemView(metaClient, timeline,
affectedFilesInCommits)
val modifiedPartitions = getWritePartitionPaths(commitsMetadata)
-
fileIndex.listMatchingPartitionPaths(HoodieFileIndex.convertFilterForTimestampKeyGenerator(metaClient,
partitionFilters))
- .map(p => p.getPath).filter(p => modifiedPartitions.contains(p))
- .flatMap { relativePartitionPath =>
-fsView.getLatestMergedFileSlicesBeforeOrOn(relativePartitionPath,
latestCommit).iterator().asScala
- }
+modifiedPartitions.asScala.flatMap { relativePartitionPath =>
Review Comment:
Confirmed this one by running it: on master an incremental read of two
commits (one per partition) with `.where("partition = '2022-01-02'")` returns
30 rows, on this branch it returns all 50 for both COW and MOR, and the plan
shows the predicate only under `PartitionFilters` with no post-scan `Filter`,
so Spark is trusting the index. Could we keep the predicate evaluation but
apply it to `modifiedPartitions` only (convert them to `PartitionPath`s and
reuse the same pruning that `listMatchingPartitionPaths` does), rather than
dropping it? That keeps the O(modified) listing this PR is after without
changing results.
##
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/HoodieIncrementalFileIndex.scala:
##
@@ -43,6 +43,25 @@ class HoodieIncrementalFileIndex(override val spark:
SparkSession,
spark, metaClient, schemaSpec, options, fileStatusCache, includeLogFiles,
shouldEmbedFileSlices = true
) with FileIndex {
+ // Skip the Spark optimizer's partition pruning rule (e.g.
Spark33HoodiePruneFileSourcePartitions)
+ // which would trigger a full-table partition listing via the base class.
The incremental file
+ // index already selects only modified file groups via listFileSplits().
+ hasPushedDownPartitionPredicates = true
+
+ override def filterFileSlices(dataFilters: Seq[Expression],
partitionFilters: Seq[Expression], isPartitionPruned: Boolean = false)
+ : Seq[(Option[BaseHoodieTableFileIndex.PartitionPath], Seq[FileSlice])] = {
Review Comment:
This does not compile against master: `BaseHoodieTableFileIndex` is not
imported here (it lives in `org.apache.hudi.core.read`), which is what all the
CI jobs are failing on at lines 52 and 58. Adding `import
org.apache.hudi.core.read.BaseHoodieTableFileIndex` fixes the build locally.
##
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/MergeOnReadIncrementalRelationV2.scala:
##
@@ -124,11 +124,9 @@ case class MergeOnReadIncrementalRelationV2(override val
sqlContext: SQLContext,
val fsView = new HoodieTableFileSystemView(metaClient, timeline,
affectedFilesInCommits)
val modifiedPartitions = getWritePartitionPaths(commitsMetadata)
-
fileIndex.listMatchingPartitionPaths(HoodieFileIndex.convertFilterForTimestampKeyGenerator(metaClient,
partitionFilters))
- .map(p => p.getPath).filter(p => modifiedPartitions.contains(p))
- .flatMap { relativePartitionPath =>
-fsView.getLatestMergedFileSlicesBeforeOrOn(relativePartitionPath,
latestCommit).iterator().asScala
- }
+modifiedPartitions.asScala.flatMap { relativePartitionPath =>
Review Comment:
non-blocking: the existing partition-filter checks in
TestCOWDataSource/TestMORDataSource only filter on a partition that is outside
the incremental range, so they pass either way. It would be worth adding a case
where the range touches two partitions and the query filters on one of them,
for both COW and MOR, so this path stays covered.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
Re: [PR] fix(spark): avoid full partition listing in incremental reads [hudi]
yihua commented on code in PR #19898:
URL: https://github.com/apache/hudi/pull/19898#discussion_r4077719970
##
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/MergeOnReadIncrementalRelationV2.scala:
##
@@ -124,11 +124,9 @@ case class MergeOnReadIncrementalRelationV2(override val
sqlContext: SQLContext,
val fsView = new HoodieTableFileSystemView(metaClient, timeline,
affectedFilesInCommits)
val modifiedPartitions = getWritePartitionPaths(commitsMetadata)
-
fileIndex.listMatchingPartitionPaths(HoodieFileIndex.convertFilterForTimestampKeyGenerator(metaClient,
partitionFilters))
- .map(p => p.getPath).filter(p => modifiedPartitions.contains(p))
- .flatMap { relativePartitionPath =>
-fsView.getLatestMergedFileSlicesBeforeOrOn(relativePartitionPath,
latestCommit).iterator().asScala
- }
+modifiedPartitions.asScala.flatMap { relativePartitionPath =>
Review Comment:
@prashantwason could you take a look? Does the PR have all the changes?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
Re: [PR] fix(spark): avoid full partition listing in incremental reads [hudi]
hudi-bot commented on PR #19898: URL: https://github.com/apache/hudi/pull/19898#issuecomment-5626117880 ## CI report: * 00cbbaa6622c56b3c8ce892c107d6be34260a0e4 UNKNOWN Bot commands @hudi-bot supports the following commands: - `@hudi-bot run azure` re-run the last Azure build -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
Re: [PR] fix(spark): avoid full partition listing in incremental reads [hudi]
hudi-bot commented on PR #19898: URL: https://github.com/apache/hudi/pull/19898#issuecomment-5626179340 ## CI report: * 00cbbaa6622c56b3c8ce892c107d6be34260a0e4 Azure: [FAILURE](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=16997) Bot commands @hudi-bot supports the following commands: - `@hudi-bot run azure` re-run the last Azure build -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
Re: [PR] fix(spark): avoid full partition listing in incremental reads [hudi]
codecov-commenter commented on PR #19898: URL: https://github.com/apache/hudi/pull/19898#issuecomment-5626049787 ## [Codecov](https://app.codecov.io/gh/apache/hudi/pull/19898?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report :white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 80.20%. Comparing base ([`648996f`](https://app.codecov.io/gh/apache/hudi/commit/648996f002c3c9e24a1e2bf53f97fe03e8bc4c81?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`00cbbaa`](https://app.codecov.io/gh/apache/hudi/commit/00cbbaa6622c56b3c8ce892c107d6be34260a0e4?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)). :warning: Report is 1 commits behind head on master. Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #19898 +/- ## - Coverage 80.20% 80.20% -0.01% + Complexity3466134657 -4 Files 2546 2546 Lines142452 142444 -8 Branches 1733017330 - Hits 114260 114252 -8 Misses2028120281 Partials 7911 7911 ``` | [Components](https://app.codecov.io/gh/apache/hudi/pull/19898/components?src=pr&el=components&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | | |---|---|---| | [hudi-common](https://app.codecov.io/gh/apache/hudi/pull/19898/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `83.84% <ø> (ø)` | | | [hudi-client](https://app.codecov.io/gh/apache/hudi/pull/19898/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `83.28% <ø> (ø)` | | | [hudi-flink](https://app.codecov.io/gh/apache/hudi/pull/19898/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `85.57% <ø> (ø)` | | | [hudi-spark-datasource](https://app.codecov.io/gh/apache/hudi/pull/19898/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `73.27% <ø> (-0.01%)` | :arrow_down: | | [hudi-utilities](https://app.codecov.io/gh/apache/hudi/pull/19898/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `78.17% <ø> (ø)` | | | [hudi-cli](https://app.codecov.io/gh/apache/hudi/pull/19898/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `69.99% <ø> (ø)` | | | [hudi-hadoop](https://app.codecov.io/gh/apache/hudi/pull/19898/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `70.81% <ø> (ø)` | | | [hudi-sync](https://app.codecov.io/gh/apache/hudi/pull/19898/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `75.99% <ø> (ø)` | | | [hudi-io](https://app.codecov.io/gh/apache/hudi/pull/19898/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `81.61% <ø> (ø)` | | | [hudi-timeline-service](https://app.codecov.io/gh/apache/hudi/pull/19898/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `83.34% <ø> (ø)` | | | [hudi-cloud](https://app.codecov.io/gh/apache/hudi/pull/19898/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `80.99% <ø> (ø)` | | | [hudi-kafka-connect](https://app.codecov.io/gh/apache/hudi/pull/19898/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `53.20% <ø> (ø)` | | | [Flag](https://app.codecov.io/gh/apache/hudi/pull/19898/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | | |---|---|---| |
Re: [PR] fix(spark): avoid full partition listing in incremental reads [hudi]
hudi-agent commented on code in PR #19898:
URL: https://github.com/apache/hudi/pull/19898#discussion_r3983854441
##
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/HoodieIncrementalFileIndex.scala:
##
@@ -43,6 +43,25 @@ class HoodieIncrementalFileIndex(override val spark:
SparkSession,
spark, metaClient, schemaSpec, options, fileStatusCache, includeLogFiles,
shouldEmbedFileSlices = true
) with FileIndex {
+ // Skip the Spark optimizer's partition pruning rule (e.g.
Spark33HoodiePruneFileSourcePartitions)
+ // which would trigger a full-table partition listing via the base class.
The incremental file
+ // index already selects only modified file groups via listFileSplits().
+ hasPushedDownPartitionPredicates = true
Review Comment:
🤖 Setting this in the constructor means
`Spark3xHoodiePruneFileSourcePartitions` never runs for this index, so
`sizeInBytes` is now computed from an empty `cachedAllInputFileSlices`
(`getTotalCachedFilesSize` == 0) at planning time — with the Hudi extension
enabled that reports a 0-byte relation, which can make the optimizer broadcast
an arbitrarily large incremental scan. Have you checked what stats the planner
sees for an incremental read after this change?
⚠️ AI-generated; verify before applying. React 👍/👎 to flag
quality.
##
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/MergeOnReadIncrementalRelationV2.scala:
##
@@ -124,11 +124,9 @@ case class MergeOnReadIncrementalRelationV2(override val
sqlContext: SQLContext,
val fsView = new HoodieTableFileSystemView(metaClient, timeline,
affectedFilesInCommits)
val modifiedPartitions = getWritePartitionPaths(commitsMetadata)
-
fileIndex.listMatchingPartitionPaths(HoodieFileIndex.convertFilterForTimestampKeyGenerator(metaClient,
partitionFilters))
- .map(p => p.getPath).filter(p => modifiedPartitions.contains(p))
- .flatMap { relativePartitionPath =>
-fsView.getLatestMergedFileSlicesBeforeOrOn(relativePartitionPath,
latestCommit).iterator().asScala
- }
+modifiedPartitions.asScala.flatMap { relativePartitionPath =>
Review Comment:
🤖 Dropping `listMatchingPartitionPaths(...)` here also drops the
partition-predicate filtering it was doing (the old code intersected the pruned
partitions with `modifiedPartitions`), so `listFileSplits` now returns every
modified partition regardless of `partitionFilters`. Since
`HoodieIncrementalFileIndex.partitionSchema` is non-empty for a partitioned
table, Spark's `FileSourceStrategy` removes partition-only predicates from
`afterScanFilters` and trusts the index to prune — so an incremental read like
`.load().where("partition_col = 'x'")` could return rows from other partitions.
Would it work to keep the predicate evaluation but apply it only to
`modifiedPartitions` (no full listing) rather than removing it? @yihua could
you sanity-check this one?
⚠️ AI-generated; verify before applying. React 👍/👎 to flag
quality.
##
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/HoodieIncrementalFileIndex.scala:
##
@@ -43,6 +43,25 @@ class HoodieIncrementalFileIndex(override val spark:
SparkSession,
spark, metaClient, schemaSpec, options, fileStatusCache, includeLogFiles,
shouldEmbedFileSlices = true
) with FileIndex {
+ // Skip the Spark optimizer's partition pruning rule (e.g.
Spark33HoodiePruneFileSourcePartitions)
+ // which would trigger a full-table partition listing via the base class.
The incremental file
+ // index already selects only modified file groups via listFileSplits().
+ hasPushedDownPartitionPredicates = true
+
+ override def filterFileSlices(dataFilters: Seq[Expression],
partitionFilters: Seq[Expression], isPartitionPruned: Boolean = false)
Review Comment:
🤖 This override returns `Option.empty` for the partition path, but the
base-class contract treats it as present (`HoodieFileIndex.listFiles` does
`partitionOpt.get.getValues`), so any caller other than the prune rules would
hit a `NoSuchElementException`. It also silently ignores the third parameter
(renamed here from `isPartitionPruneOnly` to `isPartitionPruned`), meaning the
"safety net" does a full `listFileSplits` during optimization. Would it be
cleaner to preserve the `PartitionPath` from the grouping, or keep the base
name/semantics of the flag?
⚠️ AI-generated; verify before applying. React 👍/👎 to flag
quality.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
[PR] fix(spark): avoid full partition listing in incremental reads [hudi]
prashantwason opened a new pull request, #19898: URL: https://github.com/apache/hudi/pull/19898 HoodieIncrementalFileIndex delegates file listing to MergeOnReadIncrementalRelation.listFileSplits(), which already determines the exact set of modified partitions from commit metadata. However, two code paths still trigger an O(all-partitions) listing that is redundant and expensive for large tables: 1. listFileSplits() in both V1 and V2 calls fileIndex.listMatchingPartitionPaths() which, without partition-filter pushdown (e.g. a plain incremental pull with no predicate on the partition column), falls through to listing every partition via the metadata table or catalog before the modifiedPartitions filter is even applied. On tables with tens of thousands of partitions this adds minutes of latency to what should be a sub-second file listing. 2. Spark's partition pruning optimizer rule (Spark33HoodiePruneFileSourcePartitions) invokes HoodieFileIndex.filterFileSlices() which calls ensurePreloadedPartitions(), triggering the same full-table partition enumeration. This is redundant for incremental reads that already select only modified file groups. Fix: - Replace listMatchingPartitionPaths() in listFileSplits() with direct iteration over modifiedPartitions, matching the pattern already used by collectFileSplits() in both V1 and V2. - Set hasPushedDownPartitionPredicates=true in the HoodieIncrementalFileIndex constructor so the optimizer rule skips this file index entirely. - Override filterFileSlices() as a safety net: if anything still calls it, delegate to listFileSplits() instead of the base class which would enumerate all partitions. ### Describe the issue this Pull Request addresses ### Summary and Changelog ### Impact ### Risk Level ### Documentation Update ### Contributor's checklist - [ ] Read through [contributor's guide](https://hudi.apache.org/contribute/how-to-contribute) - [ ] Enough context is provided in the sections above - [ ] Adequate tests were added if applicable -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
