Copilot commented on code in PR #9322:
URL: https://github.com/apache/seatunnel/pull/9322#discussion_r2094790706


##########
seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/psql/PostgresTypeConverter.java:
##########
@@ -103,6 +103,7 @@ public class PostgresTypeConverter implements 
TypeConverter<BasicTypeDefine> {
     public static final String PG_TIMESTAMP = "timestamp";
     // timestamp with time zone <=> timestamptz
     public static final String PG_TIMESTAMP_TZ = "timestamptz";

Review Comment:
   Consider adding a Javadoc comment to explain the new `PG_HSTORE` constant 
and its usage in type conversion.
   ```suggestion
       public static final String PG_TIMESTAMP_TZ = "timestamptz";
       /**
        * Represents the PostgreSQL `hstore` data type, which is used for 
storing sets of key-value pairs.
        * This type is commonly used for semi-structured data in PostgreSQL.
        */
   ```



##########
seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/psql/PostgresJdbcRowConverter.java:
##########
@@ -78,6 +85,26 @@ public SeaTunnelRow toInternal(ResultSet rs, TableSchema 
tableSchema) throws SQL
                                 rs.getObject(resultSetIndex) == null
                                         ? null
                                         : 
rs.getObject(resultSetIndex).toString();
+                    } else if (metaDataColumnType.equals(PG_HSTORE)) {
+                        try {
+                            Object value = rs.getObject(resultSetIndex);
+                            if (value == null) {
+                                fields[fieldIndex] = null;
+                            } else if (value instanceof PGobject) {
+                                PGobject pgObject = (PGobject) value;
+                                fields[fieldIndex] =
+                                        OBJECT_MAPPER.writeValueAsString(
+                                                
HStoreConverter.fromString(pgObject.getValue()));
+                            } else if (value instanceof Map) {
+                                Map map = (Map<String, String>) value;
+                                fields[fieldIndex] = 
OBJECT_MAPPER.writeValueAsString(map);
+                            } else {
+                                throw new SQLException(
+                                        "Unexpected HSTORE type: " + 
value.getClass().getName());
+                            }
+                        } catch (JsonProcessingException e) {
+                            throw new SQLException("Convert HSTORE to JSON 
failed", e);

Review Comment:
   Enhance the exception message to include context (e.g. the HStore value or 
column name) to aid debugging.
   ```suggestion
                               String columnName = 
rs.getMetaData().getColumnName(resultSetIndex);
                               String hstoreValue = value instanceof PGobject ? 
((PGobject) value).getValue() : value.toString();
                               throw new SQLException(
                                       String.format(
                                               "Convert HSTORE to JSON failed 
for column '%s' with value '%s'",
                                               columnName,
                                               hstoreValue),
                                       e);
   ```



##########
seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/psql/PostgresJdbcRowConverter.java:
##########
@@ -78,6 +85,26 @@ public SeaTunnelRow toInternal(ResultSet rs, TableSchema 
tableSchema) throws SQL
                                 rs.getObject(resultSetIndex) == null
                                         ? null
                                         : 
rs.getObject(resultSetIndex).toString();
+                    } else if (metaDataColumnType.equals(PG_HSTORE)) {
+                        try {
+                            Object value = rs.getObject(resultSetIndex);
+                            if (value == null) {
+                                fields[fieldIndex] = null;
+                            } else if (value instanceof PGobject) {
+                                PGobject pgObject = (PGobject) value;
+                                fields[fieldIndex] =
+                                        OBJECT_MAPPER.writeValueAsString(
+                                                
HStoreConverter.fromString(pgObject.getValue()));
+                            } else if (value instanceof Map) {
+                                Map map = (Map<String, String>) value;

Review Comment:
   [nitpick] Use a parameterized local variable (e.g. `Map<String, String> 
hstoreMap`) instead of a raw `Map` to avoid unchecked cast warnings.
   ```suggestion
                                   Map<String, String> map = (Map<String, 
String>) value;
   ```



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