Skip to content
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

Merged
merged 4 commits into from
Apr 25, 2017

Conversation

zhexuany
Copy link
Contributor

@zhexuany zhexuany commented Apr 24, 2017

This PR is related with #3124. While working on replacing Expression with ExpressionListOpt, I foundselect abs(); raising a panic. This wired behavior is caused by x.Args[0].GetType() in https://github.com/pingcap/tidb/pull/3137/files#diff-686e374c1af6ac094dcaed1db4f0fd44R303. We need check the length of x.Args. If it is 0, we need create a Null FieldType.

@zhexuany
Copy link
Contributor Author

@coocood @hanfei1991 PTAL

@shenli
Copy link
Member

shenli commented Apr 25, 2017

LGTM
@XuHuaiyu PTAL

@shenli shenli added the status/LGT1 Indicates that a PR has LGTM 1. label Apr 25, 2017
tp = types.NewFieldType(mysql.TypeNewDecimal)
default:
tp = types.NewFieldType(mysql.TypeDouble)
if len(x.Args) > 0 {
Copy link
Member

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

Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

@XuHuaiyu XuHuaiyu left a 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},
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DONE

@zhexuany zhexuany force-pushed the fixed_bug_in_typeinfer branch from c5123e3 to 3292ceb Compare April 25, 2017 14:24
@zhexuany
Copy link
Contributor Author

@XuHuaiyu PTAL.

@zhexuany zhexuany force-pushed the fixed_bug_in_typeinfer branch from 3292ceb to 4f732d8 Compare April 25, 2017 14:26
Copy link
Member

@shenli shenli left a comment

Choose a reason for hiding this comment

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

Rest LGTM

@@ -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
Copy link
Member

Choose a reason for hiding this comment

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

Mybe -> Maybe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DONE

@shenli
Copy link
Member

shenli commented Apr 25, 2017

LGTM
@XuHuaiyu @coocood PTAL

Copy link
Member

@coocood coocood left a comment

Choose a reason for hiding this comment

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

LGTM

@coocood coocood merged commit 8aab91f into pingcap:master Apr 25, 2017
@zhexuany zhexuany deleted the fixed_bug_in_typeinfer branch April 25, 2017 15:11
zhexuany added a commit to zhexuany/tidb that referenced this pull request Apr 29, 2017
ngaut pushed a commit that referenced this pull request Apr 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/LGT1 Indicates that a PR has LGTM 1.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants