You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by "laglangyue (via GitHub)" <gi...@apache.org> on 2023/03/30 15:02:37 UTC

[GitHub] [incubator-seatunnel] laglangyue commented on a diff in pull request #4440: [Bug][Connector][JDBC] set partition number to 1 if jdbc query is empty result

laglangyue commented on code in PR #4440:
URL: https://github.com/apache/incubator-seatunnel/pull/4440#discussion_r1153402548


##########
seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/source/JdbcSource.java:
##########
@@ -182,14 +186,18 @@ private PartitionParameter initPartitionParameter(String columnName, Connection
                                         "SELECT MAX(%s),MIN(%s) " + "FROM (%s) tt",
                                         columnName, columnName, query))) {
             if (rs.next()) {
-                max =
-                        jdbcSourceConfig.getPartitionUpperBound().isPresent()
-                                ? jdbcSourceConfig.getPartitionUpperBound().get()
-                                : Long.parseLong(rs.getString(1));
-                min =
-                        jdbcSourceConfig.getPartitionLowerBound().isPresent()
-                                ? jdbcSourceConfig.getPartitionLowerBound().get()
-                                : Long.parseLong(rs.getString(2));
+                if (rs.getString(1) != null && rs.getString(2) != null) {
+                    max =
+                            jdbcSourceConfig.getPartitionUpperBound().isPresent()
+                                    ? jdbcSourceConfig.getPartitionUpperBound().get()
+                                    : Long.parseLong(rs.getString(1));
+                    min =
+                            jdbcSourceConfig.getPartitionLowerBound().isPresent()
+                                    ? jdbcSourceConfig.getPartitionLowerBound().get()
+                                    : Long.parseLong(rs.getString(2));
+                } else {
+                    return null;

Review Comment:
   return null is ugly



##########
seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/source/JdbcSource.java:
##########
@@ -217,6 +225,11 @@ private PartitionParameter initPartitionParameterAndExtendSql(Connection connect
             }
             PartitionParameter partitionParameter =
                     initPartitionParameter(partitionColumn, connection);
+            if (partitionParameter == null) {
+                LOG.info(
+                        "The partition_column parameter is configured, but the result set is empty");
+                return null;

Review Comment:
   is there has some more better way solve the problem, because return null is ugly



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