yzeng1618 commented on code in PR #10048:
URL: https://github.com/apache/seatunnel/pull/10048#discussion_r2555269817


##########
seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/psql/PostgresJdbcRowConverter.java:
##########
@@ -316,4 +348,123 @@ public String microsecondsToIntervalFormatVal(String 
intervalVal) {
         if (seconds > 0) sb.append(seconds).append(" seconds");
         return sb.toString().trim();
     }
+
+    private OffsetDateTime getPostgresOffsetDateTime(ResultSet rs, int 
columnIndex)
+            throws SQLException {
+        // Read the value once to avoid drivers returning null on subsequent 
reads
+        final Object obj = rs.getObject(columnIndex);
+
+        if (obj == null) {
+            return null;
+        }
+
+        // Direct types
+        if (obj instanceof OffsetDateTime) {
+            return (OffsetDateTime) obj;
+        }
+        if (obj instanceof Timestamp) {
+            return ((Timestamp) obj).toInstant().atOffset(ZoneOffset.UTC);
+        }
+        if (obj instanceof java.time.ZonedDateTime) {
+            return ((java.time.ZonedDateTime) obj).toOffsetDateTime();
+        }
+        if (obj instanceof java.util.Date) {
+            return ((java.util.Date) obj).toInstant().atOffset(ZoneOffset.UTC);
+        }
+
+        // PostgreSQL specific objects (e.g., PGobject) or any 
org.postgresql.* class
+        final String className = obj.getClass().getName();
+        if (className.startsWith("org.postgresql.")) {
+            String str = null;
+            try {
+                str = obj.toString();
+            } catch (Exception e) {
+                log.debug("Failed to get PostgreSQL timestamp object string 
representation", e);
+            }
+            if (str != null) {
+                OffsetDateTime parsed = parseTimestampIfPresent(str);
+                if (parsed != null) {
+                    return parsed;
+                }
+            }
+        }
+
+        // String-like values
+        if (obj instanceof CharSequence) {
+            return parseTimestampIfPresent(obj.toString());
+        }
+
+        // Last resort: attempt to parse from toString() representation
+        final String str;
+        try {
+            str = String.valueOf(obj);
+        } catch (Throwable ignore) {
+            return null;
+        }
+        return parseTimestampIfPresent(str);
+    }
+
+    private OffsetDateTime parseTimestampIfPresent(String str) throws 
SQLException {
+        if (str == null) {
+            return null;
+        }
+        return parsePostgresTimestampTz(str);
+    }
+
+    private OffsetDateTime parsePostgresTimestampTz(String str) throws 
SQLException {
+        String normalized = normalizeIsoTimestamp(str);
+        if (normalized == null) {
+            return null;
+        }
+
+        try {
+            return OffsetDateTime.parse(normalized);

Review Comment:
   normalizeIsoTimestamp only normalizes common patterns and cannot guarantee 
every input is valid ISO_OFFSET_DATE_TIME, so the OffsetDateTime.parse 
try/catch plus the fallback via Timestamp.valueOf is kept to handle unexpected 
formats.



-- 
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]

Reply via email to