Skip to content

Fix temporal compatibility gaps for #24189 - #24214

Merged
16 commits merged into
matrixorigin:3.0-devfrom
robll-v1:agent/task-24189-time-date-compat
Apr 28, 2026
Merged

16 commits merged into
matrixorigin:3.0-devfrom
robll-v1:agent/task-24189-time-date-compat

Conversation

@robll-v1

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:

issue #24189

What this PR does / why we need it:

This PR backports the user-visible time/date compatibility work needed by 3.0-dev for #24189.

Main changes:

  • Adds/ports MySQL-compatible temporal functions and parser support for CURTIME/CURRENT_TIME, TIMEDIFF, TIMESTAMPADD, TIMESTAMPDIFF, GET_FORMAT, ADDTIME, and SUBTIME.
  • Aligns DATE_ADD/DATE_SUB string-input behavior and return typing with MySQL-compatible runtime behavior.
  • Fixes temporal overflow handling so large interval values fail safely and return NULL instead of panicking or wrapping.
  • Preserves time/date/datetime/timestamp scale and boundary behavior through focused regressions and distributed expected results.
  • Adds a LOAD DATA BVT that locks TIMESTAMP parsing to the session time_zone used during import.

Validation performed:

  • go test ./pkg/container/types -run 'Test(JudgeIntervalNumOverflowRejectsMinInt64|DatetimeAddInterval|Datetime_ToTime|DatetimeAddIntervalOverflowReturnsFalse|DatetimeAddDateTimeOverflowReturnsFalse)' -count=1
  • go test ./pkg/sql/plan/function -run 'TestBuiltInCurrentTimeUsesSessionTimezoneAcrossDayBoundary|Test(DateStringAddReturnTypeCompatibility|DateStringSubDateFormatOutput|.*(TimestampAdd|TimestampDiff|AddTime|SubTime|GetFormat|TimeDiff|DateStringAdd|DateStringSub))' -count=1
  • go test ./pkg/sql/colexec/external -run 'Test_getColData_Timestamp' -count=1
  • SDKROOT=$(xcrun --show-sdk-path) CPATH="$SDKROOT/usr/include/c++/v1" CPLUS_INCLUDE_PATH="$SDKROOT/usr/include/c++/v1" make build
  • Runtime SQL verified representative issue cases: curtime, timediff, timestampadd, timestampdiff, get_format, addtime, subtime, date_add, date_sub, scale casts, large-overflow NULL, and LOAD DATA TIMESTAMP session timezone behavior.
  • mo-tester targeted scopes passed with FAILED :0, ABNORAML :0, SUCCESS RATE : 100%:
    • test/distributed/cases/function/func_datetime_curtime.test
    • test/distributed/cases/function/func_datetime_addtime.test
    • test/distributed/cases/function/func_datetime_subtime.test
    • test/distributed/cases/function/func_datetime_timestampadd.test
    • test/distributed/cases/function/func_datetime_date_add.test
    • test/distributed/cases/load_data/load_data_timestamp_timezone.sql

Note: this PR is scoped to the #24189 temporal compatibility surfaces. An unrelated fulltext BVT issue was observed locally and is not changed by this PR.

robll-v1 and others added 3 commits April 24, 2026 13:30
Add parser, binder, function, and test coverage for CURTIME/CURRENT_TIME, ADDTIME, SUBTIME, TIMESTAMPADD, and GET_FORMAT on 3.0-dev.

Co-authored-by: Copilot <[email protected]>
The issue already has product support on 3.0-dev through the existing session-timezone parsing path, but it lacked a distributed SQL case that fixes the behavior at the user-visible LOAD DATA boundary.

Constraint: Product code already handles session timezone for timestamp parsing

Confidence: high

Scope-risk: narrow

Tested: go test ./pkg/sql/colexec/external -run 'Test_getColData_Timestamp' -count=1

Tested: mo-tester load_data_timestamp_timezone.sql, FAILED :0, ABNORAML :0, SUCCESS RATE : 100%

Not-tested: Full distributed BVT suite
@robll-v1
robll-v1 requested a review from a user April 27, 2026 03:20
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

The PR conflicted with newer parser generation on 3.0-dev. Merge the updated base and regenerate mysql_sql.go from the already-merged mysql_sql.y grammar so the generated parser table matches both sides.

Constraint: PR matrixorigin#24214 was marked DIRTY against 3.0-dev

Confidence: high

Scope-risk: narrow

Tested: make -B mysql_sql.go in pkg/sql/parsers/dialect/mysql

Tested: git diff --check

Tested: go test ./pkg/sql/parsers/dialect/mysql -run 'Test.*(timestampadd|timestampdiff|curtime|get_format|GetFormat|TimestampAdd|TimestampDiff|Curtime)' -count=1

Tested: go test ./pkg/container/types -run 'Test(JudgeIntervalNumOverflowRejectsMinInt64|DatetimeAddInterval|Datetime_ToTime|DatetimeAddIntervalOverflowReturnsFalse|DatetimeAddDateTimeOverflowReturnsFalse)' -count=1

Tested: go test ./pkg/sql/plan/function -run 'TestBuiltInCurrentTimeUsesSessionTimezoneAcrossDayBoundary|Test(DateStringAddReturnTypeCompatibility|DateStringSubDateFormatOutput|.*(TimestampAdd|TimestampDiff|AddTime|SubTime|GetFormat|TimeDiff|DateStringAdd|DateStringSub))' -count=1

Not-tested: Full BVT suite after merge
The previous fix for matrixorigin#24189 updated temporal behaviors correctly, but several distributed result files still encoded mismatched output formatting for the CI mo-tester lane. This refreshes the affected date/datetime/timediff/date_add expectations to the exact runner-visible format used by the 3.0 BVT jobs.

Constraint: CI job 73135408902 runs mo-tester with -n -g -o and compares runner-visible result formatting.

Rejected: Keep hand-normalized mixed formats | they diverged from the CI runner and caused false BVT failures.

Confidence: high

Scope-risk: narrow

Directive: Regenerate these temporal result files with the same mo-tester flags used in CI before changing formatting again.

Tested: go test ./pkg/sql/plan/function -run 'Test_buildInM0ExplainPhy|TestCosineDistanceArray|TestTemporalFunctionReviewTypeCompatibility' -count=1

Tested: go test ./pkg/stream/adapter/kafka -run TestPopulateBatchFromMSGWithJSON -count=1

Tested: go test ./pkg/sql/compile -run TestCompile -count=1

Tested: mo-tester ./run.sh -n -g -o -p for dtype/date, dtype/datetime, dtype/datetime_precision_comprehensive, expression/temporal_interval, function/func_datetime_date_add, function/func_datetime_timediff

Not-tested: full GitHub CI rerun completion
robll-v1 and others added 7 commits April 28, 2026 10:45
ADDTIME and SUBTIME previously performed raw int64 arithmetic when combining temporal values with parsed TIME arguments. Boundary values could wrap or produce invalid datetime/timestamp values instead of the expected NULL. DATE_SUB also returned an unrecognized date out-of-range error from its underflow path, so the function layer could surface an error instead of marking the row NULL.

Constraint: MySQL-compatible temporal overflow behavior requires invalid date/time arithmetic to return NULL for these function paths.

Rejected: Leave DateSub on the generic error-check helper | it cannot translate dateOverflowMaxError into row NULLs.

Confidence: high

Scope-risk: moderate

Directive: Keep temporal overflow paths on checked helpers; do not reintroduce direct int64 datetime arithmetic without range validation.

Tested: go test ./pkg/sql/plan/function -run 'Test(BuiltInCurrentTimeUsesSessionTimezoneAcrossDayBoundary|DateStringAddReturnTypeCompatibility|DateStringSubDateFormatOutput|AddTimeSubTimeDatetimeTimestampOverflowReturnNull|DoDateSubOverflowUsesDateOverflowError|DateSubOverflowReturnsNull|.*(TimestampAdd|TimestampDiff|AddTime|SubTime|GetFormat|TimeDiff|DateStringAdd|DateStringSub))' -count=1

Tested: make build

Tested: Manual SQL confirmed ADDTIME/SUBTIME/DATE_SUB boundary overflows return NULL

Tested: mo-tester func_datetime_addtime.test, func_datetime_subtime.test, func_datetime_date_add.test all FAILED :0, ABNORAML :0, SUCCESS RATE : 100%

Not-tested: Full repository BVT matrix after this final follow-up commit
The tenant task case executes the same manual task twice: first with a true gate and then with a false gate. Without waiting for each asynchronous run to be recorded, SHOW TASK RUNS can compare SUCCESS and SKIPPED rows before their order is stable in CI.

Constraint: The BVT must still verify both SUCCESS and SKIPPED task-run records; it must not skip or ignore the status column.

Rejected: Ignore the status column | that would hide the behavior under test.

Confidence: medium

Scope-risk: narrow

Directive: Keep the waits adjacent to the manual task executions so SHOW TASK RUNS observes completed runs in command order.

Tested: Manual mysql tenant-task repro confirmed latest two runs are SKIPPED then SUCCESS and tenant_sink count is 1.

Not-tested: Full sql_task.sql under local mo-tester; local single-file parser rejected existing delimiter result text before reaching this case.
The PR branch diverged from 3.0-dev after upstream added parser/function changes for ELT, AES, and window aggregation. The merge keeps upstream parser and function enhancements, regenerates mysql_sql.go from the merged grammar, and preserves the temporal DATE_ADD/DATE_SUB/ADDTIME/SUBTIME compatibility fixes.

Constraint: PR matrixorigin#24214 must be mergeable against current 3.0-dev without dropping upstream ELT/AES changes or temporal compatibility fixes.

Rejected: Hand-edit generated mysql_sql.go conflict hunks | regeneration from merged mysql_sql.y is safer and reproducible.

Confidence: high

Scope-risk: moderate

Directive: Keep ELT at function id 348 and assign temporal IDs after it unless a future base branch renumbers the function table.

Tested: make -B mysql_sql.go in pkg/sql/parsers/dialect/mysql

Tested: go test ./pkg/sql/parsers/dialect/mysql -run 'TestMysql' -count=1

Tested: go test ./pkg/sql/plan/function -run 'Test(Elt|TimeFormat|AddTimeSubTimeDatetimeTimestampOverflowReturnNull|DateSubOverflowReturnsNull|DoDateSubOverflowUsesDateOverflowError|TimestampDiffDateString)' -count=1

Tested: go test ./pkg/sql/plan/function -run 'Test_funids|TestFunctionIdMappings|Test.*FunctionId|Test.*FunctionID' -count=1

Tested: make build

Not-tested: Full GitHub BVT matrix after merge resolution
The conflict-resolution commit moved additional ELT overflow tests into func_binary_elt_test.go but left the required math import only in the local worktree. Static-check therefore saw math.MaxUint64 without the import.

Constraint: CI runs molint/go vet on committed files only; local unstaged imports do not count.

Rejected: Remove overflow cases | they cover the upstream ELT behavior introduced by the base merge.

Confidence: high

Scope-risk: narrow

Tested: go test ./pkg/sql/plan/function -run 'Test(Elt|TimeFormat)' -count=1

Not-tested: Full static-check locally
Multiple sql_task cases execute manual tasks and then immediately assert row counts or mo_task.sql_task_run status. CI can still observe RUNNING or stale task-run ordering because task execution and run persistence are asynchronous.

Constraint: The BVT must keep validating SUCCESS, SKIPPED, FAILED, and TIMEOUT states instead of weakening status checks.

Rejected: Revert the tenant-task wait only | the new failure shows the same timing assumption exists earlier in the file as well.

Confidence: high

Scope-risk: narrow

Directive: When sql_task BVT asserts post-execute task state, keep an explicit wait before reading task_run metadata or derived row counts.

Tested: Manual mysql repro for sql_task_cron/sql_task_manual/sql_task_gate with waits confirmed SUCCESS/SKIPPED ordering and expected row counts.

Not-tested: Full sql_task.sql via local mo-tester; local delimiter/result parsing remains unreliable for this file outside CI.
The unbuffered channel could lose the signal when postEvict fired before
the main goroutine reached <-evictStarted, causing a permanent hang.

Buffer the channel to 1 and add a 2s select timeout as a safety net.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
The latest 3.0-dev update added planner/parser work for null-safe equality and related DDL changes, conflicting with the PR branch's generated MySQL parser and function id table. The merge keeps the upstream null-safe equality function id, shifts the temporal function ids after it, and regenerates mysql_sql.go from the merged grammar.

Constraint: PR matrixorigin#24214 must remain mergeable with current 3.0-dev while preserving matrixorigin#24189 temporal compatibility fixes.

Rejected: Manually resolve generated mysql_sql.go hunks | regenerating from mysql_sql.y is safer and reproducible.

Confidence: high

Scope-risk: moderate

Directive: Keep NULL_SAFE_EQUAL before temporal function IDs unless the base branch renumbers the full function table.

Tested: make -B mysql_sql.go in pkg/sql/parsers/dialect/mysql

Tested: go test ./pkg/sql/parsers/dialect/mysql -run 'TestMysql' -count=1

Tested: go test ./pkg/sql/plan/function -run 'Test_funids|TestFunctionIdMappings|Test.*FunctionId|Test.*FunctionID|TestNullSafeEqual|Test.*Compare' -count=1

Not-tested: Full GitHub BVT matrix after this merge
This pull request was closed.

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 kind/test-ci size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants