You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by GitBox <gi...@apache.org> on 2022/02/16 03:44:09 UTC

[GitHub] [incubator-seatunnel] leo65535 opened a new pull request #1254: [Feature] [connector] Support flink jdbc sink based on new flink version

leo65535 opened a new pull request #1254:
URL: https://github.com/apache/incubator-seatunnel/pull/1254


   <!--
   
   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.-->
   
   We remove old jdbc api when upgrading the flink version because of flink remove them in dataset table api, we need to write new jdbc sink based on new flink version.
   
   ## Check list
   
   * [ ] Code changed are covered with tests, or it does not need tests for reason:
   * [ ] If any new Jar binary package adding in you PR, please add License Notice according
     [New License Guide](https://github.com/apache/incubator-seatunnel/blob/dev/docs/en/developement/NewLicenseGuide.md)
   * [ ] If necessary, please update the documentation to describe the new feature. https://github.com/apache/incubator-seatunnel/tree/dev/docs
   


-- 
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] CalvinKirs merged pull request #1254: [Feature] [connector] Support flink jdbc sink based on new flink version

Posted by GitBox <gi...@apache.org>.
CalvinKirs merged pull request #1254:
URL: https://github.com/apache/incubator-seatunnel/pull/1254


   


-- 
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] leo65535 commented on a change in pull request #1254: [Feature] [connector] Support flink jdbc sink based on new flink version

Posted by GitBox <gi...@apache.org>.
leo65535 commented on a change in pull request #1254:
URL: https://github.com/apache/incubator-seatunnel/pull/1254#discussion_r807575891



##########
File path: seatunnel-connectors/seatunnel-connector-flink-jdbc/src/main/java/org/apache/seatunnel/flink/sink/JdbcSink.java
##########
@@ -81,34 +85,24 @@ public void prepare(FlinkEnvironment env) {
     @Nullable
     public DataStreamSink<Row> outputStream(FlinkEnvironment env, DataStream<Row> dataStream) {
         Table table = env.getStreamTableEnvironment().fromDataStream(dataStream);
-        createSink(env.getStreamTableEnvironment(), table);
-        return null;
-    }
+        TypeInformation<?>[] fieldTypes = table.getSchema().getFieldTypes();
 
-    @Override
-    @Nullable
-    public DataSink<Row> outputBatch(FlinkEnvironment env, DataSet<Row> dataSet) {
-        final Table table = env.getBatchTableEnvironment().fromDataSet(dataSet);
-        createSink(env.getBatchTableEnvironment(), table);
+        int[] types = Arrays.stream(fieldTypes).mapToInt(JdbcTypeUtil::typeInformationToSqlType).toArray();
+        SinkFunction<Row> sink = org.apache.flink.connector.jdbc.JdbcSink.sink(
+            query,
+            (st, row) -> JdbcUtils.setRecordToStatement(st, types, row),
+            JdbcExecutionOptions.builder()
+                .withBatchSize(batchSize)

Review comment:
       Make sense, thanks

##########
File path: seatunnel-connectors/seatunnel-connector-flink-jdbc/src/main/java/org/apache/seatunnel/flink/sink/JdbcSink.java
##########
@@ -81,34 +85,24 @@ public void prepare(FlinkEnvironment env) {
     @Nullable
     public DataStreamSink<Row> outputStream(FlinkEnvironment env, DataStream<Row> dataStream) {
         Table table = env.getStreamTableEnvironment().fromDataStream(dataStream);
-        createSink(env.getStreamTableEnvironment(), table);
-        return null;
-    }
+        TypeInformation<?>[] fieldTypes = table.getSchema().getFieldTypes();
 
-    @Override
-    @Nullable
-    public DataSink<Row> outputBatch(FlinkEnvironment env, DataSet<Row> dataSet) {
-        final Table table = env.getBatchTableEnvironment().fromDataSet(dataSet);
-        createSink(env.getBatchTableEnvironment(), table);
+        int[] types = Arrays.stream(fieldTypes).mapToInt(JdbcTypeUtil::typeInformationToSqlType).toArray();
+        SinkFunction<Row> sink = org.apache.flink.connector.jdbc.JdbcSink.sink(
+            query,
+            (st, row) -> JdbcUtils.setRecordToStatement(st, types, row),
+            JdbcExecutionOptions.builder()
+                .withBatchSize(batchSize)
+                .build(),
+            new JdbcConnectionOptions.JdbcConnectionOptionsBuilder()
+                .withUrl(dbUrl)
+                .withDriverName(driverName)
+                .withUsername(username)
+                .withPassword(password)
+                .build());
+
+        dataStream.addSink(sink);

Review comment:
       Make sense, 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] asdf2014 commented on a change in pull request #1254: [Feature] [connector] Support flink jdbc sink based on new flink version

Posted by GitBox <gi...@apache.org>.
asdf2014 commented on a change in pull request #1254:
URL: https://github.com/apache/incubator-seatunnel/pull/1254#discussion_r807552510



##########
File path: seatunnel-connectors/seatunnel-connector-flink-jdbc/src/main/java/org/apache/seatunnel/flink/sink/JdbcSink.java
##########
@@ -81,34 +85,24 @@ public void prepare(FlinkEnvironment env) {
     @Nullable
     public DataStreamSink<Row> outputStream(FlinkEnvironment env, DataStream<Row> dataStream) {
         Table table = env.getStreamTableEnvironment().fromDataStream(dataStream);
-        createSink(env.getStreamTableEnvironment(), table);
-        return null;
-    }
+        TypeInformation<?>[] fieldTypes = table.getSchema().getFieldTypes();
 
-    @Override
-    @Nullable
-    public DataSink<Row> outputBatch(FlinkEnvironment env, DataSet<Row> dataSet) {
-        final Table table = env.getBatchTableEnvironment().fromDataSet(dataSet);
-        createSink(env.getBatchTableEnvironment(), table);
+        int[] types = Arrays.stream(fieldTypes).mapToInt(JdbcTypeUtil::typeInformationToSqlType).toArray();
+        SinkFunction<Row> sink = org.apache.flink.connector.jdbc.JdbcSink.sink(
+            query,
+            (st, row) -> JdbcUtils.setRecordToStatement(st, types, row),
+            JdbcExecutionOptions.builder()
+                .withBatchSize(batchSize)

Review comment:
       It would be better we can expose the `batchIntervalMs` and `maxRetries` options to our users. What do you think

##########
File path: seatunnel-connectors/seatunnel-connector-flink-jdbc/src/main/java/org/apache/seatunnel/flink/sink/JdbcSink.java
##########
@@ -81,34 +85,24 @@ public void prepare(FlinkEnvironment env) {
     @Nullable
     public DataStreamSink<Row> outputStream(FlinkEnvironment env, DataStream<Row> dataStream) {
         Table table = env.getStreamTableEnvironment().fromDataStream(dataStream);
-        createSink(env.getStreamTableEnvironment(), table);
-        return null;
-    }
+        TypeInformation<?>[] fieldTypes = table.getSchema().getFieldTypes();
 
-    @Override
-    @Nullable
-    public DataSink<Row> outputBatch(FlinkEnvironment env, DataSet<Row> dataSet) {
-        final Table table = env.getBatchTableEnvironment().fromDataSet(dataSet);
-        createSink(env.getBatchTableEnvironment(), table);
+        int[] types = Arrays.stream(fieldTypes).mapToInt(JdbcTypeUtil::typeInformationToSqlType).toArray();
+        SinkFunction<Row> sink = org.apache.flink.connector.jdbc.JdbcSink.sink(
+            query,
+            (st, row) -> JdbcUtils.setRecordToStatement(st, types, row),
+            JdbcExecutionOptions.builder()
+                .withBatchSize(batchSize)
+                .build(),
+            new JdbcConnectionOptions.JdbcConnectionOptionsBuilder()
+                .withUrl(dbUrl)
+                .withDriverName(driverName)
+                .withUsername(username)
+                .withPassword(password)
+                .build());
+
+        dataStream.addSink(sink);

Review comment:
       We can return the `DataStreamSink` instance instead of `null` since the `FlinkStreamSink#outputStream` interface method has a return value, right 
   
   ```suggestion
           return dataStream.addSink(sink);
   ```




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