Skip to content

[Fix][Connector-V2] Declare all Jdbc source and sink options read by the connector - #12800

Merged
davidzollo merged 2 commits into
apache:devfrom
fatmanverse:fix-jdbc-sink-table-option
Oct 16, 2026
Merged

davidzollo merged 2 commits into
apache:devfrom
fatmanverse:fix-jdbc-sink-table-option

Conversation

@fatmanverse

@fatmanverse fatmanverse commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #12796

Purpose of this pull request

--check, --dry-run static|connect and the Flink/Spark config validation call ConfigValidator#validateUnknownKeys, which accepts only keys declared in the connector's OptionRule. The Jdbc factories did not declare several documented options that the connector reads, so valid configs were rejected, for example:

Connector 'Jdbc' has unknown option keys: [table]. Please check for typos.

This PR declares them as optional options:

  • JdbcSinkFactory: table, schema, properties, connect_timeout_ms, socket_timeout_ms, decimal_type_narrowing, int_type_narrowing, handle_blob_as_string, use_kerberos, kerberos_principal, kerberos_keytab_path, krb5_path, access_key_id, secret_access_key, region. All of them are read by JdbcSinkConfig#of, JdbcConnectionConfig#of or JdbcSinkFactory.
  • JdbcSourceFactory: connect_timeout_ms, socket_timeout_ms, handle_blob_as_string, use_kerberos, kerberos_principal, kerberos_keytab_path, krb5_path, access_key_id, secret_access_key, region. They are read by the shared JdbcConnectionConfig#of; the last three are used by the DSQL connection provider for the source as well as the sink.

schema is intentionally not declared on the source: only the sink path and the catalog factories read it.

Impact checked:

  • OptionRule.Builder duplicate checks: none of these options appears elsewhere in either rule.
  • SeaTunnelConfValidateCommand#validateOptionTypes now type-checks these keys. All of them are scalar or Map<String, String>, the same types the connector already reads at runtime, so a config that runs also passes the check.
  • The REST option-rules service and the metadata export now list these options, which matches the docs.
  • Runtime behavior does not change: the options were already read at job submission, only the declarations were missing.

Does this PR introduce any user-facing change?

Yes. Configs using these documented options no longer fail --check / --dry-run with an unknown-key error. Truly unknown keys are still rejected.

How was this patch tested?

  • Added JdbcSinkFactoryTest#testDocumentedSinkOptionsAreNotUnknownKeys, #testUndeclaredSinkOptionIsUnknownKey and JdbcSourceFactoryTest#testDocumentedSourceOptionsAreNotUnknownKeys.
  • Added JdbcOptionRuleCompletenessTest. It collects every public static Option of JdbcSourceOptions / JdbcSinkOptions (including the inherited JdbcCommonOptions) by reflection and checks that validateUnknownKeys accepts all of them, with an explicit exclusion list (only schema on the source). A newly added option that is not declared makes it fail.
  • ./mvnw -pl seatunnel-connectors-v2/connector-jdbc test on JDK 17: all tests pass.
  • On a deployed Zeta cluster, bin/seatunnel.sh --check and --dry-run static|connect with a Jdbc sink that sets table were rejected before this change and pass after it.

Check list

…the connector

--check and --dry-run reject keys that are not declared in the option
rule. The Jdbc sink did not declare documented options it reads, such as
table, properties, the connection timeouts and the Kerberos and IAM
options, and the Jdbc source missed the timeout and Kerberos options.

Fixes apache#12796

@ryanmeowy ryanmeowy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cross-checked this against the module: resolving every JdbcCommonOptions / JdbcSourceOptions / JdbcSinkOptions reference in connector-jdbc to its option key (following the inheritance from JdbcCommonOptions) gives 67 distinct keys, and the declared set in the two factories resolves to the same 67 -- so as far as that audit goes, nothing the module reads is left undeclared.

