Skip to content

[Fix][Transform-V2] Make SQL case conversion locale independent - #11951

Merged
davidzollo merged 2 commits into
apache:devfrom
zhangshenghang:fix/sql-string-case-locale
Sep 1, 2026
Merged

davidzollo merged 2 commits into
apache:devfrom
zhangshenghang:fix/sql-string-case-locale

Conversation

@zhangshenghang

Copy link
Copy Markdown
Member

Purpose

Fixes #11949.

Make Zeta SQL LOWER and UPPER deterministic across worker JVM locales by using Locale.ROOT.

Changes

  • Use Locale.ROOT for SQL case conversion.
  • Add a Turkish-locale regression test for LOWER("I") and UPPER("i").

Verification

  • ./mvnw spotless:apply
  • ./mvnw -pl seatunnel-transforms-v2 -Dtest=StringFunctionTest test
  • ./mvnw -q -DskipTests verify

@zhangshenghang
zhangshenghang force-pushed the fix/sql-string-case-locale branch from 585612b to 680ceb8 Compare August 23, 2026 14:07

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

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/CastFunction for any other locale-sensitive toUpperCase()/toLowerCase() calls on user data. The other occurrences in the SQL package (SQLTransform.KEY_ENGINE, function-name dispatch in ZetaSQLType/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/UPPER are the only two case-conversion functions exposed by the Zeta SQL dialect (confirmed via ZetaSQLFunction constants) — there is no INITCAP or 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(...) or UPPER(...) 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 a try/finally block, 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

  1. 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, by zhangshenghang) both fix issue #11949 with the identical one-line Locale.ROOT change to StringFunction.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).
  2. 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 (including unit-test on all 4 OS/JDK combinations) passed; the only non-green jobs are paimon-connector-it (8, ubuntu-latest) (failure) and kudu-connector-it (11, ubuntu-latest) (cancelled, likely cascaded), both unrelated to this seatunnel-transforms-v2-only diff. This branch is also 4 commits behind current dev (and 1 ahead). Since the failure looks environment/module-unrelated and the branch is behind, syncing with the latest dev and 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 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.

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.java itself, I confirmed there are exactly two case-conversion call sites (lower() at line 264, upper() at line 272), and both now pass Locale.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-v2 module 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/155 and FieldRenameTransform.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 to LOWER/UPPER in 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 raw BOOLEAN-typed output string), nlpmodel/ModelInvocationCacheKey.java:144 — these also call unguarded toLowerCase() 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's rule_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 evaluates LOWER/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 a try/finally block, 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 against Locale.ROOT output 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

  1. 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/seatunnel run 33168835166 and companions) and confirmed the failing/cancelled jobs are: unit-test (8, ubuntu-latest) — an Awaitility mock-timing flake in CoordinatorServiceTest.testClearCoordinatorServiceDropsPendingJobsUnderRejectStrategy (seatunnel-engine, unrelated to transforms-v2); unit-test (8, windows-latest) — a PythonSourceTest failure (python connector, unrelated); all-connectors-it-2 (8, ubuntu-latest) — CouchbaseIT container-bootstrap flake (previously reported as environment-related, not code-caused); and rocketmq-connector-it (11, ubuntu-latest) cancelled, likely cascaded from the same run's timeout budget. None of these touch seatunnel-transforms-v2 or StringFunction, and the sync commit's own message confirms paimon-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.
  2. 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.

@DanielLeens

Copy link
Copy Markdown
Contributor

CI status update on Issue 2 from my last review: the apache-side Build check on the current head (c0d0ddd7f7) is now showing success — the JDK-8 unit-test flake, PythonSourceTest failure, CouchbaseIT container-bootstrap flake, and the cascaded rocketmq-connector-it cancellation I traced on 08-29 have all cleared, presumably via a rerun. So Issue 2 is resolved; no code change needed there, as expected since none of those failures touched seatunnel-transforms-v2.

Issue 1 is still the only open item: #11950 remains open and still duplicates this PR (same author-of-report, same Locale.ROOT fix, same regression-test pattern). A maintainer still needs to pick one of #11951 / #11950 to merge and close the other as a duplicate — that's a process decision, not something I can resolve from a review, so I'm not converting this to an approval yet.

@DanielLeens

Copy link
Copy Markdown
Contributor

CI follow-up on my review above: I flagged the apache-side Build check as FAILURE and traced it to a set of pre-existing, unrelated flakes (CoordinatorServiceTest Awaitility timing in engine, PythonSourceTest, a Couchbase testcontainer bootstrap issue, and a cascaded rocketmq-connector-it cancellation) — none touching seatunnel-transforms-v2 or StringFunction.

Re-checked live: the head is unchanged, and the Build check (run 98840719989) now shows pass, along with Notify test workflow and labeler. So that CI condition is resolved and no longer a blocker.

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

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

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.

[Transform-V2] SQL lower and upper depend on the worker default locale

3 participants