Skip to content

fix: preserve incomplete date strings in temporal functions - #30311

Merged
XuPeng-SH merged 16 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/loom/develop/72cc650940a3019a1ba435628d7eb7c619bf13daf977104608d484bcf68bfe27
Oct 24, 2026
Merged

XuPeng-SH merged 16 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/loom/develop/72cc650940a3019a1ba435628d7eb7c619bf13daf977104608d484bcf68bfe27

Conversation

@iamlinjunhong

@iamlinjunhong iamlinjunhong commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Related to #30234; leave open for reporter verification.

What this PR does / why we need it:

Preserve incomplete date strings until their consuming temporal function applies its calendar, warning and NULL rules. DATE_FORMAT can retain zero components; strict calendar calculations reject recognized incomplete calendars with NULL and warning 1292. Malformed complete strings keep ordinary expression-cast NULLs without warnings. This fixes constants, VARCHAR rows and both prepared protocols without changing typed DATE/DATETIME storage or global casts. Nullable result metadata lets CTAS store rejected string results safely.

DATE_FORMAT's literal-pattern width covers raw-calendar output: nine digits for %U/%u/%V/%v and ten for %X/%x. For '2020-00-00', %v returns '613566753'; CTAS now declares width 9 and subsequent INSERT SELECT preserves it. Previously the later write silently stored '61'. TIME_FORMAT bounds remain unchanged.

Use the existing expression, persisted-owner, placement, destination, same-stream and receiver admission owners. Versioning protects executable overload identities and diagnostic contracts during mixed-version operation; it does not implement SQL date semantics. Official main 7038c8520e5fc1ba456914b3c389ccedb69e22f7 advertises 126, including parser-derived VIEWS metadata. This PR appends only 127 and preserves independent main gates 120–126. Actual pinned-main registry inspection verifies that the new DATE_FORMAT/2, DATEDIFF string, TO_DAYS/1, TO_SECONDS/1, WEEK/4–5 and DAYOFWEEK/3 identities are absent there. Version 126 peers reject/fall back before affected payloads; version 127 accepts them. Cached and persisted admission rechecks the floor. Independent view metadata remains at 126 and composition with temporal strings requires 127.

Temporal binding and conversion boundaries are covered as follows:

  • DATE_FORMAT, TO_DAYS and TO_SECONDS malformed strings return NULL without warnings, matching the existing string-to-datetime expression cast. Invalid rows no longer abort valid neighbors or a reused prepared statement. Raw incomplete calendars, zero-date SQL modes and fractional precision remain unchanged.
  • DATE_ADD/SUB direct string/unknown markers retain raw components through arithmetic, then receive the original SQL unit's DATE/DATETIME(6) result cast. This preserves warning 1292 rather than losing it inside a pre-arithmetic TIMESTAMP conversion. Known and newly specialized non-string sources retain main's numeric/typed interpretation; explicit casts and NULL-interval suppression remain covered.
  • DUMP/LOAD reconstructs complete pre-migration temporal binding eras, including old formatter widths. Private historical contexts are used only for origin verification. Complete-tree equality remains mandatory, and forged metadata is rejected. Frozen generated-expression fixtures were captured using the actual pinned-main source overlay.

The compatibility design, revision 9 documents these boundaries and rollback. Earlier semantic approval remains recorded; independent approval of this revision is external. No new resource owner, cache, goroutine or unbounded wait is introduced. The existing execution-stream handshake retains its five-second timeout and parent cancellation.

Validation

Fresh validation for the malformed TO_DAYS/TO_SECONDS correction (Darwin/arm64, CGo, matrixone_test): the new focused conversion and warning tests pass, the full function package passes (7.765s), all 25 real SQL contract subcases pass (6.365s), and both changed packages pass go vet and golangci-lint (0 issues). The focused test failed on both functions before the correction. The existing cluster and connection cover literals, mixed VARCHAR rows, binary prepared calls and SQL PREPARE reuse, including invalid-to-valid-to-partial-to-invalid transitions and warning cardinality.

Starting head a4cc4145bd3d667534d2df277967c8901d520ce6 passed build, Linux UT, SCA, coverage and both active multi-CN BVT lanes in run 39590573993. That evidence and the previous local protocol/planner/compile/defines/pb-plan/colexec tests are reused for unchanged boundaries. No protocol identity, version gate or resource ownership changed in this correction. Existing race evidence is reused only for unchanged stream lifecycle code; no fresh race, live mixed-binary or throughput run is claimed.