Since completeness is the whole point of the change, would it be worth pinning it with a test? The new testDocumented*OptionsAreNotUnknownKeys tests cover the keys added here, but that list is hand-written; reflecting over the public static Option fields of JdbcCommonOptions / JdbcSourceOptions / JdbcSinkOptions and asserting each key is declared (or explicitly allow-listed) would make it self-maintaining, so the next option added to the module cannot silently reintroduce #12796.

@DanielLeens DanielLeens left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this, and for the very clear PR description! I went through the full diff and traced the validation path end to end. The approach is correct and I found no blocking issues. Details below.

What Problem Does This PR Solve?

  • User pain point: --check, --dry-run static|connect and the Flink/Spark config validation call ConfigValidator#validateUnknownKeys, which only accepts keys declared in the connector's OptionRule. A valid Jdbc config that sets documented options such as table was rejected with Connector 'Jdbc' has unknown option keys: [table] (#12796), even though the job would run fine.
  • Fix approach: declare the options that the connector already reads at runtime as optional(...) in JdbcSinkFactory#optionRule (15 keys) and JdbcSourceFactory#optionRule (7 keys).
  • One-sentence summary: the Jdbc option rules now match what the connector actually reads and documents, so strict validation stops rejecting valid configs while still rejecting real typos.

1. Code Change Review

1.1 Core Logic Analysis

Changes

  • JdbcSinkFactory.java:213-232 (optionRule()): adds TABLE, SCHEMA, PROPERTIES, CONNECT_TIMEOUT_MS, SOCKET_TIMEOUT_MS, DECIMAL_TYPE_NARROWING, INT_TYPE_NARROWING, HANDLE_BLOB_AS_STRING, USE_KERBEROS, KERBEROS_PRINCIPAL, KERBEROS_KEYTAB_PATH, KRB5_PATH, ACCESS_KEY_ID, SECRET_ACCESS_KEY, REGION to the existing .optional(...) list.
  • JdbcSourceFactory.java:84-93 (optionRule()): adds CONNECT_TIMEOUT_MS, SOCKET_TIMEOUT_MS, HANDLE_BLOB_AS_STRING, USE_KERBEROS, KERBEROS_PRINCIPAL, KERBEROS_KEYTAB_PATH, KRB5_PATH.
  • Three new unit tests.

Before / after (sink)

// before: TABLE, SCHEMA, PROPERTIES, *_TIMEOUT_MS, kerberos/aws keys ... not declared
.optional(JdbcSinkOptions.CREATE_INDEX, JdbcSinkOptions.USERNAME, JdbcSinkOptions.PASSWORD,
          JdbcSinkOptions.CONNECTION_CHECK_TIMEOUT_SEC, JdbcSinkOptions.BATCH_SIZE, ...)
// after: the same list plus the 15 options above

Runtime path

bin/seatunnel.sh --check / --dry-run
  -> SeaTunnelConfValidateCommand [L325]
      -> ConfigValidator.validateUnknownKeys(readonlyConfig, factory.optionRule(), "Jdbc")
          -> any key not present in the rule (required / optional / conditional) -> OptionValidationException
Flink/Spark path
  -> ConfigValidationUtils [L248, L307, L356] -> same validateUnknownKeys

Normal job submission
  -> JdbcSinkFactory.createSink / JdbcSourceFactory.createSource
      -> JdbcSinkConfig.of / JdbcConnectionConfig.of read the options directly from ReadonlyConfig
         (optionRule is NOT consulted for these values)

Key findings

  1. The normal job-run path does not use optionRule() to read values, so this PR does not change runtime behavior. It only reaches the strict validation path (--check, --dry-run, Flink/Spark validation) plus the option-rules REST/metadata export. This matches the PR description.
  2. I verified that every added option is a real, existing Option constant that the connector reads (for example JdbcConnectionConfig.java:110-118 for properties / narrowing / access key / secret / region, and JdbcSinkConfig.java:52 for table). Nothing is declared that the code does not read.
  3. I also cross-checked the factory lists against JdbcCommonOptions; the audit by @ryanmeowy (67 keys, declared set resolves to the same 67) is consistent with what I see. +1 to that review's conclusion on completeness.
  4. This is a precise fix for #12796 (declaration gap), not a workaround.

