ic4y commented on code in PR #4673: URL: https://github.com/apache/incubator-seatunnel/pull/4673#discussion_r1184519290
########## seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/psql/PostgresJdbcRowConverter.java: ########## @@ -17,11 +17,108 @@ package org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.psql; +import org.apache.seatunnel.api.table.type.SeaTunnelDataType; +import org.apache.seatunnel.api.table.type.SeaTunnelRow; +import org.apache.seatunnel.api.table.type.SeaTunnelRowType; +import org.apache.seatunnel.common.exception.CommonErrorCode; +import org.apache.seatunnel.connectors.seatunnel.jdbc.exception.JdbcConnectorException; import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.converter.AbstractJdbcRowConverter; +import org.postgis.PGgeography; +import org.postgis.PGgeometry; + +import java.sql.Date; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Time; +import java.sql.Timestamp; +import java.util.Optional; + public class PostgresJdbcRowConverter extends AbstractJdbcRowConverter { + + private static final String PG_GEOMETRY = "geometry"; + private static final String PG_GEOGRAPHY = "geography"; + @Override public String converterName() { return null; } + + @Override + @SuppressWarnings("checkstyle:Indentation") + public SeaTunnelRow toInternal(ResultSet rs, SeaTunnelRowType typeInfo) throws SQLException { + Object[] fields = new Object[typeInfo.getTotalFields()]; + for (int fieldIndex = 0; fieldIndex < typeInfo.getTotalFields(); fieldIndex++) { + SeaTunnelDataType<?> seaTunnelDataType = typeInfo.getFieldType(fieldIndex); + int resultSetIndex = fieldIndex + 1; + String metaDataColumnType = rs.getMetaData().getColumnTypeName(resultSetIndex); + Object columnObj = rs.getObject(resultSetIndex); + switch (seaTunnelDataType.getSqlType()) { + case STRING: + if (metaDataColumnType.equals(PG_GEOMETRY)) { + fields[fieldIndex] = ((PGgeometry) columnObj).getValue(); Review Comment: Suggest using the method `rs.getObject(resultSetIndex).toString()`, because this way it won't throw an error when the postgis package is not imported (you will get a string of numbers), and you can also get the desired data when the postgis package is imported. like ``` case STRING: String columnTypeName = metaData.getColumnTypeName(resultSetIndex).toUpperCase(Locale.ROOT); if (columnTypeName.equals("GEOGRAPHY") || columnTypeName.equals("GEOMETRY")) { fields[fieldIndex] = rs.getObject(resultSetIndex) == null ? null : rs.getObject(resultSetIndex).toString(); break; } fields[fieldIndex] = rs.getString(resultSetIndex); break; ``` -- 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: commits-unsubscr...@seatunnel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org