Skip to content

Commit e666415

Browse files
authored
[HUDI-7163] Fix not parsable text DateTimeParseException when compact (#10220)
1 parent e2dfb46 commit e666415

File tree

2 files changed

+19
-30
lines changed

2 files changed

+19
-30
lines changed

hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/action/compact/ScheduleCompactionActionExecutor.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import javax.annotation.Nullable;
4646

4747
import java.io.IOException;
48-
import java.text.ParseException;
4948
import java.util.Map;
5049

5150
import static org.apache.hudi.common.util.CollectionUtils.nonEmpty;
@@ -211,12 +210,7 @@ private boolean needCompact(CompactionTriggerStrategy compactionTriggerStrategy)
211210
}
212211

213212
private Long parsedToSeconds(String time) {
214-
long timestamp;
215-
try {
216-
timestamp = HoodieActiveTimeline.parseDateFromInstantTime(time).getTime() / 1000;
217-
} catch (ParseException e) {
218-
throw new HoodieCompactionException(e.getMessage(), e);
219-
}
220-
return timestamp;
213+
return HoodieActiveTimeline.parseDateFromInstantTimeSafely(time).orElseThrow(() -> new HoodieCompactionException("Failed to parse timestamp " + time))
214+
.getTime() / 1000;
221215
}
222216
}

hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/util/StreamerUtil.java

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
import java.io.BufferedReader;
7070
import java.io.IOException;
7171
import java.io.StringReader;
72-
import java.text.ParseException;
7372
import java.util.ArrayList;
7473
import java.util.Collections;
7574
import java.util.Date;
@@ -380,34 +379,30 @@ public static Option<HoodieTableConfig> getTableConfig(String basePath, org.apac
380379
* Returns the median instant time between the given two instant time.
381380
*/
382381
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();
397393
}
394+
return Option.of(instantTime);
398395
}
399396

400397
/**
401398
* Returns the time interval in seconds between the given instant time.
402399
*/
403400
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;
411406
}
412407

413408
public static Option<Transformer> createTransformer(List<String> classNames) throws IOException {

0 commit comments

Comments
 (0)