Skip to content

Fix UNIX_TIMESTAMP for DATETIME values in DST gaps - #30793

Merged
XuPeng-SH merged 7 commits into
matrixorigin:mainfrom
jiangxinmeng1:fix/temporal-unix-timestamp-dst-gap
Oct 23, 2026
Merged

XuPeng-SH merged 7 commits into
matrixorigin:mainfrom
jiangxinmeng1:fix/temporal-unix-timestamp-dst-gap

Conversation

@jiangxinmeng1

@jiangxinmeng1 jiangxinmeng1 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG

Which issue(s) this PR fixes:

Fixes #28570
Fixes #28563

What this PR does / why we need it:

UNIX_TIMESTAMP(DATETIME) currently goes through the strict DATETIME-to-TIMESTAMP assignment cast. A DATETIME in a spring DST gap then errors, although the string overload normalizes the same wall time. This also breaks UNIX_TIMESTAMP(DATE_ADD(...)) after date arithmetic correctly returns DATETIME.

Add a DATETIME overload that converts wall time with the session time zone, preserving fractional seconds and existing zero, NULL, and pre-epoch behavior. Add focused unit and SQL regression cases for the gap and ordinary times.

Verification: the relevant tests passed on main at c232b6d before this change. A focused test run passed on an earlier version of this branch before the request to stop branch validation. The rebased PR head has not been tested; CI will provide branch verification.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH

XuPeng-SH commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 262de85202f4e96c763c241ff1ae207e1bafc13c

Review completed. Read the assessment.

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

mo-bot review · mo-bot-local · review

Commit: 262de85202f4e96c763c241ff1ae207e1bafc13c

Assessment: request_changes

Reviewed the complete seven-file delta and surrounding binding, conversion, prepared-statement and result-type paths. The DATETIME overload appropriately reuses existing timezone normalization while preserving strict TIMESTAMP assignment behavior. Targeted tests confirm the intended DST fix. However, unrestricted overload matching also newly accepts TIME inputs through a conversion that uses the host UTC date, producing incorrect epochs. This compatibility regression needs correction.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1

  • P2 pkg/sql/plan/function/list_builtIn.go:12429: Execute SET time_zone='+00:00'; SET timestamp=1704067200; SELECT UNIX_TIMESTAMP(CAST('01:00:00' AS TIME));. The new DATETIME overload lets fixedTypeMatch select the implicit TIME-to-DATETIME conversion.
    Impact: Previously rejected TIME inputs now silently produce host-date-dependent epochs. The conversion calls types.Time.ToDatetime, which uses Today(time.UTC), ignoring the statement date and session-local date. Restrict the new overload to native DATETIME inputs while preserving legacy matching, or implement and test statement/session-aware TIME semantics.
    Evidence: The public SQL probe reported CURRENT_DATE()=2024-01-01 and 1704070800 for explicitly composing that date with 01:00:00, but the candidate TIME expression returned 1792630800, corresponding to the host date 2026-10-22. Replacing both changed production files with their exact merge-base versions rejected the expression with 'invalid argument function unix_timestamp, bad value [TIME]'. Retained time-coercion.log and base-time-coercion.log match receipts 1792664624760680684-4.json and 1792664688915612737-4.json.

Validation:

  • Source audit confirmed the pinned HEAD, clean checkout, complete supplied delta, formatting and diff checks. Receipt: checks/1792664730197671710-4.json.

  • Isolation preflight passed. Native reuse was independently reconciled against 192 current build-input hashes, seven library hashes and the successful build-owner receipt.

  • Ten focused function/planner tests passed, covering DATETIME fractions, NULL/zero/pre-epoch values, strict/nonstrict/IGNORE cast policy and prepared FSP handling. temporal-focused.log; receipt 1792664426322467664-4.json.

  • Public SQL diagnostics passed twice on the same embedded cluster: DST gaps, half-hour transitions, skipped days, fractional boundaries, prepared timezone changes, typed columns, CTAS metadata and strict explicit TIMESTAMP casts. sql-contracts.log; receipt 1792664496141963699-4.json.

  • The merge-base production-file control reproduced the original DST-gap failure. base-control.log; receipt 1792664577519317831-4.json.

  • Commands, source fingerprints, exit codes, logs and diagnostic overlays were reconciled in /home/xupeng/.local/state/mo-bot/jobs/4eb6835a2cc67257ad6e30ef/attempt-1/review-evidence.json. Full review mapping is retained in review-map.json.

Limitations:

  • Linked issue bodies and raw CI logs were not supplied; issue contracts were assessed from the frozen PR description. Recorded successful CI outcomes were supplemental to local execution.

  • No throughput benchmark was run. DATETIME calls should avoid an intermediate TIMESTAMP vector and cast-policy work; no measured speedup is claimed. No new shared state, I/O or synchronization was introduced.

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

