Is there an existing issue for the same bug?
I have checked the existing issues. #24481 is about unsupported functions on 3.0-dev; this issue is about incorrect results for already-supported time functions on 4.0-dev.
Branch Name
4.0-dev
Commit ID
47459ce
Other Environment Information
- Hardware parameters: N/A
- OS type: N/A
- Others: verified by source inspection on 4.0-dev
Actual Behavior
Several MySQL-compatible time functions return incorrect results for TIME values whose hour part is greater than 23, or for MAKETIME seconds with fractional precision:
HOUR(TIME) folds the hour with % 24, so a TIME interval such as 272:59:59 returns 8 instead of the full hour value.
TIME_FORMAT(time, "%T") folds the hour with % 24, so 123:45:06 formats as 03:45:06 instead of preserving the full hour part.
MAKETIME(hour, minute, second) truncates fractional seconds for floating second arguments and always constructs the result with microseconds set to 0.
Expected Behavior
MatrixOne should match MySQL TIME semantics:
HOUR("272:59:59") should return 272.
TIME_FORMAT("123:45:06", "%T") should return 123:45:06.
MAKETIME(12, 34, 56.789012) should preserve the fractional seconds and return 12:34:56.789012.
Steps to Reproduce
SELECT HOUR(CAST("272:59:59" AS TIME));
SELECT TIME_FORMAT(CAST("123:45:06" AS TIME), "%T");
SELECT MAKETIME(12, 34, 56.789012);
Additional information
The source currently contains these incorrect paths on 4.0-dev:
pkg/sql/plan/function/func_unary.go: TimeToHour returns hour % 24.
pkg/sql/plan/function/func_binary.go: TIME_FORMAT %T uses hour%24.
pkg/sql/plan/function/func_binary.go: MakeTime truncates floating seconds and passes 0 microseconds to types.TimeFromClock.
Is there an existing issue for the same bug?
I have checked the existing issues. #24481 is about unsupported functions on 3.0-dev; this issue is about incorrect results for already-supported time functions on 4.0-dev.
Branch Name
4.0-dev
Commit ID
47459ce
Other Environment Information
Actual Behavior
Several MySQL-compatible time functions return incorrect results for TIME values whose hour part is greater than 23, or for MAKETIME seconds with fractional precision:
HOUR(TIME)folds the hour with% 24, so a TIME interval such as272:59:59returns8instead of the full hour value.TIME_FORMAT(time, "%T")folds the hour with% 24, so123:45:06formats as03:45:06instead of preserving the full hour part.MAKETIME(hour, minute, second)truncates fractional seconds for floating second arguments and always constructs the result with microseconds set to0.Expected Behavior
MatrixOne should match MySQL TIME semantics:
HOUR("272:59:59")should return272.TIME_FORMAT("123:45:06", "%T")should return123:45:06.MAKETIME(12, 34, 56.789012)should preserve the fractional seconds and return12:34:56.789012.Steps to Reproduce
Additional information
The source currently contains these incorrect paths on 4.0-dev:
pkg/sql/plan/function/func_unary.go:TimeToHourreturnshour % 24.pkg/sql/plan/function/func_binary.go:TIME_FORMAT%Tuseshour%24.pkg/sql/plan/function/func_binary.go:MakeTimetruncates floating seconds and passes0microseconds totypes.TimeFromClock.