-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[HUDI-4140] Fixing hive style partitioning and default partition with bulk insert row writer with SimpleKeyGen and virtual keys #5664
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
yihua
merged 4 commits into
apache:master
from
nsivabalan:bulkInsertRowWriterHiveStylePartitioning
Jun 6, 2022
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,15 +18,18 @@ | |
|
|
||
| package org.apache.hudi.internal; | ||
|
|
||
| import org.apache.hudi.common.model.HoodieRecord; | ||
| import org.apache.hudi.common.testutils.HoodieTestDataGenerator; | ||
| import org.apache.hudi.common.util.Option; | ||
| import org.apache.hudi.config.HoodieWriteConfig; | ||
| import org.apache.hudi.table.HoodieSparkTable; | ||
| import org.apache.hudi.table.HoodieTable; | ||
| import org.apache.hudi.testutils.SparkDatasetTestUtils; | ||
|
|
||
| import org.apache.spark.sql.Dataset; | ||
| import org.apache.spark.sql.Row; | ||
| import org.apache.spark.sql.catalyst.InternalRow; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.Arguments; | ||
|
|
@@ -109,6 +112,51 @@ public void testDataInternalWriter(boolean sorted, boolean populateMetaFields) t | |
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testDataInternalWriterHiveStylePartitioning() throws Exception { | ||
| boolean sorted = true; | ||
| boolean populateMetaFields = false; | ||
| // init config and table | ||
| HoodieWriteConfig cfg = getWriteConfig(populateMetaFields, "true"); | ||
| HoodieTable table = HoodieSparkTable.create(cfg, context, metaClient); | ||
| for (int i = 0; i < 1; i++) { | ||
| String instantTime = "00" + i; | ||
| // init writer | ||
| HoodieBulkInsertDataInternalWriter writer = new HoodieBulkInsertDataInternalWriter(table, cfg, instantTime, RANDOM.nextInt(100000), RANDOM.nextLong(), RANDOM.nextLong(), | ||
|
Contributor
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. Is this RANDOM a fixed-seed one? |
||
| STRUCT_TYPE, populateMetaFields, sorted); | ||
|
|
||
| int size = 10 + RANDOM.nextInt(1000); | ||
| // write N rows to partition1, N rows to partition2 and N rows to partition3 ... Each batch should create a new RowCreateHandle and a new file | ||
| int batches = 3; | ||
| Dataset<Row> totalInputRows = null; | ||
|
|
||
| for (int j = 0; j < batches; j++) { | ||
| String partitionPath = HoodieTestDataGenerator.DEFAULT_PARTITION_PATHS[j % 3]; | ||
| Dataset<Row> inputRows = getRandomRows(sqlContext, size, partitionPath, false); | ||
| writeRows(inputRows, writer); | ||
| if (totalInputRows == null) { | ||
| totalInputRows = inputRows; | ||
| } else { | ||
| totalInputRows = totalInputRows.union(inputRows); | ||
| } | ||
| } | ||
|
|
||
| BaseWriterCommitMessage commitMetadata = (BaseWriterCommitMessage) writer.commit(); | ||
| Option<List<String>> fileAbsPaths = Option.of(new ArrayList<>()); | ||
| Option<List<String>> fileNames = Option.of(new ArrayList<>()); | ||
|
|
||
| // verify write statuses | ||
| assertWriteStatuses(commitMetadata.getWriteStatuses(), batches, size, sorted, fileAbsPaths, fileNames); | ||
|
|
||
| // verify rows | ||
| Dataset<Row> result = sqlContext.read().parquet(fileAbsPaths.get().toArray(new String[0])); | ||
| assertOutput(totalInputRows, result, instantTime, fileNames, populateMetaFields); | ||
nsivabalan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| result.collectAsList().forEach(entry -> Assertions.assertTrue(entry.getAs(HoodieRecord.PARTITION_PATH_METADATA_FIELD).toString() | ||
| .contains(SparkDatasetTestUtils.PARTITION_PATH_FIELD_NAME + "="))); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Issue some corrupted or wrong schematized InternalRow after few valid InternalRows so that global error is thrown. write batch 1 of valid records write batch2 of invalid records which is expected | ||
| * to throw Global Error. Verify global error is set appropriately and only first batch of records are written to disk. | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.