New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
expression: Improved precision of FROM_UNIXTIME(char) #35184 #37788
Conversation
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
modified: types/field_type.go
… into fixbug35184
modified: parser/mysql/type.go modified: types/datum.go
types/datum.go
Outdated
@@ -1468,6 +1469,14 @@ func (d *Datum) convertToMysqlDecimal(sc *stmtctx.StatementContext, target *Fiel | |||
// ProduceDecWithSpecifiedTp produces a new decimal according to `flen` and `decimal`. | |||
func ProduceDecWithSpecifiedTp(dec *MyDecimal, tp *FieldType, sc *stmtctx.StatementContext) (_ *MyDecimal, err error) { | |||
flen, decimal := tp.GetFlen(), tp.GetDecimal() | |||
|
|||
//If string to decimal, determine the precision for each string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any possible that (tp.GetFlag() & mysql.StringToDecimalFlag)
is true and flen != UnspecifiedLength && decimal != UnspecifiedLength
is false?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NO, None of these types (mysql.TypeString, mysql.TypeVarchar, mysql.TypeTinyBlob, mysql.TypeMediumBlob, mysql.TypeLongBlob, mysql.TypeBlob) GetFlen() == -1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you'd better to decrease cyclomatic complexity. I mean that you added if {}
block before origin if flen != UnspecifiedLength && decimal != UnspecifiedLength {}
, the code looks a little hard to read and maintain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
expression/integration_test.go
Outdated
result.Check(testkit.Rows(unixTime1, unixTime2)) | ||
|
||
tk.MustExec("drop table if exists ft;") | ||
tk.MustExec("create table ft (tint int, tdou double, tdec decimal(22,9),tchar longblob);") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you remove the irrelevant columns and tail semicolon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
No obvious problem was found, but please ask the developer of the relevant code to review it again. |
modified: expression/integration_test.go modified: planner/core/plan_to_pb.go modified: types/datum.go
modified: expression/builtin_time.go modified: expression/builtin_time_vec.go modified: expression/expr_to_pb.go modified: expression/expression.go modified: parser/mysql/type.go
@@ -1661,6 +1661,10 @@ func (c *fromUnixTimeFunctionClass) getFunction(ctx sessionctx.Context, args []E | |||
return nil, err | |||
} | |||
|
|||
if fieldString(arg0Tp.GetType()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use isArg0Str
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TypeUnspecified is not the expected type,which satisfies types.IsString.
and TypeVarString is an input parameter, no need to adjust the precision .
expression/builtin_time.go
Outdated
if ok { | ||
// FixUnixtimePrecision is used to adjust FromUnixTime precision #Fixbug35184 | ||
if x.FuncName.L == ast.Cast { | ||
if x.RetType.GetDecimal() == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- why need to check
x.RetType.GetDecimal()
, sometime the decimal can be -1, and it also need to be updated. - why need check if it is cast function? I think just check if the return type if decimal is ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1)string type must be equal to 0
2)The current application scenario is cast
result.Check(testkit.Rows("1973-11-30 08:38:10.1")) | ||
|
||
result = tk.MustQuery("SELECT FROM_UNIXTIME(tchar,'%Y%m%d') from ft where FROM_UNIXTIME(tchar)= '1973-11-30 08:38:10.123400' ") | ||
result.Check(testkit.Rows("19731130")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also add a test that the input is string literal?
/run-unit-test |
/run-unit-test |
1 similar comment
/run-unit-test |
/run-build |
/run-unit-test |
expression/builtin_time.go
Outdated
if ok { | ||
//used to adjust FromUnixTime precision #Fixbug35184 | ||
if x.FuncName.L == ast.Cast { | ||
if x.RetType.GetDecimal() == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add extra check to make sure the x.RetType
is decimal ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/merge |
This pull request has been accepted and is ready to merge. Commit hash: 7dbfbdf
|
@keeplearning20221: Your PR was out of date, I have automatically updated it for you. At the same time I will also trigger all tests for you: /run-all-tests If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository. |
What problem does this PR solve?
Issue Number: ref #35184
Problem Summary:
fix FROM_UNIXTIME(char/double) is not compatible with mysql
What is changed and how it works?
Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.