Deep-reviewed all seven changed files at exact head 262de85202f4e96c763c241ff1ae207e1bafc13c against declared base/merge-base a949c88af0ed2cc4fe98e2ac32f0732a1235bd85.

The intended DATETIME DST-gap fix, fractional results, NULL/zero/pre-epoch behavior, explicit strict TIMESTAMP-cast controls, and prepared FSP tests pass locally (10 focused roots across function/plan/types). Incremental vet and formatting checks pass. Reused exact-head CI run 39750043886: UT, SCA and both compose BVT legs succeeded; the changed SQL file actually executed 87/87 cases successfully.

Two concrete P2 blockers remain: newly admitted TIME inputs use the host date, and historical DATETIME-derived default expressions stop passing DUMP/LOAD verification. Both have independent exact-base controls below. I read the complete review history including review 5612789087 and independently reproduced its TIME finding; the backup compatibility finding is separate. No new design-document approval gate is being imposed on this ordinary bug fix.

Validation scope: CPU Linux/amd64, Go1.27.1, isolated exact-head/base worktrees with their own native builds. Historical metadata checks are serialized TableDef/verifier replays; no physical cross-version restart/archive or mixed-version rollout claim.

Comment thread pkg/sql/plan/function/list_builtIn.go Resolved
Comment thread pkg/sql/plan/function/list_builtIn.go Resolved

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

Re-reviewed exact head 9a8630c: the complete 13-file PR diff, incremental matcher/verifier changes since my last review, and all historical reviews/comments/resolved threads. Both previous blockers are independently verified fixed. TIME again fails ordinary binding, while native DATETIME uses the new route; four unchanged real baseline-produced TableDefs now pass old-catalog and old-payload verification, including fractional defaults and TIMESTAMP/string controls. Full-tree/type validation and scoped context propagation remain intact. No remaining actionable blocker found.

Validation: 13 focused function/plan roots passed locally, including prior independent probes, dispatch, prepared precision, runtime NULL/zero/fraction and forged-metadata rejection. Audited exact-head CI confirms all eight full plan shards and heavy race group succeed; the changed SQL file actually executes 87/87 cases in compose BVT. These compatibility experiments use production planning/verifier components, not a claimed live cross-version restart or archive transfer.

@mergify mergify Bot added the queued label Oct 23, 2026
@mergify

mergify Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-23 10:33 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ❌ Checks failed · in-place
  • 🚫 Left the queue — 2026-10-23 14:15 UTC · at 3d4d80bea49ca1b341fa1f9264c4e4a695ec43a3

This pull request spent 3 hours 42 minutes 11 seconds in the queue, with no time running CI.

Reason

The merge conditions cannot be satisfied due to failing checks

  • CI Required

Hint

You may have to fix your CI before adding the pull request to the queue again.
If you update this pull request, to fix the CI, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Waiting for any of
  • check-neutral = CI Required
  • check-skipped = CI Required
  • check-success = CI Required
All conditions

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

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

Re-reviewed the current PR diff at merge head 3d4d80bea49ca1b341fa1f9264c4e4a695ec43a3 after the base advanced to f8c872001603fed3d23784e1ada26f9a2d8f4fba.

The DATETIME-specific overload keeps TIME out of the new matching path, while legacy DUMP/LOAD verification reconstructs the previous DATETIME-to-TIMESTAMP tree as a complete candidate. The two prior findings (TIME admission and historical default binding) are addressed in the current diff, and both existing review threads are resolved. I found no new actionable issue in the current diff.

Validation boundary: this is a static review of the current diff. I could not run tests because this workspace has no MatrixOne checkout or Go runtime. The prior review's test evidence is for an earlier head; the current combined status has no checks, and the only visible workflow is unrelated Iceberg Connector E2E. The PR body also says the rebased head has not been tested.

@XuPeng-SH
XuPeng-SH merged commit 2daeb49 into matrixorigin:main Oct 23, 2026
17 of 19 checks passed
@mergify mergify Bot removed the dequeued label Oct 23, 2026

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

Incremental check on updated head deb3d1dd1f4cfce35cea5f4e3a9b010db83838a0 after synchronization. Compared with the previously reviewed head 3d4d80bea49ca1b341fa1f9264c4e4a695ec43a3, the 3-commit delta is upstream Python SDK work in four files; it does not change the UNIX_TIMESTAMP DATETIME/DST implementation or its planner/legacy-binding behavior. No new issue found in this sync delta. This PR is already merged at 2daeb49e5abcf2b1eaaddb84d309049ec7c0486c (2026-10-23 14:26 UTC). I could not run the exact head locally because this workspace has no MatrixOne checkout or Go runtime. The only visible workflow for the head is unrelated Iceberg Connector E2E in progress, and combined status has no checks. Prior exact-head test evidence applies to the previous reviewed revision; the PR body states this rebased head was not tested. Related issues #28570 and #28563 remain open and already assigned to Ariznawlll; no transfer or duplicate issue action taken.

This branch was previously deployed

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

Labels

kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

4 participants