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

paser, executor: add date literal(#3909) #4046

Merged
merged 23 commits into from Aug 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b3addba
tablecodec,mysql: mysql TypeDuration Fsp
dreamquster Jun 18, 2017
cfa8c76
executor_test: add test cases
dreamquster Jun 19, 2017
8b1f989
executor_test:
dreamquster Jun 19, 2017
b47ceff
Merge branch 'master' into master
tiancaiamao Jun 20, 2017
6bd40b2
Merge branch 'master' of https://github.com/pingcap/tidb
dreamquster Jul 3, 2017
21150d9
Merge branch 'master' of https://github.com/pingcap/tidb
dreamquster Jul 3, 2017
b5e7687
Merge branch 'master' of https://github.com/pingcap/tidb
dreamquster Jul 10, 2017
c2f45d0
Merge branch 'master' of https://github.com/pingcap/tidb
dreamquster Jul 29, 2017
de4c200
add date literal
dreamquster Aug 3, 2017
6f7affc
executor,parser: support date keyword
dreamquster Aug 4, 2017
02d6f94
executor: data literal
dreamquster Aug 5, 2017
e3b8ce3
Merge branch 'master' into date_literal
dreamquster Aug 5, 2017
d5cc881
Merge branch 'master' of https://github.com/pingcap/tidb into date_li…
dreamquster Aug 14, 2017
ddd620a
executor, expression: date literal
dreamquster Aug 15, 2017
8d7992e
Merge branch 'date_literal' of github.com:dreamquster/tidb into date_…
dreamquster Aug 15, 2017
fcce1ec
Merge branch 'master' of https://github.com/pingcap/tidb into date_li…
dreamquster Aug 15, 2017
44665ab
parser: add date_literal
dreamquster Aug 18, 2017
f5c940a
parser: add date_literal
dreamquster Aug 19, 2017
97ce7ce
Merge branch 'master' into date_literal
dreamquster Aug 21, 2017
2bf8135
parser, expression: add date_literal
dreamquster Aug 25, 2017
8ba9de3
Merge branch 'master' into date_literal
dreamquster Aug 25, 2017
ca71cad
expression, parser: add date_literal
dreamquster Aug 25, 2017
7efb6f8
Merge branch 'master' into date_literal
shenli Aug 27, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 41 additions & 0 deletions expression/integration_test.go
Expand Up @@ -2018,3 +2018,44 @@ func (s *testIntegrationSuite) TestOtherBuiltin(c *C) {
result = tk.MustQuery("select (0,1) in ((0,1), (0,2)), (0,1) in ((0,0), (0,2))")
result.Check(testkit.Rows("1 0"))
}

func (s *testIntegrationSuite) TestDateBuiltin(c *C) {
defer func() {
s.cleanEnv(c)
testleak.AfterTest(c)()
}()

tk := testkit.NewTestKit(c, s.store)
tk.MustExec("USE test;")
tk.MustExec("DROP TABLE IF EXISTS t;")
tk.MustExec("create table t (d date);")
tk.MustExec("insert into t values ('1997-01-02')")
tk.MustExec("insert into t values ('1998-01-02')")
r := tk.MustQuery("select * from t where d < date '1998-01-01';")
r.Check(testkit.Rows("1997-01-02"))

r = tk.MustQuery("select date'20171212'")
r.Check(testkit.Rows("2017-12-12"))

r = tk.MustQuery("select date'2017/12/12'")
r.Check(testkit.Rows("2017-12-12"))

r = tk.MustQuery("select date'2017/12-12'")
r.Check(testkit.Rows("2017-12-12"))

r = tk.MustQuery("select date'0000-00-00'")
r.Check(testkit.Rows("<nil>"))

r = tk.MustQuery("select date'0000-00-00 00:00:00'")
r.Check(testkit.Rows("<nil>"))

r = tk.MustQuery("select date'2017-99-99';")
r.Check(testkit.Rows("<nil>"))

r = tk.MustQuery("select date'2017-2-31';")
r.Check(testkit.Rows("<nil>"))

r = tk.MustQuery("select date'201712-31';")
r.Check(testkit.Rows("<nil>"))

}
10 changes: 9 additions & 1 deletion parser/parser.y
Expand Up @@ -2416,7 +2416,7 @@ Identifier | ReservedKeyword

UnReservedKeyword:
"ACTION" | "ASCII" | "AUTO_INCREMENT" | "AFTER" | "ALWAYS" | "AT" | "AVG" | "BEGIN" | "BIT" | "BOOL" | "BOOLEAN" | "BTREE" | "CHARSET"
| "COLUMNS" | "COMMIT" | "COMPACT" | "COMPRESSED" | "CONSISTENT" | "DATA" | "DATE" | "DATETIME" | "DEALLOCATE" | "DO"
| "COLUMNS" | "COMMIT" | "COMPACT" | "COMPRESSED" | "CONSISTENT" | "DATA" | "DATE" %prec lowerThanStringLitToken| "DATETIME" | "DEALLOCATE" | "DO"
| "DYNAMIC"| "END" | "ENGINE" | "ENGINES" | "ESCAPE" | "EXECUTE" | "FIELDS" | "FIRST" | "FIXED" | "FORMAT" | "FULL" |"GLOBAL"
| "HASH" | "LESS" | "LOCAL" | "NAMES" | "OFFSET" | "PASSWORD" %prec lowerThanEq | "PREPARE" | "QUICK" | "REDUNDANT"
| "ROLLBACK" | "SESSION" | "SIGNED" | "SNAPSHOT" | "START" | "STATUS" | "TABLES" | "TEXT" | "THAN" | "TIDB" | "TIME" | "TIMESTAMP"
Expand Down Expand Up @@ -2891,6 +2891,14 @@ FunctionCallConflict:
{
$$ = &ast.BinaryOperationExpr{Op: opcode.Mod, L: $3.(ast.ExprNode), R: $5.(ast.ExprNode)}
}
| "DATE" stringLit
{
tp := types.NewFieldType(mysql.TypeString)
tp.Charset, tp.Collate = parser.charset, parser.collation
expr := ast.NewValueExpr($2)
expr.SetType(tp)
$$ = &ast.FuncCallExpr{FnName: model.NewCIStr(ast.Date), Args: []ast.ExprNode{expr}}
}

DistinctKwd:
"DISTINCT"
Expand Down
3 changes: 3 additions & 0 deletions parser/parser_test.go
Expand Up @@ -528,6 +528,9 @@ func (s *testParserSuite) TestExpression(c *C) {
{"select n'string'", true},
// for comparison
{"select 1 <=> 0, 1 <=> null, 1 = null", true},
// for date literal
{"select date'1989-09-10'", true},
Copy link
Member

Choose a reason for hiding this comment

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

add test for invalid date literals

{"select date 19890910", false},
}
s.RunTest(c, table)
}
Expand Down