You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by "DanielLeens (via GitHub)" <gi...@apache.org> on 2026/04/20 06:56:22 UTC

Re: [PR] [Bugfix][connectors-v2]JdbcSink's subscript out-of-bounds exception repaired in createWriter [seatunnel]

DanielLeens commented on PR #10200:
URL: https://github.com/apache/seatunnel/pull/10200#issuecomment-4278481798

   Hi @chl-wxp, thank you for the focused fix. I reviewed this PR locally against the current SeaTunnel codebase rather than only looking at the diff.
   
   # What This PR Fixes
   - User pain point: JDBC Sink can fail while creating the writer when `primary_keys` is present but empty, for example `primary_keys = []`. The old factory logic treated the option as present, created a `PrimaryKey` with an empty column list, and the writer later accessed `getColumnNames().get(0)`.
   - Fix approach: `JdbcSinkFactory` now checks whether the configured primary key list is empty instead of only checking whether the option exists.
   - One-line summary: empty JDBC sink primary key configuration is now handled as “no effective primary key”, avoiding the writer creation crash.
   
   # 1. Code Change Review
   
   ## 1.1 Core Logic
   Local review info:
   - Branch: `seatunnel-review-10200`
   - PR HEAD: `1354b850452a99f380ad7d6b70c5baeca3723b54`
   - Merge base with `upstream/dev`: `7bf17f83857711430617cf57a7986d5ad98eacd9`
   - Main files reviewed:
     - `seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/sink/JdbcSinkFactory.java`
     - `seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/sink/JdbcSink.java`
     - `seatunnel-connectors-v2/connector-jdbc/src/test/java/org/apache/seatunnel/connectors/seatunnel/jdbc/JdbcFactoryTest.java`
   
   Before:
   
   ```java
   if (!config.getOptional(JdbcSinkOptions.PRIMARY_KEYS).isPresent()) {
       ...
   } else {
       PrimaryKey configPk =
               PrimaryKey.of(
                       catalogTable.getTablePath().getTableName() + "_config_pk",
                       config.get(JdbcSinkOptions.PRIMARY_KEYS));
       ...
   }
   ```
   
   After:
   
   ```java
   if (CollectionUtils.isEmpty(config.get(JdbcSinkOptions.PRIMARY_KEYS))) {
       ...
   } else {
       PrimaryKey configPk =
               PrimaryKey.of(
                       catalogTable.getTablePath().getTableName() + "_config_pk",
                       config.get(JdbcSinkOptions.PRIMARY_KEYS));
       ...
   }
   ```
   
   Key runtime path:
   
   ```text
   JDBC Sink job submission
     -> TableSinkFactoryContext(catalogTable, options)
         -> JdbcSinkFactory.createSink(context)
             -> config.get(JdbcSinkOptions.PRIMARY_KEYS)
                 -- absent or [] -> CollectionUtils.isEmpty(...) == true
                 -- non-empty list -> rebuild CatalogTable with configured primary key
             -> fallback to catalog primary key / unique key only when there is no effective configured key
             -> new JdbcSink(..., finalCatalogTable)
   
   Execution phase
     -> JdbcSink.createWriter(context)
         -> non-exactly-once writer path
             -> if CatalogTable primaryKey != null:
                 -> tableSchema.getPrimaryKey().getColumnNames().get(0)
                 -- before this PR: an empty configured key could create an empty PrimaryKey and crash here
                 -- after this PR: empty primary_keys no longer creates that empty PrimaryKey
             -> create JdbcSinkWriter
   ```
   
   Key findings:
   - The normal JDBC Sink creation path does hit this change.
   - The bug is real: `ReadonlyConfig.getOptional(PRIMARY_KEYS)` only tells us whether the key exists, not whether the parsed list has usable values.
   - The fix is precise and does not change the writer implementation, SQL generation, checkpoint behavior, or exactly-once behavior.
   - The added unit test covers the factory output for `primary_keys = []`. It would be even stronger to also cover the original writer creation crash point, but I do not see that as a merge blocker.
   
   Local command results:
   - `git diff --stat upstream/dev...HEAD`: 2 files changed, with the production code change limited to one line and a focused test added.
   - `git diff --check upstream/dev...HEAD`: clean.
   - `git merge-tree $(git merge-base upstream/dev HEAD) upstream/dev HEAD`: `JdbcSinkFactory.java` is changed on both sides but auto-merges cleanly; no conflict markers were produced.
   - GitHub checks visible from `gh pr view`: `Build`, `labeler`, and `Notify test workflow` are all successful.
   - I did not run local UT/IT for this review; this is a source-level review as requested.
   
   ## 1.2 Compatibility
   Compatibility judgment: fully compatible.
   
   - API: unchanged.
   - Config options: unchanged.
   - Defaults: unchanged.
   - Protocol: not affected.
   - Serialization format: not affected.
   - Historical behavior: only the erroneous empty-primary-key path changes. Non-empty configured `primary_keys` and catalog key fallback keep the existing behavior.
   
   ## 1.3 Performance / Side Effects
   No meaningful CPU, memory, GC, network, locking, concurrency, retry, idempotency, or resource-release side effects were found. The change is a local configuration-list check during sink creation.
   
   ## 1.4 Error Handling And Logging
   No new logging or exception handling is needed here. The PR prevents a later `IndexOutOfBoundsException` by avoiding construction of an invalid empty-column `PrimaryKey`.
   
   Formal findings: no blocking issue found.
   
   # 2. Code Quality
   
   ## 2.1 Style
   The code follows the existing JDBC connector style and reuses `CollectionUtils.isEmpty()` consistently.
   
   ## 2.2 Tests
   The new test covers the important factory behavior for empty `primary_keys`. Non-blocking suggestion: please consider extending the regression test to reach `JdbcSink.createWriter()` or otherwise assert that an empty configured list cannot produce a `PrimaryKey` with an empty column list, since that is the original crash point.
   
   ## 2.3 Documentation
   No documentation update is required. This is an internal bug fix for an invalid empty-list handling path, with no user-visible option or default change.
   
   # 3. Architecture
   
   ## 3.1 Solution Quality
   This is a precise fix. The root problem is the difference between “option exists” and “option has effective values”, and the new condition addresses exactly that.
   
   ## 3.2 Maintainability
   The boundary is clear: empty/null configured primary keys use catalog fallback; non-empty configured primary keys override the catalog schema. This should be easy to maintain.
   
   ## 3.3 Extensibility
   The pattern is useful for similar list-type options: judge the effective list content, not only optional presence.
   
   ## 3.4 Historical Compatibility
   Compatible with existing jobs. No migration is required.
   
   # 4. Findings Summary
   | No. | Finding | Location | Severity |
   |---|---|---|---|
   | - | No blocking issue found | - | - |
   
   # 5. Merge Decision
   ### Conclusion: can merge
   
   1. Blocking items
      - None.
   
   2. Recommended non-blocking improvements
      - Strengthen the regression test to cover the writer creation point that previously crashed.
   
   Overall: the fix is small, targeted, and compatible. Public CI is green, local whitespace check is clean, and the current branch auto-merges cleanly in the reviewed files. Nice focused bug fix.
   


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