Skip to content

[Bug][Transform-V2] FORMATDATETIME and FROM_UNIXTIME depend on the worker default locale #12975

Open

Description

@SEPURI-SAI-KRISHNA

Search before asking

What happened

The Zeta SQL transform builds the formatter for FORMATDATETIME and FROM_UNIXTIME with DateTimeFormatter.ofPattern(format), which captures Locale.getDefault(Locale.Category.FORMAT) at construction. Any pattern letter that renders text rather than digits (MMM, MMMM, EEE, EEEE, a, G, QQQ) therefore produces a different string depending on the default locale of whichever worker JVM runs the transform.

  • DateTimeFunction.java:616 (formatdatetime)
  • DateTimeFunction.java:799 (fromUnixTime)

The same job, over the same rows, writes different values to the sink on different workers, and the values are not reproducible across environments.

The clearest sign that this is unintended is inside the same class. DAYNAME and MONTHNAME deliberately pin English: getMonthsAndWeeks at DateTimeFunction.java:327-336 uses DateFormatSymbols.getInstance(Locale.ENGLISH). So one weekday value, in one row, in one transform, comes out of DAYNAME in English and out of FORMATDATETIME(dt, 'EEEE') in the worker's language.

I measured this by compiling seatunnel-transforms-v2 from dev and calling the real DateTimeFunction methods, not a reimplementation. Input 2026-10-23T14:05:09:

default locale DAYNAME(dt) MONTHNAME(dt) FORMATDATETIME(dt,'EEEE') FORMATDATETIME(dt,'dd MMM yyyy') FROM_UNIXTIME(ts,'MMM dd','UTC')
en-US Friday October Friday 23 Oct 2026 Oct 23
tr-TR Friday October Cuma 23 Eki 2026 Eki 23
ja-JP Friday October 金曜日 23 10月 2026 10月 23
de-DE Friday October Freitag 23 Okt. 2026 Okt. 23
ar-EG Friday October الجمعة 23 أكتوبر 2026 أكتوبر 23

What is not affected, checked rather than assumed. Numeric-only patterns are stable: yyyy-MM-dd HH:mm:ss through the same function gives one distinct result across all five locales. All 13 patterns of ZetaDateTimeFormat are numeric-only and produced zero variation across seven locales including th-TH-u-ca-buddhist and ar-EG-u-nu-arab, so that enum is not part of this report. Every existing use of these two functions in the tests, the e2e configs and the docs is numeric-only, which is why no test catches this today.

SeaTunnel Version

dev at 14a27ac26a0a71b56722f86cdf8ec2779094ceaf

SeaTunnel Config

env {
  job.mode = "BATCH"
}

source {
  FakeSource {
    plugin_output = "fake"
    schema = {
      fields {
        id = "int"
        dt = "timestamp"
      }
    }
    rows = [
      {fields = [1, "2026-10-23T14:05:09"], kind = INSERT}
    ]
  }
}

transform {
  Sql {
    plugin_input = "fake"
    plugin_output = "out"
    query = "select id, DAYNAME(dt) as a, FORMATDATETIME(dt, 'EEEE') as b, FORMATDATETIME(dt, 'dd MMM yyyy') as c from fake"
  }
}

sink {
  Console {
    plugin_input = "out"
  }
}

Running Command

# the pattern text is the only thing that changes between these two runs
./bin/seatunnel.sh --config ./config/sql_locale.conf -e local
JAVA_TOOL_OPTIONS="-Duser.language=tr -Duser.country=TR" ./bin/seatunnel.sh --config ./config/sql_locale.conf -e local

Error Exception

No exception is raised. That is what makes this hard to notice: the job succeeds and writes different data.

# default locale en-US
a = Friday,  b = Friday,  c = 23 Oct 2026

# default locale tr-TR, same job, same row
a = Friday,  b = Cuma,    c = 23 Eki 2026
#            ^^^^^^^^^^ DAYNAME stays English because DateTimeFunction.java:331
#                       pins Locale.ENGLISH, while FORMATDATETIME follows the JVM

