kalencaya opened a new issue, #1829:
URL: https://github.com/apache/incubator-seatunnel/issues/1829

   ### Search before asking
   
   - [X] I had searched in the 
[feature](https://github.com/apache/incubator-seatunnel/issues?q=is%3Aissue+label%3A%22Feature%22)
 and found no similar feature requirement.
   
   
   ### Description
   
   a typical `JdbcSink` config follows:
   ```
   JdbcSink {
       source_table_name = fake
       driver = com.mysql.jdbc.Driver
       url = "jdbc:mysql://localhost/test"
       username = root
       query = "insert into test(name,age) values(?,?)"
       batch_size = 2
   }
   ```
   `insert into test(name,age) values(?,?)` requires that `Row` fields must 
match `name, age` order as `JdbcUtils#setRecordToStatement` implemention:
   ```
       public DataStreamSink<Row> outputStream(FlinkEnvironment env, 
DataStream<Row> dataStream) {
           Table table = 
env.getStreamTableEnvironment().fromDataStream(dataStream);
           TypeInformation<?>[] fieldTypes = table.getSchema().getFieldTypes();
           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), // 
the key reason
               JdbcExecutionOptions.builder()
                   .withBatchSize(batchSize)
                   .withBatchIntervalMs(batchIntervalMs)
                   .withMaxRetries(maxRetries)
                   .build(),
               new JdbcConnectionOptions.JdbcConnectionOptionsBuilder()
                   .withUrl(dbUrl)
                   .withDriverName(driverName)
                   .withUsername(username)
                   .withPassword(password)
                   .build());
   
           if (config.hasPath(PARALLELISM)) {
               return 
dataStream.addSink(sink).setParallelism(config.getInt(PARALLELISM));
           }
           return dataStream.addSink(sink);
       }
   ```
   now query should support param placeholder such as `insert into 
test(name,age) values(#{name},#{age})`  would be better for  two reasons:
   * more brief semantics
   * jdbc upsert support. `insert into xxx on duplicate xxx` and `replace into` 
grammar will work
   
   
   ### Usage Scenario
   
   flink-connector-jdbc supports upsert
   
   ### Related issues
   
   _No response_
   
   ### Are you willing to submit a PR?
   
   - [X] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


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