Skip to content

fix: align time functions with MySQL semantics#24786

Closed
LeftHandCold wants to merge 1 commit into
matrixorigin:4.0-devfrom
LeftHandCold:fix/4.0-time-functions-compat
Closed

fix: align time functions with MySQL semantics#24786
LeftHandCold wants to merge 1 commit into
matrixorigin:4.0-devfrom
LeftHandCold:fix/4.0-time-functions-compat

Conversation

@LeftHandCold

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 #24784

What this PR does / why we need it:

This PR fixes three MySQL compatibility issues in time functions on 4.0-dev:

  • HOUR(TIME) now returns the full TIME hour part instead of folding it with % 24. MySQL TIME values can represent intervals up to 838:59:59, so HOUR("272:59:59") should return 272.
  • TIME_FORMAT(time, "%T") now preserves the full hour part instead of formatting hour % 24.
  • MAKETIME(hour, minute, second) now preserves fractional seconds from floating second arguments when constructing the TIME value.

Regression tests cover large-hour HOUR, large-hour %T, and fractional-second MAKETIME.

Local validation:

  • git diff --check passes.
  • go test ./pkg/sql/plan/function -run 'TestHour|TestTimeFormat|TestMakeTimePreservesFractionalSeconds' -count=1 is blocked in this local environment by missing cgo headers: usearch.h and xxhash.h.

Copilot AI review requested due to automatic review settings June 2, 2026 10:16
@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 →

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR targets MySQL compatibility for TIME-related functions in the SQL function layer, ensuring large-hour TIME values and fractional seconds are handled more like MySQL.

Changes:

  • Update HOUR(TIME) to return the full hour component (no % 24) and adjust its declared return type.
  • Update TIME_FORMAT(..., "%T") to format the full hour component (no % 24).
  • Update MAKETIME(hour, minute, second) to preserve fractional seconds (microseconds) when second is provided as a float, and add regression tests.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/sql/plan/function/list_builtIn.go Changes the HOUR(TIME) overload return type to uint16.
pkg/sql/plan/function/func_unary.go Removes % 24 folding in TimeToHour and changes the result element type to uint16.
pkg/sql/plan/function/func_unary_test.go Extends HOUR(TIME) tests to cover a large-hour TIME input and updates expected type/values.
pkg/sql/plan/function/func_binary.go Updates %T formatting to use the full hour value; updates MAKETIME to compute/preserve microseconds for float seconds.
pkg/sql/plan/function/func_binary_test.go Adds a large-hour %T test case and a new test ensuring MAKETIME preserves fractional seconds.

Comment on lines 7591 to 7595
overloadId: 2,
args: []types.T{types.T_time},
retType: func(parameters []types.Type) types.Type {
return types.T_uint8.ToType()
return types.T_uint16.ToType()
},
Comment on lines 3697 to 3701
func TimeToHour(ivecs []*vector.Vector, result vector.FunctionResultWrapper, proc *process.Process, length int, selectList *FunctionSelectList) error {
return opUnaryFixedToFixed[types.Time, uint8](ivecs, result, proc, length, func(v types.Time) uint8 {
return opUnaryFixedToFixed[types.Time, uint16](ivecs, result, proc, length, func(v types.Time) uint16 {
hour, _, _, _, _ := v.ClockFormat()
// HOUR function returns 0-23, so we need to take modulo 24
return uint8(hour % 24)
return uint16(hour)
}, selectList)
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 size/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants