Repository navigation
fix(plan): accept native temporal operands in unary minus and plus - #33014
Conversation
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 reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
Queue requested — the merge queue status continues in this comment ↓. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
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.
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
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.
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
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.
🚫 Left the queue · pull request dequeued1 h 4 min in the queue, with no time running CI. So far
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.
To get back in the queue
Tick the box to put this pull request back in the merge queue (same as
Times in UTC · dashboard · how the merge queue works |
|
CI 状态:最近一轮 matrixone-ci 被取消(日志仅含 cancellation,无任何 --- FAIL 测试失败),非代码问题。已重新触发被取消的 CI,等待新一轮结果。 |
What type of PR is this?
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+.Review follow-up
Addressed the requested change that unary temporal negation is not equivalent to
0 - valuein MySQL:DATETIME(6) '2024-06-18 01:02:03.123456'and the equivalent TIMESTAMP now assert the DOUBLE result-20240618010203.125000.Validation
go test -p=1 ./pkg/sql/plan/function -count=1passed (25.007s).git diff --checkpassed.pkg/sql/plancompilation 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.