nzw921rx opened a new issue, #13407:
URL: https://github.com/apache/seatunnel/issues/13407

   ### Search before asking
   
   - [x] I had searched in the 
[feature](https://github.com/apache/seatunnel/issues?q=is%3Aissue+label%3A%22Feature%22)
 and found no similar feature requirement.
   
   
   ### Description
   
   Add an optional `update_condition_sql` setting to the JDBC Sink so users can 
control when an incoming row may update an existing target row.
   
   ```hocon
   generate_sink_sql = true
   primary_keys = ["id"]
   update_condition_sql = ":update_time > update_time"
   ```
   
   Here, `:update_time` is a bound parameter from the incoming row, and 
`update_time` is the column in the target table.
   
   When this option is set, use the existing key lookup to choose between 
INSERT and UPDATE:
   
   - If the key is missing, use the existing INSERT path.
   - If the key exists, append the configured predicate in parentheses to the 
generated UPDATE's key condition. For this example, the WHERE clause becomes 
`WHERE id = :id AND (:update_time > update_time)`.
   - The database evaluates the predicate when executing the UPDATE. If it 
evaluates to false or NULL, skip the update.
   
   Help wanted with implementation and integration tests. 
`JdbcOutputFormatBuilder#createInsertOrUpdateByQueryExecutor` already prepares 
the lookup, INSERT, and UPDATE statements. One useful regression test is two 
versions of the same key arriving in one batch, newer first. With the example 
condition, the newer version should win.
   
   ### Usage Scenario
   
   A batch backfill runs while a CDC job continues writing to the same orders 
table. The backfill reads order 42 at 10:03. Before that row reaches the sink, 
CDC writes the 10:05 version. The condition keeps the 10:05 version in the 
target while allowing the backfill to insert missing orders.
   
   ### Related issues
   
   _No response_
   
   ### Are you willing to submit a PR?
   
   - [ ] 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