yzeng1618 commented on code in PR #10048:
URL: https://github.com/apache/seatunnel/pull/10048#discussion_r2555267491
##########
seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/utils/JdbcFieldTypeUtils.java:
##########
@@ -95,12 +100,109 @@ public static byte[] getBytes(ResultSet resultSet, int
columnIndex) throws SQLEx
return resultSet.getBytes(columnIndex);
}
+ public static OffsetDateTime getOffsetDateTime(ResultSet resultSet, int
columnIndex)
+ throws SQLException {
+ final Object obj = resultSet.getObject(columnIndex);
+ if (obj == null) {
+ return null;
+ }
+
+ // Handle OffsetDateTime directly
+ if (obj instanceof OffsetDateTime) {
+ return (OffsetDateTime) obj;
+ }
+
+ // Handle ZonedDateTime
+ if (obj instanceof ZonedDateTime) {
+ return ((ZonedDateTime) obj).toOffsetDateTime();
+ }
+
+ // Handle Instant
+ if (obj instanceof Instant) {
+ return ((Instant) obj).atOffset(ZoneOffset.UTC);
+ }
+
+ // Handle java.sql.Timestamp
+ if (obj instanceof Timestamp) {
+ return ((Timestamp)
obj).toLocalDateTime().atOffset(ZoneOffset.UTC);
+ }
+
+ // Handle java.util.Date
+ if (obj instanceof java.util.Date) {
+ return ((java.util.Date) obj).toInstant().atOffset(ZoneOffset.UTC);
+ }
+
+ // Handle Long (epoch milliseconds)
+ if (obj instanceof Long) {
+ return Instant.ofEpochMilli((Long) obj).atOffset(ZoneOffset.UTC);
+ }
+
+ // Try to parse as string
+ String str = obj.toString();
+ try {
+ return parseOffsetDateTimeFromString(str);
+ } catch (Exception e) {
+ throw new SQLException(
+ "Failed to parse OffsetDateTime value: "
+ + str
+ + " (class: "
+ + obj.getClass().getName()
+ + ")",
+ e);
+ }
+ }
+
+ public static OffsetDateTime parseOffsetDateTimeFromString(String str)
+ throws DateTimeParseException {
+ if (str == null || str.trim().isEmpty()) {
Review Comment:
The explicit str == null check is removed
--
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]