You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by "zhilinli123 (via GitHub)" <gi...@apache.org> on 2023/04/25 16:19:24 UTC

[GitHub] [incubator-seatunnel] zhilinli123 opened a new pull request, #4673: [Feature][PostgreSQL-jdbc] Supports GEOMETRY data type for PostgreSQL…

zhilinli123 opened a new pull request, #4673:
URL: https://github.com/apache/incubator-seatunnel/pull/4673

   
   <!--
   
   Thank you for contributing to SeaTunnel! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [GITHUB issue](https://github.com/apache/incubator-seatunnel/issues).
   
     - Name the pull request in the form "[Feature] [component] Title of the pull request", where *Feature* can be replaced by `Hotfix`, `Bug`, etc.
   
     - Minor fixes should be named following this pattern: `[hotfix] [docs] Fix typo in README.md doc`.
   
   -->
   
   ## Purpose of this pull request
   
   <!-- Describe the purpose of this pull request. For example: This pull request adds checkstyle plugin.-->
   
   ## Check list
   
   * [ ] Code changed are covered with tests, or it does not need tests for reason:
   * [ ] If any new Jar binary package adding in your PR, please add License Notice according
     [New License Guide](https://github.com/apache/incubator-seatunnel/blob/dev/docs/en/contribution/new-license.md)
   * [ ] If necessary, please update the documentation to describe the new feature. https://github.com/apache/incubator-seatunnel/tree/dev/docs
   * [ ] If you are contributing the connector code, please check that the following files are updated:
     1. Update change log that in connector document. For more details you can refer to [connector-v2](https://github.com/apache/incubator-seatunnel/tree/dev/docs/en/connector-v2)
     2. Update [plugin-mapping.properties](https://github.com/apache/incubator-seatunnel/blob/dev/plugin-mapping.properties) and add new connector information in it
     3. Update the pom file of [seatunnel-dist](https://github.com/apache/incubator-seatunnel/blob/dev/seatunnel-dist/pom.xml)
   * [ ] Update the [`release-note`](https://github.com/apache/incubator-seatunnel/blob/dev/release-note.md).


-- 
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-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] zhilinli123 commented on pull request #4673: [Feature][PostgreSQL-jdbc] Supports GEOMETRY data type for PostgreSQL…

Posted by "zhilinli123 (via GitHub)" <gi...@apache.org>.
zhilinli123 commented on PR #4673:
URL: https://github.com/apache/incubator-seatunnel/pull/4673#issuecomment-1526837008

   > 1. When obtaining the GEOMETRY type directly through (AbstractJdbcRowConverter.toInternal), you can only get a string of numbers that are not understandable.
   > 
   > https://github.com/apache/incubator-seatunnel/blob/5430ca9621ffdd7f7ec183235eed29764ecd6205/seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/converter/AbstractJdbcRowConverter.java#L53-L55
   > 
   > Therefore, it is necessary to introduce the PostGIS dependency, and then obtain the PGgeometry instance through the rs.getObject method and then call toString to get an understandable string.
   > 
   > ```
   >  <dependency>
   >             <groupId>net.postgis</groupId>
   >             <artifactId>postgis-jdbc</artifactId>
   >             <version>2.5.0</version>
   >   </dependency>
   > ```
   > 
   > 2. Spatial data types not only include GEOMETRY but also GEOGRAPHY, which also needs to be supported.
   
   Done


-- 
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-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] zhilinli123 commented on pull request #4673: [Feature][PostgreSQL-jdbc] Supports GEOMETRY data type for PostgreSQL…

Posted by "zhilinli123 (via GitHub)" <gi...@apache.org>.
zhilinli123 commented on PR #4673:
URL: https://github.com/apache/incubator-seatunnel/pull/4673#issuecomment-1522841430

   > Please reference https://github.com/apache/incubator-seatunnel/pull/4590/files and finished the document update.
   After the current merger, I will complete the pg connector documentation @EricJoy2048 
   


-- 
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-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] zhilinli123 commented on pull request #4673: [Feature][PostgreSQL-jdbc] Supports GEOMETRY data type for PostgreSQL…

Posted by "zhilinli123 (via GitHub)" <gi...@apache.org>.
zhilinli123 commented on PR #4673:
URL: https://github.com/apache/incubator-seatunnel/pull/4673#issuecomment-1526836722

   Done


-- 
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-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] EricJoy2048 commented on a diff in pull request #4673: [Feature][PostgreSQL-jdbc] Supports GEOMETRY data type for PostgreSQL…

Posted by "EricJoy2048 (via GitHub)" <gi...@apache.org>.
EricJoy2048 commented on code in PR #4673:
URL: https://github.com/apache/incubator-seatunnel/pull/4673#discussion_r1177310806


##########
seatunnel-e2e/seatunnel-connector-v2-e2e/connector-jdbc-e2e/connector-jdbc-e2e-part-1/src/test/resources/jdbc_pg_source_and_sink_pg.conf:
##########
@@ -0,0 +1,45 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+env {
+  execution.parallelism = 1
+  job.mode = "BATCH"
+}
+
+source{
+    jdbc{
+        url = "jdbc:postgresql://postgresql:5432/test?loggerLevel=OFF"
+        driver = "org.postgresql.Driver"
+        user = "test"
+        password = "test"
+        query = "select * from spatial_data"

Review Comment:
   Can you test all supported field types?
   A rigorous test can refer to the following information:
   1. The input and output of the test should include all supported data types.
   2. The input data should be deterministic and the values of each row and column can be verified in the output.
   3. In the output table, the values of each column in each row of data should be verified to ensure that there are no type conversion errors (precision loss, etc.) or missing values (a non null value in the input becomes null in the output) during the synchronization process.



-- 
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-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] zhilinli123 commented on a diff in pull request #4673: [Feature][PostgreSQL-jdbc] Supports GEOMETRY data type for PostgreSQL…

Posted by "zhilinli123 (via GitHub)" <gi...@apache.org>.
zhilinli123 commented on code in PR #4673:
URL: https://github.com/apache/incubator-seatunnel/pull/4673#discussion_r1179953013


##########
seatunnel-e2e/seatunnel-connector-v2-e2e/connector-jdbc-e2e/connector-jdbc-e2e-part-1/src/test/resources/jdbc_pg_source_and_sink_pg.conf:
##########
@@ -0,0 +1,45 @@
+#

Review Comment:
   > 
   
   > Remove this file
   > 
   > add geo field into this testcase
   > 
   > https://github.com/apache/incubator-seatunnel/blob/dev/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-jdbc-e2e/connector-jdbc-e2e-part-3/src/test/resources/jdbc_postgres_source_and_sink.conf
   
   Done
   



-- 
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-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] hailin0 commented on a diff in pull request #4673: [Feature][PostgreSQL-jdbc] Supports GEOMETRY data type for PostgreSQL…

Posted by "hailin0 (via GitHub)" <gi...@apache.org>.
hailin0 commented on code in PR #4673:
URL: https://github.com/apache/incubator-seatunnel/pull/4673#discussion_r1179902096


##########
seatunnel-e2e/seatunnel-connector-v2-e2e/connector-jdbc-e2e/connector-jdbc-e2e-part-1/src/test/resources/jdbc_pg_source_and_sink_pg.conf:
##########
@@ -0,0 +1,45 @@
+#

Review Comment:
   Remove this file
   
   add geo field into this testcase
   
   https://github.com/apache/incubator-seatunnel/blob/dev/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-jdbc-e2e/connector-jdbc-e2e-part-3/src/test/resources/jdbc_postgres_source_and_sink.conf



-- 
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-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] ic4y commented on a diff in pull request #4673: [Feature][PostgreSQL-jdbc] Supports GEOMETRY data type for PostgreSQL…

Posted by "ic4y (via GitHub)" <gi...@apache.org>.
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-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] zhilinli123 commented on pull request #4673: [Feature][PostgreSQL-jdbc] Supports GEOMETRY data type for PostgreSQL…

