in src/main/java/com/aliyun/odps/jdbc/utils/transformer/to/jdbc/ToJdbcDateTransformer.java [52:91]
public Object transform(
Object o,
String charset,
Calendar cal,
TimeZone timeZone) throws SQLException {
if (o == null) {
return null;
}
try {
if (o instanceof byte[]) {
String str = encodeBytes((byte[]) o, charset);
// convert to local date
o = RecordConverterCache.get(timeZone).parseObject(str, TypeInfoFactory.DATE);
}
if (o instanceof Binary) {
String str = encodeBytes(((Binary) o).data(), charset);
// convert to local date
o = RecordConverterCache.get(timeZone).parseObject(str, TypeInfoFactory.DATE);
}
if (o instanceof LocalDate) {
return TimeUtils.getDate(java.sql.Date.valueOf((LocalDate) o), timeZone);
} else if (o instanceof ZonedDateTime) {
Date date = Date.valueOf(((ZonedDateTime) o).toLocalDate());
return TimeUtils.getDate(date, timeZone);
} else if (o instanceof Instant) {
return TimeUtils.getDate((Instant) o, timeZone);
} else if (o instanceof LocalDateTime) {
Date date = Date.valueOf(((LocalDateTime) o).toLocalDate());
return TimeUtils.getDate(date, timeZone);
} else {
String errorMsg = getInvalidTransformationErrorMsg(o.getClass(), Date.class);
throw new SQLException(errorMsg);
}
} catch (SQLException e) {
throw e;
} catch (Exception e) {
String errorMsg = getTransformationErrMsg(Objects.toString(o), Date.class, e.getMessage());
throw new SQLException(errorMsg, e);
}
}