Source-qualified predecessor evidence uses actual-main registry blob 16b2c8a64c9f2f31be9de1814ae0e95f7c706a60 and a Go AST inspection of all six affected registries. Frozen catalog fixtures and numeric prepared SELECT/CTAS evidence originate from the historical 838cc78aa1… / MORPC125 source overlay; these are distinct from the new main126 registry proof. This is not a live mixed-binary cluster run.

The TO_SECONDS hot-path optimization is unchanged: choose DAY versus SECOND and its epoch offset before the row loop, then use one DateTimeDiff per valid row. Historical matched 1024-row binder/executor benchmarks (Go 1.27.1, GOMAXPROCS=4, three 500ms measured rounds) reduced median date cost from 194.3 to 125.8 ns/row and datetime cost from 235.4 to 163.8 ns/row, retaining 48 bytes/one allocation per batch. These historical expression CPU measurements do not establish whole-query throughput; no new performance measurement is claimed for this rebase.

New-head CI will run after this correction is pushed. The earlier DATE_FORMAT BVT errors and old statistics-test failure are superseded by the successful starting-head run above; no old run is rerun. Independent code/design review for this correction passed before delivery.

@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 15, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 232ba0bfb83563085046f819e5967052bdefe979

Review belongs to an older commit; it is not a review of the current head.

@XuPeng-SH

XuPeng-SH commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-xupeng · superseded

Commit: a4cc4145bd3d667534d2df277967c8901d520ce6

"interrupted"

@XuPeng-SH

XuPeng-SH commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: a4cc4145bd3d667534d2df277967c8901d520ce6

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: a4cc4145bd3d667534d2df277967c8901d520ce6

Assessment: request_changes

Reviewed the complete 36-file delta, design revision 9, callers, tests and supplied discussions. The consumer-local calendar design and reuse of existing compatibility owners are reasonable. Prior width, nullability, performance and protocol concerns are addressed, but malformed inputs now regress TO_DAYS and TO_SECONDS.

Model: gpt-6-astra / xhigh

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

  • P2 pkg/sql/plan/function/temporal_incomplete.go:243: Evaluate TO_DAYS or TO_SECONDS on malformed strings such as '2024-02-30', through a literal, VARCHAR column or prepared parameter.
    Impact: Returning the parser error aborts the statement instead of producing NULL for the invalid row, including queries containing valid neighboring rows. Preserve the previous expression-cast conversion-to-NULL policy while retaining incomplete-calendar warnings.
    Evidence: Real SQL tests reproduced error 20301 for both functions across literal, column and binary-prepared calls: sql-contracts.log, receipt 1792585770415709720-3.json. The component probe failed eight malformed-input cases; all 24 cases passed when restoring the exact base registry, whose cast/parser/typed executors are unchanged. See malformed-candidate.log and malformed-base-registry.log, receipts 1792585634001550621-3.json and 1792585694514108248-3.json.

Validation:

  • Isolation preflight passed. Fresh native prerequisites were built through the repository Makefile; 192 input blobs and 56 artifact hashes were verified.

  • 28 focused root tests passed across protobuf plan, function, planner and compiler, covering metadata, prepared specialization, persisted compatibility and execution-stream admission/cleanup. Receipt: 1792585825182589356-3.json.

  • All 25 original SQL integration scenarios passed alongside the six failing diagnostic cases; service and port cleanup completed.

  • Verified clean frozen source, complete patch equivalence apart from its trailing newline, and the base126/candidate127 registry boundary.

  • Reconciled commands, source fingerprints, terminal exits and retained logs in /home/xupeng/.local/state/mo-bot/jobs/f47035a0812a7bc328360744/attempt-1/validation-evidence.json. Final audit receipt: 1792585901103215751-5.json.

Limitations:

  • Supplied exact-head CI reports successful Linux UT, static analysis, coverage and active multi-CN BVT suites; raw CI logs and the full linked issue body were unavailable.

  • The baseline control restored the exact base registry within the candidate framework; it was not a full baseline server build.

  • No fresh race, live mixed-binary or throughput benchmark run. Source analysis confirms one DateTimeDiff per TO_SECONDS row and one additional handshake round trip for affected remote fragments.