Posted by "zhilinli123 (via GitHub)" <gi...@apache.org>.
zhilinli123 commented on PR #4673:
URL: https://github.com/apache/incubator-seatunnel/pull/4673#issuecomment-1528818151

   RUN CI
   


-- 
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-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] zhilinli123 commented on pull request #4673: [Feature][PostgreSQL-jdbc] Supports GEOMETRY data type for PostgreSQL…

Posted by "zhilinli123 (via GitHub)" <gi...@apache.org>.
zhilinli123 commented on PR #4673:
URL: https://github.com/apache/incubator-seatunnel/pull/4673#issuecomment-1528818234

   > RUN CI thanks
   


-- 
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-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] zhilinli123 closed pull request #4673: [Feature][PostgreSQL-jdbc] Supports GEOMETRY data type for PostgreSQL…

Posted by "zhilinli123 (via GitHub)" <gi...@apache.org>.
zhilinli123 closed pull request #4673: [Feature][PostgreSQL-jdbc] Supports GEOMETRY data type for PostgreSQL…
URL: https://github.com/apache/incubator-seatunnel/pull/4673


-- 
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-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] EricJoy2048 commented on pull request #4673: [Feature][PostgreSQL-jdbc] Supports GEOMETRY data type for PostgreSQL…

Posted by "EricJoy2048 (via GitHub)" <gi...@apache.org>.
EricJoy2048 commented on PR #4673:
URL: https://github.com/apache/incubator-seatunnel/pull/4673#issuecomment-1522749244

   Please reference https://github.com/apache/incubator-seatunnel/pull/4590/files and finished the document update.


