nsivabalan commented on code in PR #8605:
URL: https://github.com/apache/hudi/pull/8605#discussion_r1186572034
##########
hudi-client/hudi-spark-client/src/test/java/org/apache/hudi/client/functional/TestHoodieIndex.java:
##########
@@ -587,6 +594,43 @@ public void
testSimpleGlobalIndexTagLocationWhenShouldUpdatePartitionPath() thro
assertEquals(incomingPayloadSamePartition.getJsonData(),
((RawTripTestPayload) record.getData()).getJsonData());
}
+ @Test
+ public void testCheckIfValidCommit() throws Exception {
+ setUp(IndexType.BLOOM, true, false);
+
+ // When timeline is empty, all commits are invalid
+ HoodieTimeline timeline = new
HoodieDefaultTimeline(Collections.EMPTY_LIST.stream(),
metaClient.getActiveTimeline()::getInstantDetails);
+ assertTrue(timeline.empty());
+ assertFalse(HoodieIndexUtils.checkIfValidCommit(timeline, "001"));
+ assertFalse(HoodieIndexUtils.checkIfValidCommit(timeline,
HoodieActiveTimeline.createNewInstantTime()));
+ assertFalse(HoodieIndexUtils.checkIfValidCommit(timeline,
HoodieTableMetadata.SOLO_COMMIT_TIMESTAMP));
+
+ // Valid when timeline contains the timestamp or the timestamp is before
timeline start
+ final HoodieInstant instant1 = new HoodieInstant(false,
HoodieTimeline.DELTA_COMMIT_ACTION, "010");
+ String instantTimestamp = HoodieActiveTimeline.createNewInstantTime();
+ final HoodieInstant instant2 = new HoodieInstant(false,
HoodieTimeline.DELTA_COMMIT_ACTION,
HoodieActiveTimeline.createNewInstantTime());
+ timeline = new HoodieDefaultTimeline(Arrays.asList(instant1,
instant2).stream(), metaClient.getActiveTimeline()::getInstantDetails);
+ assertFalse(timeline.empty());
+ assertTrue(HoodieIndexUtils.checkIfValidCommit(timeline,
instant1.getTimestamp()));
+ assertTrue(HoodieIndexUtils.checkIfValidCommit(timeline,
instant2.getTimestamp()));
+ // no instant on timeline
+ assertFalse(HoodieIndexUtils.checkIfValidCommit(timeline,
instantTimestamp));
+ // future timestamp
+ assertFalse(HoodieIndexUtils.checkIfValidCommit(timeline,
HoodieActiveTimeline.createNewInstantTime()));
+ // timestamp before timeline starts
+ assertTrue(HoodieIndexUtils.checkIfValidCommit(timeline, "001"));
+ assertTrue(HoodieIndexUtils.checkIfValidCommit(timeline,
HoodieTableMetadata.SOLO_COMMIT_TIMESTAMP));
+
+ // Check for older timestamp which have sec granularity and an extension
of DEFAULT_MILLIS_EXT may have been added via Timeline operations
+ instantTimestamp = HoodieActiveTimeline.createNewInstantTime();
+ final String instanceTimestampSec = instantTimestamp.substring(0,
instantTimestamp.length() -
HoodieInstantTimeGenerator.DEFAULT_MILLIS_EXT.length());
+ final HoodieInstant instant3 = new HoodieInstant(false,
HoodieTimeline.DELTA_COMMIT_ACTION, instanceTimestampSec);
+ timeline = new HoodieDefaultTimeline(Arrays.asList(instant1,
instant3).stream(), metaClient.getActiveTimeline()::getInstantDetails);
+ assertFalse(timeline.empty());
+ assertFalse(HoodieIndexUtils.checkIfValidCommit(timeline,
instantTimestamp));
Review Comment:
minor.
can we add couple of more cases.
a. generate a sec format instant time and checkIfValid should return false
assuming its > first entry in the active timeline. CheckifContainsOrBefore()
should return false.
b. generate a sec format instant time lesser than first entry in the active
timeline. CheckifContainsOrBefore() should return true
--
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]