@XuPeng-SH

XuPeng-SH commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 007ad7088e303da5bfaa82c6b6e64af92f8d9631

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: 007ad7088e303da5bfaa82c6b6e64af92f8d9631

Assessment: approve

Reviewed the complete 36-file delta and captured review concerns. The consumer-local temporal design preserves existing storage, binding and protocol ownership. The malformed TO_DAYS/TO_SECONDS regression is fixed; no actionable findings remain.

Model: gpt-6-astra / xhigh

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

Validation:

  • Fresh Linux/amd64 CGo validation passed 10 temporal function tests and all 25 SQL scenarios, covering prepared protocols, warnings, malformed values, NULLs, CTAS metadata and subsequent writes. Receipt: checks/1792592643403882697-3.json; log: current-temporal-tests.log.

  • Reconciled retained commands, source fingerprints, exit receipts and log hashes from job f47035a0812a7bc328360744. Reused unchanged planner, metadata, catalog-origin and protocol coverage; reran changed scalar and SQL behavior.

  • Isolation preflight passed. Verified 192 current native inputs and 56 retained artifact hashes before testing.

  • Verified clean frozen source, matching patch, whitespace checks and base-126 registry versus appended version-127 identities. Current-head CI metadata reports successful Linux UT, SCA, coverage and both substantive multi-CN BVT lanes.

  • Performance review confirmed removal of duplicate complete-date parsing and redundant TO_SECONDS calculations. Affected remote fragments reuse one bounded handshake; unaffected typed projections add none. Detailed evidence is retained in review-notes.md and validation-evidence.json.

Limitations:

  • No fresh comparative benchmark, race run, live mixed-binary cluster or MySQL reference-server run; historical expression measurements do not establish current whole-query throughput.

  • Raw CI logs and the full linked issue body were absent; review used the captured contract, comments, source and retained/local execution evidence.

  • The explicitly excluded, preexisting LAST_DAY valid-month/zero-day discrepancy remains unchanged.

@XuPeng-SH

XuPeng-SH commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 9384137904cd95a22f5631a7cd3ce19b81aa818b

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: 9384137904cd95a22f5631a7cd3ce19b81aa818b

Assessment: approve

Reviewed the complete 36-file delta, design revision 10, affected callers and captured review concerns. The consumer-local calendar design preserves typed storage and reuses existing binding, warning, compatibility and cleanup owners. Earlier correctness, metadata, performance and protocol concerns are resolved. No actionable findings remain.

Model: gpt-6-astra / xhigh

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

Validation:

  • Isolation preflight passed. Repository-owned native provenance verification passed; reconciled 191 identical native inputs, one unrelated Makefile target addition and 56 artifact hashes.

  • 31 focused test roots passed, including all 25 real SQL integration scenarios covering malformed inputs, warnings, prepared reuse, NULL suppression, CTAS metadata and subsequent writes.

  • Test-only overlays verified immediate-predecessor 129 rejection and version 130 acceptance across placement, destination, receiver, cached execution and execution-stream boundaries, including failure cleanup.

  • 468 complete/malformed input, function and SQL-mode comparisons passed against released-registry bindings. This was a production binder/executor comparison, not a separate baseline server.

  • Verified clean frozen source, complete patch equivalence, whitespace and base/captured-main registry boundaries. Six successful receipts and retained logs are reconciled in /home/xupeng/.local/state/mo-bot/jobs/6c5dd63f57629d4a238442dc/attempt-1/validation-evidence.json; review coverage is recorded alongside it.

  • Frozen current-head CI metadata reports successful build, Ubuntu UT, static analysis, coverage and active multi-CN BVT lanes. Source analysis confirms removal of redundant parsing/calculation; affected remote fragments add one bounded handshake.

Limitations:

  • Raw CI/author logs and the full linked issue body were unavailable; local_validation was empty.

  • No fresh race run, live mixed-binary cluster, MySQL reference execution or comparative benchmark. Historical measurements do not establish current whole-query throughput.

  • The explicitly excluded, preexisting LAST_DAY valid-month/zero-day discrepancy remains unchanged.

This branch had an error being deployed

1 failed 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 kind/enhancement kind/refactor Code refactor kind/test-ci size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants