in hugegraph-loader/src/main/java/org/apache/hugegraph/loader/util/DataTypeUtil.java [154:210]
private static Date parseDate(String key, InputSource source, Object value) {
List<String> extraDateFormats = null;
String dateFormat = null;
String timeZone = null;
switch (source.type()) {
case KAFKA:
KafkaSource kafkaSource = (KafkaSource) source;
extraDateFormats = kafkaSource.getExtraDateFormats();
dateFormat = kafkaSource.getDateFormat();
timeZone = kafkaSource.getTimeZone();
break;
case JDBC:
/*
* Warn: it uses system default timezone,
* should we think a better way to compatible differ timezone people?
*/
long timestamp = 0L;
if (value instanceof Date) {
timestamp = ((Date) value).getTime();
} else if (value instanceof LocalDateTime) {
timestamp = ((LocalDateTime) value).atZone(ZoneId.systemDefault())
.toInstant()
.toEpochMilli();
}
value = new Date(timestamp);
break;
case HDFS:
case FILE:
FileSource fileSource = (FileSource) source;
dateFormat = fileSource.dateFormat();
timeZone = fileSource.timeZone();
break;
default:
throw new IllegalArgumentException("Date format source " +
source.getClass().getName() + " not supported");
}
if (extraDateFormats == null || extraDateFormats.isEmpty()) {
return parseDate(key, value, dateFormat, timeZone);
}
Set<String> allDateFormats = new HashSet<>(extraDateFormats);
allDateFormats.add(dateFormat);
int size = allDateFormats.size();
for (String df : allDateFormats) {
try {
return parseDate(key, value, df, timeZone);
} catch (Exception e) {
if (--size <= 0) {
throw e;
}
}
}
return parseDate(key, value, dateFormat, timeZone);
}