parser: use ExpressionListOpt for json functions. (#3362)

This commit is contained in:
Ewan Chou
2017-05-31 13:46:22 +08:00
committed by GitHub
parent 8eed6456e9
commit b73b833e02
2 changed files with 12 additions and 17 deletions

View File

@ -3642,28 +3642,17 @@ FunctionCallNonKeyword:
{
$$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1), Args: $3.([]ast.ExprNode)}
}
| "JSON_EXTRACT" '(' Expression ',' ExpressionList ')'
| "JSON_EXTRACT" '(' ExpressionListOpt ')'
{
var args = []ast.ExprNode{$3.(ast.ExprNode)}
args = append(args, $5.([]ast.ExprNode)...)
$$ = &ast.FuncCallExpr{
FnName: model.NewCIStr($1),
Args: args,
}
$$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1), Args: $3.([]ast.ExprNode)}
}
| "JSON_UNQUOTE" '(' Expression ')'
| "JSON_UNQUOTE" '(' ExpressionListOpt ')'
{
$$ = &ast.FuncCallExpr{
FnName: model.NewCIStr($1),
Args: []ast.ExprNode{$3.(ast.ExprNode)},
}
$$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1), Args: $3.([]ast.ExprNode)}
}
| "JSON_TYPE" '(' Expression ')'
| "JSON_TYPE" '(' ExpressionListOpt ')'
{
$$ = &ast.FuncCallExpr{
FnName: model.NewCIStr($1),
Args: []ast.ExprNode{$3.(ast.ExprNode)},
}
$$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1), Args: $3.([]ast.ExprNode)}
}
GetFormatSelector:

View File

@ -1026,6 +1026,12 @@ func (s *testParserSuite) TestBuiltin(c *C) {
{`SELECT UNCOMPRESS('any string');`, true},
{`SELECT UNCOMPRESSED_LENGTH(@compressed_string);`, true},
{`SELECT VALIDATE_PASSWORD_STRENGTH(@str);`, true},
// For JSON functions.
{`SELECT JSON_EXTRACT();`, true},
{`SELECT JSON_UNQUOTE();`, true},
{`SELECT JSON_TYPE('[123]');`, true},
{`SELECT JSON_TYPE();`, true},
}
s.RunTest(c, table)
}