-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
allowed zero argument in typeinferer #3137
Conversation
@coocood @hanfei1991 PTAL |
LGTM |
plan/typeinferer.go
Outdated
tp = types.NewFieldType(mysql.TypeNewDecimal) | ||
default: | ||
tp = types.NewFieldType(mysql.TypeDouble) | ||
if len(x.Args) > 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.
if len(x.Args) == 0 {
tp = types.NewFieldType(mysql.TypeNull)
break
}
// Normal conditions
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.
I guess it can be put before the starting of switch statement, because every case statement do the check.
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.
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.
@tiancaiamao
Many functions have zero arguments and the type is not null.
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.
@tiancaiamao That was my approach. If we simple skip switch if Args
has 0 length, then for function curr_time()
, test will not pass.
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.
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.
Address the comments, rest LGTM.
@@ -122,6 +122,7 @@ func (ts *testTypeInferrerSuite) TestInferType(c *C) { | |||
// Functions | |||
{"version()", mysql.TypeVarString, charset.CharsetUTF8, 0}, | |||
{"count(c_int)", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag}, | |||
{"abs()", mysql.TypeNull, charset.CharsetBin, mysql.BinaryFlag}, |
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 test cases for ceil/ceiling/floor/ifnull/nullif/fromunixtime/round.
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.
This approach will cause a mixed feature in one PR. I have to modify parser.y in order to let zero arguments passed into executor stage. It is better to file another PR to add these test you mentioned.
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.
I think since you've modified the type inferer of these functions,
it better to test it in the same PR.
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.
@zhexuany
We can add tests, and comment it out, then comment back after the other PR gets merged.
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.
@coocood yep. I plan to do so. I will add these test tonight.
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
c5123e3
to
3292ceb
Compare
added commented test case. Will uncomment in another PR.
@XuHuaiyu PTAL. |
3292ceb
to
4f732d8
Compare
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.
Rest LGTM
plan/typeinferer.go
Outdated
@@ -292,19 +292,30 @@ func (v *typeInferrer) getFsp(x *ast.FuncCallExpr) int { | |||
return 0 | |||
} | |||
|
|||
// handleFuncCallExpr ... | |||
// TODO: (zhexuany) this function contains too much redundant things. Mybe replace with a map like |
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.
Mybe -> Maybe
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
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
This PR is related with #3124. While working on replacing
Expression
withExpressionListOpt
, I foundselect abs();
raising a panic. This wired behavior is caused byx.Args[0].GetType()
in https://github.com/pingcap/tidb/pull/3137/files#diff-686e374c1af6ac094dcaed1db4f0fd44R303. We need check the length ofx.Args
. If it is 0, we need create a Null FieldType.