Correctness notes

  • Adding options as optional cannot make a previously valid config invalid for the unknown-key check. The only new rejections can come from validateOptionTypes, which now type-checks these keys; they are scalar or Map<String, String>, the same types the connector reads at runtime, so a config that runs also passes the check.
  • No duplicate declaration inside the same OptionRule.Builder (the PR notes this was checked; I agree from reading both lists).

1.2 Compatibility Impact

Fully compatible. No API, option name, default value, protocol or serialization change. Historical behavior is unchanged for configs that already passed; configs that were wrongly rejected by --check / --dry-run are now accepted. Unknown keys are still rejected (see testUndeclaredSinkOptionIsUnknownKey). The REST option-rules service and metadata export will now list the added options, which matches docs/en. No incompatible-changes.md entry is needed.

1.3 Performance / Side-Effect Analysis

Declaration-only change: no CPU, memory, GC, network, lock, retry or idempotency impact, and no resources to release. Sensitive options (secret_access_key, kerberos_keytab_path) are only declared, not logged.

1.4 Error Handling and Logging

No new exception or logging paths. The existing unknown-key message is unchanged and now fires only for genuinely undeclared keys.

No blocking issues found.

2. Code Quality Assessment

2.1 Coding Standards

Follows existing conventions, imports and formatting. The new tests carry Javadoc explaining their purpose. No new core methods or fields, so no comment gaps.

2.2 Test Coverage and Test Stability

  • JdbcSinkFactoryTest#testDocumentedSinkOptionsAreNotUnknownKeys, #testUndeclaredSinkOptionIsUnknownKey and JdbcSourceFactoryTest#testDocumentedSourceOptionsAreNotUnknownKeys exercise the exact failing call (validateUnknownKeys) and would fail if any of the added declarations were removed. The negative test guards against the rule becoming permissive.
  • Stability rating: Stable. Pure in-memory config validation, no sleeps, ports, containers, ordering or time dependencies (JdbcSinkFactoryTest.java:192-233, JdbcSourceFactoryTest.java:68-88).

Non-blocking suggestions (Low):

  • Suggestion A (+1 to @ryanmeowy's review): the test key lists are hand-maintained, so a future option added to JdbcCommonOptions / JdbcSourceOptions / JdbcSinkOptions could silently reintroduce #12796. A reflection-based test over the public static Option fields (with an explicit allow-list for the few intentionally undeclared ones) would make the guarantee self-maintaining. Happy for this to be a follow-up if you prefer to keep this PR small.
  • Suggestion B: the source test covers only the 7 newly added keys. If you add the reflection test above, it will cover the pre-existing source keys too.

2.3 Documentation Updates

Not required: the options are already documented in docs/en/connectors/source/Jdbc.md and the sink doc, and this PR does not change user-facing semantics beyond fixing validation. No docs/zh change is needed.

3. Architectural Soundness

3.1 Elegance of the Solution

Precise fix. It is minimal and uses the existing OptionRule mechanism.

3.2 Maintainability

Clear and low-risk. The only long-term risk is declaration drift, addressed by Suggestion A.

3.3 Extensibility

Adding the reflection-style completeness test would give a reusable pattern for other connectors with the same drift risk.

3.4 Historical-Version Compatibility

Compatible with all historical configs and job files; no upgrade action required.

4. Issue Summary

Number Issue Location Severity
(none) No blocking issues found - -
S1 Optional: self-maintaining completeness test (+1 to @ryanmeowy) JdbcSinkFactoryTest.java / JdbcSourceFactoryTest.java Low

5. Merge Recommendation

Conclusion: Ready to merge

  1. Blockers - must be fixed: none from the code side.
  2. Recommended fixes - non-blocking: S1 above. It does not block because it is a hardening of future maintenance, not a defect in this change.

CI status: at the time of this review, the Build workflow for the current head was still queued/pending on the fork (the apache-side Build entry is only a pointer to it), and the PR is BLOCKED only on required checks/approval. Please keep an eye on it and let me know if any lane fails; I am happy to help dig into it. I would suggest merging once it is green.

Overall assessment: correct, minimal, well tested, and fully compatible. No better alternative implementation is needed; Option A (this PR as is) is enough, and Option B (add the reflection-based completeness test, here or as a follow-up) is a nice-to-have.

Thanks again for the fix!

Collect every Option of JdbcSourceOptions and JdbcSinkOptions (including
JdbcCommonOptions) by reflection and check that the factory rule accepts
all of them, so a newly added option cannot reintroduce apache#12796. This also
declares the DSQL options access_key_id, secret_access_key and region on
the source, which reads them through the shared connection provider.
@fatmanverse

Copy link
Copy Markdown
Contributor Author

Thanks @ryanmeowy and @DanielLeens for the reviews.

Added the reflection-based completeness test in 59b7d7c: JdbcOptionRuleCompletenessTest collects every public static Option of JdbcSourceOptions and JdbcSinkOptions (including the inherited JdbcCommonOptions) and checks that the factory rule accepts all of them through validateUnknownKeys. The exclusion list has a single entry, schema on the source, which only the sink path and the catalog factories read.

The test found three more keys missing on the source: access_key_id, secret_access_key and region. The source reaches the DSQL connection provider through the shared JdbcConnectionConfig too, so they are now declared there as well. The PR description is updated.

@DanielLeens DanielLeens left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @fatmanverse, thank you for acting on the suggestion so quickly, and for the extra audit of the source side. I re-reviewed the new head 59b7d7c7 against c79be20b (the head I reviewed last time, when the only open item was CI). The code-side verdict stays the same and I do not have any new blockers.

What Problem Does This PR Solve?

User pain point: --check, --dry-run static|connect and the Flink/Spark config validation call ConfigValidator#validateUnknownKeys, which only accepts keys declared in the connector's OptionRule. The Jdbc factories did not declare several documented options the connector reads, so valid configs failed with Connector 'Jdbc' has unknown option keys: [table] (#12796).

Fix approach: Declare the missing options as optional in JdbcSinkFactory and JdbcSourceFactory, and pin completeness with a reflection-based test.

One-sentence summary: Close the option-declaration gap in the Jdbc factories so strict config validation stops rejecting documented options.

1. Code Change Review

1.1 Core Logic Analysis

What changed since my last review: one commit adding JdbcOptionRuleCompletenessTest and three more source declarations (access_key_id, secret_access_key, region) that the new test surfaced. I checked the source path: JdbcConnectionConfig.of (shared by source and sink) reads ACCESS_KEY_ID, SECRET_ACCESS_KEY and REGION (JdbcConnectionConfig.java:116-118), so the source really does consume them (DSQL provider) and declaring them on the source is correct.

  • The normal job-run path does not consult optionRule() for values, so runtime behavior is unchanged. The change reaches the strict validation path (--check, --dry-run, Flink/Spark validation) plus the option-rules REST/metadata export, as described in the PR.
  • Options are added as optional, so a config that was previously valid cannot become invalid under the unknown-key check; schema is correctly left off the source.
  • OptionRule fallback keys are covered by ConfigValidator itself, so no alias is lost.

1.2 Compatibility Impact

Fully compatible. No API, option name, default, protocol or serialization change; previously valid configs behave identically and previously wrongly-rejected configs are now accepted. Truly unknown keys are still rejected. No incompatible-changes.md entry is needed.

1.3 Performance / Side-Effect Analysis

Declaration-only change with no CPU, memory, network, lock or retry impact. Sensitive options (secret_access_key, kerberos_keytab_path) are only declared, not logged.

1.4 Error Handling and Logging

No new exception or logging path. The existing unknown-key message now fires only for genuinely undeclared keys.

No blocking issues found.

2. Code Quality Assessment

2.1 Coding Standards

Consistent with the surrounding code; the new test class carries a Javadoc explaining the regression it guards.

2.2 Test Coverage and Test Stability

  • JdbcOptionRuleCompletenessTest collects every public static Option of JdbcSourceOptions/JdbcSinkOptions (including inherited JdbcCommonOptions) and asserts validateUnknownKeys accepts them all. It fails if any declaration is removed from either factory, and also if a future option is added without being declared, which is exactly the drift risk. The single exclusion (schema on the source) is explicit. Thank you, this makes the guarantee self-maintaining.
  • The earlier testDocumented*OptionsAreNotUnknownKeys / testUndeclaredSinkOptionIsUnknownKey tests remain.
  • Stability rating: Stable. Pure in-memory validation: no sleeps, ports, containers, ordering or timing dependence. I did not run them locally; the CI unit-test job is the evidence.

Tiny non-blocking nit (Low): the completeness test only walks the three option classes, so an Option defined elsewhere in the module (for example a catalog-only option class) is not covered. Your own audit of 67 keys suggests that is not a gap today; no change is needed here.

2.3 Documentation Updates

Not required: the options are already documented in the Jdbc source/sink docs and the change does not alter user-facing semantics beyond fixing validation. docs/zh is unaffected.

3. Architectural Soundness

3.1 Elegance of the Solution

Precise fix using the existing OptionRule mechanism.

3.2 Maintainability

Clear and low-risk, and with the new reflection test the declaration drift risk is covered.

3.3 Extensibility

The completeness-test pattern can be reused for other connectors with the same drift risk.

3.4 Historical-Version Compatibility

Compatible with all historical configs and job files; no upgrade action is required.

4. Issue Summary

Number Issue Location Severity
- No blocking issues found - -

5. Merge Recommendation

Conclusion: Ready to merge

  1. Blockers - must be fixed: none from the code side.
  2. Recommended fixes - non-blocking: the nit in 2.2 only.

CI status: when I checked, the Build workflow on the current head was still in progress (apache-side Build check https://github.com/apache/seatunnel/runs/116786819731, fork run https://github.com/fatmanverse/seatunnel/actions/runs/38842898243), so I cannot yet call it green. The branch is also 12 commits behind dev, which is not a conflict. If a lane fails and the failure is unrelated to the Jdbc factories, syncing the latest dev and re-running is the cheapest next step; ping me with the failing link and I will help narrow it down. Once CI is green I am happy to approve.

Overall assessment: correct, minimal, well tested and fully compatible. No better alternative implementation is needed.

Thanks again for the fix!

@DanielLeens DanielLeens left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI update for head 59b7d7c78, with no code change since my last review.

In my last review the only open gate was CI: the Build workflow on this head was still in progress. That fact has changed. The apache-side Build check (see https://github.com/apache/seatunnel/runs/116786819731) is now SUCCESS on this exact head.

CI was previously the only remaining blocker, and it is now passing, so I am changing my conclusion to approve. I did not find any code-side blocker in my last review and nothing has changed in the diff since.

This approval is based on a static review of the code plus the passing CI above; I did not execute the PR myself. A committer approval is still required for merge.

Thanks for the contribution!

@davidzollo davidzollo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving: Build is green on this exact head and the code-side review found no blockers.

@davidzollo
davidzollo added this pull request to the merge queue Oct 16, 2026
Merged via the queue into apache:dev with commit 5734e4f Oct 16, 2026
3 checks passed
Asthenia0412 added a commit to Asthenia0412/seatunnel that referenced this pull request Oct 18, 2026
…the connector (apache#12800)

Co-authored-by: chen <7748128+chen_sir_sor_admin@user.noreply.gitee.com>

Signed-off-by: Asthenia0412 <Asthenia0412@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug][Connector-V2][Jdbc] --check and --dry-run reject documented Jdbc options such as table as unknown keys

4 participants