Repository navigation
[Fix][Connector-V2] Declare all Jdbc source and sink options read by the connector - #12800
Conversation
…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
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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|connectand the Flink/Spark config validation callConfigValidator#validateUnknownKeys, which only accepts keys declared in the connector'sOptionRule. A valid Jdbc config that sets documented options such astablewas rejected withConnector '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(...)inJdbcSinkFactory#optionRule(15 keys) andJdbcSourceFactory#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()): addsTABLE,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,REGIONto the existing.optional(...)list.JdbcSourceFactory.java:84-93(optionRule()): addsCONNECT_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 aboveRuntime 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
- 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. - I verified that every added option is a real, existing
Optionconstant that the connector reads (for exampleJdbcConnectionConfig.java:110-118for properties / narrowing / access key / secret / region, andJdbcSinkConfig.java:52fortable). Nothing is declared that the code does not read. - 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. - This is a precise fix for #12796 (declaration gap), not a workaround.
Correctness notes
- Adding options as
optionalcannot make a previously valid config invalid for the unknown-key check. The only new rejections can come fromvalidateOptionTypes, which now type-checks these keys; they are scalar orMap<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,#testUndeclaredSinkOptionIsUnknownKeyandJdbcSourceFactoryTest#testDocumentedSourceOptionsAreNotUnknownKeysexercise 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/JdbcSinkOptionscould silently reintroduce #12796. A reflection-based test over the public staticOptionfields (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
- Blockers - must be fixed: none from the code side.
- 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.
|
Thanks @ryanmeowy and @DanielLeens for the reviews. Added the reflection-based completeness test in 59b7d7c: The test found three more keys missing on the source: |
DanielLeens
left a comment
There was a problem hiding this comment.
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;schemais correctly left off the source. OptionRulefallback keys are covered byConfigValidatoritself, 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
JdbcOptionRuleCompletenessTestcollects every public staticOptionofJdbcSourceOptions/JdbcSinkOptions(including inheritedJdbcCommonOptions) and assertsvalidateUnknownKeysaccepts 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 (schemaon the source) is explicit. Thank you, this makes the guarantee self-maintaining.- The earlier
testDocumented*OptionsAreNotUnknownKeys/testUndeclaredSinkOptionIsUnknownKeytests 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
- Blockers - must be fixed: none from the code side.
- 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
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
Approving: Build is green on this exact head and the code-side review found no blockers.
…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>
Fixes #12796
Purpose of this pull request
--check,--dry-run static|connectand the Flink/Spark config validation callConfigValidator#validateUnknownKeys, which accepts only keys declared in the connector'sOptionRule. The Jdbc factories did not declare several documented options that the connector reads, so valid configs were rejected, for example: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 byJdbcSinkConfig#of,JdbcConnectionConfig#oforJdbcSinkFactory.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 sharedJdbcConnectionConfig#of; the last three are used by the DSQL connection provider for the source as well as the sink.schemais intentionally not declared on the source: only the sink path and the catalog factories read it.Impact checked:
OptionRule.Builderduplicate checks: none of these options appears elsewhere in either rule.SeaTunnelConfValidateCommand#validateOptionTypesnow type-checks these keys. All of them are scalar orMap<String, String>, the same types the connector already reads at runtime, so a config that runs also passes the check.option-rulesservice and the metadata export now list these options, which matches the docs.Does this PR introduce any user-facing change?
Yes. Configs using these documented options no longer fail
--check/--dry-runwith an unknown-key error. Truly unknown keys are still rejected.How was this patch tested?
JdbcSinkFactoryTest#testDocumentedSinkOptionsAreNotUnknownKeys,#testUndeclaredSinkOptionIsUnknownKeyandJdbcSourceFactoryTest#testDocumentedSourceOptionsAreNotUnknownKeys.JdbcOptionRuleCompletenessTest. It collects every public staticOptionofJdbcSourceOptions/JdbcSinkOptions(including the inheritedJdbcCommonOptions) by reflection and checks thatvalidateUnknownKeysaccepts all of them, with an explicit exclusion list (onlyschemaon the source). A newly added option that is not declared makes it fail../mvnw -pl seatunnel-connectors-v2/connector-jdbc teston JDK 17: all tests pass.bin/seatunnel.sh --checkand--dry-run static|connectwith a Jdbc sink that setstablewere rejected before this change and pass after it.Check list
New License Guide
incompatible-changes.mdto describe the incompatibility caused by this PR. (not needed)