Skip to content

Commit

Permalink
expression, parser: refine parser of localtime and localtimestamp (#4503
Browse files Browse the repository at this point in the history
)
  • Loading branch information
XuHuaiyu authored and hanfei1991 committed Sep 12, 2017
1 parent 5095067 commit 262260a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
8 changes: 8 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,14 @@ func (s *testIntegrationSuite) TestTimeBuiltin(c *C) {
// for extract
result = tk.MustQuery(`select extract(day from '800:12:12'), extract(hour from '800:12:12'), extract(month from 20170101), extract(day_second from '2017-01-01 12:12:12')`)
result.Check(testkit.Rows("12 800 1 1121212"))

// for localtime, localtimestamp
result = tk.MustQuery(`select localtime() = now(), localtime = now(), localtimestamp() = now(), localtimestamp = now()`)
result.Check(testkit.Rows("1 1 1 1"))

// for current_timestamp, current_timestamp()
result = tk.MustQuery(`select current_timestamp() = now(), current_timestamp = now()`)
result.Check(testkit.Rows("1 1"))
}

func (s *testIntegrationSuite) TestOpBuiltin(c *C) {
Expand Down
16 changes: 12 additions & 4 deletions parser/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -3026,13 +3026,21 @@ FunctionCallKeyword:
{
$$ = &ast.FuncCallExpr{FnName:model.NewCIStr(ast.InsertFunc), Args: $3.([]ast.ExprNode)}
}
| "LOCALTIME" '(' ExpressionListOpt ')'
| "LOCALTIME" FuncDatetimePrec
{
$$ = &ast.FuncCallExpr{FnName:model.NewCIStr($1), Args: $3.([]ast.ExprNode)}
args := []ast.ExprNode{}
if $2 != nil {
args = append(args, $2.(ast.ExprNode))
}
$$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1), Args: args}
}
| "LOCALTIMESTAMP" '(' ExpressionListOpt ')'
| "LOCALTIMESTAMP" FuncDatetimePrec
{
$$ = &ast.FuncCallExpr{FnName:model.NewCIStr($1), Args: $3.([]ast.ExprNode)}
args := []ast.ExprNode{}
if $2 != nil {
args = append(args, $2.(ast.ExprNode))
}
$$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1), Args: args}
}
| "QUARTER" '(' ExpressionListOpt ')'
{
Expand Down

0 comments on commit 262260a

Please sign in to comment.