Zeta or Flink or Spark Version

Not engine specific. The defect is in seatunnel-transforms-v2, which every engine shares. I ran the functions directly rather than a cluster, so I am not claiming a cluster reproduction here.

Java or Scala Version

openjdk 17.0.20.1 2026-08-18, build 17.0.20.1+1-1-24.04-Ubuntu

Screenshots

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. SEZ9 commented on Oct 25, 2026

    @SEZ9
    Collaborator

    Thanks for the detailed report and for measuring against the real DateTimeFunction methods rather than a reimplementation. The contrast with DAYNAME/MONTHNAME, which already pin Locale.ENGLISH via DateFormatSymbols, is a strong sign the locale-dependent output of FORMATDATETIME and FROM_UNIXTIME is unintended.

    A fix would likely be to pin an explicit locale when building the formatter in both formatdatetime and fromUnixTime, plus a unit test that runs under a non-English default locale to guard against regressions.

    Since you've indicated you're willing to submit a PR, please go ahead. One thing to keep in mind: pinning to English is a behavior change for users on non-English workers who currently get localized month/day names, so it's worth calling out in the PR description. An optional locale argument could be considered in a follow-up, but deterministic output across workers should be the default.

  2. SEPURI-SAI-KRISHNA commented on Oct 25, 2026

    @SEPURI-SAI-KRISHNA
    CollaboratorAuthor

    Thanks @SEZ9. The PR is already open as #12976 and it does what you describe.

    Both call sites now pass an explicit locale:

    // formatdatetime, DateTimeFunction:619   and   fromUnixTime, DateTimeFunction:803
    DateTimeFormatter df = DateTimeFormatter.ofPattern(format, Locale.ENGLISH);

    On the behaviour change, it is called out in the PR description, and Locale.ENGLISH was chosen over Locale.ROOT for exactly that reason. I measured both against today's output rather than assuming they agree:

    pattern today, en-US Locale.ROOT Locale.ENGLISH
    EEEE Friday Fri Friday
    MMMM October Oct October

    Locale.ROOT silently abbreviates 2 of the 7 text patterns, so it would change output for English workers too. Locale.ENGLISH changes 0 of 7, which keeps the change confined to the workers that were producing localized text. It also matches what this class already does for DAYNAME and MONTHNAME through DateFormatSymbols.getInstance(Locale.ENGLISH).

    So users on a non-English worker who were getting localized month and day names will now get English, which is the deliberate part of the fix, and users on an English worker see byte identical output.

    The regression test runs the real SQLTransform under ENGLISH, tr-TR and ja-JP defaults and restores the previous locale in a finally, following testAtTimeZone in the same class. One case asserts FORMATDATETIME(dt,'EEEE') equals DAYNAME(dt) and FORMATDATETIME(dt,'MMMM') equals MONTHNAME(dt), which is the inconsistency this fixes, with a numeric-pattern control alongside.

    Agreed that an optional locale argument is a separate follow-up; this PR keeps the default deterministic and does not add an option.

  3. SEZ9 commented on Oct 26, 2026

    @SEZ9
    Collaborator

    Thanks for the detailed follow-up, and for measuring Locale.ROOT vs Locale.ENGLISH instead of assuming they agree. The EEEE → Fri and MMMM → Oct abbreviation under Locale.ROOT is exactly the kind of silent change we want to avoid for English workers, so Locale.ENGLISH is the right pick here, and lining it up with what DAYNAME/MONTHNAME already do via DateFormatSymbols.getInstance(Locale.ENGLISH) makes the behaviour of the class internally consistent. Passing the explicit locale at both the formatdatetime and fromUnixTime call sites covers the scope of what I flagged.

    The test shape also sounds right: running the real SQLTransform under ENGLISH, tr-TR and ja-JP, restoring the default in a finally the way testAtTimeZone does, and asserting FORMATDATETIME(dt,'EEEE') equals DAYNAME(dt) and FORMATDATETIME(dt,'MMMM') equals MONTHNAME(dt) with a numeric control alongside.

    Two small asks before I sign off on the PR:

    1. You mention 7 text patterns but the table shows 2. Could you either add the remaining ones (at least MMM, a, G, QQQ from the original report) to the locale-switching test, or paste the rest of that comparison in the PR so the "0 of 7 changed" claim is verifiable?
    2. Since non-English workers will now see English month/day names, please make sure the PR description's behaviour-change note is also reflected in the function docs for FORMATDATETIME/FROM_UNIXTIME so it shows up in release notes.

    Agreed that an optional locale argument is a separate follow-up; keeping this PR to a deterministic default is the right scope.

  4. SEPURI-SAI-KRISHNA commented on Oct 26, 2026

    @SEPURI-SAI-KRISHNA
    CollaboratorAuthor

    Thanks @SEZ9. Both asks, in order.

    1. The full comparison, and the test now drives it. You offered two options and the first is the better one, so the locale switching test exercises all ten text bearing patterns instead of three, with de-DE added as a fourth default. Measured on 2024-06-15, a Saturday in Q2, afternoon:

    pattern ENGLISH tr-TR ja-JP de-DE
    G AD MS 西暦 n. Chr.
    MMM Jun Haz 6月 Juni
    MMMM June Haziran 6月 Juni
    LLLL June Haziran 6月 Juni
    EEE Sat Cmt 土 Sa.
    EEEE Saturday Cumartesi 土曜日 Samstag
    ccc Sat Cmt 土 Sa
    a PM ÖS 午後 PM
    QQQ Q2 Ç2 Q2 Q2
    QQQQ 2nd quarter 2. çeyrek 第2四半期 2. Quartal

    All ten are now asserted under all four defaults, so the claim is checked by CI rather than by a table in a thread.

    A correction to my earlier comment. I said Locale.ROOT changes 2 of 7. Measured properly it is 4 of 10: MMMM, EEEE, QQQQ and LLLL all abbreviate under ROOT. Locale.ENGLISH changes 0 of 10. The conclusion is unchanged and in fact stronger, but the numbers I gave you were understated and I should have measured before quoting them.

    2. Already in the PR. docs/en/transforms/sql-functions.md and the ZH page both carry the behaviour note, under FORMATDATETIME and again under FROM_UNIXTIME.

    One thing you did not ask for, which came out of @DanielLeens's review and is worth knowing before you sign off: the pinned locale also pins WeekFields, so the localised numeric fields Y, w, W, e and c change too. A de-DE or en-GB worker formatting 2021-01-01 with YYYY got 2020 and now gets 2021. en-GB matters there: an English language default is not interchangeable with Locale.ENGLISH for these fields. Both upgrade notes and both function pages now document it, and there is a regression covering it.

  5. SEZ9 commented on Oct 27, 2026

    @SEZ9
    Collaborator

    @SEPURI-SAI-KRISHNA thanks for measuring rather than quoting — this covers both asks.

    1. Comparison and test. The four-default, ten-pattern table is exactly what I wanted, and asserting it in the locale-switching test is the right place for it. The corrected figures (Locale.ROOT abbreviating MMMM, EEEE, QQQQ and LLLL, 4 of 10, versus Locale.ENGLISH changing 0 of 10) only strengthen the case for Locale.ENGLISH, and it stays consistent with what DAYNAME/MONTHNAME already do via DateFormatSymbols.getInstance(Locale.ENGLISH). If the earlier 2-of-7 figure appears anywhere in the PR description or docs, please update it to the measured numbers.

    2. Docs. Good — the behaviour note under both FORMATDATETIME and FROM_UNIXTIME on the EN and ZH pages is what I was after.

    Nothing further from me on this item.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions