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

*: add builtin function FLOOR #2484

Merged
merged 3 commits into from Jan 22, 2017
Merged

Conversation

zhexuany
Copy link
Contributor

@zhexuany zhexuany commented Jan 16, 2017

@CLAassistant
Copy link

CLAassistant commented Jan 16, 2017

CLA assistant check
All committers have signed the CLA.

@ngaut
Copy link
Member

ngaut commented Jan 17, 2017

Good job.

@@ -237,6 +237,7 @@ import (
events "EVENTS"
fieldKwd "FIELD_KWD"
findInSet "FIND_IN_SET"
floor "FLOOR"
Copy link
Member

Choose a reason for hiding this comment

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

Use tab to make the code align.

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

@@ -2684,6 +2685,10 @@ FunctionCallNonKeyword:
{
$$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1), Args: []ast.ExprNode{$3.(ast.ExprNode)}}
}
| "FLOOR" '(' Expression ')'
Copy link
Member

Choose a reason for hiding this comment

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

Use tab to make the code align.

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

@@ -274,7 +274,7 @@ func (v *typeInferrer) handleFuncCallExpr(x *ast.FuncCallExpr) {
}
case "interval":
tp = types.NewFieldType(mysql.TypeLonglong)
case "ceil", "ceiling":
case "ceil", "ceiling", "floor":
Copy link
Member

Choose a reason for hiding this comment

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

Add a test case in plan/typeinferer_test.go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried. But I could not find ceil in this test file. This is kinda confused me. If I add test for floor, then so does ceil and ceiling.

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. Let me know, if you want me to add test case for ceil and ceiling.

Copy link
Member

Choose a reason for hiding this comment

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

Nice! But you could do this in another PR.

return args[0], nil
}

f, err := args[0].ToFloat64(ctx.GetSessionVars().StmtCtx)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please check the result of floor("abc") in MySQL and your implementation in TiDB. It seems ToFloat64 will cause an error.

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 builtin-floor branch 4 times, most recently from a878a6d to 12f34ef Compare January 17, 2017 06:37
@@ -147,6 +147,7 @@ var Funcs = map[string]Func{
ast.Abs: {builtinAbs, 1, 1},
ast.Ceil: {builtinCeil, 1, 1},
ast.Ceiling: {builtinCeil, 1, 1},
ast.Floor: {builtinFloor, 1, 1},
Copy link
Member

Choose a reason for hiding this comment

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

return args[0], nil
}
if args[0].Kind() == types.KindString {
args[0].SetFloat64(0)
Copy link
Member

Choose a reason for hiding this comment

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

why set args[0] to 0, instead of d ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, This is outdated commit. Already changed in lasted commit.

@zhexuany
Copy link
Contributor Author

zhexuany commented Jan 17, 2017

@XuHuaiyu Passed all test cases. Ready to merge into mater. Already rebased and applied all my commit on top of lasted master branch.

@zhexuany zhexuany force-pushed the builtin-floor branch 5 times, most recently from 71267ae to c7142d4 Compare January 17, 2017 10:32
@zhexuany
Copy link
Contributor Author

@shenli PTAL, is this ok?

@zhexuany zhexuany force-pushed the builtin-floor branch 2 times, most recently from 5daa544 to c7142d4 Compare January 17, 2017 11:30
sc.IgnoreTruncate = false
return d, errors.Trace(err)
}
sc.IgnoreTruncate = false
Copy link
Member

Choose a reason for hiding this comment

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

Why change this? Maybe the original value of sc.IgnoreTruncate is true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FLOOR(-1.b2) = -1 This will cause ErrTruncated error. Hence, sc.IgnoreTruncate has false value. I need to set sc.IgnoreTruncate to true in order to avoid ErrTruncated error which is came from getValidFloatPrefix(sc, str) in https://github.com/pingcap/tidb/blob/master/util/types/convert.go#L242

Copy link
Member

Choose a reason for hiding this comment

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

Maybe the original IgnoreTruncate value is true. So you must record an old IgnoreTruncate value

@@ -274,7 +274,7 @@ func (v *typeInferrer) handleFuncCallExpr(x *ast.FuncCallExpr) {
}
case "interval":
tp = types.NewFieldType(mysql.TypeLonglong)
case "ceil", "ceiling":
case "ceil", "ceiling", "floor":
Copy link
Member

Choose a reason for hiding this comment

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

Nice! But you could do this in another PR.

@zhexuany
Copy link
Contributor Author

@XuHuaiyu PTAL, is this ok to you?

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.

Rest LGTM

@@ -33,6 +33,7 @@ import (
var (
_ functionClass = &absFunctionClass{}
_ functionClass = &ceilFunctionClass{}
_ functionClass = &floorFunctionClass{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add definitions of floorFunctionClass and builtinFloorSig at the beginning of this file.

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 @XuHuaiyu

@zhexuany zhexuany force-pushed the builtin-floor branch 2 times, most recently from 825505f to b3490f3 Compare January 18, 2017 09:48
@ngaut
Copy link
Member

ngaut commented Jan 19, 2017

PTAL

@@ -49,6 +50,7 @@ var (
var (
_ builtinFunc = &builtinAbsSig{}
_ builtinFunc = &builtinCeilSig{}
_ builtinFunc = &builtinFloorSig{}
Copy link
Member

Choose a reason for hiding this comment

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

Also add for floorFunctionClass and add it into map funcs

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.

@@ -309,6 +310,7 @@ var funcs = map[string]functionClass{
ast.Abs: &absFunctionClass{baseFunctionClass{ast.Abs, 1, 1}},
ast.Ceil: &ceilFunctionClass{baseFunctionClass{ast.Ceil, 1, 1}},
ast.Ceiling: &ceilFunctionClass{baseFunctionClass{ast.Ceiling, 1, 1}},
ast.Floor: &ceilFunctionClass{baseFunctionClass{ast.Floor, 1, 1}},
Copy link
Member

Choose a reason for hiding this comment

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

Why use ceilFunctionClass?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad. I did it too fast.

Dtbl := tblToDtbl(tbl)

for _, t := range Dtbl {
v, err := builtinFloor(t["Arg"], s.ctx)
Copy link
Member

Choose a reason for hiding this comment

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

Test it by getting function class from funcs.

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.

@hanfei1991
Copy link
Member

@zhexuany fix CI

@zhexuany zhexuany force-pushed the builtin-floor branch 2 times, most recently from 0c0b642 to 647d8fd Compare January 19, 2017 09:28
@zhexuany
Copy link
Contributor Author

@hanfei1991 fixed.

{-1.23, -2, IsNil},
{"1.23", 1, IsNil},
{"-1.23", -2, IsNil},
// {"-1.b23", -1, NotNil},
Copy link
Member

Choose a reason for hiding this comment

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

Why comment these?

@zhexuany zhexuany force-pushed the builtin-floor branch 2 times, most recently from 5492695 to 56e3f85 Compare January 19, 2017 13:17
@zhexuany
Copy link
Contributor Author

@hanfei1991 passed the CI and rewrite the test cases. Shall be all good now.

*: address the test failure

*: fixed indentation issue in parser.y

*: added more test cases

*: fixed truncated data error in floor

*: fixed test case in plan related with function floor

*: added builtin func

*: adding floor into funs map

*: changing test case style

*: fixing CI
@zhexuany
Copy link
Contributor Author

@hanfei1991 @XuHuaiyu @shenli PTAL

@shenli
Copy link
Member

shenli commented Jan 21, 2017

LGTM
@hanfei1991 @XuHuaiyu PTAL

return d, errors.Trace(err)
}

sc.IgnoreTruncate = false
Copy link
Member

Choose a reason for hiding this comment

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

The original IgnoreTruncate may be true, so you need to store the old value as a local var.

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

Copy link
Member

@hanfei1991 hanfei1991 left a comment

Choose a reason for hiding this comment

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

LGTM

@hanfei1991 hanfei1991 merged commit 383f203 into pingcap:master Jan 22, 2017
@zhexuany zhexuany deleted the builtin-floor branch January 22, 2017 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants