Repository navigation
[Fix][Transform-V2] Make SQL case conversion locale independent - #11951
Conversation
585612b to
680ceb8
Compare
DanielLeens
left a comment
There was a problem hiding this comment.
What Problem Does This PR Solve?
The SQL transform's LOWER/UPPER functions called Java's locale-sensitive String.toLowerCase() / String.toUpperCase() without specifying a locale. Under certain JVM default locales (most famously Turkish, tr-TR), Java's case folding is not the simple ASCII-style mapping most users expect: "I".toLowerCase() becomes the dotless ı and "i".toUpperCase() becomes dotted İ. Since a distributed SeaTunnel job can run its worker JVMs under different host locales, the same SQL transform could silently produce different output data depending on which machine executed it. This PR fixes that by switching both calls to Locale.ROOT, which is what SQL engines are generally expected to do for case conversion — it is deterministic and independent of the runtime environment.
1. Code Change Review
1.1 Core Logic Analysis
The change is a precise two-line fix in StringFunction.java:
// before
return arg.toLowerCase();
...
return arg.toUpperCase();
// after
return arg.toLowerCase(Locale.ROOT);
...
return arg.toUpperCase(Locale.ROOT);Key Findings:
- I checked the rest of
ZetaSQLFunction/StringFunction/DateTimeFunction/NumericFunction/CastFunctionfor any other locale-sensitivetoUpperCase()/toLowerCase()calls on user data. The other occurrences in the SQL package (SQLTransform.KEY_ENGINE, function-name dispatch inZetaSQLType/ZetaSQLFunction,CastFunction's type-name switch, etc.) all operate on internal keywords/identifiers written in ASCII by the SQL author, not on arbitrary user row data, so they are out of scope for this bug and correctly left untouched. LOWER/UPPERare the only two case-conversion functions exposed by the Zeta SQL dialect (confirmed viaZetaSQLFunctionconstants) — there is noINITCAPor similar function that would need the same treatment.- Null handling is preserved unchanged (
if (arg == null) return null;stays before the call). - This is a genuine hot/normal-path fix: any user job that runs a SQL transform with
LOWER(...)orUPPER(...)executes this exact method on every row, on the Zeta worker's task thread — it is not a boundary/recovery-only path.
Runtime path for a Zeta job using this transform:
Worker task thread
-> SQLTransform.map(SeaTunnelRow)
-> ZetaSQLEngine evaluates the LOWER/UPPER function call
-> StringFunction.lower(args) / .upper(args) <-- fixed here
No checkpoint, serialization, or cross-thread state is involved; the change is confined to a pure, stateless string transformation.
1.2 Compatibility Impact
Fully compatible. For the overwhelming majority of deployments (JVM default locale en_US, zh_CN, C/POSIX, etc.), Locale.ROOT and the previous default-locale behavior produce byte-identical output — Locale.ROOT's case-folding rules match the common Latin-alphabet locales. The only behavior change is for the narrow set of locales with special-cased Unicode casing rules (Turkish/Azerbaijani "dotted/dotless i", Lithuanian, etc.), and there the new behavior is strictly a correctness fix converging on the documented, expected SQL semantics rather than an incompatible change to any documented contract.
1.3 Performance / Side-Effect Analysis
None. Locale.ROOT is a static singleton; passing it explicitly has no measurable overhead versus relying on Locale.getDefault(), and no new allocations or branches are introduced.
1.4 Error Handling and Logging
Not applicable — no error paths were touched, and none are needed for this fix.
No issues raised in this section.
2. Code Quality Assessment
2.1 Coding Standards
lower()/upper() are pre-existing package-private-style static helpers with no Javadoc in this file (consistent with every other function in StringFunction.java, e.g. left(), right()), so the lack of a new Javadoc comment here is consistent with the surrounding code style and not a regression.
2.2 Test Coverage and Test Stability
A new regression test, testLowerAndUpperAreLocaleIndependent, is added:
- Captures and restores
Locale.getDefault()in atry/finallyblock, so it cannot leak global JVM state into other tests even if an assertion fails — this avoids the classic "shared static state" flaky-test anti-pattern. - Uses
Locale.setDefault(Locale.forLanguageTag("tr-TR"))to deterministically reproduce the exact bug condition described in the linked issue, then asserts exact string equality ("i"/"I") — no timing, no sleeps, no floating point, no ordering dependency on other tests.
Stability rating: Stable.
2.3 Documentation Updates
Not required — this is a bug fix restoring documented/expected LOWER/UPPER semantics, not a new option or a documented behavior change; no docs/en or docs/zh updates are needed.
3. Architectural Soundness
3.1 Elegance of the Solution
Precise fix. This is exactly the idiomatic, minimal, long-term-correct way to fix locale-dependent casing in Java (Locale.ROOT is the standard recommendation for this exact bug class).
3.2 Maintainability
Trivial to maintain; no new abstractions, no new surface area.
3.3 Extensibility
N/A — no new extension points introduced or needed.
3.4 Historical-Version Compatibility
No config/protocol/serialization/checkpoint impact whatsoever; purely an in-memory string transformation. Fully safe for in-place upgrade.
4. Issue Summary
| Number | Issue | Location | Severity |
|---|---|---|---|
| 1 | This PR duplicates PR #11950, which makes the byte-for-byte identical production code change (Locale.ROOT in lower()/upper()) plus a functionally identical regression test, for the same underlying issue #11949 |
seatunnel-transforms-v2/.../StringFunction.java |
Informational (needs maintainer reconciliation, not a code defect) |
No functional, compatibility, or stability defects were found in this PR's own diff.
5. Merge Recommendation
Conclusion: Ready to merge after fixes
- Blockers — must be fixed: None from a correctness standpoint. The only blocking action needed is process-level: I verified by reading both diffs directly that PR #11950 (opened by
tagadearpit, the original reporter of issue #11949) and this PR (#11951, byzhangshenghang) both fix issue #11949 with the identical one-lineLocale.ROOTchange toStringFunction.lower()/upper()and near-identical regression tests (only the test method name differs). A maintainer needs to pick one of the two to merge and close the other as a duplicate — merging both would just be a no-op re-application of the same diff (the second to merge would show as "no changes" or trivially conflict). - Recommended fixes — non-blocking: The overall "Build" check shows as
cancelled, but drilling into the fork's own Actions run shows all 30-plus core jobs (includingunit-teston all 4 OS/JDK combinations) passed; the only non-green jobs arepaimon-connector-it (8, ubuntu-latest)(failure) andkudu-connector-it (11, ubuntu-latest)(cancelled, likely cascaded), both unrelated to thisseatunnel-transforms-v2-only diff. This branch is also 4 commits behind currentdev(and 1 ahead). Since the failure looks environment/module-unrelated and the branch is behind, syncing with the latestdevand re-running CI is a reasonable, low-risk next step before merge — but it is not evidence of a real defect in this PR.
Overall: the fix itself is small, correct, well-tested, and safe to merge on its own technical merits. The only real gating item is the duplicate-PR situation with #11950, which a maintainer should resolve by picking one canonical PR.
Merge apache/seatunnel dev (1ff72ce) into fix/sql-string-case-locale. paimon-connector-it (8) hung in PaimonIT on the old base: the job got stuck in CANCELING after the expected NoPrivilegeException and never finished, which reproduces across runs on this branch but not on current dev, where the Paimon E2E stabilization commits (apache#11608, apache#11718) landed. Syncing picks those up (dev's latest Build run has paimon-connector-it 8/11 green), along with the new merge queue CI (apache#11963). No functional changes beyond the merge: the PR diff vs dev is still StringFunction + its unit test.
DanielLeens
left a comment
There was a problem hiding this comment.
What Problem Does This PR Solve?
The SQL transform's LOWER/UPPER functions called Java's locale-sensitive String.toLowerCase() / String.toUpperCase() without specifying a locale. Under certain JVM default locales (most famously Turkish, tr-TR), Java's case folding is not the simple ASCII-style mapping most users expect: "I".toLowerCase() becomes the dotless ı and "i".toUpperCase() becomes dotted İ. Since a distributed SeaTunnel job can run its worker JVMs under different host locales, the same SQL transform could silently produce different output data depending on which machine executed it. This PR fixes that by switching both calls to Locale.ROOT, which is deterministic and independent of the runtime environment.
This is a re-review against the current head (c0d0ddd7f7) per the NEED_REREVIEW process, since a new commit landed after my last review on 2026-08-24.
0. What Changed Since My Last Review
I re-fetched the branch and diffed it against the current dev base. The only new commit is:
c0d0ddd7f7d Merge: [Fix][Transform-V2] Sync SQL locale fix with latest dev
This is a merge-with-dev commit only — its own message states, and I independently verified via git diff dev...HEAD --stat, that the PR's net diff against dev is still exactly the same two files I reviewed before: StringFunction.java (+3/-2) and StringFunctionTest.java (+14). There is no new production logic to review. The purpose of the sync was to pick up unrelated Paimon E2E stabilization fixes that had landed on dev (the branch was previously behind dev and hitting a stale, since-fixed Paimon hang). My prior technical analysis of the fix itself therefore still stands; nothing was missed in the previous round, and there is no new code-level content to flag. I re-verified all findings below from scratch against the current head rather than assuming carryover.
1. Code Change Review
1.1 Core Logic Analysis
The fix in StringFunction.java:
// before
return arg.toLowerCase();
...
return arg.toUpperCase();
// after
return arg.toLowerCase(Locale.ROOT);
...
return arg.toUpperCase(Locale.ROOT);Key findings (re-verified against current head via git grep on the PR branch, not just the diff):
- Within
StringFunction.javaitself, I confirmed there are exactly two case-conversion call sites (lower()at line 264,upper()at line 272), and both now passLocale.ROOT. There is no third unguarded call left in this file — the fix is complete for its stated scope. - I re-swept the entire
seatunnel-transforms-v2module for other.toLowerCase()/.toUpperCase()calls that operate on user row data (as opposed to SQL keywords/function names/config values written by the job author, which are ASCII-only and out of scope for this bug class):TableRenameTransform.java:153/155andFieldRenameTransform.java:167/170— these convert user table/field names and are exactly the same bug class, but they are correctly not touched by this PR since it's scoped toLOWER/UPPERin the SQL transform. They are addressed by the sibling PR #11994 (see section 1.5 below) rather than needing to be folded into this PR.nlpmodel/embedding/multimodal/ModalityType.java,PayloadFormat.java,nlpmodel/llm/remote/AbstractModel.java:123(lowercases an LLM's rawBOOLEAN-typed output string),nlpmodel/ModelInvocationCacheKey.java:144— these also call unguardedtoLowerCase()on user/model-influenced strings and are theoretically susceptible to the same locale class of bug, but they live in a completely different transform family (LLM/embedding) and are out of scope for a PR titled "Make SQL case conversion locale independent." Flagged as a non-blocking follow-up in section 4, not a gap in this PR.- All remaining occurrences (
ZetaSQLFunction,ZetaSQLType,CastFunction,DateTimeFunction,NumericFunction,VectorFunction,SystemFunction,SQLTransform.KEY_ENGINE,DataValidatorTransformConfig'srule_type/boolean-config parsing) all operate on SQL keywords, function names, type names, or job-config literals that are always written in ASCII by the SQL/config author, never on arbitrary row data — correctly out of scope.
- Null handling is preserved unchanged (
if (arg == null) return null;still precedes the call). - Runtime path confirmed unchanged from my prior review: Worker task thread ->
SQLTransform.map(SeaTunnelRow)-> Zeta SQL engine evaluatesLOWER/UPPER->StringFunction.lower()/upper(). This is the normal per-row hot path for any job using these two functions, not a boundary/recovery-only path. No checkpoint, serialization, or cross-thread state is involved.
1.2 Compatibility Impact
Fully compatible. For the overwhelming majority of deployments (JVM default locale en_US, zh_CN, C/POSIX, etc.), Locale.ROOT and the previous default-locale behavior produce byte-identical output. The only behavior change is for the narrow set of locales with special-cased Unicode casing rules (Turkish/Azerbaijani, Lithuanian, etc.), where the new behavior is a correctness fix converging on standard SQL semantics rather than an incompatible change to any documented contract.
1.3 Performance / Side-Effect Analysis
None. Locale.ROOT is a static singleton; passing it explicitly has no measurable overhead versus relying on Locale.getDefault(), and no new allocations or branches are introduced.
1.4 Error Handling and Logging
Not applicable — no error paths were touched, and none are needed for this fix.
No issues raised in this section.
1.5 Cross-reference: sibling PR #11994
I checked #11994 ("[Fix][Transform-V2] Make rename transform case conversion locale independent") as requested. It fixes the same root cause (Turkish-locale toUpperCase()/toLowerCase()) but in a different code path: TableRenameTransform.convertCase() and FieldRenameTransform.convertCase(), not StringFunction. Its own PR description explicitly says "this is the same class of bug as the SQL lower()/upper() functions (#11949) — but those PRs only fixed StringFunction, leaving the rename transforms affected," and its regression test also drives Locale.setDefault(Locale.forLanguageTag("tr-TR")), mirroring this PR's test pattern. This is a correctly-scoped companion fix, not a duplicate of this PR, and both PRs are independently mergeable — I'll leave a short cross-reference comment on #11994 noting consistency with this PR's approach.
2. Code Quality Assessment
2.1 Coding Standards
lower()/upper() are pre-existing package-private-style static helpers with no Javadoc in this file (consistent with every other function in StringFunction.java), so the lack of a new Javadoc comment here is consistent with the surrounding code style and not a regression.
2.2 Test Coverage and Test Stability
testLowerAndUpperAreLocaleIndependent in StringFunctionTest.java:
- Captures and restores
Locale.getDefault()in atry/finallyblock, so a failed assertion cannot leak global JVM locale state into other tests — avoids the classic shared-static-state flaky-test anti-pattern. - Uses
Locale.setDefault(Locale.forLanguageTag("tr-TR"))to deterministically reproduce the exact bug condition from the linked issue (not just asserting againstLocale.ROOToutput in isolation), then asserts exact string equality ("i"/"I") — this is a genuine regression test that would fail against the pre-fix code, not just a happy-path check. No timing, no sleeps, no ordering dependency on other tests.
Stability rating: Stable.
2.3 Documentation Updates
Not required — this is a bug fix restoring documented/expected LOWER/UPPER semantics, not a new option or a documented behavior change; no docs/en/docs/zh updates are needed.
3. Architectural Soundness
3.1 Elegance of the Solution
Precise fix. Locale.ROOT is the standard, idiomatic Java fix for this exact bug class.
3.2 Maintainability
Trivial to maintain; no new abstractions, no new surface area.
3.3 Extensibility
N/A — no new extension points introduced or needed.
3.4 Historical-Version Compatibility
No config/protocol/serialization/checkpoint impact whatsoever; purely an in-memory string transformation. Fully safe for in-place upgrade.
4. Issue Summary
| Number | Issue | Location | Severity | Raised by another reviewer |
|---|---|---|---|---|
| 1 | Carryover from my 2026-08-24 review: this PR duplicates #11950 (same author-of-report tagadearpit's PR), which makes the byte-for-byte identical Locale.ROOT change plus a near-identical regression test for the same issue #11949. Still unresolved — #11950 remains open. |
seatunnel-transforms-v2/.../StringFunction.java |
Informational (process, not a code defect) | No |
| 2 | The apache-side "Build" check on the current head shows FAILURE, but this is CI noise unrelated to this diff (see CI State below for per-job breakdown) — not a code defect in this PR. | CI | Informational | No |
| 3 | Several other toLowerCase()/toUpperCase() call sites on user/model-influenced strings elsewhere in seatunnel-transforms-v2 (LLM/embedding transforms: ModalityType.java, PayloadFormat.java, AbstractModel.java:123, ModelInvocationCacheKey.java:144) are still unguarded and theoretically susceptible to the same locale bug class, but are out of scope for this PR's stated purpose. |
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/nlpmodel/** |
Low (follow-up, non-blocking) | No |
No functional, compatibility, or stability defects were found in this PR's own diff.
5. Merge Recommendation
Conclusion: Ready to merge after fixes
- Blockers — must be fixed: None from a correctness standpoint; the fix itself is unchanged from my prior review and remains correct, complete for its stated scope, and well-tested. The two gating items are process-level, not code-level:
- Issue 1: a maintainer needs to pick one of #11951 / #11950 to merge and close the other as a duplicate.
- Issue 2: current CI shows the apache-side "Build" check as FAILURE. I traced this to the fork's per-job results (
zhangshenghang/seatunnelrun33168835166and companions) and confirmed the failing/cancelled jobs are:unit-test (8, ubuntu-latest)— an Awaitility mock-timing flake inCoordinatorServiceTest.testClearCoordinatorServiceDropsPendingJobsUnderRejectStrategy(seatunnel-engine, unrelated to transforms-v2);unit-test (8, windows-latest)— aPythonSourceTestfailure (python connector, unrelated);all-connectors-it-2 (8, ubuntu-latest)—CouchbaseITcontainer-bootstrap flake (previously reported as environment-related, not code-caused); androcketmq-connector-it (11, ubuntu-latest)cancelled, likely cascaded from the same run's timeout budget. None of these touchseatunnel-transforms-v2orStringFunction, and the sync commit's own message confirmspaimon-connector-it— the previous CI concern from my last review — is now green after picking up dev's stabilization fixes. This looks safe to clear with a job-level rerun rather than a code change.
- Recommended fixes — non-blocking: Issue 3 (other unguarded locale-sensitive casing in the LLM/embedding transforms) is worth a separate follow-up PR; it is out of scope here.
Overall: the fix itself is small, correct, well-tested, and technically ready to merge on its own. The gating items are entirely process (duplicate PR reconciliation) and CI hygiene (rerunning known-unrelated flaky jobs), not anything in this PR's diff.
|
CI status update on Issue 2 from my last review: the apache-side Issue 1 is still the only open item: #11950 remains open and still duplicates this PR (same author-of-report, same |
|
CI follow-up on my review above: I flagged the apache-side Re-checked live: the head is unchanged, and the No change to my code-side conclusion — no blockers there. The one item still open is Issue 1 from my last review: a maintainer needs to pick one of #11951 / #11950 to merge and close the other as a duplicate. Once that's settled, this looks mergeable from my side; a write-capable maintainer will still need to give the final approval, since I review with read-level permission here. |
davidzollo
left a comment
There was a problem hiding this comment.
+1
LGTM
Thanks for your contribution! This is a solid addition to the project, and your attention to detail really shows. Contributors like you are what keep this community moving forward. Feel free to keep the PRs coming — we're always glad to have you here!
Please ignore the following message if you have joined in the Slack~
To facilitate focused communication among contributors, we’ve created a brand-new dedicated #contributors channel in official Slack workspace.
Slack workspace link: https://s.apache.org/seatunnel-slack
This channel is designed for technical discussions, feature design brainstorming, roadmap sync and direct communication with project core Contributors. Everyone who contributes code, docs, test cases or community ideas is warmly invited to join, share thoughts and collaborate together under The Apache Way. Welcome to join 😄
Purpose
Fixes #11949.
Make Zeta SQL
LOWERandUPPERdeterministic across worker JVM locales by usingLocale.ROOT.Changes
Locale.ROOTfor SQL case conversion.LOWER("I")andUPPER("i").Verification
./mvnw spotless:apply./mvnw -pl seatunnel-transforms-v2 -Dtest=StringFunctionTest test./mvnw -q -DskipTests verify