-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[HUDI-3825] Fixing non-partitioned table Partition Records persistence in MT #5259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ca5f955
Filter out empty string (for non-partitioned table) being added to "_…
2848ecf
Instead of filtering, transform empty partition-id to `NON_PARTITIONE…
edffe32
Cleaned up `HoodieBackedTableMetadataWriter`
07b2e10
Tidying up
cbddee4
Make sure REPLACE_COMMITS are handled as well
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,7 +87,6 @@ | |
| import java.util.Map; | ||
| import java.util.Properties; | ||
| import java.util.Set; | ||
| import java.util.concurrent.atomic.AtomicLong; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import static org.apache.hudi.common.table.HoodieTableConfig.ARCHIVELOG_FOLDER; | ||
|
|
@@ -1012,28 +1011,21 @@ private void initialCommit(String createInstantTime, List<MetadataPartitionType> | |
| LOG.info("Initializing metadata table by using file listings in " + dataWriteConfig.getBasePath()); | ||
| engineContext.setJobStatus(this.getClass().getSimpleName(), "Initializing metadata table by listing files and partitions"); | ||
|
|
||
| Map<MetadataPartitionType, HoodieData<HoodieRecord>> partitionToRecordsMap = new HashMap<>(); | ||
|
|
||
| List<DirectoryInfo> partitionInfoList = listAllPartitions(dataMetaClient); | ||
| List<String> partitions = new ArrayList<>(); | ||
| AtomicLong totalFiles = new AtomicLong(0); | ||
| Map<String, Map<String, Long>> partitionToFilesMap = partitionInfoList.stream().map(p -> { | ||
| final String partitionName = HoodieTableMetadataUtil.getPartition(p.getRelativePath()); | ||
| partitions.add(partitionName); | ||
| totalFiles.addAndGet(p.getTotalFiles()); | ||
| return Pair.of(partitionName, p.getFileNameToSizeMap()); | ||
| }).collect(Collectors.toMap(Pair::getKey, Pair::getValue)); | ||
| final Map<MetadataPartitionType, HoodieData<HoodieRecord>> partitionToRecordsMap = new HashMap<>(); | ||
| Map<String, Map<String, Long>> partitionToFilesMap = partitionInfoList.stream() | ||
| .map(p -> { | ||
| String partitionName = HoodieTableMetadataUtil.getPartitionIdentifier(p.getRelativePath()); | ||
| return Pair.of(partitionName, p.getFileNameToSizeMap()); | ||
| }) | ||
| .collect(Collectors.toMap(Pair::getKey, Pair::getValue)); | ||
|
|
||
| List<String> partitions = new ArrayList<>(partitionToFilesMap.keySet()); | ||
|
|
||
| if (partitionTypes.contains(MetadataPartitionType.FILES)) { | ||
| // Record which saves the list of all partitions | ||
| HoodieRecord allPartitionRecord = HoodieMetadataPayload.createPartitionListRecord(partitions); | ||
| if (partitions.isEmpty()) { | ||
| // in case of initializing of a fresh table, there won't be any partitions, but we need to make a boostrap commit | ||
| final HoodieData<HoodieRecord> allPartitionRecordsRDD = engineContext.parallelize( | ||
| Collections.singletonList(allPartitionRecord), 1); | ||
| partitionToRecordsMap.put(MetadataPartitionType.FILES, allPartitionRecordsRDD); | ||
| commit(createInstantTime, partitionToRecordsMap, false); | ||
| return; | ||
| } | ||
| HoodieData<HoodieRecord> filesPartitionRecords = getFilesPartitionRecords(createInstantTime, partitionInfoList, allPartitionRecord); | ||
| ValidationUtils.checkState(filesPartitionRecords.count() == (partitions.size() + 1)); | ||
| partitionToRecordsMap.put(MetadataPartitionType.FILES, filesPartitionRecords); | ||
|
|
@@ -1051,28 +1043,31 @@ private void initialCommit(String createInstantTime, List<MetadataPartitionType> | |
| partitionToRecordsMap.put(MetadataPartitionType.COLUMN_STATS, recordsRDD); | ||
| } | ||
|
|
||
| LOG.info("Committing " + partitions.size() + " partitions and " + totalFiles + " files to metadata"); | ||
| LOG.info("Committing " + partitions.size() + " partitions and " + partitionToFilesMap.values().size() + " files to metadata"); | ||
|
|
||
| commit(createInstantTime, partitionToRecordsMap, false); | ||
| } | ||
|
|
||
| private HoodieData<HoodieRecord> getFilesPartitionRecords(String createInstantTime, List<DirectoryInfo> partitionInfoList, HoodieRecord allPartitionRecord) { | ||
| HoodieData<HoodieRecord> filesPartitionRecords = engineContext.parallelize(Arrays.asList(allPartitionRecord), 1); | ||
| if (!partitionInfoList.isEmpty()) { | ||
| HoodieData<HoodieRecord> fileListRecords = engineContext.parallelize(partitionInfoList, partitionInfoList.size()).map(partitionInfo -> { | ||
| Map<String, Long> fileNameToSizeMap = partitionInfo.getFileNameToSizeMap(); | ||
| // filter for files that are part of the completed commits | ||
| Map<String, Long> validFileNameToSizeMap = fileNameToSizeMap.entrySet().stream().filter(fileSizePair -> { | ||
| String commitTime = FSUtils.getCommitTime(fileSizePair.getKey()); | ||
| return HoodieTimeline.compareTimestamps(commitTime, HoodieTimeline.LESSER_THAN_OR_EQUALS, createInstantTime); | ||
| }).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); | ||
|
|
||
| // Record which saves files within a partition | ||
| return HoodieMetadataPayload.createPartitionFilesRecord( | ||
| HoodieTableMetadataUtil.getPartition(partitionInfo.getRelativePath()), Option.of(validFileNameToSizeMap), Option.empty()); | ||
| }); | ||
| filesPartitionRecords = filesPartitionRecords.union(fileListRecords); | ||
| if (partitionInfoList.isEmpty()) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just inverted conditional to simplify control flow |
||
| return filesPartitionRecords; | ||
| } | ||
| return filesPartitionRecords; | ||
|
|
||
| HoodieData<HoodieRecord> fileListRecords = engineContext.parallelize(partitionInfoList, partitionInfoList.size()).map(partitionInfo -> { | ||
| Map<String, Long> fileNameToSizeMap = partitionInfo.getFileNameToSizeMap(); | ||
| // filter for files that are part of the completed commits | ||
| Map<String, Long> validFileNameToSizeMap = fileNameToSizeMap.entrySet().stream().filter(fileSizePair -> { | ||
| String commitTime = FSUtils.getCommitTime(fileSizePair.getKey()); | ||
| return HoodieTimeline.compareTimestamps(commitTime, HoodieTimeline.LESSER_THAN_OR_EQUALS, createInstantTime); | ||
| }).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); | ||
|
|
||
| // Record which saves files within a partition | ||
| return HoodieMetadataPayload.createPartitionFilesRecord( | ||
| HoodieTableMetadataUtil.getPartitionIdentifier(partitionInfo.getRelativePath()), Option.of(validFileNameToSizeMap), Option.empty()); | ||
| }); | ||
|
|
||
| return filesPartitionRecords.union(fileListRecords); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just pure duplication