garyli1019 commented on a change in pull request #3221:
URL: https://github.com/apache/hudi/pull/3221#discussion_r663662255
##########
File path: hudi-flink/src/main/java/org/apache/hudi/util/StreamerUtil.java
##########
@@ -265,16 +268,26 @@ public static HoodieFlinkWriteClient
createWriteClient(Configuration conf, Runti
* Return the median instant time between the given two instant time.
*/
public static String medianInstantTime(String highVal, String lowVal) {
- long high = Long.parseLong(highVal);
- long low = Long.parseLong(lowVal);
- long median = low + (high - low) / 2;
- return String.valueOf(median);
+ try {
+ long high =
HoodieActiveTimeline.COMMIT_FORMATTER.parse(highVal).getTime();
+ long low = HoodieActiveTimeline.COMMIT_FORMATTER.parse(lowVal).getTime();
+ long median = low + (high - low) / 2;
+ return HoodieActiveTimeline.COMMIT_FORMATTER.format(new Date(median));
+ } catch (ParseException e) {
+ throw new HoodieException("Get median instant time with interval [" +
lowVal + ", " + highVal + "] error", e);
+ }
}
/**
* Returns the time interval in seconds between the given instant time.
*/
public static long instantTimeDiff(String newInstantTime, String
oldInstantTime) {
Review comment:
`instantTimeDiffInSesond`?
##########
File path: hudi-flink/src/test/java/org/apache/hudi/utils/TestStreamerUtil.java
##########
@@ -70,5 +74,24 @@ public void testInitTableIfNotExists() throws IOException {
.build();
assertFalse(metaClient2.getTableConfig().getPartitionColumns().isPresent());
}
+
+ @Test
+ void testMedianInstantTime() {
+ String higher = "20210705125921";
+ String lower = "20210705125806";
+ String median1 = StreamerUtil.medianInstantTime(higher, lower);
+ assertThat(median1, is("20210705125843"));
+ // test symmetry
+ String median2 = StreamerUtil.medianInstantTime(lower, higher);
Review comment:
If the order is reversed, I think we should throw an error? Otherwise,
this may hide a bug
--
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]