|
69 | 69 | import java.io.BufferedReader;
|
70 | 70 | import java.io.IOException;
|
71 | 71 | import java.io.StringReader;
|
72 |
| -import java.text.ParseException; |
73 | 72 | import java.util.ArrayList;
|
74 | 73 | import java.util.Collections;
|
75 | 74 | import java.util.Date;
|
@@ -380,34 +379,30 @@ public static Option<HoodieTableConfig> getTableConfig(String basePath, org.apac
|
380 | 379 | * Returns the median instant time between the given two instant time.
|
381 | 380 | */
|
382 | 381 | public static Option<String> medianInstantTime(String highVal, String lowVal) {
|
383 |
| - try { |
384 |
| - long high = HoodieActiveTimeline.parseDateFromInstantTime(highVal).getTime(); |
385 |
| - long low = HoodieActiveTimeline.parseDateFromInstantTime(lowVal).getTime(); |
386 |
| - ValidationUtils.checkArgument(high > low, |
387 |
| - "Instant [" + highVal + "] should have newer timestamp than instant [" + lowVal + "]"); |
388 |
| - long median = low + (high - low) / 2; |
389 |
| - final String instantTime = HoodieActiveTimeline.formatDate(new Date(median)); |
390 |
| - if (HoodieTimeline.compareTimestamps(lowVal, HoodieTimeline.GREATER_THAN_OR_EQUALS, instantTime) |
391 |
| - || HoodieTimeline.compareTimestamps(highVal, HoodieTimeline.LESSER_THAN_OR_EQUALS, instantTime)) { |
392 |
| - return Option.empty(); |
393 |
| - } |
394 |
| - return Option.of(instantTime); |
395 |
| - } catch (ParseException e) { |
396 |
| - throw new HoodieException("Get median instant time with interval [" + lowVal + ", " + highVal + "] error", e); |
| 382 | + long high = HoodieActiveTimeline.parseDateFromInstantTimeSafely(highVal) |
| 383 | + .orElseThrow(() -> new HoodieException("Get instant time diff with interval [" + highVal + "] error")).getTime(); |
| 384 | + long low = HoodieActiveTimeline.parseDateFromInstantTimeSafely(lowVal) |
| 385 | + .orElseThrow(() -> new HoodieException("Get instant time diff with interval [" + lowVal + "] error")).getTime(); |
| 386 | + ValidationUtils.checkArgument(high > low, |
| 387 | + "Instant [" + highVal + "] should have newer timestamp than instant [" + lowVal + "]"); |
| 388 | + long median = low + (high - low) / 2; |
| 389 | + final String instantTime = HoodieActiveTimeline.formatDate(new Date(median)); |
| 390 | + if (HoodieTimeline.compareTimestamps(lowVal, HoodieTimeline.GREATER_THAN_OR_EQUALS, instantTime) |
| 391 | + || HoodieTimeline.compareTimestamps(highVal, HoodieTimeline.LESSER_THAN_OR_EQUALS, instantTime)) { |
| 392 | + return Option.empty(); |
397 | 393 | }
|
| 394 | + return Option.of(instantTime); |
398 | 395 | }
|
399 | 396 |
|
400 | 397 | /**
|
401 | 398 | * Returns the time interval in seconds between the given instant time.
|
402 | 399 | */
|
403 | 400 | public static long instantTimeDiffSeconds(String newInstantTime, String oldInstantTime) {
|
404 |
| - try { |
405 |
| - long newTimestamp = HoodieActiveTimeline.parseDateFromInstantTime(newInstantTime).getTime(); |
406 |
| - long oldTimestamp = HoodieActiveTimeline.parseDateFromInstantTime(oldInstantTime).getTime(); |
407 |
| - return (newTimestamp - oldTimestamp) / 1000; |
408 |
| - } catch (ParseException e) { |
409 |
| - throw new HoodieException("Get instant time diff with interval [" + oldInstantTime + ", " + newInstantTime + "] error", e); |
410 |
| - } |
| 401 | + long newTimestamp = HoodieActiveTimeline.parseDateFromInstantTimeSafely(newInstantTime) |
| 402 | + .orElseThrow(() -> new HoodieException("Get instant time diff with interval [" + oldInstantTime + ", " + newInstantTime + "] error")).getTime(); |
| 403 | + long oldTimestamp = HoodieActiveTimeline.parseDateFromInstantTimeSafely(oldInstantTime) |
| 404 | + .orElseThrow(() -> new HoodieException("Get instant time diff with interval [" + oldInstantTime + ", " + newInstantTime + "] error")).getTime(); |
| 405 | + return (newTimestamp - oldTimestamp) / 1000; |
411 | 406 | }
|
412 | 407 |
|
413 | 408 | public static Option<Transformer> createTransformer(List<String> classNames) throws IOException {
|
|
0 commit comments