-- 
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-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] zhilinli123 commented on pull request #4673: [Feature][PostgreSQL-jdbc] Supports GEOMETRY data type for PostgreSQL…

Posted by "zhilinli123 (via GitHub)" <gi...@apache.org>.
zhilinli123 commented on PR #4673:
URL: https://github.com/apache/incubator-seatunnel/pull/4673#issuecomment-1547331535

   @EricJoy2048 @hailin0 Please check it out. Thank you
   


-- 
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-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] ic4y commented on pull request #4673: [Feature][PostgreSQL-jdbc] Supports GEOMETRY data type for PostgreSQL…

Posted by "ic4y (via GitHub)" <gi...@apache.org>.
ic4y commented on PR #4673:
URL: https://github.com/apache/incubator-seatunnel/pull/4673#issuecomment-1525643839

   1. When obtaining the GEOMETRY type directly through (AbstractJdbcRowConverter.toInternal), you can only get a string of numbers that are not understandable.
   
   https://github.com/apache/incubator-seatunnel/blob/5430ca9621ffdd7f7ec183235eed29764ecd6205/seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/converter/AbstractJdbcRowConverter.java#L53-L55
   
   Therefore, it is necessary to introduce the PostGIS dependency, and then obtain the PGgeometry instance through the rs.getObject method and then call toString to get an understandable string.
   
   ```
    <dependency>
               <groupId>net.postgis</groupId>
               <artifactId>postgis-jdbc</artifactId>
               <version>2.5.0</version>
     </dependency>
   ```
   
   2. Spatial data types not only include GEOMETRY but also GEOGRAPHY, which also needs to be supported.


-- 
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-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] zhilinli123 commented on pull request #4673: [Feature][PostgreSQL-jdbc] Supports GEOMETRY data type for PostgreSQL…

Posted by "zhilinli123 (via GitHub)" <gi...@apache.org>.
zhilinli123 commented on PR #4673:
URL: https://github.com/apache/incubator-seatunnel/pull/4673#issuecomment-1539314442

   @ic4y help review thanks
   
   


-- 
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-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] Hisoka-X merged pull request #4673: [Feature][PostgreSQL-jdbc] Supports GEOMETRY data type for PostgreSQL…

Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X merged PR #4673:
URL: https://github.com/apache/incubator-seatunnel/pull/4673


-- 
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-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-seatunnel] zhilinli123 commented on a diff in pull request #4673: [Feature][PostgreSQL-jdbc] Supports GEOMETRY data type for PostgreSQL…

Posted by "zhilinli123 (via GitHub)" <gi...@apache.org>.
zhilinli123 commented on code in PR #4673:
URL: https://github.com/apache/incubator-seatunnel/pull/4673#discussion_r1178766204


##########
seatunnel-e2e/seatunnel-connector-v2-e2e/connector-jdbc-e2e/connector-jdbc-e2e-part-1/src/test/resources/jdbc_pg_source_and_sink_pg.conf:
##########
@@ -0,0 +1,45 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+env {
+  execution.parallelism = 1
+  job.mode = "BATCH"
+}
+
+source{
+    jdbc{
+        url = "jdbc:postgresql://postgresql:5432/test?loggerLevel=OFF"
+        driver = "org.postgresql.Driver"
+        user = "test"
+        password = "test"
+        query = "select * from spatial_data"

Review Comment:
   I think so, because currently pr supports geometric types, and if I wanted to test all types, I think I could open one and create a separate pr header such as Pg e2e to test it
   @EricJoy2048 



-- 
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-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org