You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by "yihua (via GitHub)" <gi...@apache.org> on 2026/09/28 02:21:12 UTC
[PR] fix(spark): group file slices by partition in the file index listing [hudi]
yihua opened a new pull request, #20115:
URL: https://github.com/apache/hudi/pull/20115
### Describe the issue this Pull Request addresses
closes #20114
part of #20064
Since HUDI-9451 (#13351) `HoodieFileIndex.prepareFileSlices` returns one `PartitionDirectory` per file slice, on the snapshot and incremental paths and in both `shouldEmbedFileSlices` modes. HUDI-9451 did that so a task is shipped only the slice it reads instead of the whole partition's slice mapping, which for partitions with tens of thousands of slices reached 100 MB+ per task. The mapping is only attached to slices with log files or a bootstrap base, though. Base-file-only slices, which is every slice of a copy-on-write table, carry plain partition values, so splitting them per slice gains nothing and changes what every consumer of `FileIndex.listFiles` sees: `FileSourceScanExec` reports the slice count as `numPartitions`, dynamic partition pruning walks one entry per slice, and listeners or stats consumers that enumerate the relation's partitions get one entry per slice. On a table with 2,334 partitions and 15K slices a query listener that logs input partitions wrote 15K entri
es per query, and over a long ETL job a 21 MB line that slowed the driver's task scheduling.
### Summary and Changelog
`PartitionDirectoryConverter.convertFileSlicesToPartitionDirectories` takes the slices of one partition and returns one directory with plain partition values holding the delegate files of all base-file-only slices, plus one directory per slice that has log files or a bootstrap base, each with a single-entry `HoodiePartitionFileSliceMapping` as before. `prepareFileSlices` takes the slices grouped by partition values, which is how both `listFiles` callers already produce them, and the non-embedded branch puts all files of a partition into one directory again. Non-partitioned tables get the same grouping under their single empty partition value.
Split planning is unchanged: Spark flattens the directories to files, sorts them by length and bin-packs them, and the file order is preserved for base-file-only slices. On a mixed partition the base-file-only directory comes before the per-slice directories, so files of equal length may swap places between tasks, with the same task count and task sizes.
Tests: `TestPartitionDirectoryConverter.testConvertFileSlicesToPartitionDirectories` checks the directory shapes for a partition mixing base-file-only, base plus log, log-only and bootstrap slices. `TestHoodieFileIndex.testListFilesGroupsFileSlicesByPartition` writes 3 file groups into each of 5 partitions of a COW and a MOR table and checks that `listFiles` returns 5 directories, that after an update the two file groups with log files get their own directories, and that the file partitions Spark plans match those planned from one directory per slice. Without the fix it fails with `expected: <5> but was: <15>`.
### Impact
`listFiles` returns one directory per partition for copy-on-write tables and for the base-file-only slices of merge-on-read tables. `numPartitions` in the scan metrics reports partitions again. Fewer driver objects per scan.
### Risk Level
low. Slices that need the mapping keep exactly the per-slice shape of HUDI-9451, and the executor read path is untouched.
### Documentation Update
none
### 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: commits-unsubscribe@hudi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(spark): group file slices by partition in the file index listing [hudi]
Posted by "hudi-bot (via GitHub)" <gi...@apache.org>.
hudi-bot commented on PR #20115:
URL: https://github.com/apache/hudi/pull/20115#issuecomment-5863369892
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "2d23bca880c9bb76bd8de2ebde9ef2bfbd8b65f3",
"status" : "SUCCESS",
"url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17322",
"triggerID" : "2d23bca880c9bb76bd8de2ebde9ef2bfbd8b65f3",
"triggerType" : "PUSH"
}, {
"hash" : "eaf4e8519970e86d2422fc613557d87ae45d17cb",
"status" : "UNKNOWN",
"url" : "TBD",
"triggerID" : "eaf4e8519970e86d2422fc613557d87ae45d17cb",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* 2d23bca880c9bb76bd8de2ebde9ef2bfbd8b65f3 Azure: [SUCCESS](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17322)
* eaf4e8519970e86d2422fc613557d87ae45d17cb UNKNOWN
<details>
<summary>Bot commands</summary>
@hudi-bot supports the following commands:
- `@hudi-bot run azure` re-run the last Azure build
</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(spark): group file slices by partition in the file index listing [hudi]
Posted by "hudi-bot (via GitHub)" <gi...@apache.org>.
hudi-bot commented on PR #20115:
URL: https://github.com/apache/hudi/pull/20115#issuecomment-5863947251
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "2d23bca880c9bb76bd8de2ebde9ef2bfbd8b65f3",
"status" : "DELETED",
"url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17322",
"triggerID" : "2d23bca880c9bb76bd8de2ebde9ef2bfbd8b65f3",
"triggerType" : "PUSH"
}, {
"hash" : "eaf4e8519970e86d2422fc613557d87ae45d17cb",
"status" : "FAILURE",
"url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17326",
"triggerID" : "eaf4e8519970e86d2422fc613557d87ae45d17cb",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* eaf4e8519970e86d2422fc613557d87ae45d17cb Azure: [FAILURE](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17326)
<details>
<summary>Bot commands</summary>
@hudi-bot supports the following commands:
- `@hudi-bot run azure` re-run the last Azure build
</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(spark): group file slices by partition in the file index listing [hudi]
Posted by "hudi-bot (via GitHub)" <gi...@apache.org>.
hudi-bot commented on PR #20115:
URL: https://github.com/apache/hudi/pull/20115#issuecomment-5862225923
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "2d23bca880c9bb76bd8de2ebde9ef2bfbd8b65f3",
"status" : "UNKNOWN",
"url" : "TBD",
"triggerID" : "2d23bca880c9bb76bd8de2ebde9ef2bfbd8b65f3",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* 2d23bca880c9bb76bd8de2ebde9ef2bfbd8b65f3 UNKNOWN
<details>
<summary>Bot commands</summary>
@hudi-bot supports the following commands:
- `@hudi-bot run azure` re-run the last Azure build
</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(spark): group file slices by partition in the file index listing [hudi]
Posted by "yihua (via GitHub)" <gi...@apache.org>.
yihua commented on code in PR #20115:
URL: https://github.com/apache/hudi/pull/20115#discussion_r4189884523
##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/TestHoodieFileIndex.scala:
##########
@@ -890,6 +891,162 @@ class TestHoodieFileIndex extends HoodieSparkClientTestBase with ScalaAssertionS
assertEquals(expected, HoodieFileIndex.extractNestedPartitionFilters(filters, partitionColumns))
}
+
+ /**
+ * The file index returns one directory per partition for base-file-only slices, so that consumers
+ * of the listing see partitions rather than file slices, while slices with log files keep a directory
+ * of their own. Split planning stays the same as for one directory per file slice.
+ */
+ @ParameterizedTest
+ @EnumSource(classOf[HoodieTableType])
+ def testListFilesGroupsFileSlicesByPartition(tableType: HoodieTableType): Unit = {
+ val partitionCount = 5
+ val commitCount = 3
+ val writeOpts = writeFileGroups(tableType, partitionCount, commitCount)
+ val fileIndex = HoodieFileIndex(spark, metaClient, None, queryOpts,
+ includeLogFiles = tableType == HoodieTableType.MERGE_ON_READ, shouldEmbedFileSlices = true)
+
+ val directories = fileIndex.listFiles(Nil, Nil)
+ assertEquals(partitionCount, directories.size)
+ assertEquals(partitionCount, directories.map(_.values).distinct.size)
+ directories.foreach { directory =>
+ assertFalse(directory.values.isInstanceOf[HoodiePartitionFileSliceMapping])
+ assertEquals(commitCount, directory.files.size)
+ }
+ assertSameSplitPlanning(fileIndex, directories, exactFileOrder = true)
+
+ val incrementalRelation = spark.read.format("hudi")
+ .option(DataSourceReadOptions.QUERY_TYPE.key, DataSourceReadOptions.QUERY_TYPE_INCREMENTAL_OPT_VAL)
+ .option(DataSourceReadOptions.START_COMMIT.key, "000")
+ .load(basePath)
+ .queryExecution.analyzed.collectFirst { case relation: LogicalRelation => relation.relation.asInstanceOf[HadoopFsRelation] }.get
+ assertEquals(partitionCount, incrementalRelation.location.listFiles(Nil, Nil).size)
+
+ if (tableType == HoodieTableType.MERGE_ON_READ) {
+ // update one record in each of the first two partitions, which adds log files to one file group of each
+ upsertRecords(writeOpts, Seq(("key-0-0", 0, "ts-3"), ("key-0-1", 1, "ts-3")))
+ fileIndex.refresh()
+
+ val directoriesWithLogFiles = fileIndex.listFiles(Nil, Nil)
+ val (perSliceDirectories, perPartitionDirectories) =
+ directoriesWithLogFiles.partition(_.values.isInstanceOf[HoodiePartitionFileSliceMapping])
+ assertEquals(partitionCount, perPartitionDirectories.size)
+ assertEquals(partitionCount * commitCount - 2, perPartitionDirectories.map(_.files.size).sum)
+ assertEquals(2, perSliceDirectories.size)
+ perSliceDirectories.foreach(directory => assertTrue(getMappedSlice(directory).hasLogFiles))
+ assertSameSplitPlanning(fileIndex, directoriesWithLogFiles, exactFileOrder = false)
+
+ // without embedded file slices, a partition directory lists the base and log files of the partition
+ val legacyFileIndex = HoodieFileIndex(spark, metaClient, None, queryOpts, includeLogFiles = true)
+ val legacyDirectories = legacyFileIndex.listFiles(Nil, Nil)
+ assertEquals(partitionCount, legacyDirectories.size)
+ assertFalse(legacyDirectories.exists(_.values.isInstanceOf[HoodiePartitionFileSliceMapping]))
+ assertEquals(partitionCount * commitCount + 2, legacyDirectories.map(_.files.size).sum)
+ }
+ }
+
+ @ParameterizedTest
+ @EnumSource(classOf[HoodieTableType])
+ def testListFilesGroupsFileSlicesOfNonPartitionedTable(tableType: HoodieTableType): Unit = {
+ val commitCount = 3
+ val writeOpts = writeFileGroups(tableType, partitionCount = 1, commitCount, partitioned = false)
+ val fileIndex = HoodieFileIndex(spark, metaClient, None, queryOpts,
+ includeLogFiles = tableType == HoodieTableType.MERGE_ON_READ, shouldEmbedFileSlices = true)
+
+ val directories = fileIndex.listFiles(Nil, Nil)
+ assertEquals(1, directories.size)
+ assertEquals(commitCount, directories.head.files.size)
+ assertFalse(directories.head.values.isInstanceOf[HoodiePartitionFileSliceMapping])
+ assertSameSplitPlanning(fileIndex, directories, exactFileOrder = true)
+
+ if (tableType == HoodieTableType.MERGE_ON_READ) {
+ upsertRecords(writeOpts, Seq(("key-0-0", 0, "ts-3")))
+ fileIndex.refresh()
+
+ val directoriesWithLogFiles = fileIndex.listFiles(Nil, Nil)
+ assertEquals(2, directoriesWithLogFiles.size)
+ assertFalse(directoriesWithLogFiles.head.values.isInstanceOf[HoodiePartitionFileSliceMapping])
+ assertEquals(commitCount - 1, directoriesWithLogFiles.head.files.size)
+ assertTrue(getMappedSlice(directoriesWithLogFiles.last).hasLogFiles)
+ }
+ }
+
+ /**
+ * Writes `commitCount` inserts, each adding a new file group to every partition, and returns the write options.
+ */
+ private def writeFileGroups(tableType: HoodieTableType, partitionCount: Int, commitCount: Int,
+ partitioned: Boolean = true): Map[String, String] = {
+ val writeOpts = commonOpts ++ Map(
+ DataSourceWriteOptions.TABLE_TYPE.key -> tableType.name,
+ DataSourceWriteOptions.PARTITIONPATH_FIELD.key -> (if (partitioned) "partition" else ""),
+ HoodieCompactionConfig.PARQUET_SMALL_FILE_LIMIT.key -> "0")
Review Comment:
It is not needed here: the default Spark index is SIMPLE, which cannot index log files, so `SparkUpsertDeltaCommitPartitioner.getSmallFileCandidates` returns no candidates once `PARQUET_SMALL_FILE_LIMIT` is 0, before the candidates limit is applied, and the upserts are updates to existing keys, which always go to the log files of their file group on MOR. With an index that can index log files, both limits are bypassed (any slice under the max file size is a candidate), so pinning `hoodie.index.type=SIMPLE` would be the stricter guard.
--
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(spark): group file slices by partition in the file index listing [hudi]
Posted by "yihua (via GitHub)" <gi...@apache.org>.
yihua merged PR #20115:
URL: https://github.com/apache/hudi/pull/20115
--
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(spark): group file slices by partition in the file index listing [hudi]
Posted by "hudi-bot (via GitHub)" <gi...@apache.org>.
hudi-bot commented on PR #20115:
URL: https://github.com/apache/hudi/pull/20115#issuecomment-5863308276
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "2d23bca880c9bb76bd8de2ebde9ef2bfbd8b65f3",
"status" : "SUCCESS",
"url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17322",
"triggerID" : "2d23bca880c9bb76bd8de2ebde9ef2bfbd8b65f3",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* 2d23bca880c9bb76bd8de2ebde9ef2bfbd8b65f3 Azure: [SUCCESS](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17322)
<details>
<summary>Bot commands</summary>
@hudi-bot supports the following commands:
- `@hudi-bot run azure` re-run the last Azure build
</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(spark): group file slices by partition in the file index listing [hudi]
Posted by "hudi-bot (via GitHub)" <gi...@apache.org>.
hudi-bot commented on PR #20115:
URL: https://github.com/apache/hudi/pull/20115#issuecomment-5863450532
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "2d23bca880c9bb76bd8de2ebde9ef2bfbd8b65f3",
"status" : "SUCCESS",
"url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17322",
"triggerID" : "2d23bca880c9bb76bd8de2ebde9ef2bfbd8b65f3",
"triggerType" : "PUSH"
}, {
"hash" : "eaf4e8519970e86d2422fc613557d87ae45d17cb",
"status" : "PENDING",
"url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17326",
"triggerID" : "eaf4e8519970e86d2422fc613557d87ae45d17cb",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* 2d23bca880c9bb76bd8de2ebde9ef2bfbd8b65f3 Azure: [SUCCESS](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17322)
* eaf4e8519970e86d2422fc613557d87ae45d17cb Azure: [PENDING](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17326)
<details>
<summary>Bot commands</summary>
@hudi-bot supports the following commands:
- `@hudi-bot run azure` re-run the last Azure build
</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(spark): group file slices by partition in the file index listing [hudi]
Posted by "hudi-bot (via GitHub)" <gi...@apache.org>.
hudi-bot commented on PR #20115:
URL: https://github.com/apache/hudi/pull/20115#issuecomment-6005725584
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "eaf4e8519970e86d2422fc613557d87ae45d17cb",
"status" : "UNKNOWN",
"url" : "TBD",
"triggerID" : "eaf4e8519970e86d2422fc613557d87ae45d17cb",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* eaf4e8519970e86d2422fc613557d87ae45d17cb UNKNOWN
<details>
<summary>Bot commands</summary>
@hudi-bot supports the following commands:
- `@hudi-bot run azure` re-run the last Azure build
</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(spark): group file slices by partition in the file index listing [hudi]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #20115:
URL: https://github.com/apache/hudi/pull/20115#issuecomment-5862280671
## [Codecov](https://app.codecov.io/gh/apache/hudi/pull/20115?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.40%. Comparing base ([`ead194c`](https://app.codecov.io/gh/apache/hudi/commit/ead194cce54829fae9113689a2f28772d0d76045?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`2d23bca`](https://app.codecov.io/gh/apache/hudi/commit/2d23bca880c9bb76bd8de2ebde9ef2bfbd8b65f3?dropdown=coverage&el=desc&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 @@
## master #20115 +/- ##
============================================
- Coverage 80.40% 80.40% -0.01%
+ Complexity 34874 34863 -11
============================================
Files 2546 2546
Lines 142889 142865 -24
Branches 17374 17370 -4
============================================
- Hits 114895 114872 -23
- Misses 20082 20083 +1
+ Partials 7912 7910 -2
```
| [Components](https://app.codecov.io/gh/apache/hudi/pull/20115/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/20115/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `83.97% <ø> (ø)` | |
| [hudi-client](https://app.codecov.io/gh/apache/hudi/pull/20115/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `83.44% <ø> (-0.01%)` | :arrow_down: |
| [hudi-flink](https://app.codecov.io/gh/apache/hudi/pull/20115/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `85.74% <ø> (ø)` | |
| [hudi-spark-datasource](https://app.codecov.io/gh/apache/hudi/pull/20115/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `73.84% <ø> (-0.02%)` | :arrow_down: |
| [hudi-utilities](https://app.codecov.io/gh/apache/hudi/pull/20115/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/20115/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `70.05% <ø> (ø)` | |
| [hudi-hadoop](https://app.codecov.io/gh/apache/hudi/pull/20115/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `70.99% <ø> (ø)` | |
| [hudi-sync](https://app.codecov.io/gh/apache/hudi/pull/20115/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `76.02% <ø> (ø)` | |
| [hudi-io](https://app.codecov.io/gh/apache/hudi/pull/20115/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `81.50% <ø> (ø)` | |
| [hudi-timeline-service](https://app.codecov.io/gh/apache/hudi/pull/20115/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `83.06% <ø> (ø)` | |
| [hudi-cloud](https://app.codecov.io/gh/apache/hudi/pull/20115/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `81.00% <ø> (ø)` | |
| [hudi-kafka-connect](https://app.codecov.io/gh/apache/hudi/pull/20115/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/20115/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [hadoop-mr-java-client](https://app.codecov.io/gh/apache/hudi/pull/20115/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `43.99% <ø> (+<0.01%)` | :arrow_up: |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
| [Files with missing lines](https://app.codecov.io/gh/apache/hudi/pull/20115?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [...c/main/scala/org/apache/hudi/HoodieFileIndex.scala](https://app.codecov.io/gh/apache/hudi/pull/20115?src=pr&el=tree&filepath=hudi-spark-datasource%2Fhudi-spark-common%2Fsrc%2Fmain%2Fscala%2Forg%2Fapache%2Fhudi%2FHoodieFileIndex.scala&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-aHVkaS1zcGFyay1kYXRhc291cmNlL2h1ZGktc3BhcmstY29tbW9uL3NyYy9tYWluL3NjYWxhL29yZy9hcGFjaGUvaHVkaS9Ib29kaWVGaWxlSW5kZXguc2NhbGE=) | `82.18% <ø> (-0.18%)` | :arrow_down: |
| [...a/org/apache/hudi/HoodieIncrementalFileIndex.scala](https://app.codecov.io/gh/apache/hudi/pull/20115?src=pr&el=tree&filepath=hudi-spark-datasource%2Fhudi-spark-common%2Fsrc%2Fmain%2Fscala%2Forg%2Fapache%2Fhudi%2FHoodieIncrementalFileIndex.scala&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-aHVkaS1zcGFyay1kYXRhc291cmNlL2h1ZGktc3BhcmstY29tbW9uL3NyYy9tYWluL3NjYWxhL29yZy9hcGFjaGUvaHVkaS9Ib29kaWVJbmNyZW1lbnRhbEZpbGVJbmRleC5zY2FsYQ==) | `100.00% <ø> (+3.70%)` | :arrow_up: |
| [.../org/apache/hudi/PartitionDirectoryConverter.scala](https://app.codecov.io/gh/apache/hudi/pull/20115?src=pr&el=tree&filepath=hudi-spark-datasource%2Fhudi-spark-common%2Fsrc%2Fmain%2Fscala%2Forg%2Fapache%2Fhudi%2FPartitionDirectoryConverter.scala&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-aHVkaS1zcGFyay1kYXRhc291cmNlL2h1ZGktc3BhcmstY29tbW9uL3NyYy9tYWluL3NjYWxhL29yZy9hcGFjaGUvaHVkaS9QYXJ0aXRpb25EaXJlY3RvcnlDb252ZXJ0ZXIuc2NhbGE=) | `75.00% <ø> (-15.00%)` | :arrow_down: |
... and [1 file with indirect coverage changes](https://app.codecov.io/gh/apache/hudi/pull/20115/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
</details>
<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.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</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(spark): group file slices by partition in the file index listing [hudi]
Posted by "hudi-bot (via GitHub)" <gi...@apache.org>.
hudi-bot commented on PR #20115:
URL: https://github.com/apache/hudi/pull/20115#issuecomment-6005850268
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "eaf4e8519970e86d2422fc613557d87ae45d17cb",
"status" : "FAILURE",
"url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17326",
"triggerID" : "eaf4e8519970e86d2422fc613557d87ae45d17cb",
"triggerType" : "PUSH"
}, {
"hash" : "bfe10a6c6e1875bbf3e68686c77221b70ec43172",
"status" : "UNKNOWN",
"url" : "TBD",
"triggerID" : "bfe10a6c6e1875bbf3e68686c77221b70ec43172",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* eaf4e8519970e86d2422fc613557d87ae45d17cb Azure: [FAILURE](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17326)
* bfe10a6c6e1875bbf3e68686c77221b70ec43172 UNKNOWN
<details>
<summary>Bot commands</summary>
@hudi-bot supports the following commands:
- `@hudi-bot run azure` re-run the last Azure build
</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(spark): group file slices by partition in the file index listing [hudi]
Posted by "yihua (via GitHub)" <gi...@apache.org>.
yihua commented on code in PR #20115:
URL: https://github.com/apache/hudi/pull/20115#discussion_r4189884110
##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/HoodieFileIndex.scala:
##########
@@ -200,11 +200,10 @@ case class HoodieFileIndex(spark: SparkSession,
partitionFilters
}
- val slices = filterFileSlices(dataFilters, effectivePartitionFilters).flatMap(
- { case (partitionOpt, fileSlices) =>
- fileSlices.filter(!_.isEmpty).map(fs => (InternalRow.fromSeq(partitionOpt.get.getValues), fs))
- }
- )
+ val slices = filterFileSlices(dataFilters, effectivePartitionFilters).map {
+ case (partitionOpt, fileSlices) =>
+ (InternalRow.fromSeq(partitionOpt.get.getValues), fileSlices.filter(!_.isEmpty))
Review Comment:
It is dropped: `prepareFileSlices` filters out entries with no slices (`slices.filter(_._2.nonEmpty)`) before building directories, which covers both this caller and `HoodieIncrementalFileIndex`. A partition with only empty slices yields no directory, same as before.
##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/TestHoodieFileIndex.scala:
##########
@@ -890,6 +891,162 @@ class TestHoodieFileIndex extends HoodieSparkClientTestBase with ScalaAssertionS
assertEquals(expected, HoodieFileIndex.extractNestedPartitionFilters(filters, partitionColumns))
}
+
+ /**
+ * The file index returns one directory per partition for base-file-only slices, so that consumers
+ * of the listing see partitions rather than file slices, while slices with log files keep a directory
+ * of their own. Split planning stays the same as for one directory per file slice.
+ */
+ @ParameterizedTest
+ @EnumSource(classOf[HoodieTableType])
+ def testListFilesGroupsFileSlicesByPartition(tableType: HoodieTableType): Unit = {
+ val partitionCount = 5
+ val commitCount = 3
+ val writeOpts = writeFileGroups(tableType, partitionCount, commitCount)
+ val fileIndex = HoodieFileIndex(spark, metaClient, None, queryOpts,
+ includeLogFiles = tableType == HoodieTableType.MERGE_ON_READ, shouldEmbedFileSlices = true)
+
+ val directories = fileIndex.listFiles(Nil, Nil)
+ assertEquals(partitionCount, directories.size)
+ assertEquals(partitionCount, directories.map(_.values).distinct.size)
+ directories.foreach { directory =>
+ assertFalse(directory.values.isInstanceOf[HoodiePartitionFileSliceMapping])
+ assertEquals(commitCount, directory.files.size)
+ }
+ assertSameSplitPlanning(fileIndex, directories, exactFileOrder = true)
+
+ val incrementalRelation = spark.read.format("hudi")
+ .option(DataSourceReadOptions.QUERY_TYPE.key, DataSourceReadOptions.QUERY_TYPE_INCREMENTAL_OPT_VAL)
Review Comment:
Not fully. The snapshot cases build the index directly with the settings the COW and MOR snapshot factories use (`includeLogFiles` false/true with embedded slices), and only the incremental check goes through `spark.read`; MOR read-optimized is not covered, where after the update the listing should be 5 plain directories holding the 15 base files. Loading snapshot and read-optimized through `spark.read` and checking the rows read back (`key-0-0` at `ts-3` vs `ts-0`) would cover both, plus the factory wiring.
##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/TestHoodieFileIndex.scala:
##########
@@ -890,6 +891,162 @@ class TestHoodieFileIndex extends HoodieSparkClientTestBase with ScalaAssertionS
assertEquals(expected, HoodieFileIndex.extractNestedPartitionFilters(filters, partitionColumns))
}
+
+ /**
+ * The file index returns one directory per partition for base-file-only slices, so that consumers
+ * of the listing see partitions rather than file slices, while slices with log files keep a directory
+ * of their own. Split planning stays the same as for one directory per file slice.
+ */
+ @ParameterizedTest
+ @EnumSource(classOf[HoodieTableType])
+ def testListFilesGroupsFileSlicesByPartition(tableType: HoodieTableType): Unit = {
+ val partitionCount = 5
+ val commitCount = 3
+ val writeOpts = writeFileGroups(tableType, partitionCount, commitCount)
+ val fileIndex = HoodieFileIndex(spark, metaClient, None, queryOpts,
+ includeLogFiles = tableType == HoodieTableType.MERGE_ON_READ, shouldEmbedFileSlices = true)
+
+ val directories = fileIndex.listFiles(Nil, Nil)
+ assertEquals(partitionCount, directories.size)
+ assertEquals(partitionCount, directories.map(_.values).distinct.size)
+ directories.foreach { directory =>
+ assertFalse(directory.values.isInstanceOf[HoodiePartitionFileSliceMapping])
+ assertEquals(commitCount, directory.files.size)
+ }
+ assertSameSplitPlanning(fileIndex, directories, exactFileOrder = true)
+
+ val incrementalRelation = spark.read.format("hudi")
+ .option(DataSourceReadOptions.QUERY_TYPE.key, DataSourceReadOptions.QUERY_TYPE_INCREMENTAL_OPT_VAL)
+ .option(DataSourceReadOptions.START_COMMIT.key, "000")
+ .load(basePath)
+ .queryExecution.analyzed.collectFirst { case relation: LogicalRelation => relation.relation.asInstanceOf[HadoopFsRelation] }.get
+ assertEquals(partitionCount, incrementalRelation.location.listFiles(Nil, Nil).size)
+
+ if (tableType == HoodieTableType.MERGE_ON_READ) {
+ // update one record in each of the first two partitions, which adds log files to one file group of each
+ upsertRecords(writeOpts, Seq(("key-0-0", 0, "ts-3"), ("key-0-1", 1, "ts-3")))
+ fileIndex.refresh()
+
+ val directoriesWithLogFiles = fileIndex.listFiles(Nil, Nil)
+ val (perSliceDirectories, perPartitionDirectories) =
+ directoriesWithLogFiles.partition(_.values.isInstanceOf[HoodiePartitionFileSliceMapping])
+ assertEquals(partitionCount, perPartitionDirectories.size)
+ assertEquals(partitionCount * commitCount - 2, perPartitionDirectories.map(_.files.size).sum)
+ assertEquals(2, perSliceDirectories.size)
+ perSliceDirectories.foreach(directory => assertTrue(getMappedSlice(directory).hasLogFiles))
+ assertSameSplitPlanning(fileIndex, directoriesWithLogFiles, exactFileOrder = false)
+
+ // without embedded file slices, a partition directory lists the base and log files of the partition
+ val legacyFileIndex = HoodieFileIndex(spark, metaClient, None, queryOpts, includeLogFiles = true)
+ val legacyDirectories = legacyFileIndex.listFiles(Nil, Nil)
+ assertEquals(partitionCount, legacyDirectories.size)
+ assertFalse(legacyDirectories.exists(_.values.isInstanceOf[HoodiePartitionFileSliceMapping]))
+ assertEquals(partitionCount * commitCount + 2, legacyDirectories.map(_.files.size).sum)
+ }
+ }
+
+ @ParameterizedTest
+ @EnumSource(classOf[HoodieTableType])
+ def testListFilesGroupsFileSlicesOfNonPartitionedTable(tableType: HoodieTableType): Unit = {
+ val commitCount = 3
+ val writeOpts = writeFileGroups(tableType, partitionCount = 1, commitCount, partitioned = false)
+ val fileIndex = HoodieFileIndex(spark, metaClient, None, queryOpts,
+ includeLogFiles = tableType == HoodieTableType.MERGE_ON_READ, shouldEmbedFileSlices = true)
+
+ val directories = fileIndex.listFiles(Nil, Nil)
+ assertEquals(1, directories.size)
+ assertEquals(commitCount, directories.head.files.size)
+ assertFalse(directories.head.values.isInstanceOf[HoodiePartitionFileSliceMapping])
+ assertSameSplitPlanning(fileIndex, directories, exactFileOrder = true)
+
+ if (tableType == HoodieTableType.MERGE_ON_READ) {
+ upsertRecords(writeOpts, Seq(("key-0-0", 0, "ts-3")))
+ fileIndex.refresh()
+
+ val directoriesWithLogFiles = fileIndex.listFiles(Nil, Nil)
+ assertEquals(2, directoriesWithLogFiles.size)
+ assertFalse(directoriesWithLogFiles.head.values.isInstanceOf[HoodiePartitionFileSliceMapping])
+ assertEquals(commitCount - 1, directoriesWithLogFiles.head.files.size)
+ assertTrue(getMappedSlice(directoriesWithLogFiles.last).hasLogFiles)
+ }
+ }
+
+ /**
+ * Writes `commitCount` inserts, each adding a new file group to every partition, and returns the write options.
+ */
+ private def writeFileGroups(tableType: HoodieTableType, partitionCount: Int, commitCount: Int,
+ partitioned: Boolean = true): Map[String, String] = {
+ val writeOpts = commonOpts ++ Map(
+ DataSourceWriteOptions.TABLE_TYPE.key -> tableType.name,
+ DataSourceWriteOptions.PARTITIONPATH_FIELD.key -> (if (partitioned) "partition" else ""),
+ HoodieCompactionConfig.PARQUET_SMALL_FILE_LIMIT.key -> "0")
Review Comment:
It is not needed here: the default Spark index is SIMPLE, which cannot index log files, so `SparkUpsertDeltaCommitPartitioner.getSmallFileCandidates` returns no candidates once `PARQUET_SMALL_FILE_LIMIT` is 0, before the candidates limit is applied, and the upserts are updates to existing keys, which always go to the log files of their file group on MOR. With an index that can index log files, both limits are bypassed (any slice under the max file size is a candidate), so pinning `hoodie.index.type=SIMPLE` would be the stricter guard.
--
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(spark): group file slices by partition in the file index listing [hudi]
Posted by "hudi-bot (via GitHub)" <gi...@apache.org>.
hudi-bot commented on PR #20115:
URL: https://github.com/apache/hudi/pull/20115#issuecomment-5862278628
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "2d23bca880c9bb76bd8de2ebde9ef2bfbd8b65f3",
"status" : "PENDING",
"url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17322",
"triggerID" : "2d23bca880c9bb76bd8de2ebde9ef2bfbd8b65f3",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* 2d23bca880c9bb76bd8de2ebde9ef2bfbd8b65f3 Azure: [PENDING](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17322)
<details>
<summary>Bot commands</summary>
@hudi-bot supports the following commands:
- `@hudi-bot run azure` re-run the last Azure build
</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(spark): group file slices by partition in the file index listing [hudi]
Posted by "hudi-bot (via GitHub)" <gi...@apache.org>.
hudi-bot commented on PR #20115:
URL: https://github.com/apache/hudi/pull/20115#issuecomment-6005970072
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "eaf4e8519970e86d2422fc613557d87ae45d17cb",
"status" : "FAILURE",
"url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17326",
"triggerID" : "eaf4e8519970e86d2422fc613557d87ae45d17cb",
"triggerType" : "PUSH"
}, {
"hash" : "bfe10a6c6e1875bbf3e68686c77221b70ec43172",
"status" : "PENDING",
"url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17470",
"triggerID" : "bfe10a6c6e1875bbf3e68686c77221b70ec43172",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* eaf4e8519970e86d2422fc613557d87ae45d17cb Azure: [FAILURE](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17326)
* bfe10a6c6e1875bbf3e68686c77221b70ec43172 Azure: [PENDING](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17470)
<details>
<summary>Bot commands</summary>
@hudi-bot supports the following commands:
- `@hudi-bot run azure` re-run the last Azure build
</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(spark): group file slices by partition in the file index listing [hudi]
Posted by "yihua (via GitHub)" <gi...@apache.org>.
yihua commented on code in PR #20115:
URL: https://github.com/apache/hudi/pull/20115#discussion_r4189928834
##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/TestHoodieFileIndex.scala:
##########
@@ -890,6 +891,162 @@ class TestHoodieFileIndex extends HoodieSparkClientTestBase with ScalaAssertionS
assertEquals(expected, HoodieFileIndex.extractNestedPartitionFilters(filters, partitionColumns))
}
+
+ /**
+ * The file index returns one directory per partition for base-file-only slices, so that consumers
+ * of the listing see partitions rather than file slices, while slices with log files keep a directory
+ * of their own. Split planning stays the same as for one directory per file slice.
+ */
+ @ParameterizedTest
+ @EnumSource(classOf[HoodieTableType])
+ def testListFilesGroupsFileSlicesByPartition(tableType: HoodieTableType): Unit = {
+ val partitionCount = 5
+ val commitCount = 3
+ val writeOpts = writeFileGroups(tableType, partitionCount, commitCount)
+ val fileIndex = HoodieFileIndex(spark, metaClient, None, queryOpts,
+ includeLogFiles = tableType == HoodieTableType.MERGE_ON_READ, shouldEmbedFileSlices = true)
+
+ val directories = fileIndex.listFiles(Nil, Nil)
+ assertEquals(partitionCount, directories.size)
+ assertEquals(partitionCount, directories.map(_.values).distinct.size)
+ directories.foreach { directory =>
+ assertFalse(directory.values.isInstanceOf[HoodiePartitionFileSliceMapping])
+ assertEquals(commitCount, directory.files.size)
+ }
+ assertSameSplitPlanning(fileIndex, directories, exactFileOrder = true)
+
+ val incrementalRelation = spark.read.format("hudi")
+ .option(DataSourceReadOptions.QUERY_TYPE.key, DataSourceReadOptions.QUERY_TYPE_INCREMENTAL_OPT_VAL)
+ .option(DataSourceReadOptions.START_COMMIT.key, "000")
+ .load(basePath)
+ .queryExecution.analyzed.collectFirst { case relation: LogicalRelation => relation.relation.asInstanceOf[HadoopFsRelation] }.get
+ assertEquals(partitionCount, incrementalRelation.location.listFiles(Nil, Nil).size)
+
+ if (tableType == HoodieTableType.MERGE_ON_READ) {
+ // update one record in each of the first two partitions, which adds log files to one file group of each
+ upsertRecords(writeOpts, Seq(("key-0-0", 0, "ts-3"), ("key-0-1", 1, "ts-3")))
+ fileIndex.refresh()
+
+ val directoriesWithLogFiles = fileIndex.listFiles(Nil, Nil)
+ val (perSliceDirectories, perPartitionDirectories) =
+ directoriesWithLogFiles.partition(_.values.isInstanceOf[HoodiePartitionFileSliceMapping])
+ assertEquals(partitionCount, perPartitionDirectories.size)
+ assertEquals(partitionCount * commitCount - 2, perPartitionDirectories.map(_.files.size).sum)
+ assertEquals(2, perSliceDirectories.size)
+ perSliceDirectories.foreach(directory => assertTrue(getMappedSlice(directory).hasLogFiles))
+ assertSameSplitPlanning(fileIndex, directoriesWithLogFiles, exactFileOrder = false)
+
+ // without embedded file slices, a partition directory lists the base and log files of the partition
+ val legacyFileIndex = HoodieFileIndex(spark, metaClient, None, queryOpts, includeLogFiles = true)
+ val legacyDirectories = legacyFileIndex.listFiles(Nil, Nil)
+ assertEquals(partitionCount, legacyDirectories.size)
+ assertFalse(legacyDirectories.exists(_.values.isInstanceOf[HoodiePartitionFileSliceMapping]))
+ assertEquals(partitionCount * commitCount + 2, legacyDirectories.map(_.files.size).sum)
+ }
+ }
+
+ @ParameterizedTest
+ @EnumSource(classOf[HoodieTableType])
+ def testListFilesGroupsFileSlicesOfNonPartitionedTable(tableType: HoodieTableType): Unit = {
+ val commitCount = 3
+ val writeOpts = writeFileGroups(tableType, partitionCount = 1, commitCount, partitioned = false)
+ val fileIndex = HoodieFileIndex(spark, metaClient, None, queryOpts,
+ includeLogFiles = tableType == HoodieTableType.MERGE_ON_READ, shouldEmbedFileSlices = true)
+
+ val directories = fileIndex.listFiles(Nil, Nil)
+ assertEquals(1, directories.size)
+ assertEquals(commitCount, directories.head.files.size)
+ assertFalse(directories.head.values.isInstanceOf[HoodiePartitionFileSliceMapping])
+ assertSameSplitPlanning(fileIndex, directories, exactFileOrder = true)
+
+ if (tableType == HoodieTableType.MERGE_ON_READ) {
+ upsertRecords(writeOpts, Seq(("key-0-0", 0, "ts-3")))
+ fileIndex.refresh()
+
+ val directoriesWithLogFiles = fileIndex.listFiles(Nil, Nil)
+ assertEquals(2, directoriesWithLogFiles.size)
+ assertFalse(directoriesWithLogFiles.head.values.isInstanceOf[HoodiePartitionFileSliceMapping])
+ assertEquals(commitCount - 1, directoriesWithLogFiles.head.files.size)
+ assertTrue(getMappedSlice(directoriesWithLogFiles.last).hasLogFiles)
+ }
+ }
+
+ /**
+ * Writes `commitCount` inserts, each adding a new file group to every partition, and returns the write options.
+ */
+ private def writeFileGroups(tableType: HoodieTableType, partitionCount: Int, commitCount: Int,
+ partitioned: Boolean = true): Map[String, String] = {
+ val writeOpts = commonOpts ++ Map(
+ DataSourceWriteOptions.TABLE_TYPE.key -> tableType.name,
+ DataSourceWriteOptions.PARTITIONPATH_FIELD.key -> (if (partitioned) "partition" else ""),
+ HoodieCompactionConfig.PARQUET_SMALL_FILE_LIMIT.key -> "0")
Review Comment:
`HoodieCompactionConfig.PARQUET_SMALL_FILE_LIMIT` works.
--
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(spark): group file slices by partition in the file index listing [hudi]
Posted by "hudi-bot (via GitHub)" <gi...@apache.org>.
hudi-bot commented on PR #20115:
URL: https://github.com/apache/hudi/pull/20115#issuecomment-6008320748
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "eaf4e8519970e86d2422fc613557d87ae45d17cb",
"status" : "DELETED",
"url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17326",
"triggerID" : "eaf4e8519970e86d2422fc613557d87ae45d17cb",
"triggerType" : "PUSH"
}, {
"hash" : "bfe10a6c6e1875bbf3e68686c77221b70ec43172",
"status" : "SUCCESS",
"url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17470",
"triggerID" : "bfe10a6c6e1875bbf3e68686c77221b70ec43172",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* bfe10a6c6e1875bbf3e68686c77221b70ec43172 Azure: [SUCCESS](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17470)
<details>
<summary>Bot commands</summary>
@hudi-bot supports the following commands:
- `@hudi-bot run azure` re-run the last Azure build
</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(spark): group file slices by partition in the file index listing [hudi]
Posted by "yihua (via GitHub)" <gi...@apache.org>.
yihua commented on code in PR #20115:
URL: https://github.com/apache/hudi/pull/20115#discussion_r4189624155
##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/HoodieFileIndex.scala:
##########
@@ -200,11 +200,10 @@ case class HoodieFileIndex(spark: SparkSession,
partitionFilters
}
- val slices = filterFileSlices(dataFilters, effectivePartitionFilters).flatMap(
- { case (partitionOpt, fileSlices) =>
- fileSlices.filter(!_.isEmpty).map(fs => (InternalRow.fromSeq(partitionOpt.get.getValues), fs))
- }
- )
+ val slices = filterFileSlices(dataFilters, effectivePartitionFilters).map {
+ case (partitionOpt, fileSlices) =>
+ (InternalRow.fromSeq(partitionOpt.get.getValues), fileSlices.filter(!_.isEmpty))
Review Comment:
If `fileSlices.filter(!_.isEmpty)` is empty, should the entry be dropped?
--
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(spark): group file slices by partition in the file index listing [hudi]
Posted by "yihua (via GitHub)" <gi...@apache.org>.
yihua commented on code in PR #20115:
URL: https://github.com/apache/hudi/pull/20115#discussion_r4189854297
##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/TestHoodieFileIndex.scala:
##########
@@ -890,6 +891,162 @@ class TestHoodieFileIndex extends HoodieSparkClientTestBase with ScalaAssertionS
assertEquals(expected, HoodieFileIndex.extractNestedPartitionFilters(filters, partitionColumns))
}
+
+ /**
+ * The file index returns one directory per partition for base-file-only slices, so that consumers
+ * of the listing see partitions rather than file slices, while slices with log files keep a directory
+ * of their own. Split planning stays the same as for one directory per file slice.
+ */
+ @ParameterizedTest
+ @EnumSource(classOf[HoodieTableType])
+ def testListFilesGroupsFileSlicesByPartition(tableType: HoodieTableType): Unit = {
+ val partitionCount = 5
+ val commitCount = 3
+ val writeOpts = writeFileGroups(tableType, partitionCount, commitCount)
+ val fileIndex = HoodieFileIndex(spark, metaClient, None, queryOpts,
+ includeLogFiles = tableType == HoodieTableType.MERGE_ON_READ, shouldEmbedFileSlices = true)
+
+ val directories = fileIndex.listFiles(Nil, Nil)
+ assertEquals(partitionCount, directories.size)
+ assertEquals(partitionCount, directories.map(_.values).distinct.size)
+ directories.foreach { directory =>
+ assertFalse(directory.values.isInstanceOf[HoodiePartitionFileSliceMapping])
+ assertEquals(commitCount, directory.files.size)
+ }
+ assertSameSplitPlanning(fileIndex, directories, exactFileOrder = true)
+
+ val incrementalRelation = spark.read.format("hudi")
+ .option(DataSourceReadOptions.QUERY_TYPE.key, DataSourceReadOptions.QUERY_TYPE_INCREMENTAL_OPT_VAL)
+ .option(DataSourceReadOptions.START_COMMIT.key, "000")
+ .load(basePath)
+ .queryExecution.analyzed.collectFirst { case relation: LogicalRelation => relation.relation.asInstanceOf[HadoopFsRelation] }.get
+ assertEquals(partitionCount, incrementalRelation.location.listFiles(Nil, Nil).size)
+
+ if (tableType == HoodieTableType.MERGE_ON_READ) {
+ // update one record in each of the first two partitions, which adds log files to one file group of each
+ upsertRecords(writeOpts, Seq(("key-0-0", 0, "ts-3"), ("key-0-1", 1, "ts-3")))
+ fileIndex.refresh()
+
+ val directoriesWithLogFiles = fileIndex.listFiles(Nil, Nil)
+ val (perSliceDirectories, perPartitionDirectories) =
+ directoriesWithLogFiles.partition(_.values.isInstanceOf[HoodiePartitionFileSliceMapping])
+ assertEquals(partitionCount, perPartitionDirectories.size)
+ assertEquals(partitionCount * commitCount - 2, perPartitionDirectories.map(_.files.size).sum)
+ assertEquals(2, perSliceDirectories.size)
+ perSliceDirectories.foreach(directory => assertTrue(getMappedSlice(directory).hasLogFiles))
+ assertSameSplitPlanning(fileIndex, directoriesWithLogFiles, exactFileOrder = false)
+
+ // without embedded file slices, a partition directory lists the base and log files of the partition
+ val legacyFileIndex = HoodieFileIndex(spark, metaClient, None, queryOpts, includeLogFiles = true)
+ val legacyDirectories = legacyFileIndex.listFiles(Nil, Nil)
+ assertEquals(partitionCount, legacyDirectories.size)
+ assertFalse(legacyDirectories.exists(_.values.isInstanceOf[HoodiePartitionFileSliceMapping]))
+ assertEquals(partitionCount * commitCount + 2, legacyDirectories.map(_.files.size).sum)
+ }
+ }
+
+ @ParameterizedTest
+ @EnumSource(classOf[HoodieTableType])
+ def testListFilesGroupsFileSlicesOfNonPartitionedTable(tableType: HoodieTableType): Unit = {
+ val commitCount = 3
+ val writeOpts = writeFileGroups(tableType, partitionCount = 1, commitCount, partitioned = false)
+ val fileIndex = HoodieFileIndex(spark, metaClient, None, queryOpts,
+ includeLogFiles = tableType == HoodieTableType.MERGE_ON_READ, shouldEmbedFileSlices = true)
+
+ val directories = fileIndex.listFiles(Nil, Nil)
+ assertEquals(1, directories.size)
+ assertEquals(commitCount, directories.head.files.size)
+ assertFalse(directories.head.values.isInstanceOf[HoodiePartitionFileSliceMapping])
+ assertSameSplitPlanning(fileIndex, directories, exactFileOrder = true)
+
+ if (tableType == HoodieTableType.MERGE_ON_READ) {
+ upsertRecords(writeOpts, Seq(("key-0-0", 0, "ts-3")))
+ fileIndex.refresh()
+
+ val directoriesWithLogFiles = fileIndex.listFiles(Nil, Nil)
+ assertEquals(2, directoriesWithLogFiles.size)
+ assertFalse(directoriesWithLogFiles.head.values.isInstanceOf[HoodiePartitionFileSliceMapping])
+ assertEquals(commitCount - 1, directoriesWithLogFiles.head.files.size)
+ assertTrue(getMappedSlice(directoriesWithLogFiles.last).hasLogFiles)
+ }
+ }
+
+ /**
+ * Writes `commitCount` inserts, each adding a new file group to every partition, and returns the write options.
+ */
+ private def writeFileGroups(tableType: HoodieTableType, partitionCount: Int, commitCount: Int,
+ partitioned: Boolean = true): Map[String, String] = {
+ val writeOpts = commonOpts ++ Map(
+ DataSourceWriteOptions.TABLE_TYPE.key -> tableType.name,
+ DataSourceWriteOptions.PARTITIONPATH_FIELD.key -> (if (partitioned) "partition" else ""),
+ HoodieCompactionConfig.PARQUET_SMALL_FILE_LIMIT.key -> "0")
Review Comment:
Is `hoodie.merge.small.file.group.candidates.limit` set to 0 so MOR only writes log files for updates?
##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/TestHoodieFileIndex.scala:
##########
@@ -890,6 +891,162 @@ class TestHoodieFileIndex extends HoodieSparkClientTestBase with ScalaAssertionS
assertEquals(expected, HoodieFileIndex.extractNestedPartitionFilters(filters, partitionColumns))
}
+
+ /**
+ * The file index returns one directory per partition for base-file-only slices, so that consumers
+ * of the listing see partitions rather than file slices, while slices with log files keep a directory
+ * of their own. Split planning stays the same as for one directory per file slice.
+ */
+ @ParameterizedTest
+ @EnumSource(classOf[HoodieTableType])
+ def testListFilesGroupsFileSlicesByPartition(tableType: HoodieTableType): Unit = {
+ val partitionCount = 5
+ val commitCount = 3
+ val writeOpts = writeFileGroups(tableType, partitionCount, commitCount)
+ val fileIndex = HoodieFileIndex(spark, metaClient, None, queryOpts,
+ includeLogFiles = tableType == HoodieTableType.MERGE_ON_READ, shouldEmbedFileSlices = true)
+
+ val directories = fileIndex.listFiles(Nil, Nil)
+ assertEquals(partitionCount, directories.size)
+ assertEquals(partitionCount, directories.map(_.values).distinct.size)
+ directories.foreach { directory =>
+ assertFalse(directory.values.isInstanceOf[HoodiePartitionFileSliceMapping])
+ assertEquals(commitCount, directory.files.size)
+ }
+ assertSameSplitPlanning(fileIndex, directories, exactFileOrder = true)
+
+ val incrementalRelation = spark.read.format("hudi")
+ .option(DataSourceReadOptions.QUERY_TYPE.key, DataSourceReadOptions.QUERY_TYPE_INCREMENTAL_OPT_VAL)
Review Comment:
Are snapshot and read-optimized queries both tested?
--
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