-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[HUDI-5394] Fix tests for RowCustomColumnsSortPartitioner #8741
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,7 +55,7 @@ | |
| */ | ||
| public class TestBulkInsertInternalPartitionerForRows extends HoodieClientTestHarness { | ||
|
|
||
| private static final Comparator<Row> KEY_COMPARATOR = | ||
| private static final Comparator<Row> DEFAULT_KEY_COMPARATOR = | ||
| Comparator.comparing(o -> (o.getAs(HoodieRecord.PARTITION_PATH_METADATA_FIELD) + "+" + o.getAs(HoodieRecord.RECORD_KEY_METADATA_FIELD))); | ||
|
|
||
| @BeforeEach | ||
|
|
@@ -103,8 +103,7 @@ public void testBulkInsertInternalPartitioner(BulkInsertSortMode sortMode, | |
| boolean isGloballySorted, | ||
| boolean isLocallySorted, | ||
| boolean populateMetaFields) { | ||
| Dataset<Row> records1 = generateTestRecords(); | ||
| Dataset<Row> records2 = generateTestRecords(); | ||
| Dataset<Row> records = generateTestRecords(); | ||
|
|
||
| HoodieWriteConfig config = HoodieWriteConfig | ||
| .newBuilder() | ||
|
|
@@ -116,36 +115,24 @@ public void testBulkInsertInternalPartitioner(BulkInsertSortMode sortMode, | |
|
|
||
| testBulkInsertInternalPartitioner( | ||
| BulkInsertInternalPartitionerWithRowsFactory.get(config, isTablePartitioned, enforceNumOutputPartitions), | ||
| records1, | ||
| records, | ||
| enforceNumOutputPartitions, | ||
| isGloballySorted, | ||
| isLocallySorted, | ||
| generateExpectedPartitionNumRecords(records1), | ||
| Option.empty(), | ||
| populateMetaFields); | ||
| testBulkInsertInternalPartitioner( | ||
| BulkInsertInternalPartitionerWithRowsFactory.get(config, isTablePartitioned, enforceNumOutputPartitions), | ||
| records2, | ||
| enforceNumOutputPartitions, | ||
| isGloballySorted, | ||
| isLocallySorted, | ||
| generateExpectedPartitionNumRecords(records2), | ||
| generateExpectedPartitionNumRecords(records), | ||
| Option.empty(), | ||
| populateMetaFields); | ||
| } | ||
|
|
||
| @Test | ||
| public void testCustomColumnSortPartitionerWithRows() { | ||
| Dataset<Row> records1 = generateTestRecords(); | ||
| Dataset<Row> records2 = generateTestRecords(); | ||
| String sortColumnString = records1.columns()[5]; | ||
| Dataset<Row> records = generateTestRecords(); | ||
| String sortColumnString = records.columns()[5]; | ||
| String[] sortColumns = sortColumnString.split(","); | ||
| Comparator<Row> comparator = getCustomColumnComparator(sortColumns); | ||
|
|
||
| testBulkInsertInternalPartitioner(new RowCustomColumnsSortPartitioner(sortColumns), | ||
| records1, true, false, true, generateExpectedPartitionNumRecords(records1), Option.of(comparator), true); | ||
| testBulkInsertInternalPartitioner(new RowCustomColumnsSortPartitioner(sortColumns), | ||
| records2, true, false, true, generateExpectedPartitionNumRecords(records2), Option.of(comparator), true); | ||
| records, true, true, true, generateExpectedPartitionNumRecords(records), Option.of(comparator), true); | ||
|
Comment on lines
-148
to
+135
Member
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. the existing test treated the partitioner as non-global and hence failed the test scenario under spark 3.2 |
||
|
|
||
| HoodieWriteConfig config = HoodieWriteConfig | ||
| .newBuilder() | ||
|
|
@@ -154,9 +141,7 @@ public void testCustomColumnSortPartitionerWithRows() { | |
| .withUserDefinedBulkInsertPartitionerSortColumns(sortColumnString) | ||
| .build(); | ||
| testBulkInsertInternalPartitioner(new RowCustomColumnsSortPartitioner(config), | ||
| records1, true, false, true, generateExpectedPartitionNumRecords(records1), Option.of(comparator), true); | ||
| testBulkInsertInternalPartitioner(new RowCustomColumnsSortPartitioner(config), | ||
| records2, true, false, true, generateExpectedPartitionNumRecords(records2), Option.of(comparator), true); | ||
| records, true, true, true, generateExpectedPartitionNumRecords(records), Option.of(comparator), true); | ||
| } | ||
|
|
||
| private void testBulkInsertInternalPartitioner(BulkInsertPartitioner partitioner, | ||
|
|
@@ -227,13 +212,13 @@ public Dataset<Row> generateTestRecords() { | |
|
|
||
| private void verifyRowsAscendingOrder(List<Row> records, Option<Comparator<Row>> comparator) { | ||
| List<Row> expectedRecords = new ArrayList<>(records); | ||
| Collections.sort(expectedRecords, comparator.orElse(KEY_COMPARATOR)); | ||
| Collections.sort(expectedRecords, comparator.orElse(DEFAULT_KEY_COMPARATOR)); | ||
| assertEquals(expectedRecords, records); | ||
| } | ||
|
|
||
| private Comparator<Row> getCustomColumnComparator(String[] sortColumns) { | ||
| Comparator<Row> comparator = Comparator.comparing(row -> { | ||
| StringBuilder sb = new StringBuilder(); | ||
| StringBuilder sb = new StringBuilder(row.getAs(HoodieRecord.PARTITION_PATH_METADATA_FIELD)); | ||
| for (String col : sortColumns) { | ||
| sb.append(row.getAs(col).toString()); | ||
| } | ||
|
|
||
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.
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.
not sure why the existing test case runs the same logic twice with
records1andrecords2. @boneanxs any thoughts?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.
testCustomColumnSortPartitionerWithRowswas copied fromtestBulkInsertInternalPartitioner. And I lookedorg.apache.hudi.execution.bulkinsert.TestBulkInsertInternalPartitioner#testBulkInsertInternalPartitioner:177, it actually generates two records sets with different union times:So I think this should be a mistake, and I think union it twice should be enough(Here different union times for different partitions?)
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.
There is no change for any codes in the write path, so why the tests run successfully for Spark 3.1 or 2.4 ?
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.
the test only passes spark 2.4 which is an coincident. The existing test logic asserts 2 rdd partitions after re-partition by the partitioner. with spark 2.4's sort and coalesce, it gives 2 and passes the test as a local partitioner. The correct expectation is the partitioner is doing global sort and the resulting num partition should be 2 or less, which is what spark 3 gives us.