Skip to content

fix(plan): accept native temporal operands in unary minus and plus - #33014

Merged
XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
MatrixAdventurer:fix/unary-minus-plus-temporal
Nov 21, 2026
Merged

XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
MatrixAdventurer:fix/unary-minus-plus-temporal

Conversation

@MatrixAdventurer

@MatrixAdventurer MatrixAdventurer commented Nov 20, 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:

Fixes #33013

What this PR does / why we need it:

Native DATE, TIME, DATETIME, and TIMESTAMP operands were rejected by unary - and +.

  • Unary plus returns the temporal operand unchanged, matching MySQL parser behavior.
  • Unary minus casts each temporal operand through the existing temporal-to-FLOAT64 path and then uses the established DOUBLE overload. This matches MySQL unary semantics, including FLOAT64 rounding and result/CTAS metadata; binary temporal subtraction remains unchanged.
  • TIMESTAMP conversion remains session-time-zone aware, and NULLs retain NULL.

Review follow-up

Addressed the requested change that unary temporal negation is not equivalent to 0 - value in MySQL:

  • DATETIME(6) '2024-06-18 01:02:03.123456' and the equivalent TIMESTAMP now assert the DOUBLE result -20240618010203.125000.
  • Regression coverage asserts DOUBLE result types for DATE/TIME/DATETIME/TIMESTAMP and includes TIMESTAMP NULL.
  • BVT expectations now assert DOUBLE client metadata and DOUBLE CTAS columns.

Validation

  • RED on the prior head: the focused matcher regression failed because DATE selected BIGINT/overload 3 instead of FLOAT64/overload 5.
  • GREEN after the fix: the same regression passed.
  • go test -p=1 ./pkg/sql/plan/function -count=1 passed (25.007s).
  • Focused temporal numeric conversion, session-time-zone, and NULL tests passed.
  • git diff --check passed.
  • Independent review: APPROVE, no findings.
  • Local pkg/sql/plan compilation was attempted twice but the compiler was killed by the environment memory limit before tests ran; PR CI must complete that package and the BVT suite.

Unary minus casts DATE to BIGINT and TIME/DATETIME/TIMESTAMP to DECIMAL
(keeping fsp), matching binary arithmetic and MySQL. Unary plus returns
a temporal operand unchanged, as MySQL's parser drops it.

Fixes matrixorigin#33013
@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 →

@mergify

mergify Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Queue requested — the merge queue status continues in this comment ↓.

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

I checked the existing temporal arithmetic/conversion paths, the new planner and SQL tests, the prior discussion, and the current head against MySQL 8.0.46. The new path accepts the previously rejected inputs, but its assumption that unary negation has the same numeric domain as binary subtraction is not true in MySQL. This changes both observable results and persisted CTAS schemas, so the compatibility issue needs to be addressed before approval.

Validation: the MySQL comparison below was reproduced through the real MatrixOne embedded SQL frontend on this exact head and against a separate MySQL 8.0.46 instance. The added comparison test intentionally fails on the value/type mismatch; the PR CI is green, but its current fractional examples do not expose this difference.

Comment thread pkg/sql/plan/function/operatorSet.go Resolved
@XuPeng-SH

XuPeng-SH commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: b160c79325e1e5889163a362c5b3bf3107881a35

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

Assessment: request_changes

Unary plus preserves native temporal values. Unary minus accepts them but uses the binary-subtraction types. The exact-head MySQL comparison shows a different unary result value and different client and CTAS types.

Model: gpt-6.2-sol / xhigh

Session: 01a1f0a0-5126-78f3-9ab8-ef4e87f2f119 · slot 0 · generation 3

  • P2 pkg/sql/plan/function/operatorSet.go:1705: A query negates a native temporal column. For example, SELECT -dt reads DATETIME(6) containing 2024-06-18 01:02:03.123456.
    Impact: MatrixOne returns exact DECIMAL -20240618010203.123456 where MySQL 8.0.46 returns DOUBLE -20240618010203.125000. Client metadata differs even for exactly representable values, and CTAS persists BIGINT or DECIMAL columns where the MySQL comparison produced DOUBLE columns.
    Evidence: The matcher selects BIGINT and DECIMAL overloads, and those overloads return the cast argument type. The new expected result at test/distributed/cases/function/unary_sign_temporal.result:38 records the resulting schema. The same-head SQL comparison in review_comments:4649112041 and reviews:6001047598 confirms the MySQL difference. Reuse the existing temporal-to-FLOAT64 conversion in pkg/sql/plan/function/func_temporal_context.go:52 and the DOUBLE unary overload where they match the MySQL value and metadata. Update the regression oracle to check a nonrepresentable fraction and CTAS types against MySQL. Keep binary subtraction's existing semantics.

Validation:

  • Verified the assigned checkout, target, merge base, frozen patch and diff whitespace. See scope.stdout and checks/1795231487244629112-2.json.

  • An isolated arithmetic check confirmed that .123456 rounds to .125000 in this DOUBLE value, while the PR fixture's .250 is exactly representable. See rounding.stdout and checks/1795231547463163111-2.json.

  • Reconciled the frozen same-head embedded MatrixOne and MySQL 8.0.46 SQL comparison with overload selection, result metadata, and CTAS inference. The exact-head CI snapshot reports successful Linux build, unit, coverage, arm64 SCA, and multi-CN BVT checks.

Limitations:

  • The SQL differential was reported in the frozen review. This attempt did not run a second server comparison. The local rounding check exercised arithmetic only.

@XuPeng-SH

XuPeng-SH commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 9046e03f0885843269bd270c77f21efbc0f4e73a

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: 9046e03f0885843269bd270c77f21efbc0f4e73a

Assessment: approve

Unary plus preserves native temporal values and types. Unary minus reuses the existing temporal cast and DOUBLE overload, which resolves the prior rounding and result-type findings. The SQL check confirmed that binary subtraction still preserves the exact fractional value.

Model: gpt-6.2-sol / xhigh

Session: 01a1f0a0-5126-78f3-9ab8-ef4e87f2f119 · slot 0 · generation 3

Validation:

  • Verified the assigned head, target, merge base, frozen patch and diff whitespace. See scope-check.log and checks/1795244863280115373-3.json.

  • Focused planner and function tests passed, including all cases in TestUnarySignTemporalOperands. See focused-tests.log and checks/1795245032433595926-29.json.

  • An isolated two-CN SQL check passed for fractional DATETIME and TIMESTAMP rounding, session time zone, NULLs, client and CTAS metadata, and prepared execution. A bare parameter served as the control for prepared unary plus. See public-sql-prepared-control.log and checks/1795245145471105424-2.json.

Limitations:

  • The MySQL 8.0.46 comparison came from the frozen review evidence. Local checks ran MatrixOne.

  • The maintained SQL fixture uses an exactly representable fraction. The maintained Go test and the isolated SQL check cover the rounding-sensitive fraction.

@mergify mergify Bot added the queued label Nov 21, 2026
@mergify

mergify Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue · pull request dequeued

1 h 4 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Sat 21 Nov, 07:13 · rule main · triggered by rule Automatic queue on approval for main
  • ⏹️ Testing stopped · in place
  • 🚫 Left the queue 08:17 · 1f75dc4

Reason

Pull request #33014 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

To get back in the queue

  • Push a change if one is needed: the pull request is queued again once its queue conditions match.
  • If no change is needed, tick the box below to queue it again as it is.

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

  • Requeue this pull request

Times in UTC · dashboard · how the merge queue works

@MatrixAdventurer

Copy link
Copy Markdown
Contributor Author

CI 状态:最近一轮 matrixone-ci 被取消(日志仅含 cancellation,无任何 --- FAIL 测试失败),非代码问题。已重新触发被取消的 CI,等待新一轮结果。

This branch was previously deployed

1 inactive deployment
ci — 1f75dc4b Deployed Nov 21, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: unary minus / unary plus reject native DATE, TIME, DATETIME and TIMESTAMP operands

3 participants