Skip to content

fix: accept native temporal operands in unary bitwise NOT - #32927

Merged
XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
ck89119:issue-32873-main
Nov 20, 2026
Merged

XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
ck89119:issue-32873-main

Conversation

@ck89119

@ck89119 ck89119 commented Nov 19, 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:

issue #32873

What this PR does / why we need it:

Unary bitwise NOT (~) rejected native DATE, TIME, DATETIME and TIMESTAMP operands:

SELECT ~CAST('2024-06-18' AS DATE);
-- ERROR 20203 (HY000): invalid argument operator unary_tilde, bad value [DATE]

Root cause

#32642 made the native temporal-to-integer conversion a per-parameter contract (integerParameters with temporalOnlyIntegerParameter). That declaration drives both argument-type normalization (checkArgumentTypes) and the binder's appendSourceDependentIntegerArgument, which inserts TemporalIntegerArgumentCastOverload. It was added to &, |, ^, <<, >> and BIT_COUNT, but not to UNARY_TILDE. For ~, unaryTildeTypeMatch only adds an implicit cast for CHAR/VARCHAR/TEXT, so a temporal operand fell through to direct overload matching and was rejected.

Fix

Declare integerParameters: {{position: 0, mode: temporalOnlyIntegerParameter}} on UNARY_TILDE. No new mechanism is needed. For any non-temporal source, sourceTarget reports "not applicable", so integer, text, binary and BIT behavior is unchanged.

Validation

  • The new planner UTs fail on the base commit with invalid argument operator unary_tilde, bad value [DATE|DATETIME|TIME|TIMESTAMP] and pass with the fix. They cover literals, columns (NULL, zero value, negative and fractional TIME, TIMESTAMP in UTC), a prepared ~? with native temporal parameters and template reuse, and integer/text controls.
  • BVT temporal_numeric_consumer is extended with ~ cases, including the equivalence from the issue (~(d & -1) = ~CAST(d AS SIGNED) = 18446744073689310997). .result was generated by mo-tester against a locally built standalone service. The case passes 60/60. Related cases also pass: func_bit_count 210/210, mysql_compat_temporal_numeric_cast 30/30, bit_integer_parameter_coercion 47/47, integer_parameter_coercion 118/118, mysql_compat_bitwise_expr 25/25.
  • Go packages ./pkg/sql/plan and ./pkg/sql/plan/function pass in full, and so does TestTypeSwitchFamilies. go vet and incremental golangci-lint report no issues.
  • Not run locally: the full BVT suite and repository-wide SCA, which are left to CI.

matrixorigin#32642 declared the native DATE/TIME/DATETIME/TIMESTAMP-to-integer
conversion as a per-parameter contract (temporalOnlyIntegerParameter)
for `&`, `|`, `^`, `<<`, `>>` and BIT_COUNT, but left UNARY_TILDE
without the declaration. Neither the argument-type normalization nor the
binder inserted the temporal integer cast for `~`, and
unaryTildeTypeMatch only handles text inputs, so `~CAST(... AS DATE)`
failed with "invalid argument operator unary_tilde".

Declare the same temporal-only integer parameter on UNARY_TILDE so it
shares the conversion of the other bitwise consumers. Other source types
are unaffected.

Fixes matrixorigin#32873
Binding unary NOT operands in the integer-source context dropped the
DEFAULT column type, so ~X'0102' changed from a bytewise BINARY value
to a uint64 and tables created before the upgrade failed table dump
verification. Bind the operand in its ordinary context and insert the
temporal integer conversion only after binding proves a native
DATE/TIME/DATETIME/TIMESTAMP source.
@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 19, 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.

Reviewed head 38dd56444eff142cfe35358acfce0f95e5c9112f.

The change routes native temporal operands through the existing integer conversion and keeps ordinary operand binding for other types, including persisted defaults. I traced AST binding, plan rebinding, prepared-parameter specialization and ENUM/SET handling; I found no blocking correctness, lifecycle, performance or design issue in this delta. There are no unresolved prior reviewer comments on this PR.

Validation: current-head required CI, UT and relevant BVT jobs are green. Locally, the temporal literal/column and prepared-parameter tests, ordinary operand/default binding tests, historical table-dump fixtures, and function metadata test all passed. The new tests cover NULLs, signed/fractional TIME, TIMESTAMP and repeated prepared executions; I did not run an additional live upgrade test.

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

mergify Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue · pull request dequeued

2 h 31 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Fri 20 Nov, 05:50 · rule main · triggered by rule Automatic queue on approval for main
  • ⏹️ Testing stopped · in place
  • 🚫 Left the queue 08:21 · 9823940

Reason

Pull request #32927 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.

Merge conditions not met when it left the queue

  • any of · required by GitHub branch protection:
    • check-neutral = CI Required
    • check-skipped = CI Required
    • check-success = CI Required

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

  • Requeue this pull request
2 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection

Times in UTC · dashboard · how the merge queue works

This branch was previously deployed

1 inactive deployment
ci — 9823940c Deployed Nov 20, 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.

3 participants