[HUDI-2769] Fix StreamerUtil#medianInstantTime for very near instant time (#4005)
This commit is contained in:
@@ -33,6 +33,7 @@ import org.apache.hudi.common.table.HoodieTableMetaClient;
|
||||
import org.apache.hudi.common.table.log.HoodieLogFormat;
|
||||
import org.apache.hudi.common.table.timeline.HoodieActiveTimeline;
|
||||
import org.apache.hudi.common.table.timeline.HoodieInstant;
|
||||
import org.apache.hudi.common.table.timeline.HoodieTimeline;
|
||||
import org.apache.hudi.common.table.view.FileSystemViewStorageConfig;
|
||||
import org.apache.hudi.common.util.Option;
|
||||
import org.apache.hudi.common.util.ReflectionUtils;
|
||||
@@ -414,7 +415,12 @@ public class StreamerUtil {
|
||||
ValidationUtils.checkArgument(high > low,
|
||||
"Instant [" + highVal + "] should have newer timestamp than instant [" + lowVal + "]");
|
||||
long median = low + (high - low) / 2;
|
||||
return low >= median ? Option.empty() : Option.of(HoodieActiveTimeline.formatInstantTime(new Date(median)));
|
||||
final String instantTime = HoodieActiveTimeline.formatInstantTime(new Date(median));
|
||||
if (HoodieTimeline.compareTimestamps(lowVal, HoodieTimeline.GREATER_THAN_OR_EQUALS, instantTime)
|
||||
|| HoodieTimeline.compareTimestamps(highVal, HoodieTimeline.LESSER_THAN_OR_EQUALS, instantTime)) {
|
||||
return Option.empty();
|
||||
}
|
||||
return Option.of(instantTime);
|
||||
} catch (ParseException e) {
|
||||
throw new HoodieException("Get median instant time with interval [" + lowVal + ", " + highVal + "] error", e);
|
||||
}
|
||||
|
||||
@@ -86,6 +86,8 @@ public class TestStreamerUtil {
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> StreamerUtil.medianInstantTime(lower, higher),
|
||||
"The first argument should have newer instant time");
|
||||
// test very near instant time
|
||||
assertFalse(StreamerUtil.medianInstantTime("20211116115634", "20211116115633").isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user