fix: align time functions with MySQL semantics#24786
Closed
LeftHandCold wants to merge 1 commit into
Closed
Conversation
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? |
There was a problem hiding this comment.
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) whensecondis 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
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 to838:59:59, soHOUR("272:59:59")should return272.TIME_FORMAT(time, "%T")now preserves the full hour part instead of formattinghour % 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-secondMAKETIME.Local validation:
git diff --checkpasses.go test ./pkg/sql/plan/function -run 'TestHour|TestTimeFormat|TestMakeTimePreservesFractionalSeconds' -count=1is blocked in this local environment by missing cgo headers:usearch.handxxhash.h.