-
Notifications
You must be signed in to change notification settings - Fork 489
/
parser_test.go
2739 lines (2513 loc) · 122 KB
/
parser_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2015 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package parser
import (
"fmt"
"runtime"
"strings"
"testing"
. "github.com/pingcap/check"
"github.com/pingcap/errors"
"github.com/pingcap/parser/ast"
"github.com/pingcap/parser/charset"
"github.com/pingcap/parser/model"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/parser/terror"
_ "github.com/pingcap/tidb/types/parser_driver"
)
func TestT(t *testing.T) {
CustomVerboseFlag = true
TestingT(t)
}
var _ = Suite(&testParserSuite{})
type testParserSuite struct {
enableWindowFunc bool
}
func (s *testParserSuite) TestSimple(c *C) {
parser := New()
reservedKws := []string{
"add", "all", "alter", "analyze", "and", "as", "asc", "between", "bigint",
"binary", "blob", "both", "by", "cascade", "case", "change", "character", "check", "collate",
"column", "constraint", "convert", "create", "cross", "current_date", "current_time",
"current_timestamp", "current_user", "database", "databases", "day_hour", "day_microsecond",
"day_minute", "day_second", "decimal", "default", "delete", "desc", "describe",
"distinct", "distinctRow", "div", "double", "drop", "dual", "else", "enclosed", "escaped",
"exists", "explain", "false", "float", "for", "force", "foreign", "from",
"fulltext", "grant", "group", "having", "hour_microsecond", "hour_minute",
"hour_second", "if", "ignore", "in", "index", "infile", "inner", "insert", "int", "into", "integer",
"interval", "is", "join", "key", "keys", "kill", "leading", "left", "like", "limit", "lines", "load",
"localtime", "localtimestamp", "lock", "longblob", "longtext", "mediumblob", "maxvalue", "mediumint", "mediumtext",
"minute_microsecond", "minute_second", "mod", "not", "no_write_to_binlog", "null", "numeric",
"on", "option", "or", "order", "outer", "partition", "precision", "primary", "procedure", "range", "read", "real",
"references", "regexp", "rename", "repeat", "replace", "revoke", "restrict", "right", "rlike",
"schema", "schemas", "second_microsecond", "select", "set", "show", "smallint",
"starting", "table", "terminated", "then", "tinyblob", "tinyint", "tinytext", "to",
"trailing", "true", "union", "unique", "unlock", "unsigned",
"update", "use", "using", "utc_date", "values", "varbinary", "varchar",
"when", "where", "write", "xor", "year_month", "zerofill",
"generated", "virtual", "stored", "usage",
"delayed", "high_priority", "low_priority",
"cumeDist", "denseRank", "firstValue", "lag", "lastValue", "lead", "nthValue", "ntile",
"over", "percentRank", "rank", "row", "rows", "rowNumber", "window",
// TODO: support the following keywords
// "with",
}
for _, kw := range reservedKws {
src := fmt.Sprintf("SELECT * FROM db.%s;", kw)
_, err := parser.ParseOneStmt(src, "", "")
c.Assert(err, IsNil, Commentf("source %s", src))
src = fmt.Sprintf("SELECT * FROM %s.desc", kw)
_, err = parser.ParseOneStmt(src, "", "")
c.Assert(err, IsNil, Commentf("source %s", src))
src = fmt.Sprintf("SELECT t.%s FROM t", kw)
_, err = parser.ParseOneStmt(src, "", "")
c.Assert(err, IsNil, Commentf("source %s", src))
}
// Testcase for unreserved keywords
unreservedKws := []string{
"auto_increment", "after", "begin", "bit", "bool", "boolean", "charset", "columns", "commit",
"date", "datediff", "datetime", "deallocate", "do", "from_days", "end", "engine", "engines", "execute", "first", "full",
"local", "names", "offset", "password", "prepare", "quick", "rollback", "session", "signed",
"start", "global", "tables", "tablespace", "text", "time", "timestamp", "tidb", "transaction", "truncate", "unknown",
"value", "warnings", "year", "now", "substr", "subpartition", "subpartitions", "substring", "mode", "any", "some", "user", "identified",
"collation", "comment", "avg_row_length", "checksum", "compression", "connection", "key_block_size",
"max_rows", "min_rows", "national", "quarter", "escape", "grants", "status", "fields", "triggers",
"delay_key_write", "isolation", "partitions", "repeatable", "committed", "uncommitted", "only", "serializable", "level",
"curtime", "variables", "dayname", "version", "btree", "hash", "row_format", "dynamic", "fixed", "compressed",
"compact", "redundant", "sql_no_cache sql_no_cache", "sql_cache sql_cache", "action", "round",
"enable", "disable", "reverse", "space", "privileges", "get_lock", "release_lock", "sleep", "no", "greatest", "least",
"binlog", "hex", "unhex", "function", "indexes", "from_unixtime", "processlist", "events", "less", "than", "timediff",
"ln", "log", "log2", "log10", "timestampdiff", "pi", "quote", "none", "super", "shared", "exclusive",
"always", "stats", "stats_meta", "stats_histogram", "stats_buckets", "stats_healthy", "tidb_version", "replication", "slave", "client",
"max_connections_per_hour", "max_queries_per_hour", "max_updates_per_hour", "max_user_connections", "event", "reload", "routine", "temporary",
"following", "preceding", "unbounded", "respect", "nulls", "current", "last",
}
for _, kw := range unreservedKws {
src := fmt.Sprintf("SELECT %s FROM tbl;", kw)
_, err := parser.ParseOneStmt(src, "", "")
c.Assert(err, IsNil, Commentf("source %s", src))
}
// Testcase for prepared statement
src := "SELECT id+?, id+? from t;"
_, err := parser.ParseOneStmt(src, "", "")
c.Assert(err, IsNil)
// Testcase for -- Comment and unary -- operator
src = "CREATE TABLE foo (a SMALLINT UNSIGNED, b INT UNSIGNED); -- foo\nSelect --1 from foo;"
stmts, err := parser.Parse(src, "", "")
c.Assert(err, IsNil)
c.Assert(stmts, HasLen, 2)
// Testcase for /*! xx */
// See http://dev.mysql.com/doc/refman/5.7/en/comments.html
// Fix: https://github.com/pingcap/tidb/issues/971
src = "/*!40101 SET character_set_client = utf8 */;"
stmts, err = parser.Parse(src, "", "")
c.Assert(err, IsNil)
c.Assert(stmts, HasLen, 1)
stmt := stmts[0]
_, ok := stmt.(*ast.SetStmt)
c.Assert(ok, IsTrue)
// for issue #2017
src = "insert into blobtable (a) values ('/*! truncated */');"
stmt, err = parser.ParseOneStmt(src, "", "")
c.Assert(err, IsNil)
is, ok := stmt.(*ast.InsertStmt)
c.Assert(ok, IsTrue)
c.Assert(is.Lists, HasLen, 1)
c.Assert(is.Lists[0], HasLen, 1)
c.Assert(is.Lists[0][0].(ast.ValueExpr).GetDatumString(), Equals, "/*! truncated */")
// Testcase for CONVERT(expr,type)
src = "SELECT CONVERT('111', SIGNED);"
st, err := parser.ParseOneStmt(src, "", "")
c.Assert(err, IsNil)
ss, ok := st.(*ast.SelectStmt)
c.Assert(ok, IsTrue)
c.Assert(len(ss.Fields.Fields), Equals, 1)
cv, ok := ss.Fields.Fields[0].Expr.(*ast.FuncCastExpr)
c.Assert(ok, IsTrue)
c.Assert(cv.FunctionType, Equals, ast.CastConvertFunction)
// for query start with comment
srcs := []string{
"/* some comments */ SELECT CONVERT('111', SIGNED) ;",
"/* some comments */ /*comment*/ SELECT CONVERT('111', SIGNED) ;",
"SELECT /*comment*/ CONVERT('111', SIGNED) ;",
"SELECT CONVERT('111', /*comment*/ SIGNED) ;",
"SELECT CONVERT('111', SIGNED) /*comment*/;",
}
for _, src := range srcs {
st, err = parser.ParseOneStmt(src, "", "")
c.Assert(err, IsNil)
ss, ok = st.(*ast.SelectStmt)
c.Assert(ok, IsTrue)
}
// for issue #961
src = "create table t (c int key);"
st, err = parser.ParseOneStmt(src, "", "")
c.Assert(err, IsNil)
cs, ok := st.(*ast.CreateTableStmt)
c.Assert(ok, IsTrue)
c.Assert(cs.Cols, HasLen, 1)
c.Assert(cs.Cols[0].Options, HasLen, 1)
c.Assert(cs.Cols[0].Options[0].Tp, Equals, ast.ColumnOptionPrimaryKey)
// for issue #4497
src = "create table t1(a NVARCHAR(100));"
_, err = parser.ParseOneStmt(src, "", "")
c.Assert(err, IsNil)
// for issue 2803
src = "use quote;"
_, err = parser.ParseOneStmt(src, "", "")
c.Assert(err, IsNil)
// issue #4354
src = "select b'';"
_, err = parser.ParseOneStmt(src, "", "")
c.Assert(err, IsNil)
src = "select B'';"
_, err = parser.ParseOneStmt(src, "", "")
c.Assert(err, IsNil)
// src = "select 0b'';"
// _, err = parser.ParseOneStmt(src, "", "")
// c.Assert(err, NotNil)
// for #4909, support numericType `signed` filedOpt.
src = "CREATE TABLE t(_sms smallint signed, _smu smallint unsigned);"
_, err = parser.ParseOneStmt(src, "", "")
c.Assert(err, IsNil)
// for #7371, support NATIONAL CHARACTER
// reference link: https://dev.mysql.com/doc/refman/5.7/en/charset-national.html
src = "CREATE TABLE t(c1 NATIONAL CHARACTER(10));"
_, err = parser.ParseOneStmt(src, "", "")
c.Assert(err, IsNil)
src = `CREATE TABLE t(a tinyint signed,
b smallint signed,
c mediumint signed,
d int signed,
e int1 signed,
f int2 signed,
g int3 signed,
h int4 signed,
i int8 signed,
j integer signed,
k bigint signed,
l bool signed,
m boolean signed
);`
st, err = parser.ParseOneStmt(src, "", "")
c.Assert(err, IsNil)
ct, ok := st.(*ast.CreateTableStmt)
c.Assert(ok, IsTrue)
for _, col := range ct.Cols {
c.Assert(col.Tp.Flag&mysql.UnsignedFlag, Equals, uint(0))
}
// for issue #4006
src = `insert into tb(v) (select v from tb);`
_, err = parser.ParseOneStmt(src, "", "")
c.Assert(err, IsNil)
}
type testCase struct {
src string
ok bool
restore string
}
type testErrMsgCase struct {
src string
ok bool
err error
}
func (s *testParserSuite) RunTest(c *C, table []testCase) {
parser := New()
parser.EnableWindowFunc(s.enableWindowFunc)
for _, t := range table {
_, err := parser.Parse(t.src, "", "")
comment := Commentf("source %v", t.src)
if !t.ok {
c.Assert(err, NotNil, comment)
continue
}
c.Assert(err, IsNil, comment)
// restore correctness test
if t.ok && t.restore != "" {
s.RunRestoreTest(c, t.src, t.restore)
}
}
}
func (s *testParserSuite) RunRestoreTest(c *C, sourceSQLs, expectSQLs string) {
var sb strings.Builder
parser := New()
comment := Commentf("source %v", sourceSQLs)
stmts, err := parser.Parse(sourceSQLs, "", "")
c.Assert(err, IsNil, comment)
restoreSQLs := ""
for _, stmt := range stmts {
err = stmt.Restore(ast.NewRestoreCtx(ast.DefaultRestoreFlags, &sb))
c.Assert(err, IsNil, comment)
restoreSQL := sb.String()
comment = Commentf("source %v; restore %v", sourceSQLs, restoreSQL)
restoreStmt, err := parser.ParseOneStmt(restoreSQL, "", "")
c.Assert(err, IsNil, comment)
CleanNodeText(stmt)
CleanNodeText(restoreStmt)
c.Assert(restoreStmt, DeepEquals, stmt, comment)
if restoreSQLs != "" {
restoreSQLs += "; "
}
restoreSQLs += restoreSQL
}
comment = Commentf("restore %v; expect %v", restoreSQLs, expectSQLs)
c.Assert(restoreSQLs, Equals, expectSQLs, comment)
}
func (s *testParserSuite) RunErrMsgTest(c *C, table []testErrMsgCase) {
parser := New()
for _, t := range table {
_, err := parser.Parse(t.src, "", "")
comment := Commentf("source %v", t.src)
if t.err != nil {
c.Assert(terror.ErrorEqual(err, t.err), IsTrue, comment)
} else {
c.Assert(err, IsNil, comment)
}
}
}
func (s *testParserSuite) TestDMLStmt(c *C) {
table := []testCase{
{"", true, ""},
{";", true, ""},
{"INSERT INTO foo VALUES (1234)", true, ""},
{"INSERT INTO foo VALUES (1234, 5678)", true, ""},
{"INSERT INTO t1 (SELECT * FROM t2)", true, ""},
// 15
{"INSERT INTO foo VALUES (1 || 2)", true, ""},
{"INSERT INTO foo VALUES (1 | 2)", true, ""},
{"INSERT INTO foo VALUES (false || true)", true, ""},
{"INSERT INTO foo VALUES (bar(5678))", true, ""},
// 20
{"INSERT INTO foo VALUES ()", true, ""},
{"SELECT * FROM t", true, ""},
{"SELECT * FROM t AS u", true, ""},
// 25
{"SELECT * FROM t, v", true, ""},
{"SELECT * FROM t AS u, v", true, ""},
{"SELECT * FROM t, v AS w", true, ""},
{"SELECT * FROM t AS u, v AS w", true, ""},
{"SELECT * FROM foo, bar, foo", true, ""},
// 30
{"SELECT DISTINCTS * FROM t", false, ""},
{"SELECT DISTINCT * FROM t", true, ""},
{"SELECT DISTINCTROW * FROM t", true, ""},
{"SELECT ALL * FROM t", true, ""},
{"SELECT DISTINCT ALL * FROM t", false, ""},
{"SELECT DISTINCTROW ALL * FROM t", false, ""},
{"INSERT INTO foo (a) VALUES (42)", true, ""},
{"INSERT INTO foo (a,) VALUES (42,)", false, ""},
// 35
{"INSERT INTO foo (a,b) VALUES (42,314)", true, ""},
{"INSERT INTO foo (a,b,) VALUES (42,314)", false, ""},
{"INSERT INTO foo (a,b,) VALUES (42,314,)", false, ""},
{"INSERT INTO foo () VALUES ()", true, ""},
{"INSERT INTO foo VALUE ()", true, ""},
// for issue 2402
{"INSERT INTO tt VALUES (01000001783);", true, ""},
{"INSERT INTO tt VALUES (default);", true, ""},
{"REPLACE INTO foo VALUES (1 || 2)", true, ""},
{"REPLACE INTO foo VALUES (1 | 2)", true, ""},
{"REPLACE INTO foo VALUES (false || true)", true, ""},
{"REPLACE INTO foo VALUES (bar(5678))", true, ""},
{"REPLACE INTO foo VALUES ()", true, ""},
{"REPLACE INTO foo (a,b) VALUES (42,314)", true, ""},
{"REPLACE INTO foo (a,b,) VALUES (42,314)", false, ""},
{"REPLACE INTO foo (a,b,) VALUES (42,314,)", false, ""},
{"REPLACE INTO foo () VALUES ()", true, ""},
{"REPLACE INTO foo VALUE ()", true, ""},
// 40
{`SELECT stuff.id
FROM stuff
WHERE stuff.value >= ALL (SELECT stuff.value
FROM stuff)`, true, ""},
{"BEGIN", true, ""},
{"START TRANSACTION", true, ""},
// 45
{"COMMIT", true, ""},
{"ROLLBACK", true, ""},
{`BEGIN;
INSERT INTO foo VALUES (42, 3.14);
INSERT INTO foo VALUES (-1, 2.78);
COMMIT;`, true, ""},
{`BEGIN;
INSERT INTO tmp SELECT * from bar;
SELECT * from tmp;
ROLLBACK;`, true, ""},
// qualified select
{"SELECT a.b.c FROM t", true, ""},
{"SELECT a.b.*.c FROM t", false, ""},
{"SELECT a.b.* FROM t", true, ""},
{"SELECT a FROM t", true, ""},
{"SELECT a.b.c.d FROM t", false, ""},
// do statement
{"DO 1", true, ""},
{"DO 1 from t", false, ""},
// load data
{"load data infile '/tmp/t.csv' into table t", true, ""},
{"load data infile '/tmp/t.csv' into table t character set utf8", true, ""},
{"load data infile '/tmp/t.csv' into table t fields terminated by 'ab'", true, ""},
{"load data infile '/tmp/t.csv' into table t columns terminated by 'ab'", true, ""},
{"load data infile '/tmp/t.csv' into table t fields terminated by 'ab' enclosed by 'b'", true, ""},
{"load data infile '/tmp/t.csv' into table t fields terminated by 'ab' enclosed by 'b' escaped by '*'", true, ""},
{"load data infile '/tmp/t.csv' into table t lines starting by 'ab'", true, ""},
{"load data infile '/tmp/t.csv' into table t lines starting by 'ab' terminated by 'xy'", true, ""},
{"load data infile '/tmp/t.csv' into table t fields terminated by 'ab' lines terminated by 'xy'", true, ""},
{"load data infile '/tmp/t.csv' into table t terminated by 'xy' fields terminated by 'ab'", false, ""},
{"load data local infile '/tmp/t.csv' into table t", true, ""},
{"load data local infile '/tmp/t.csv' into table t fields terminated by 'ab'", true, ""},
{"load data local infile '/tmp/t.csv' into table t columns terminated by 'ab'", true, ""},
{"load data local infile '/tmp/t.csv' into table t fields terminated by 'ab' enclosed by 'b'", true, ""},
{"load data local infile '/tmp/t.csv' into table t fields terminated by 'ab' enclosed by 'b' escaped by '*'", true, ""},
{"load data local infile '/tmp/t.csv' into table t character set utf8 fields terminated by 'ab' enclosed by 'b' escaped by '*'", true, ""},
{"load data local infile '/tmp/t.csv' into table t lines starting by 'ab'", true, ""},
{"load data local infile '/tmp/t.csv' into table t lines starting by 'ab' terminated by 'xy'", true, ""},
{"load data local infile '/tmp/t.csv' into table t fields terminated by 'ab' lines terminated by 'xy'", true, ""},
{"load data local infile '/tmp/t.csv' into table t terminated by 'xy' fields terminated by 'ab'", false, ""},
{"load data infile '/tmp/t.csv' into table t (a,b)", true, ""},
{"load data local infile '/tmp/t.csv' into table t (a,b)", true, ""},
{"load data local infile '/tmp/t.csv' into table t fields terminated by 'ab' (a,b)", true, ""},
{"load data local infile '/tmp/t.csv' into table t columns terminated by 'ab' (a,b)", true, ""},
{"load data local infile '/tmp/t.csv' into table t fields terminated by 'ab' enclosed by 'b' (a,b)", true, ""},
{"load data local infile '/tmp/t.csv' into table t fields terminated by 'ab' enclosed by 'b' escaped by '*' (a,b)", true, ""},
{"load data local infile '/tmp/t.csv' into table t character set utf8 fields terminated by 'ab' enclosed by 'b' escaped by '*' (a,b)", true, ""},
{"load data local infile '/tmp/t.csv' into table t lines starting by 'ab' (a,b)", true, ""},
{"load data local infile '/tmp/t.csv' into table t lines starting by 'ab' terminated by 'xy' (a,b)", true, ""},
{"load data local infile '/tmp/t.csv' into table t character set utf8 fields terminated by 'ab' lines terminated by 'xy' (a,b)", true, ""},
{"load data local infile '/tmp/t.csv' into table t fields terminated by 'ab' lines terminated by 'xy' (a,b)", true, ""},
{"load data local infile '/tmp/t.csv' into table t (a,b) fields terminated by 'ab'", false, ""},
{"load data local infile '/tmp/t.csv' into table t ignore 1 lines", true, ""},
{"load data local infile '/tmp/t.csv' into table t ignore -1 lines", false, ""},
{"load data local infile '/tmp/t.csv' into table t fields terminated by 'ab' enclosed by 'b' (a,b) ignore 1 lines", false, ""},
{"load data local infile '/tmp/t.csv' into table t lines starting by 'ab' terminated by 'xy' ignore 1 lines", true, ""},
{"load data local infile '/tmp/t.csv' into table t fields terminated by 'ab' enclosed by 'b' escaped by '*' ignore 1 lines (a,b)", true, ""},
{"load data local infile '/tmp/t.csv' into table t fields terminated by 'ab' enclosed by 'b' escaped by ''", true, ""},
// select for update
{"SELECT * from t for update", true, ""},
{"SELECT * from t lock in share mode", true, ""},
// from join
{"SELECT * from t1, t2, t3", true, ""},
{"select * from t1 join t2 left join t3 on t2.id = t3.id", true, ""},
{"select * from t1 right join t2 on t1.id = t2.id left join t3 on t3.id = t2.id", true, ""},
{"select * from t1 right join t2 on t1.id = t2.id left join t3", false, ""},
{"select * from t1 join t2 left join t3 using (id)", true, ""},
{"select * from t1 right join t2 using (id) left join t3 using (id)", true, ""},
{"select * from t1 right join t2 using (id) left join t3", false, ""},
{"select * from t1 natural join t2", true, ""},
{"select * from t1 natural right join t2", true, ""},
{"select * from t1 natural left outer join t2", true, ""},
{"select * from t1 natural inner join t2", false, ""},
{"select * from t1 natural cross join t2", false, ""},
// for straight_join
{"select * from t1 straight_join t2 on t1.id = t2.id", true, ""},
{"select straight_join * from t1 join t2 on t1.id = t2.id", true, ""},
{"select straight_join * from t1 left join t2 on t1.id = t2.id", true, ""},
{"select straight_join * from t1 right join t2 on t1.id = t2.id", true, ""},
{"select straight_join * from t1 straight_join t2 on t1.id = t2.id", true, ""},
// for "USE INDEX" in delete statement
{"DELETE FROM t1 USE INDEX(idx_a) WHERE t1.id=1;", true, ""},
{"DELETE t1, t2 FROM t1 USE INDEX(idx_a) JOIN t2 WHERE t1.id=t2.id;", true, ""},
{"DELETE t1, t2 FROM t1 USE INDEX(idx_a) JOIN t2 USE INDEX(idx_a) WHERE t1.id=t2.id;", true, ""},
// for admin
{"admin show ddl;", true, ""},
{"admin show ddl jobs;", true, ""},
{"admin show ddl jobs 20;", true, ""},
{"admin show ddl jobs -1;", false, ""},
{"admin show ddl job queries 1", true, ""},
{"admin show ddl job queries 1, 2, 3, 4", true, ""},
{"admin show t1 next_row_id", true, ""},
{"admin check table t1, t2;", true, ""},
{"admin check index tableName idxName;", true, ""},
{"admin check index tableName idxName (1, 2), (4, 5);", true, ""},
{"admin checksum table t1, t2;", true, ""},
{"admin cancel ddl jobs 1", true, ""},
{"admin cancel ddl jobs 1, 2", true, ""},
{"admin recover index t1 idx_a", true, ""},
{"admin cleanup index t1 idx_a", true, ""},
{"admin show slow top 3", true, ""},
{"admin show slow top internal 7", true, ""},
{"admin show slow top all 9", true, ""},
{"admin show slow recent 11", true, ""},
// for on duplicate key update
{"INSERT INTO t (a,b,c) VALUES (1,2,3),(4,5,6) ON DUPLICATE KEY UPDATE c=VALUES(a)+VALUES(b);", true, ""},
{"INSERT IGNORE INTO t (a,b,c) VALUES (1,2,3),(4,5,6) ON DUPLICATE KEY UPDATE c=VALUES(a)+VALUES(b);", true, ""},
// for delete statement
{"DELETE t1, t2 FROM t1 INNER JOIN t2 INNER JOIN t3 WHERE t1.id=t2.id AND t2.id=t3.id;", true, ""},
{"DELETE FROM t1, t2 USING t1 INNER JOIN t2 INNER JOIN t3 WHERE t1.id=t2.id AND t2.id=t3.id;", true, ""},
{"DELETE t1, t2 FROM t1 INNER JOIN t2 INNER JOIN t3 WHERE t1.id=t2.id AND t2.id=t3.id limit 10;", false, ""},
{"DELETE /*+ TiDB_INLJ(t1, t2) */ t1, t2 from t1, t2 where t1.id=t2.id;", true, ""},
{"DELETE /*+ TiDB_HJ(t1, t2) */ t1, t2 from t1, t2 where t1.id=t2.id", true, ""},
// for update statement
{"UPDATE t SET id = id + 1 ORDER BY id DESC;", true, ""},
{"UPDATE items,month SET items.price=month.price WHERE items.id=month.id;", true, ""},
{"UPDATE items,month SET items.price=month.price WHERE items.id=month.id LIMIT 10;", false, ""},
{"UPDATE user T0 LEFT OUTER JOIN user_profile T1 ON T1.id = T0.profile_id SET T0.profile_id = 1 WHERE T0.profile_id IN (1);", true, ""},
{"UPDATE /*+ TiDB_INLJ(t1, t2) */ t1, t2 set t1.profile_id = 1, t2.profile_id = 1 where ta.a=t.ba", true, ""},
{"UPDATE /*+ TiDB_SMJ(t1, t2) */ t1, t2 set t1.profile_id = 1, t2.profile_id = 1 where ta.a=t.ba", true, ""},
// for select with where clause
{"SELECT * FROM t WHERE 1 = 1", true, ""},
// for dual
{"select 1 from dual", true, ""},
{"select 1 from dual limit 1", true, ""},
{"select 1 where exists (select 2)", false, ""},
{"select 1 from dual where not exists (select 2)", true, ""},
{"select 1 as a from dual order by a", true, ""},
{"select 1 as a from dual where 1 < any (select 2) order by a", true, ""},
{"select 1 order by 1", true, ""},
// for https://github.com/pingcap/tidb/issues/320
{`(select 1);`, true, ""},
// for https://github.com/pingcap/tidb/issues/1050
{`SELECT /*!40001 SQL_NO_CACHE */ * FROM test WHERE 1 limit 0, 2000;`, true, ""},
{`ANALYZE TABLE t`, true, ""},
// for comments
{`/** 20180417 **/ show databases;`, true, ""},
{`/* 20180417 **/ show databases;`, true, ""},
{`/** 20180417 */ show databases;`, true, ""},
{`/** 20180417 ******/ show databases;`, true, ""},
// for Binlog stmt
{`BINLOG '
BxSFVw8JAAAA8QAAAPUAAAAAAAQANS41LjQ0LU1hcmlhREItbG9nAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAEzgNAAgAEgAEBAQEEgAA2QAEGggAAAAICAgCAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAA5gm5Mg==
'/*!*/;`, true, ""},
}
s.RunTest(c, table)
}
func (s *testParserSuite) TestDBAStmt(c *C) {
table := []testCase{
// for SHOW statement
{"SHOW VARIABLES LIKE 'character_set_results'", true, ""},
{"SHOW GLOBAL VARIABLES LIKE 'character_set_results'", true, ""},
{"SHOW SESSION VARIABLES LIKE 'character_set_results'", true, ""},
{"SHOW VARIABLES", true, ""},
{"SHOW GLOBAL VARIABLES", true, ""},
{"SHOW GLOBAL VARIABLES WHERE Variable_name = 'autocommit'", true, ""},
{"SHOW STATUS", true, ""},
{"SHOW GLOBAL STATUS", true, ""},
{"SHOW SESSION STATUS", true, ""},
{`SHOW STATUS LIKE 'Up%'`, true, ""},
{`SHOW STATUS WHERE Variable_name LIKE 'Up%'`, true, ""},
{`SHOW FULL TABLES FROM icar_qa LIKE play_evolutions`, true, ""},
{`SHOW FULL TABLES WHERE Table_Type != 'VIEW'`, true, ""},
{`SHOW GRANTS`, true, ""},
{`SHOW GRANTS FOR 'test'@'localhost'`, true, ""},
{`SHOW GRANTS FOR current_user()`, true, ""},
{`SHOW GRANTS FOR current_user`, true, ""},
{`SHOW COLUMNS FROM City;`, true, ""},
{`SHOW COLUMNS FROM tv189.1_t_1_x;`, true, ""},
{`SHOW FIELDS FROM City;`, true, ""},
{`SHOW TRIGGERS LIKE 't'`, true, ""},
{`SHOW DATABASES LIKE 'test2'`, true, ""},
{`SHOW PROCEDURE STATUS WHERE Db='test'`, true, ""},
{`SHOW FUNCTION STATUS WHERE Db='test'`, true, ""},
{`SHOW INDEX FROM t;`, true, ""},
{`SHOW KEYS FROM t;`, true, ""},
{`SHOW INDEX IN t;`, true, ""},
{`SHOW KEYS IN t;`, true, ""},
{`SHOW INDEXES IN t where true;`, true, ""},
{`SHOW KEYS FROM t FROM test where true;`, true, ""},
{`SHOW EVENTS FROM test_db WHERE definer = 'current_user'`, true, ""},
{`SHOW PLUGINS`, true, ""},
{`SHOW PROFILES`, true, ""},
{`SHOW MASTER STATUS`, true, ""},
{`SHOW PRIVILEGES`, true, ""},
// for show character set
{"show character set;", true, ""},
{"show charset", true, ""},
// for show collation
{"show collation", true, ""},
{`show collation like 'utf8%'`, true, ""},
{"show collation where Charset = 'utf8' and Collation = 'utf8_bin'", true, ""},
// for show full columns
{"show columns in t;", true, ""},
{"show full columns in t;", true, ""},
// for show create table
{"show create table test.t", true, ""},
{"show create table t", true, ""},
// for show stats_meta.
{"show stats_meta", true, ""},
{"show stats_meta where table_name = 't'", true, ""},
// for show stats_histograms
{"show stats_histograms", true, ""},
{"show stats_histograms where col_name = 'a'", true, ""},
// for show stats_buckets
{"show stats_buckets", true, ""},
{"show stats_buckets where col_name = 'a'", true, ""},
// for show stats_healthy.
{"show stats_healthy", true, ""},
{"show stats_healthy where table_name = 't'", true, ""},
// for load stats
{"load stats '/tmp/stats.json'", true, ""},
// set
// user defined
{"SET @ = 1", true, ""},
{"SET @' ' = 1", true, ""},
{"SET @! = 1", false, ""},
{"SET @1 = 1", true, ""},
{"SET @a = 1", true, ""},
{"SET @b := 1", true, ""},
{"SET @.c = 1", true, ""},
{"SET @_d = 1", true, ""},
{"SET @_e._$. = 1", true, ""},
{"SET @~f = 1", false, ""},
{"SET @`g,` = 1", true, ""},
// session system variables
{"SET SESSION autocommit = 1", true, ""},
{"SET @@session.autocommit = 1", true, ""},
{"SET @@SESSION.autocommit = 1", true, ""},
{"SET @@GLOBAL.GTID_PURGED = '123'", true, ""},
{"SET @MYSQLDUMP_TEMP_LOG_BIN = @@SESSION.SQL_LOG_BIN", true, ""},
{"SET LOCAL autocommit = 1", true, ""},
{"SET @@local.autocommit = 1", true, ""},
{"SET @@autocommit = 1", true, ""},
{"SET autocommit = 1", true, ""},
// global system variables
{"SET GLOBAL autocommit = 1", true, ""},
{"SET @@global.autocommit = 1", true, ""},
// set default value
{"SET @@global.autocommit = default", true, ""},
{"SET @@session.autocommit = default", true, ""},
// SET CHARACTER SET
{"SET CHARACTER SET utf8mb4;", true, ""},
{"SET CHARACTER SET 'utf8mb4';", true, ""},
// set password
{"SET PASSWORD = 'password';", true, ""},
{"SET PASSWORD FOR 'root'@'localhost' = 'password';", true, ""},
// SET TRANSACTION Syntax
{"SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ", true, ""},
{"SET GLOBAL TRANSACTION ISOLATION LEVEL REPEATABLE READ", true, ""},
{"SET SESSION TRANSACTION READ WRITE", true, ""},
{"SET SESSION TRANSACTION READ ONLY", true, ""},
{"SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED", true, ""},
{"SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED", true, ""},
{"SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE", true, ""},
{"SET TRANSACTION ISOLATION LEVEL REPEATABLE READ", true, ""},
{"SET TRANSACTION READ WRITE", true, ""},
{"SET TRANSACTION READ ONLY", true, ""},
{"SET TRANSACTION ISOLATION LEVEL READ COMMITTED", true, ""},
{"SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED", true, ""},
{"SET TRANSACTION ISOLATION LEVEL SERIALIZABLE", true, ""},
// for set names
{"set names utf8", true, ""},
{"set names utf8 collate utf8_unicode_ci", true, ""},
{"set names binary", true, ""},
// for set names and set vars
{"set names utf8, @@session.sql_mode=1;", true, ""},
{"set @@session.sql_mode=1, names utf8, charset utf8;", true, ""},
// for FLUSH statement
{"flush no_write_to_binlog tables tbl1 with read lock", true, ""},
{"flush table", true, ""},
{"flush tables", true, ""},
{"flush tables tbl1", true, ""},
{"flush no_write_to_binlog tables tbl1", true, ""},
{"flush local tables tbl1", true, ""},
{"flush table with read lock", true, ""},
{"flush tables tbl1, tbl2, tbl3", true, ""},
{"flush tables tbl1, tbl2, tbl3 with read lock", true, ""},
{"flush privileges", true, ""},
{"flush status", true, ""},
}
s.RunTest(c, table)
}
func (s *testParserSuite) TestFlushTable(c *C) {
parser := New()
stmt, err := parser.Parse("flush local tables tbl1,tbl2 with read lock", "", "")
c.Assert(err, IsNil)
flushTable := stmt[0].(*ast.FlushStmt)
c.Assert(flushTable.Tp, Equals, ast.FlushTables)
c.Assert(flushTable.Tables[0].Name.L, Equals, "tbl1")
c.Assert(flushTable.Tables[1].Name.L, Equals, "tbl2")
c.Assert(flushTable.NoWriteToBinLog, IsTrue)
c.Assert(flushTable.ReadLock, IsTrue)
}
func (s *testParserSuite) TestFlushPrivileges(c *C) {
parser := New()
stmt, err := parser.Parse("flush privileges", "", "")
c.Assert(err, IsNil)
flushPrivilege := stmt[0].(*ast.FlushStmt)
c.Assert(flushPrivilege.Tp, Equals, ast.FlushPrivileges)
}
func (s *testParserSuite) TestExpression(c *C) {
table := []testCase{
// sign expression
{"SELECT ++1", true, ""},
{"SELECT -*1", false, ""},
{"SELECT -+1", true, ""},
{"SELECT -1", true, ""},
{"SELECT --1", true, ""},
// for string literal
{`select '''a''', """a"""`, true, ""},
{`select ''a''`, false, ""},
{`select ""a""`, false, ""},
{`select '''a''';`, true, ""},
{`select '\'a\'';`, true, ""},
{`select "\"a\"";`, true, ""},
{`select """a""";`, true, ""},
{`select _utf8"string";`, true, ""},
{`select _binary"string";`, true, ""},
{"select N'string'", true, ""},
{"select n'string'", true, ""},
// for comparison
{"select 1 <=> 0, 1 <=> null, 1 = null", true, ""},
// for date literal
{"select date'1989-09-10'", true, ""},
{"select date 19890910", false, ""},
// for time literal
{"select time '00:00:00.111'", true, ""},
{"select time 19890910", false, ""},
// for timestamp literal
{"select timestamp '1989-09-10 11:11:11'", true, ""},
{"select timestamp 19890910", false, ""},
// The ODBC syntax for time/date/timestamp literal.
// See: https://dev.mysql.com/doc/refman/5.7/en/date-and-time-literals.html
{"select {ts '1989-09-10 11:11:11'}", true, ""},
{"select {d '1989-09-10'}", true, ""},
{"select {t '00:00:00.111'}", true, ""},
// If the identifier is not in (t, d, ts), we just ignore it and consider the following expression as the value.
// See: https://dev.mysql.com/doc/refman/5.7/en/expressions.html
{"select {ts123 '1989-09-10 11:11:11'}", true, ""},
{"select {ts123 123}", true, ""},
{"select {ts123 1 xor 1}", true, ""},
}
s.RunTest(c, table)
}
func (s *testParserSuite) TestBuiltin(c *C) {
table := []testCase{
// for builtin functions
{"SELECT POW(1, 2)", true, ""},
{"SELECT POW(1, 2, 1)", true, ""}, // illegal number of arguments shall pass too
{"SELECT POW(1, 0.5)", true, ""},
{"SELECT POW(1, -1)", true, ""},
{"SELECT POW(-1, 1)", true, ""},
{"SELECT RAND();", true, ""},
{"SELECT RAND(1);", true, ""},
{"SELECT MOD(10, 2);", true, ""},
{"SELECT ROUND(-1.23);", true, ""},
{"SELECT ROUND(1.23, 1);", true, ""},
{"SELECT ROUND(1.23, 1, 1);", true, ""},
{"SELECT CEIL(-1.23);", true, ""},
{"SELECT CEILING(1.23);", true, ""},
{"SELECT FLOOR(-1.23);", true, ""},
{"SELECT LN(1);", true, ""},
{"SELECT LN(1, 2);", true, ""},
{"SELECT LOG(-2);", true, ""},
{"SELECT LOG(2, 65536);", true, ""},
{"SELECT LOG(2, 65536, 1);", true, ""},
{"SELECT LOG2(2);", true, ""},
{"SELECT LOG2(2, 2);", true, ""},
{"SELECT LOG10(10);", true, ""},
{"SELECT LOG10(10, 1);", true, ""},
{"SELECT ABS(10, 1);", true, ""},
{"SELECT ABS(10);", true, ""},
{"SELECT ABS();", true, ""},
{"SELECT CONV(10+'10'+'10'+X'0a',10,10);", true, ""},
{"SELECT CONV();", true, ""},
{"SELECT CRC32('MySQL');", true, ""},
{"SELECT CRC32();", true, ""},
{"SELECT SIGN();", true, ""},
{"SELECT SIGN(0);", true, ""},
{"SELECT SQRT(0);", true, ""},
{"SELECT SQRT();", true, ""},
{"SELECT ACOS();", true, ""},
{"SELECT ACOS(1);", true, ""},
{"SELECT ACOS(1, 2);", true, ""},
{"SELECT ASIN();", true, ""},
{"SELECT ASIN(1);", true, ""},
{"SELECT ASIN(1, 2);", true, ""},
{"SELECT ATAN(0), ATAN(1), ATAN(1, 2);", true, ""},
{"SELECT ATAN2(), ATAN2(1,2);", true, ""},
{"SELECT COS(0);", true, ""},
{"SELECT COS(1);", true, ""},
{"SELECT COS(1, 2);", true, ""},
{"SELECT COT();", true, ""},
{"SELECT COT(1);", true, ""},
{"SELECT COT(1, 2);", true, ""},
{"SELECT DEGREES();", true, ""},
{"SELECT DEGREES(0);", true, ""},
{"SELECT EXP();", true, ""},
{"SELECT EXP(1);", true, ""},
{"SELECT PI();", true, ""},
{"SELECT PI(1);", true, ""},
{"SELECT RADIANS();", true, ""},
{"SELECT RADIANS(1);", true, ""},
{"SELECT SIN();", true, ""},
{"SELECT SIN(1);", true, ""},
{"SELECT TAN(1);", true, ""},
{"SELECT TAN();", true, ""},
{"SELECT TRUNCATE(1.223,1);", true, ""},
{"SELECT TRUNCATE();", true, ""},
{"SELECT SUBSTR('Quadratically',5);", true, ""},
{"SELECT SUBSTR('Quadratically',5, 3);", true, ""},
{"SELECT SUBSTR('Quadratically' FROM 5);", true, ""},
{"SELECT SUBSTR('Quadratically' FROM 5 FOR 3);", true, ""},
{"SELECT SUBSTRING('Quadratically',5);", true, ""},
{"SELECT SUBSTRING('Quadratically',5, 3);", true, ""},
{"SELECT SUBSTRING('Quadratically' FROM 5);", true, ""},
{"SELECT SUBSTRING('Quadratically' FROM 5 FOR 3);", true, ""},
{"SELECT CONVERT('111', SIGNED);", true, ""},
{"SELECT LEAST(), LEAST(1, 2, 3);", true, ""},
{"SELECT INTERVAL(1, 0, 1, 2)", true, ""},
{"SELECT DATE_ADD('2008-01-02', INTERVAL INTERVAL(1, 0, 1) DAY);", true, ""},
// information functions
{"SELECT DATABASE();", true, ""},
{"SELECT SCHEMA();", true, ""},
{"SELECT USER();", true, ""},
{"SELECT USER(1);", true, ""},
{"SELECT CURRENT_USER();", true, ""},
{"SELECT CURRENT_USER;", true, ""},
{"SELECT CONNECTION_ID();", true, ""},
{"SELECT VERSION();", true, ""},
{"SELECT BENCHMARK(1000000, AES_ENCRYPT('text',UNHEX('F3229A0B371ED2D9441B830D21A390C3')));", true, ""},
{"SELECT BENCHMARK(AES_ENCRYPT('text',UNHEX('F3229A0B371ED2D9441B830D21A390C3')));", true, ""},
{"SELECT CHARSET('abc');", true, ""},
{"SELECT COERCIBILITY('abc');", true, ""},
{"SELECT COERCIBILITY('abc', 'a');", true, ""},
{"SELECT COLLATION('abc');", true, ""},
{"SELECT ROW_COUNT();", true, ""},
{"SELECT SESSION_USER();", true, ""},
{"SELECT SYSTEM_USER();", true, ""},
{"SELECT SUBSTRING_INDEX('www.mysql.com', '.', 2);", true, ""},
{"SELECT SUBSTRING_INDEX('www.mysql.com', '.', -2);", true, ""},
{`SELECT ASCII(), ASCII(""), ASCII("A"), ASCII(1);`, true, ""},
{`SELECT LOWER("A"), UPPER("a")`, true, ""},
{`SELECT LCASE("A"), UCASE("a")`, true, ""},
{`SELECT REPLACE('www.mysql.com', 'w', 'Ww')`, true, ""},
{`SELECT LOCATE('bar', 'foobarbar');`, true, ""},
{`SELECT LOCATE('bar', 'foobarbar', 5);`, true, ""},
{`SELECT tidb_version();`, true, ""},
{`SELECT tidb_is_ddl_owner();`, true, ""},
// for time fsp
{"CREATE TABLE t( c1 TIME(2), c2 DATETIME(2), c3 TIMESTAMP(2) );", true, ""},
// for row
{"select row(1)", false, ""},
{"select row(1, 1,)", false, ""},
{"select (1, 1,)", false, ""},
{"select row(1, 1) > row(1, 1), row(1, 1, 1) > row(1, 1, 1)", true, ""},
{"Select (1, 1) > (1, 1)", true, ""},
{"create table t (`row` int)", true, ""},
{"create table t (row int)", false, ""},
// for cast with charset
{"SELECT *, CAST(data AS CHAR CHARACTER SET utf8) FROM t;", true, ""},
// for cast as JSON
{"SELECT *, CAST(data AS JSON) FROM t;", true, ""},
// for cast as signed int, fix issue #3691.
{"select cast(1 as signed int);", true, ""},
// for last_insert_id
{"SELECT last_insert_id();", true, ""},
{"SELECT last_insert_id(1);", true, ""},
// for binary operator
{"SELECT binary 'a';", true, ""},
// for bit_count
{`SELECT BIT_COUNT(1);`, true, ""},
// select time
{"select current_timestamp", true, ""},
{"select current_timestamp()", true, ""},
{"select current_timestamp(6)", true, ""},
{"select current_timestamp(null)", false, ""},
{"select current_timestamp(-1)", false, ""},
{"select current_timestamp(1.0)", false, ""},
{"select current_timestamp('2')", false, ""},
{"select now()", true, ""},
{"select now(6)", true, ""},
{"select sysdate(), sysdate(6)", true, ""},
{"SELECT time('01:02:03');", true, ""},
{"SELECT time('01:02:03.1')", true, ""},
{"SELECT time('20.1')", true, ""},
{"SELECT TIMEDIFF('2000:01:01 00:00:00', '2000:01:01 00:00:00.000001');", true, ""},
{"SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01');", true, ""},
{"SELECT TIMESTAMPDIFF(YEAR,'2002-05-01','2001-01-01');", true, ""},
{"SELECT TIMESTAMPDIFF(MINUTE,'2003-02-01','2003-05-01 12:05:55');", true, ""},
// select current_time
{"select current_time", true, ""},
{"select current_time()", true, ""},
{"select current_time(6)", true, ""},
{"select current_time(-1)", false, ""},
{"select current_time(1.0)", false, ""},
{"select current_time('1')", false, ""},
{"select current_time(null)", false, ""},
{"select curtime()", true, ""},
{"select curtime(6)", true, ""},
{"select curtime(-1)", false, ""},
{"select curtime(1.0)", false, ""},
{"select curtime('1')", false, ""},
{"select curtime(null)", false, ""},
// select utc_timestamp
{"select utc_timestamp", true, ""},
{"select utc_timestamp()", true, ""},
{"select utc_timestamp(6)", true, ""},
{"select utc_timestamp(-1)", false, ""},
{"select utc_timestamp(1.0)", false, ""},
{"select utc_timestamp('1')", false, ""},
{"select utc_timestamp(null)", false, ""},
// select utc_time
{"select utc_time", true, ""},
{"select utc_time()", true, ""},
{"select utc_time(6)", true, ""},
{"select utc_time(-1)", false, ""},
{"select utc_time(1.0)", false, ""},
{"select utc_time('1')", false, ""},
{"select utc_time(null)", false, ""},
// for microsecond, second, minute, hour
{"SELECT MICROSECOND('2009-12-31 23:59:59.000010');", true, ""},
{"SELECT SECOND('10:05:03');", true, ""},
{"SELECT MINUTE('2008-02-03 10:05:03');", true, ""},
{"SELECT HOUR(), HOUR('10:05:03');", true, ""},
// for date, day, weekday
{"SELECT CURRENT_DATE, CURRENT_DATE(), CURDATE()", true, ""},
{"SELECT CURRENT_DATE, CURRENT_DATE(), CURDATE(1)", false, ""},
{"SELECT DATEDIFF('2003-12-31', '2003-12-30');", true, ""},
{"SELECT DATE('2003-12-31 01:02:03');", true, ""},
{"SELECT DATE();", true, ""},
{"SELECT DATE('2003-12-31 01:02:03', '');", true, ""},
{`SELECT DATE_FORMAT('2003-12-31 01:02:03', '%W %M %Y');`, true, ""},
{"SELECT DAY('2007-02-03');", true, ""},
{"SELECT DAYOFMONTH('2007-02-03');", true, ""},
{"SELECT DAYOFWEEK('2007-02-03');", true, ""},
{"SELECT DAYOFYEAR('2007-02-03');", true, ""},
{"SELECT DAYNAME('2007-02-03');", true, ""},
{"SELECT FROM_DAYS(1423);", true, ""},
{"SELECT WEEKDAY('2007-02-03');", true, ""},
// for utc_date
{"SELECT UTC_DATE, UTC_DATE();", true, ""},
{"SELECT UTC_DATE(), UTC_DATE()+0", true, ""},
// for week, month, year
{"SELECT WEEK();", true, ""},
{"SELECT WEEK('2007-02-03');", true, ""},
{"SELECT WEEK('2007-02-03', 0);", true, ""},
{"SELECT WEEKOFYEAR('2007-02-03');", true, ""},
{"SELECT MONTH('2007-02-03');", true, ""},
{"SELECT MONTHNAME('2007-02-03');", true, ""},
{"SELECT YEAR('2007-02-03');", true, ""},
{"SELECT YEARWEEK('2007-02-03');", true, ""},
{"SELECT YEARWEEK('2007-02-03', 0);", true, ""},
// for ADDTIME, SUBTIME
{"SELECT ADDTIME('01:00:00.999999', '02:00:00.999998');", true, ""},
{"SELECT ADDTIME('02:00:00.999998');", true, ""},
{"SELECT ADDTIME();", true, ""},
{"SELECT SUBTIME('01:00:00.999999', '02:00:00.999998');", true, ""},
// for CONVERT_TZ
{"SELECT CONVERT_TZ();", true, ""},
{"SELECT CONVERT_TZ('2004-01-01 12:00:00','+00:00','+10:00');", true, ""},
{"SELECT CONVERT_TZ('2004-01-01 12:00:00','+00:00','+10:00', '+10:00');", true, ""},
// for GET_FORMAT
{"SELECT GET_FORMAT(DATE, 'USA');", true, ""},
{"SELECT GET_FORMAT(DATETIME, 'USA');", true, ""},
{"SELECT GET_FORMAT(TIME, 'USA');", true, ""},