15 package com.cloudera.impala.analysis;
17 import static org.junit.Assert.assertEquals;
18 import static org.junit.Assert.assertNotNull;
19 import static org.junit.Assert.assertTrue;
20 import static org.junit.Assert.fail;
22 import java.io.StringReader;
23 import java.math.BigInteger;
24 import java.util.ArrayList;
25 import java.util.List;
31 import com.google.common.base.Preconditions;
32 import com.google.common.collect.Lists;
38 new String[] {
"i",
"5",
"true",
"NULL",
"'a'",
"(1.5 * 8)" };
44 SqlScanner input =
new SqlScanner(
new StringReader(stmt));
45 SqlParser
parser =
new SqlParser(input);
48 result = parser.parse().value;
49 }
catch (Exception e) {
50 System.err.println(parser.getErrorMsg(stmt));
52 fail(
"\n" + parser.getErrorMsg(stmt));
54 assertNotNull(result);
62 public <C extends Expr> Object
ParsesOk(String selectStmtSql, Class<C> cl) {
63 Object parseNode =
ParsesOk(selectStmtSql);
65 fail(String.format(
"Statement parsed ok but it is not a select stmt: %s",
68 SelectStmt selectStmt = (SelectStmt) parseNode;
69 Expr firstExpr = selectStmt.getSelectList().getItems().get(0).getExpr();
71 assertTrue(String.format(
72 "Expression is of class '%s'. Expected class '%s'",
73 firstExpr.getClass().getSimpleName(), cl.getSimpleName()),
74 firstExpr.getClass().equals(cl));
81 public void ParserError(String stmt, String expectedErrorString) {
82 SqlScanner input =
new SqlScanner(
new StringReader(stmt));
83 SqlParser
parser =
new SqlParser(input);
86 result = parser.parse().value;
87 }
catch (Exception e) {
88 if (expectedErrorString != null) {
89 String errorString = parser.getErrorMsg(stmt);
90 assertTrue(errorString.startsWith(expectedErrorString));
94 fail(
"Stmt didn't result in parsing error: " + stmt);
107 ParsesOk(
"select 1 + 1, 'two', f(3), a + b");
119 ParsesOk(
"select a, b, c, d from tbl");
120 ParsesOk(
"select true, false, NULL from tbl");
121 ParsesOk(
"select all a, b, c from tbl");
133 char[] quotes = {
'\'',
'"',
'`',
' '};
134 for (
int i = 0; i < quotes.length; ++i) {
135 char quote = quotes[i];
137 ParsesOk(
"select a 'b' from tbl".replace(
'\'', quote));
138 ParsesOk(
"select a as 'b' from tbl".replace(
'\'', quote));
139 ParsesOk(
"select a 'x', b as 'y', c 'z' from tbl".replace(
'\'', quote));
141 "select a 'x', b as 'y', sum(x) over () 'z' from tbl".replace(
'\'', quote));
142 ParsesOk(
"select a.b 'x' from tbl".replace(
'\'', quote));
143 ParsesOk(
"select a.b as 'x' from tbl".replace(
'\'', quote));
144 ParsesOk(
"select a.b.c.d 'x' from tbl".replace(
'\'', quote));
145 ParsesOk(
"select a.b.c.d as 'x' from tbl".replace(
'\'', quote));
147 ParsesOk(
"select a from tbl 'b'".replace(
'\'', quote));
148 ParsesOk(
"select a from tbl as 'b'".replace(
'\'', quote));
149 ParsesOk(
"select a from db.tbl 'b'".replace(
'\'', quote));
150 ParsesOk(
"select a from db.tbl as 'b'".replace(
'\'', quote));
151 ParsesOk(
"select a from db.tbl.col 'b'".replace(
'\'', quote));
152 ParsesOk(
"select a from db.tbl.col as 'b'".replace(
'\'', quote));
153 ParsesOk(
"select a from (select * from tbl) 'b'".replace(
'\'', quote));
154 ParsesOk(
"select a from (select * from tbl) as 'b'".replace(
'\'', quote));
155 ParsesOk(
"select a from (select * from tbl b) as 'b'".replace(
'\'', quote));
157 ParsesOk(
"with 't' as (select 1) select * from t".replace(
'\'', quote));
167 ParsesOk(
"select db.tbl.* from tbl");
168 ParsesOk(
"select db.tbl.struct_col.* from tbl");
174 ParsesOk(
"select * from tbl where f(*) = 5");
176 ParserError(
"select * from tbl where f(tbl.*) = 5");
203 ParsesOk(
"/**\n* Doc style\n*/select 1");
204 ParsesOk(
"/************\n*\n* Header style\n*\n***********/select 1");
205 ParsesOk(
"/* 1 */ select 1 /* 2 */");
219 ParsesOk(
"/* select 1; */ select 1");
220 ParsesOk(
"/** select 1; */ select 1");
221 ParsesOk(
"/* select */ select 1 /* 1 */");
235 ParsesOk(
"--foo\r\nselect 1 --bar");
251 Preconditions.checkState(selectStmt.getTableRefs().size() > 1);
252 List<String> actualHints = Lists.newArrayList();
253 assertEquals(null, selectStmt.
getTableRefs().get(0).getJoinHints());
254 for (
int i = 1; i < selectStmt.getTableRefs().size(); ++i) {
255 List<String> hints = selectStmt.getTableRefs().
get(i).getJoinHints();
256 if (hints != null) actualHints.addAll(hints);
258 if (actualHints.isEmpty()) actualHints = Lists.<String>newArrayList((String) null);
259 assertEquals(Lists.newArrayList(expectedHints), actualHints);
268 List<String> actualHints = selectStmt.getSelectList().getPlanHints();
269 if (actualHints == null) actualHints = Lists.<String>newArrayList((String) null);
270 assertEquals(Lists.newArrayList(expectedHints), actualHints);
278 List<String> actualHints = insertStmt.getPlanHints();
279 if (actualHints == null) actualHints = Lists.<String>newArrayList((String) null);
280 assertEquals(Lists.newArrayList(expectedHints), actualHints);
286 String[][] hintStyles =
new String[][] {
287 new String[] {
"/* +",
"*/" },
288 new String[] {
"-- +",
"\n" },
289 new String[] {
"\n-- +",
"\n" },
290 new String[] {
"[",
"]" }
292 String[][] commentStyles =
new String[][] {
293 new String[] {
"/*",
"*/" },
294 new String[] {
"--",
"\n" }
296 for (String[] hintStyle: hintStyles) {
297 String prefix = hintStyle[0];
298 String suffix = hintStyle[1];
301 "select * from functional.alltypes a join %sbroadcast%s " +
302 "functional.alltypes b", prefix, suffix),
"broadcast");
304 "select * from functional.alltypes a join %sbroadcast%s " +
305 "functional.alltypes b using(id)", prefix, suffix),
"broadcast");
307 "select * from functional.alltypes a join %sbroadcast%s " +
308 "functional.alltypes b on(a.id = b.id)", prefix, suffix),
"broadcast");
310 "select * from functional.alltypes a cross join %sbroadcast%s " +
311 "functional.alltypes b", prefix, suffix),
"broadcast");
314 "select * from functional.alltypes a join " +
315 "%sbroadcast,shuffle,foo,bar%s " +
316 "functional.alltypes b using(id)", prefix, suffix),
317 "broadcast",
"shuffle",
"foo",
"bar");
320 "select * from functional.alltypes a " +
321 "join %sbroadcast%s functional.alltypes b using(id) " +
322 "join %sshuffle%s functional.alltypes c using(int_col) " +
323 "join %sbroadcast%s functional.alltypes d using(int_col) " +
324 "join %sshuffle%s functional.alltypes e using(string_col)",
325 prefix, suffix, prefix, suffix, prefix, suffix, prefix, suffix),
326 "broadcast",
"shuffle",
"broadcast",
"shuffle");
329 "select * from functional.alltypes a " +
330 "join %sbroadcast%s functional.alltypes b using(id) " +
331 "join %sshuffle%s functional.alltypes c using(int_col) " +
332 "join %sbroadcast%s functional.alltypes d using(int_col) " +
333 "join %sshuffle%s functional.alltypes e using(string_col)",
334 prefix, suffix, suffix, prefix, prefix, suffix, suffix, prefix));
337 "select * from functional.alltypes a " +
338 "join %sbroadcast%s functional.alltypes b using(id) " +
339 "join %sshuffle%s functional.alltypes c using(int_col) " +
340 "join %sbroadcast%s functional.alltypes d using(int_col) " +
341 "join %sshuffle%s functional.alltypes e using(string_col)",
342 suffix, suffix, suffix, suffix, prefix,
"",
"",
""));
346 "insert into t %snoshuffle%s select * from t", prefix, suffix),
349 "insert overwrite t %snoshuffle%s select * from t", prefix, suffix),
352 "insert into t partition(x, y) %snoshuffle%s select * from t",
353 prefix, suffix),
"noshuffle");
355 "insert into t(a, b) partition(x, y) %sshuffle%s select * from t",
356 prefix, suffix),
"shuffle");
358 "insert overwrite t(a, b) partition(x, y) %sfoo,bar,baz%s select * from t",
359 prefix, suffix),
"foo",
"bar",
"baz");
363 if (prefix.contains(
"[")) {
368 "select %sstraight_join%s * from functional.alltypes a", prefix, suffix),
371 if (!prefix.equals(
"")) {
373 "select %sfoo,bar,baz%s * from functional.alltypes a", prefix, suffix),
374 "foo",
"bar",
"baz");
376 if (prefix.isEmpty())
continue;
379 for (String[] commentStyle: commentStyles) {
380 String commentPrefix = commentStyle[0];
381 String commentSuffix = commentStyle[1];
382 String queryTemplate =
383 "$1comment$2 select $1comment$2 $3straight_join$4 $1comment$2 * " +
384 "from $1comment$2 functional.alltypes a join $1comment$2 $3shuffle$4 " +
385 "$1comment$2 functional.alltypes b $1comment$2 on $1comment$2 " +
387 String query = queryTemplate.replaceAll(
"\\$1", commentPrefix)
388 .replaceAll(
"\\$2", commentSuffix).replaceAll(
"\\$3", prefix)
389 .replaceAll(
"\\$4", suffix);
395 TestJoinHints(
"select * from functional.alltypes a join /* comment */" +
396 "functional.alltypes b using (int_col)", (String) null);
399 TestInsertHints(
"insert into t(a, b) partition(x, y) /* comment */ select 1",
417 ParserError(
"select -- +straight_join * from functional.alltypes");
418 ParserError(
"select \n-- +straight_join * from functional.alltypes");
421 ParserError(
"select * from functional.alltypes a join + */" +
422 "functional.alltypes b using (int_col)");
423 ParserError(
"select * from functional.alltypes a join /* + " +
424 "functional.alltypes b using (int_col)");
430 ParserError(
"select /* /* +straight_join */ */ * from functional.alltypes");
435 String tblRefs[] =
new String[] {
"tbl",
"db.tbl",
"db.tbl.col",
"db.tbl.col.fld" };
436 for (String tbl: tblRefs) {
438 (
"select * from $TBL src1 " +
439 "left outer join $TBL src2 on " +
440 " src1.key = src2.key and src1.key < 10 and src2.key > 10 " +
441 "right outer join $TBL src3 on " +
442 " src2.key = src3.key and src3.key < 10 " +
443 "full outer join $TBL src3 on " +
444 " src2.key = src3.key and src3.key < 10 " +
445 "left semi join $TBL src3 on " +
446 " src2.key = src3.key and src3.key < 10 " +
447 "left anti join $TBL src3 on " +
448 " src2.key = src3.key and src3.key < 10 " +
449 "right semi join $TBL src3 on " +
450 " src2.key = src3.key and src3.key < 10 " +
451 "right anti join $TBL src3 on " +
452 " src2.key = src3.key and src3.key < 10 " +
453 "join $TBL src3 on " +
454 " src2.key = src3.key and src3.key < 10 " +
455 "inner join $TBL src3 on " +
456 " src2.key = src3.key and src3.key < 10 ").replace(
"$TBL", tbl));
458 (
"select * from $TBL src1 " +
459 "left outer join $TBL src2 using (a, b, c) " +
460 "right outer join $TBL src3 using (d, e, f) " +
461 "full outer join $TBL src4 using (d, e, f) " +
462 "left semi join $TBL src5 using (d, e, f) " +
463 "left anti join $TBL src6 using (d, e, f) " +
464 "right semi join $TBL src7 using (d, e, f) " +
465 "right anti join $TBL src8 using (d, e, f) " +
466 "join $TBL src9 using (d, e, f) " +
467 "inner join $TBL src10 using (d, e, f) ").replace(
"$TBL", tbl));
470 ParsesOk(
"select * from $TBL cross join $TBL".replace(
"$TBL", tbl));
474 ParsesOk(
"select * from src src1 " +
475 "left outer join src src2 on NULL " +
476 "right outer join src src3 on (NULL) " +
477 "full outer join src src3 on NULL " +
478 "left semi join src src3 on (NULL) " +
479 "left anti join src src3 on (NULL) " +
480 "right semi join src src3 on (NULL) " +
481 "right anti join src src3 on (NULL) " +
482 "join src src3 on NULL " +
483 "inner join src src3 on (NULL) " +
484 "where src2.bla = src3.bla " +
485 "order by src1.key, src1.value, src2.key, src2.value, src3.key, src3.value");
487 ParsesOk(
"select * from src src1 join src src2 on ('a')");
488 ParsesOk(
"select * from src src1 join src src2 on (f(a, b))");
490 "left outer join src src2 on (src1.key = src2.key and)");
493 ParserError(
"select * from src src1 join src src2 using (1)");
494 ParserError(
"select * from src src1 join src src2 using (f(id))");
496 ParserError(
"select * from src src1 join src src2 using id");
499 ParserError(
"select * from a cross join b on (a.id = b.id)");
500 ParserError(
"select * from a cross join b using (id)");
505 ParsesOk(
"select a, b from t where a > 15");
506 ParsesOk(
"select a, b from t where true");
507 ParsesOk(
"select a, b from t where NULL");
509 ParsesOk(
"select a, b from t where case a when b then true else false end");
510 ParsesOk(
"select a, b from t where if (a > b, true, false)");
511 ParsesOk(
"select a, b from t where bool_col");
513 ParsesOk(
"select a, b from t where 10.5");
514 ParsesOk(
"select a, b from t where trim('abc')");
515 ParsesOk(
"select a, b from t where s + 20");
516 ParserError(
"select a, b from t where a > 15 from test");
523 ParsesOk(
"select a, b, count(c) from test group by 1, 2");
524 ParsesOk(
"select a, b, count(c) from test group by a, b");
525 ParsesOk(
"select a, b, count(c) from test group by true, false, NULL");
527 ParsesOk(
"select a, b, count(c) from test group by 1, b");
528 ParserError(
"select a, b, count(c) from test group 1, 2");
529 ParserError(
"select a, b, count(c) from test group by order by a");
534 ParsesOk(
"select int_col, string_col, bigint_col, count(*) from alltypes " +
535 "order by string_col, 15.7 * float_col, int_col + bigint_col");
536 ParsesOk(
"select int_col, string_col, bigint_col, count(*) from alltypes " +
537 "order by string_col asc, 15.7 * float_col desc, int_col + bigint_col asc");
538 ParsesOk(
"select int_col, string_col, bigint_col, count(*) from alltypes " +
539 "order by string_col asc, float_col desc, int_col + bigint_col " +
541 ParsesOk(
"select int_col, string_col, bigint_col, count(*) from alltypes " +
542 "order by string_col asc, float_col desc, int_col + bigint_col " +
544 ParsesOk(
"select int_col, string_col, bigint_col, count(*) from alltypes " +
545 "order by string_col asc, float_col desc, int_col + bigint_col " +
547 ParsesOk(
"select int_col, string_col, bigint_col, count(*) from alltypes " +
548 "order by string_col asc, float_col desc nulls last, int_col + bigint_col " +
550 ParsesOk(
"select int_col from alltypes order by true, false, NULL");
551 ParserError(
"select int_col, string_col, bigint_col, count(*) from alltypes " +
552 "order by by string_col asc desc");
553 ParserError(
"select int_col, string_col, bigint_col, count(*) from alltypes " +
555 ParserError(
"select int_col, string_col, bigint_col, count(*) from alltypes " +
556 "order by string_col nulls");
557 ParserError(
"select int_col, string_col, bigint_col, count(*) from alltypes " +
558 "order by string_col nulls first asc");
559 ParserError(
"select int_col, string_col, bigint_col, count(*) from alltypes " +
560 "order by string_col nulls first last");
565 ParsesOk(
"select a, b, count(c) from test group by a, b having count(*) > 5");
566 ParsesOk(
"select a, b, count(c) from test group by a, b having NULL");
567 ParsesOk(
"select a, b, count(c) from test group by a, b having true");
568 ParsesOk(
"select a, b, count(c) from test group by a, b having false");
570 ParsesOk(
"select count(c) from test group by a having if (a > b, true, false)");
571 ParsesOk(
"select count(c) from test group by a " +
572 "having case a when b then true else false end");
574 ParsesOk(
"select a, b, count(c) from test group by a, b having 5");
575 ParserError(
"select a, b, count(c) from test group by a, b having order by 5");
576 ParserError(
"select a, b, count(c) from test having count(*) > 5 group by a, b");
581 ParsesOk(
"select a, b, c from test inner join test2 using(a) limit 10");
582 ParsesOk(
"select a, b, c from test inner join test2 using(a) limit 10 + 10");
585 ParsesOk(
"select a, b, c from test inner join test2 using(a) limit 'a'");
586 ParsesOk(
"select a, b, c from test inner join test2 using(a) limit a");
587 ParsesOk(
"select a, b, c from test inner join test2 using(a) limit true");
588 ParsesOk(
"select a, b, c from test inner join test2 using(a) limit false");
589 ParsesOk(
"select a, b, c from test inner join test2 using(a) limit NULL");
591 ParserError(
"select a, b, c from test inner join test2 using(a) limit 10 " +
597 ParsesOk(
"select a from test order by a limit 10 offset 5");
598 ParsesOk(
"select a from test order by a limit 10 offset 0");
599 ParsesOk(
"select a from test order by a limit 10 offset 0 + 5 / 2");
600 ParsesOk(
"select a from test order by a asc limit 10 offset 5");
601 ParsesOk(
"select a from test order by a offset 5");
602 ParsesOk(
"select a from test limit 10 offset 5");
603 ParsesOk(
"select a from test offset 5");
604 ParsesOk(
"select a from (select a from test offset 5) A");
605 ParsesOk(
"select a from (select a from test order by a offset 5) A");
606 ParserError(
"select a from test order by a limit offset");
607 ParserError(
"select a from test order by a limit offset 5");
613 ParsesOk(
"select a from test union select a from test");
614 ParsesOk(
"select a from test union all select a from test");
615 ParsesOk(
"select a from test union distinct select a from test");
617 ParsesOk(
"select a from test union select a from test " +
618 "union select a from test union select a from test");
619 ParsesOk(
"select a from test union all select a from test " +
620 "union all select a from test union all select a from test");
621 ParsesOk(
"select a from test union distinct select a from test " +
622 "union distinct select a from test union distinct select a from test ");
624 ParsesOk(
"select a from test union select a from test " +
625 "union all select a from test union distinct select a from test");
627 ParsesOk(
"select sin() union select cos()");
628 ParsesOk(
"select sin() union all select cos()");
629 ParsesOk(
"select sin() union distinct select cos()");
632 ParsesOk(
"(select a from test) union (select a from test) " +
633 "union (select a from test) union (select a from test)");
635 ParsesOk(
"(select a from test) union (select a from test) " +
636 "union (select a from test) union (select a from test) order by a");
637 ParsesOk(
"(select a from test) union (select a from test) " +
638 "union (select a from test) union (select a from test) order by a nulls first");
640 ParsesOk(
"(select a from test) union (select a from test) " +
641 "union (select a from test) union (select a from test) limit 10");
643 ParsesOk(
"(select a from test) union (select a from test) " +
644 "union (select a from test) union (select a from test) order by a limit 10");
645 ParsesOk(
"(select a from test) union (select a from test) " +
646 "union (select a from test) union (select a from test) order by a " +
647 "nulls first limit 10");
648 ParsesOk(
"(select a from test) union (select a from test) " +
649 "union (select a from test) union (select a from test) order by a " +
650 "nulls first offset 10");
651 ParserError(
"select a from test union (select a from test) " +
652 "union (select a from test) union (select a from test) offset 10");
654 ParsesOk(
"(select a from test) union select a from test " +
655 "union (select a from test) union select a from test");
656 ParsesOk(
"select a from test union (select a from test) " +
657 "union select a from test union (select a from test)");
659 ParsesOk(
"(select a from test) union (select a from test) " +
660 "union select a from test union select a from test order by a limit 10");
661 ParsesOk(
"(select a from test) union (select a from test) " +
662 "union select a from test union select a from test order by a offset 10");
663 ParsesOk(
"(select a from test) union (select a from test) " +
664 "union select a from test union select a from test order by a");
667 ParsesOk(
"select a from test union (select a from test) " +
668 "union select a from test union (select a from test order by a limit 10) " +
669 "order by a limit 1");
670 ParsesOk(
"select a from test union (select a from test) " +
671 "union select a from test union (select a from test order by a offset 10) " +
672 "order by a limit 1");
673 ParsesOk(
"select a from test union (select a from test) " +
674 "union select a from test union (select a from test order by a) " +
675 "order by a limit 1");
677 ParsesOk(
"select a from test order by a union select a from test");
678 ParsesOk(
"select a from test order by a offset 5 union select a from test");
679 ParsesOk(
"select a from test offset 5 union select a from test");
682 ParsesOk(
"select a from test union select a from test " +
683 "union select a from test union select a from test order by a limit 10 " +
684 "order by a limit 1");
688 "((select b) union (select c) order by 1 limit 1)");
690 "((select b) union " +
691 " ((select c) union (select d) " +
692 " order by 1 limit 1) " +
693 " order by 1 limit 1)");
696 ParsesOk(
"insert into table t select a from test union select a from test");
697 ParsesOk(
"insert into table t select a from test union select a from test " +
698 "union select a from test union select a from test");
699 ParsesOk(
"insert overwrite table t select a from test union select a from test");
700 ParsesOk(
"insert overwrite table t select a from test union select a from test " +
701 "union select a from test union select a from test");
704 ParserError(
"a from test union select a from test");
706 ParserError(
"select a from test union a from test");
715 ParsesOk(
"values(1, 'a', abc, 1.0, *)");
716 ParsesOk(
"select * from (values(1, 'a', abc, 1.0, *)) as t");
717 ParsesOk(
"values(1, 'a', abc, 1.0, *) union all values(1, 'a', abc, 1.0, *)");
718 ParsesOk(
"insert into t values(1, 'a', abc, 1.0, *)");
720 ParsesOk(
"values(1, abc), ('x', cde), (2), (efg, fgh, ghi)");
721 ParsesOk(
"select * from (values(1, abc), ('x', cde), (2), (efg, fgh, ghi)) as t");
722 ParsesOk(
"values(1, abc), ('x', cde), (2), (efg, fgh, ghi) " +
723 "union all values(1, abc), ('x', cde), (2), (efg, fgh, ghi)");
724 ParsesOk(
"insert into t values(1, abc), ('x', cde), (2), (efg, fgh, ghi)");
726 ParsesOk(
"(values(1, abc), ('x', cde), (2), (efg, fgh, ghi))");
727 ParsesOk(
"values((1, abc), ('x', cde), (2), (efg, fgh, ghi))");
728 ParsesOk(
"(values((1, abc), ('x', cde), (2), (efg, fgh, ghi)))");
730 ParsesOk(
"values(1 as x, 2 as y, 3 as z)");
732 ParsesOk(
"values(1, 'a') limit 10");
733 ParsesOk(
"values(1, 'a') order by 1");
734 ParsesOk(
"values(1, 'a') order by 1 limit 10");
735 ParsesOk(
"values(1, 'a') order by 1 offset 10");
736 ParsesOk(
"values(1, 'a') offset 10");
737 ParsesOk(
"values(1, 'a'), (2, 'b') order by 1 limit 10");
738 ParsesOk(
"values((1, 'a'), (2, 'b')) order by 1 limit 10");
744 ParserError(
"select * from values(1, 'a', abc, 1.0) as t");
746 ParserError(
"values((1, 'a'), (1, 'a') order by 1)");
747 ParserError(
"values((1, 'a'), (1, 'a') limit 10)");
752 ParsesOk(
"with t as (select 1 as a) select a from t");
753 ParsesOk(
"with t as (select c from tab) select * from t");
754 ParsesOk(
"with t as (values(1, 2, 3), (4, 5, 6)) select * from t");
755 ParsesOk(
"with t1 as (select 1 as a), t2 as (select 2 as a) select a from t1");
756 ParsesOk(
"with t1 as (select c from tab), t2 as (select c from tab)" +
759 ParsesOk(
"with t1 as (select 1 as a), t2 as (select 2 as a)" +
760 "select a from t1 union all select a from t2");
762 ParsesOk(
"with t1 as (select 1 as a), t2 as (select 2 as a)" +
763 "select a from t1 inner join t2 on t1.a = t2.a");
765 ParsesOk(
"select * from (with t as (select 1 as a) select * from t) as a");
767 ParsesOk(
"insert into x with t as (select * from tab) select * from t");
768 ParsesOk(
"insert into x with t as (values(1, 2, 3)) select * from t");
770 ParsesOk(
"with t as (select 1) insert into x select * from t");
773 ParsesOk(
"with `t1` as (select 1 a), 't2' as (select 2 a), \"t3\" as (select 3 a)" +
774 "select a from t1 union all select a from t2 union all select a from t3");
779 "(with t as (select 2) select * from t) union all " +
780 "(with t as (select 3) select * from t)");
782 "(with t as (select 2) select * from t) union all " +
783 "(with t as (select 3) select * from t) order by 1 limit 1");
785 ParsesOk(
"with t as (select 1) insert into x with t as (select 2) select * from t");
790 ParserError(
"select * from (with t as (select 1 as a)) as a");
793 ParserError(
"with t as select 1 as a select a from t");
794 ParserError(
"with t as select 1 as a union all select a from t");
795 ParserError(
"with t1 as (select 1 as a), t2 as select 2 as a select a from t");
796 ParserError(
"with t as select 1 as a select a from t");
798 ParserError(
"with t as (insert into x select * from tab) select * from t");
800 ParserError(
"select * from t union all with t as (select 2) select * from t");
806 ParsesOk(String.format(
"select %s", Byte.toString(Byte.MIN_VALUE)));
807 ParsesOk(String.format(
"select %s", Byte.toString(Byte.MAX_VALUE)));
808 ParsesOk(String.format(
"select %s", Short.toString(Short.MIN_VALUE)));
809 ParsesOk(String.format(
"select %s", Short.toString(Short.MAX_VALUE)));
810 ParsesOk(String.format(
"select %s", Integer.toString(Integer.MIN_VALUE)));
811 ParsesOk(String.format(
"select %s", Integer.toString(Integer.MAX_VALUE)));
812 ParsesOk(String.format(
"select %s", Long.toString(Long.MIN_VALUE)));
813 ParsesOk(String.format(
"select %s", Long.toString(Long.MAX_VALUE)));
816 ParsesOk(String.format(
"select %s1", Long.toString(Long.MIN_VALUE)));
817 ParsesOk(String.format(
"select %s1", Long.toString(Long.MAX_VALUE)));
819 BigInteger minMinusOne = BigInteger.valueOf(Long.MAX_VALUE);
820 minMinusOne = minMinusOne.add(BigInteger.ONE);
821 ParsesOk(String.format(
"select %s", minMinusOne.toString()));
823 BigInteger maxPlusOne = BigInteger.valueOf(Long.MAX_VALUE);
824 maxPlusOne = maxPlusOne.add(BigInteger.ONE);
825 ParsesOk(String.format(
"select %s", maxPlusOne.toString()));
828 ParsesOk(String.format(
"select %s", Float.toString(Float.MIN_VALUE)));
829 ParsesOk(String.format(
"select %s", Float.toString(Float.MAX_VALUE)));
830 ParsesOk(String.format(
"select -%s", Float.toString(Float.MIN_VALUE)));
831 ParsesOk(String.format(
"select -%s", Float.toString(Float.MAX_VALUE)));
832 ParsesOk(String.format(
"select %s", Double.toString(Double.MIN_VALUE)));
833 ParsesOk(String.format(
"select %s", Double.toString(Double.MAX_VALUE)));
834 ParsesOk(String.format(
"select -%s", Double.toString(Double.MIN_VALUE)));
835 ParsesOk(String.format(
"select -%s", Double.toString(Double.MAX_VALUE)));
838 ParsesOk(String.format(
"select %s1", Double.toString(Double.MIN_VALUE)));
839 ParsesOk(String.format(
"select %s1", Double.toString(Double.MAX_VALUE)));
845 ParsesOk(
"select a from `default`.`t`");
846 ParsesOk(
"select a from `default`.t");
847 ParsesOk(
"select a from default.`t`");
848 ParsesOk(
"select 01a from default.`01_t`");
850 ParsesOk(
"select `a` from default.t");
851 ParsesOk(
"select `tbl`.`a` from default.t");
852 ParsesOk(
"select `db`.`tbl`.`a` from default.t");
853 ParsesOk(
"select `12db`.`tbl`.`12_a` from default.t");
861 ParsesOk(
"select `db`.tbl.`a` from default.t");
862 ParsesOk(
"select `db.table.a` from default.t");
874 ParsesOk(
"select a from ` a a a `");
877 ParsesOk(
"select a from `all types`");
878 ParsesOk(
"select a from `default`.`all types`");
879 ParsesOk(
"select a from `~!@#$%^&*()-_=+|;:'\",<.>/?`");
881 ParsesOk(
"select a from `ab\rabc`");
882 ParsesOk(
"select a from `ab\tabc`");
883 ParsesOk(
"select a from `ab\fabc`");
884 ParsesOk(
"select a from `ab\babc`");
885 ParsesOk(
"select a from `ab\nabc`");
887 ParsesOk(
"select a from `abc\u0000abc`");
888 ParsesOk(
"select a from `abc\u0019abc`");
889 ParsesOk(
"select a from `abc\u007fabc`");
892 ParsesOk(
"select `select`, `insert` from `table` where `where` = 10");
903 "select `db`.`tbl`.`a` from `default`.`t` `alias` where `alias`.`col` = 'string'"
904 +
" group by `alias`.`col`");
1010 "Syntax error in line 1:\n" +
1011 "select \"\\\" from t\n" +
1013 "Encountered: Unexpected character");
1016 "Syntax error in line 1:\n" +
1019 "Encountered: Unexpected character");
1025 String singleQuoteQuery =
"select " +
"'" + s +
"'" +
" from t";
1026 String doubleQuoteQuery =
"select " +
"\"" + s +
"\"" +
" from t";
1033 ParsesOk(
"select f1(5), f2('five'), f3(5.0, i + 5) from t");
1034 ParsesOk(
"select f1(true), f2(true and false), f3(null) from t");
1036 ParsesOk(
"select f1(distinct col)");
1037 ParsesOk(
"select f1(distinct col, col2)");
1038 ParsesOk(
"select decode(col, col2, col3)");
1046 for (String rop: operands_) {
1052 String expr = String.format(
"%s %s %s", lop, op.toString(), rop);
1053 ParsesOk(String.format(
"select %s from t where %s", expr, expr));
1057 String bitNotExpr = String.format(
"%s %s",
1058 ArithmeticExpr.Operator.BITNOT.toString(), lop);
1059 ParsesOk(String.format(
"select %s from t where %s", bitNotExpr, bitNotExpr));
1084 ParsesOk(
"select a + interval b " + timeUnit.toString());
1085 ParsesOk(
"select a - interval b " + timeUnit.toString());
1086 ParsesOk(
"select NULL + interval NULL " + timeUnit.toString());
1087 ParsesOk(
"select NULL - interval NULL " + timeUnit.toString());
1089 ParsesOk(
"select interval b " + timeUnit.toString() +
" + a");
1090 ParsesOk(
"select interval NULL " + timeUnit.toString() +
" + NULL");
1092 ParserError(
"select interval b " + timeUnit.toString() +
" - a");
1094 ParsesOk(
"select date_add(a, interval b " + timeUnit.toString() +
")");
1095 ParsesOk(
"select date_sub(a, interval b " + timeUnit.toString() +
")");
1096 ParsesOk(
"select date_add(NULL, interval NULL " + timeUnit.toString() +
")");
1097 ParsesOk(
"select date_sub(NULL, interval NULL " + timeUnit.toString() +
")");
1099 ParsesOk(
"select error(a, interval b " + timeUnit.toString() +
")");
1101 ParsesOk(
"select error(a, interval b error)");
1104 ParserError(
"select date_add(a, b " + timeUnit.toString() +
")");
1105 ParserError(
"select date_sub(a, b " + timeUnit.toString() +
")");
1107 ParserError(
"select date_sub(distinct NULL, interval NULL " +
1108 timeUnit.toString() +
")");
1109 ParserError(
"select date_sub(*, interval NULL " + timeUnit.toString() +
")");
1113 ParsesOk(
"select a + interval b years + interval c months + interval d days");
1114 ParsesOk(
"select a - interval b years - interval c months - interval d days");
1115 ParsesOk(
"select a + interval b years - interval c months + interval d days");
1117 ParsesOk(
"select interval b years + a + interval c months + interval d days");
1118 ParsesOk(
"select interval b years + a - interval c months - interval d days");
1119 ParsesOk(
"select interval b years + a - interval c months + interval d days");
1122 ParserError(
"select date_sub(a, c, interval b year)");
1123 ParserError(
"select date_sub(a, interval b year, c)");
1129 ParsesOk(
"select case a when '5' then x when '6' then y else z end from t");
1130 ParsesOk(
"select case when 'a' then x when false then y else z end from t");
1132 ParsesOk(
"select case when a > 2 then x when false then false else true end from t");
1133 ParsesOk(
"select case false when a > 2 then x when '6' then false else true end " +
1136 ParsesOk(
"select case NULL when NULL then NULL when NULL then NULL else NULL end " +
1138 ParsesOk(
"select case when NULL then NULL when NULL then NULL else NULL end from t");
1140 ParserError(
"select case a when true then x when false then y else z from t");
1142 ParserError(
"select case a when true when false then y else z end from t");
1144 ParserError(
"select case a when true, false then y else z end from t");
1149 ParsesOk(
"select cast(a + 5.0 as string) from t");
1150 ParsesOk(
"select cast(NULL as string) from t");
1151 ParserError(
"select cast(a + 5.0 as badtype) from t");
1152 ParserError(
"select cast(a + 5.0, string) from t");
1157 ParsesOk(
"select if(TRUE, TRUE, FALSE) from t");
1158 ParsesOk(
"select if(NULL, NULL, NULL) from t");
1159 ParsesOk(
"select c1, c2, if(TRUE, TRUE, FALSE) from t");
1160 ParsesOk(
"select if(1 = 2, c1, c2) from t");
1161 ParsesOk(
"select if(1 = 2, c1, c2)");
1167 ParsesOk(
"select count(*), count(a), count(distinct a, b) from t");
1168 ParsesOk(
"select count(NULL), count(TRUE), count(FALSE), " +
1169 "count(distinct TRUE, FALSE, NULL) from t");
1170 ParsesOk(
"select count(all *) from t");
1171 ParsesOk(
"select count(all 1) from t");
1172 ParsesOk(
"select min(a), min(distinct a) from t");
1173 ParsesOk(
"select max(a), max(distinct a) from t");
1174 ParsesOk(
"select sum(a), sum(distinct a) from t");
1175 ParsesOk(
"select avg(a), avg(distinct a) from t");
1176 ParsesOk(
"select distinct a, b, c from t");
1177 ParsesOk(
"select distinctpc(a), distinctpc(distinct a) from t");
1178 ParsesOk(
"select distinctpcsa(a), distinctpcsa(distinct a) from t");
1179 ParsesOk(
"select ndv(a), ndv(distinct a) from t");
1180 ParsesOk(
"select group_concat(a) from t");
1181 ParsesOk(
"select group_concat(a, ', ') from t");
1182 ParsesOk(
"select group_concat(a, ', ', c) from t");
1187 ParsesOk(
"select sum(v) over (partition by a, 2*b order by 3*c rows between "
1188 +
"2+2 preceding and 2-2 following) from t");
1189 ParsesOk(
"select sum(v) over (order by 3*c rows between "
1190 +
"unbounded preceding and unbounded following) from t");
1191 ParsesOk(
"select sum(v) over (partition by a, 2*b) from t");
1192 ParsesOk(
"select sum(v) over (partition by a, 2*b order by 3*c range between "
1193 +
"unbounded preceding and unbounded following) from t");
1194 ParsesOk(
"select sum(v) over (order by 3*c range between "
1195 +
"2 following and 4 following) from t");
1196 ParsesOk(
"select sum(v) over (partition by a, 2*b) from t");
1197 ParsesOk(
"select 2 * x, sum(v) over (partition by a, 2*b order by 3*c rows between "
1198 +
"2+2 preceding and 2-2 following), rank() over (), y from t");
1200 ParserError(
"select v over (partition by a, 2*b order by 3*c rows between 2 "
1201 +
"preceding and 2 following) from t");
1203 ParserError(
"select sum(v) over (partition a, 2*b order by 3*c rows between "
1204 +
"unbounded preceding and current row) from t");
1205 ParserError(
"select sum(v) over (partition by a, 2*b order 3*c rows between 2 "
1206 +
"preceding and 2 following) from t");
1207 ParserError(
"select sum(v) over (partition by a, 2*b order by 3*c rows 2 "
1208 +
"preceding and 2 following) from t");
1209 ParsesOk(
"select sum(v) over (partition by a, 2*b) from t");
1213 ParserError(
"select decode(1, 2, 3) over () from t");
1218 ArrayList<String> operations =
new ArrayList<String>();
1220 operations.add(op.toString());
1222 operations.add(
"like");
1223 operations.add(
"rlike");
1224 operations.add(
"regexp");
1227 for (String rop: operands_) {
1228 for (String op : operations) {
1229 String expr = String.format(
"%s %s %s", lop, op.toString(), rop);
1230 ParsesOk(String.format(
"select %s from t where %s", expr, expr));
1233 String isNullExr = String.format(
"%s is null", lop);
1234 String isNotNullExr = String.format(
"%s is not null", lop);
1235 ParsesOk(String.format(
"select %s from t where %s", isNullExr, isNullExr));
1236 ParsesOk(String.format(
"select %s from t where %s", isNotNullExr, isNotNullExr));
1242 ParsesOk(
"select a, b, c from t where a = 5 " + andStr +
" f(b)");
1244 ParsesOk(
"select a, b, c from t where a = 5 " + orStr +
" f(b)");
1246 ParsesOk(
"select a, b, c from t where (a = 5 " + orStr +
" f(b)) " +
1249 ParsesOk(
"select a, b, c from t where " + notStr +
"a = 5");
1251 ParsesOk(
"select a, b, c from t where " + notStr +
"f(a)");
1253 ParsesOk(
"select a, b, c from t where (" + notStr +
"a = 5 " + orStr +
" " +
1254 notStr +
"f(b)) " + andStr +
" " + notStr +
"c = 7");
1256 ParsesOk(
"select a, b, c from t where (" + notStr +
"(" + notStr +
"a = 5))");
1258 ParsesOk(
"select a, b, c from t where (" + notStr +
"(" + notStr +
"f(a)))");
1260 ParsesOk(
"select a, b, c from t where a = " + notStr +
"5");
1263 "(a = 5 " + orStr +
" b = 6) " + andStr +
" c = 7)");
1265 "((a = 5 " + orStr +
" b = 6) " + andStr +
" c = 7");
1267 ParserError(
"select a, b, c from t where a = 5 " + orStr +
" " + notStr);
1268 ParserError(
"select a, b, c from t where " + notStr +
"(a = 5) " + orStr +
" " + notStr);
1272 String[] truthValues = {
"true",
"false",
"null"};
1273 for (String l: truthValues) {
1274 for (String r: truthValues) {
1275 String andExpr = String.format(
"%s %s %s", l, andStr, r);
1276 String orExpr = String.format(
"%s %s %s", l, orStr, r);
1277 ParsesOk(String.format(
"select %s from t where %s", andExpr, andExpr));
1278 ParsesOk(String.format(
"select %s from t where %s", orExpr, orExpr));
1280 String notExpr = String.format(
"%s %s", notStr, l);
1281 ParsesOk(String.format(
"select %s from t where %s", notExpr, notExpr));
1287 String[] andStrs = {
"and",
"&&" };
1288 String[] orStrs = {
"or",
"||" };
1290 String[] notStrs = {
"!",
"not " };
1292 for (String andStr : andStrs) {
1293 for (String orStr : orStrs) {
1294 for (String notStr : notStrs) {
1302 for (String notStr : notStrs) {
1306 Expr e = stmt.getSelectList().getItems().get(0).getExpr();
1308 CompoundPredicate cp = (CompoundPredicate) e;
1309 assertEquals(CompoundPredicate.Operator.NOT, cp.
getOp());
1310 assertEquals(1, cp.getChildren().size());
1317 ParsesOk(
"select a, b, c from t where i between x and y");
1318 ParsesOk(
"select a, b, c from t where i not between x and y");
1319 ParsesOk(
"select a, b, c from t where true not between false and NULL");
1320 ParsesOk(
"select a, b, c from t where 'abc' between 'a' like 'a' and 'b' like 'b'");
1322 ParsesOk(
"select a, b, c from t where true and false and i between x and y");
1323 ParsesOk(
"select a, b, c from t where i between x and y and true and false");
1324 ParsesOk(
"select a, b, c from t where i between x and (y and true) and false");
1325 ParsesOk(
"select a, b, c from t where i between x and (y and (true and false))");
1327 ParsesOk(
"select a, b, c from t " +
1328 "where true between false and true and 'b' between 'a' and 'c'");
1330 ParsesOk(
"select a, b, c from t " +
1331 "where true between 'b' between 'a' and 'c' and 'bb' between 'aa' and 'cc'");
1333 ParserError(
"select a, b, c from t where between 5 and 10");
1335 ParserError(
"select a, b, c from t where i between and 10");
1337 ParserError(
"select a, b, c from t where i between 5 and");
1339 ParserError(
"select a, b, c from t where i between");
1341 ParserError(
"select a, b, c from t where true between 5 or 10 and 20");
1346 ParsesOk(
"select a, b, c from t where i in (x, y, z)");
1347 ParsesOk(
"select a, b, c from t where i not in (x, y, z)");
1349 ParsesOk(
"select a, b, c from t where NULL in (NULL, NULL, NULL)");
1350 ParsesOk(
"select a, b, c from t where true in (true, false, true)");
1351 ParsesOk(
"select a, b, c from t where NULL not in (NULL, NULL, NULL)");
1352 ParsesOk(
"select a, b, c from t where true not in (true, false, true)");
1354 ParserError(
"select a, b, c from t where in (x, y, z)");
1356 ParserError(
"select a, b, c from t where i in x, y, z");
1357 ParserError(
"select a, b, c from t where i in (x, y, z");
1358 ParserError(
"select a, b, c from t where i in x, y, z)");
1361 ParserError(
"select a, b, c from t where i in ( )");
1366 ParsesOk(
"select a from t where b > 5");
1367 ParsesOk(
"select a.b from a where b > 5");
1368 ParsesOk(
"select a.b.c from a.b where b > 5");
1369 ParsesOk(
"select a.b.c.d from a.b where b > 5");
1376 for (String qualifier:
new String[] {
"overwrite",
"into"}) {
1377 for (String optTbl:
new String[] {
"",
"table"}) {
1379 ParsesOk(String.format(
"insert %s %s t select a from src where b > 5",
1380 qualifier, optTbl));
1383 "insert %s %s t partition (pk1=10) select a from src where b > 5",
1384 qualifier, optTbl));
1387 "insert %s %s t partition (pk1) select a from src where b > 5",
1388 qualifier, optTbl));
1390 ParsesOk(String.format(
"insert %s %s t partition (pk1=10, pk2=20) " +
1391 "select a from src where b > 5",
1392 qualifier, optTbl));
1395 "insert %s %s t partition (pk1, pk2) select a from src where b > 5",
1396 qualifier, optTbl));
1399 "insert %s %s t partition (pk1=10, pk2) select a from src where b > 5",
1400 qualifier, optTbl));
1403 "insert %s %s t partition (pk1, pk2=20) select a from src where b > 5",
1404 qualifier, optTbl));
1406 ParsesOk(String.format(
"insert %s %s t partition (pk1=NULL, pk2=NULL) " +
1407 "select a from src where b > 5",
1408 qualifier, optTbl));
1410 ParsesOk(String.format(
"insert %s %s t partition (pk1=false, pk2=true) " +
1411 "select a from src where b > 5",
1412 qualifier, optTbl));
1414 ParsesOk(String.format(
"insert %s %s t partition (pk1=abc, pk2=(5*8+10)) " +
1415 "select a from src where b > 5",
1416 qualifier, optTbl));
1418 "insert %s %s t partition (pk1=f(a), pk2=!true and false) " +
1419 "select a from src where b > 5",
1420 qualifier, optTbl));
1422 ParsesOk(String.format(
"insert %s %s t(a,b,c) values(1,2,3)",
1423 qualifier, optTbl));
1425 ParsesOk(String.format(
"insert %s %s t(a,b,c) values(1,2,3,4,5,6)",
1426 qualifier, optTbl));
1428 ParsesOk(String.format(
"insert %s %s t(a,b,c) partition(d) values(1,2,3,4)",
1429 qualifier, optTbl));
1431 ParsesOk(String.format(
"insert %s %s t() select 1 from a",
1432 qualifier, optTbl));
1434 ParsesOk(String.format(
"insert %s %s t() partition(d) ",
1435 qualifier, optTbl));
1436 ParsesOk(String.format(
"insert %s %s t() ",
1437 qualifier, optTbl));
1439 ParserError(String.format(
"insert %s %s t(a b c) select 1 from a",
1440 qualifier, optTbl));
1442 ParserError(String.format(
"insert %s %s t('a') select 1 from a",
1443 qualifier, optTbl));
1445 ParserError(String.format(
"insert %s %s t(a=1, b) select 1 from a",
1446 qualifier, optTbl));
1458 ParserError(
"insert table t select a from src where b > 5");
1460 ParserError(
"insert overwrite table select a from src where b > 5");
1462 ParserError(
"insert into table select a from src where b > 5");
1468 ParserError(
"insert overwrite table t partition pk1=10 " +
1469 "select a from src where b > 5");
1471 ParserError(
"insert into table t partition pk1=10 " +
1472 "select a from src where b > 5");
1474 ParserError(
"insert overwrite table t partition (pk1=10 pk2=20) " +
1475 "select a from src where b > 5");
1477 ParserError(
"insert into table t partition (pk1=10 pk2=20) " +
1478 "select a from src where b > 5");
1480 ParserError(
"insert [shuffle] into table t partition (pk1=10 pk2=20) " +
1481 "select a from src where b > 5");
1482 ParserError(
"insert into [shuffle] table t partition (pk1=10 pk2=20) " +
1483 "select a from src where b > 5");
1484 ParserError(
"insert into table t [shuffle] partition (pk1=10 pk2=20) " +
1485 "select a from src where b > 5");
1486 ParserError(
"insert into table t partition [shuffle] (pk1=10 pk2=20) " +
1487 "select a from src where b > 5");
1502 ParsesOk(
"SHOW TABLES 'tablename|othername'");
1508 ParsesOk(
"SHOW DATABASES LIKE 'pattern'");
1509 ParsesOk(
"SHOW SCHEMAS LIKE 'p*ttern'");
1512 ParsesOk(
"SHOW DATA SOURCES 'pattern'");
1513 ParsesOk(
"SHOW DATA SOURCES LIKE 'pattern'");
1514 ParsesOk(
"SHOW DATA SOURCES LIKE 'p*ttern'");
1517 for (String fnType:
new String[] {
"",
"AGGREGATE",
"ANALYTIC"}) {
1518 ParsesOk(String.format(
"SHOW %s FUNCTIONS", fnType));
1519 ParsesOk(String.format(
"SHOW %s FUNCTIONS LIKE 'pattern'", fnType));
1520 ParsesOk(String.format(
"SHOW %s FUNCTIONS LIKE 'p*ttern'", fnType));
1521 ParsesOk(String.format(
"SHOW %s FUNCTIONS", fnType));
1522 ParsesOk(String.format(
"SHOW %s FUNCTIONS in DB LIKE 'pattern'", fnType));
1523 ParsesOk(String.format(
"SHOW %s FUNCTIONS in DB", fnType));
1528 ParsesOk(
"SHOW TABLE STATS db.tbl");
1529 ParsesOk(
"SHOW TABLE STATS `db`.`tbl`");
1531 ParsesOk(
"SHOW COLUMN STATS db.tbl");
1532 ParsesOk(
"SHOW COLUMN STATS `db`.`tbl`");
1536 ParsesOk(
"SHOW PARTITIONS db.tbl");
1537 ParsesOk(
"SHOW PARTITIONS `db`.`tbl`");
1542 ParsesOk(
"SHOW FILES IN `db`.`tbl`");
1543 ParsesOk(
"SHOW FILES IN db.tbl PARTITION(x='a',y='b')");
1552 ParserError(
"SHOW DATA SOURCE LIKE NotStrLiteral");
1570 ParsesOk(
"SHOW CREATE TABLE db.x");
1583 ParsesOk(
"DESCRIBE FORMATTED tablename");
1586 ParsesOk(
"DESCRIBE databasename.tablename");
1587 ParsesOk(
"DESCRIBE FORMATTED databasename.tablename");
1593 String [] dbKeywords = {
"DATABASE",
"SCHEMA"};
1594 for (String kw: dbKeywords) {
1595 ParsesOk(String.format(
"CREATE %s Foo", kw));
1596 ParsesOk(String.format(
"CREATE %s IF NOT EXISTS Foo", kw));
1598 ParsesOk(String.format(
"CREATE %s Foo COMMENT 'Some comment'", kw));
1599 ParsesOk(String.format(
"CREATE %s Foo LOCATION '/hdfs_location'", kw));
1600 ParsesOk(String.format(
"CREATE %s Foo LOCATION '/hdfs_location'", kw));
1602 "CREATE %s Foo COMMENT 'comment' LOCATION '/hdfs_location'", kw));
1605 ParserError(String.format(
"CREATE %s Foo COMMENT mytable", kw));
1606 ParserError(String.format(
"CREATE %s Foo LOCATION /hdfs_location", kw));
1610 "CREATE %s Foo LOCATION '/hdfs/location' COMMENT 'comment'", kw));
1612 ParserError(String.format(
"CREATE %s Foo COMMENT LOCATION '/hdfs_location'", kw));
1613 ParserError(String.format(
"CREATE %s Foo LOCATION", kw));
1614 ParserError(String.format(
"CREATE %s Foo LOCATION 'dfsd' 'dafdsf'", kw));
1617 ParserError(String.format(
"CREATE %s 'Foo'", kw));
1619 ParserError(String.format(
"CREATE %s IF EXISTS Foo", kw));
1627 ParsesOk(
"CREATE FUNCTION Foo() RETURNS INT LOCATION 'f.jar' SYMBOL='class.Udf'");
1628 ParsesOk(
"CREATE FUNCTION Foo(INT, INT) RETURNS STRING LOCATION " +
1629 "'f.jar' SYMBOL='class.Udf'");
1630 ParsesOk(
"CREATE FUNCTION Foo(INT, DOUBLE) RETURNS STRING LOCATION " +
1631 "'f.jar' SYMBOL='class.Udf'");
1632 ParsesOk(
"CREATE FUNCTION Foo() RETURNS STRING LOCATION " +
1633 "'f.jar' SYMBOL='class.Udf' COMMENT='hi'");
1634 ParsesOk(
"CREATE FUNCTION IF NOT EXISTS Foo() RETURNS INT LOCATION 'foo.jar' " +
1635 "SYMBOL='class.Udf'");
1638 ParsesOk(
"CREATE FUNCTION User.Foo() RETURNS INT LOCATION 'a'");
1639 ParsesOk(
"CREATE FUNCTION `Foo`() RETURNS INT LOCATION 'a'");
1640 ParsesOk(
"CREATE FUNCTION `Foo.Bar`() RETURNS INT LOCATION 'a'");
1641 ParsesOk(
"CREATE FUNCTION `Foo`.Bar() RETURNS INT LOCATION 'a'");
1644 ParserError(
"CREATE FUNCTION User.() RETURNS INT LOCATION 'a'");
1645 ParserError(
"CREATE FUNCTION User.Foo.() RETURNS INT LOCATION 'a'");
1646 ParserError(
"CREATE FUNCTION User..Foo() RETURNS INT LOCATION 'a'");
1648 ParsesOk(
"CREATE FUNCTION A.B.C.D.Foo() RETURNS INT LOCATION 'a'");
1654 ParserError(
"CREATE FUNCTION FOO() LOCATION 'foo.jar'");
1657 ParserError(
"CREATE FUNCTION Foo() RETURNS INT SYMBOL='1' LOCATION 'a'");
1658 ParserError(
"CREATE FUNCTION Foo() RETURNS INT LOCATION 'a' SYMBOL");
1659 ParserError(
"CREATE FUNCTION Foo() RETURNS INT LOCATION 'a' SYMBOL='1' SYMBOL='2'");
1662 ParserError(
"CREATE FUNCTION Foo RETURNS INT LOCATION 'f.jar'");
1663 ParserError(
"CREATE FUNCTION Foo(INT,) RETURNS INT LOCATION 'f.jar'");
1664 ParserError(
"CREATE FUNCTION FOO RETURNS INT LOCATION 'foo.jar'");
1667 ParserError(
"CREATE FUNCTION Foo(NULL) RETURNS INT LOCATION 'f.jar'");
1668 ParserError(
"CREATE FUNCTION Foo(NULL, INT) RETURNS INT LOCATION 'f.jar'");
1669 ParserError(
"CREATE FUNCTION Foo(INT, NULL) RETURNS INT LOCATION 'f.jar'");
1670 ParserError(
"CREATE FUNCTION Foo() RETURNS NULL LOCATION 'f.jar'");
1675 String fnCreates[] = {
"CREATE FUNCTION ",
"CREATE AGGREGATE FUNCTION " };
1676 for (String fnCreate: fnCreates) {
1677 ParsesOk(fnCreate +
"Foo(int...) RETURNS INT LOCATION 'f.jar'");
1678 ParsesOk(fnCreate +
"Foo(int ...) RETURNS INT LOCATION 'f.jar'");
1679 ParsesOk(fnCreate +
"Foo(int, double ...) RETURNS INT LOCATION 'f.jar'");
1681 ParserError(fnCreate +
"Foo(...) RETURNS INT LOCATION 'f.jar'");
1682 ParserError(fnCreate +
"Foo(int..., double) RETURNS INT LOCATION 'f.jar'");
1683 ParserError(fnCreate +
"Foo(int) RETURNS INT... LOCATION 'f.jar'");
1684 ParserError(fnCreate +
"Foo(int. . .) RETURNS INT... LOCATION 'f.jar'");
1685 ParserError(fnCreate +
"Foo(int, ...) RETURNS INT... LOCATION 'f.jar'");
1691 String loc =
" LOCATION 'f.so' UPDATE_FN='class' ";
1692 String c =
"CREATE AGGREGATE FUNCTION Foo() RETURNS INT ";
1695 ParsesOk(c +
"INTERMEDIATE STRING" + loc +
"comment='c'");
1696 ParsesOk(c + loc +
"comment='abcd'");
1697 ParsesOk(c + loc +
"init_fn='InitFnSymbol'");
1698 ParsesOk(c + loc +
"init_fn='I' merge_fn='M'");
1699 ParsesOk(c + loc +
"merge_fn='M' init_fn='I'");
1700 ParsesOk(c + loc +
"merge_fn='M' Init_fn='I' serialize_fn='S' Finalize_fn='F'");
1701 ParsesOk(c + loc +
"Init_fn='M' Finalize_fn='I' merge_fn='S' serialize_fn='F'");
1702 ParsesOk(c + loc +
"merge_fn='M'");
1703 ParsesOk(c +
"INTERMEDIATE CHAR(10)" + loc);
1705 ParserError(
"CREATE UNKNOWN FUNCTION " +
"Foo() RETURNS INT" + loc);
1716 ParsesOk(c +
"INTERMEDIATE CHAR(0)" + loc);
1719 ParserError(
"CREATE UNKNOWN FUNCTION " +
"Foo() RETURNS INT" + loc);
1720 ParserError(
"CREATE AGGREGATE FUNCTION Foo() init_fn='1' RETURNS INT" + loc);
1724 ParsesOk(
"CREATE AGGREGATE FUNCTION Foo(INT...) RETURNS INT LOCATION 'f.jar'");
1729 String[] addReplaceKw = {
"ADD",
"REPLACE"};
1730 for (String addReplace: addReplaceKw) {
1732 "ALTER TABLE Foo %s COLUMNS (i int, s string)", addReplace));
1734 "ALTER TABLE TestDb.Foo %s COLUMNS (i int, s string)", addReplace));
1736 "ALTER TABLE TestDb.Foo %s COLUMNS (i int)", addReplace));
1738 "ALTER TABLE TestDb.Foo %s COLUMNS (i int comment 'hi')", addReplace));
1741 ParserError(String.format(
"ALTER TABLE TestDb.Foo %s COLUMNS i int", addReplace));
1743 "ALTER TABLE TestDb.Foo %s COLUMNS (int i)", addReplace));
1745 "ALTER TABLE TestDb.Foo %s COLUMNS (i int COMMENT)", addReplace));
1746 ParserError(String.format(
"ALTER TestDb.Foo %s COLUMNS (i int)", addReplace));
1747 ParserError(String.format(
"ALTER TestDb.Foo %s COLUMNS", addReplace));
1748 ParserError(String.format(
"ALTER TestDb.Foo %s COLUMNS ()", addReplace));
1749 ParserError(String.format(
"ALTER Foo %s COLUMNS (i int, s string)", addReplace));
1750 ParserError(String.format(
"ALTER TABLE %s COLUMNS (i int, s string)", addReplace));
1752 ParserError(String.format(
"ALTER TABLE Foo %s COLUMN i int", addReplace));
1753 ParserError(String.format(
"ALTER TABLE Foo %s COLUMN (i int)", addReplace));
1759 ParsesOk(
"ALTER TABLE Foo ADD PARTITION (i=1)");
1760 ParsesOk(
"ALTER TABLE TestDb.Foo ADD IF NOT EXISTS PARTITION (i=1, s='Hello')");
1761 ParsesOk(
"ALTER TABLE TestDb.Foo ADD PARTITION (i=1, s='Hello') LOCATION '/a/b'");
1762 ParsesOk(
"ALTER TABLE Foo ADD PARTITION (i=NULL)");
1763 ParsesOk(
"ALTER TABLE Foo ADD PARTITION (i=NULL, j=2, k=NULL)");
1764 ParsesOk(
"ALTER TABLE Foo ADD PARTITION (i=abc, j=(5*8+10), k=!true and false)");
1767 ParserError(
"ALTER TABLE TestDb.Foo ADD PARTITION (partcol)");
1768 ParserError(
"ALTER TABLE TestDb.Foo ADD PARTITION (i=1, partcol)");
1770 ParserError(
"ALTER TABLE TestDb.Foo ADD PARTITION (i=1, s='Hello') LOCATION a/b");
1773 ParsesOk(
"ALTER TABLE Foo ADD PARTITION (j=2) CACHED IN 'pool'");
1774 ParsesOk(
"ALTER TABLE Foo ADD PARTITION (j=2) CACHED IN 'pool'");
1775 ParserError(
"ALTER TABLE Foo ADD PARTITION (j=2) CACHED 'pool'");
1776 ParserError(
"ALTER TABLE Foo ADD PARTITION (j=2) CACHED IN");
1777 ParserError(
"ALTER TABLE Foo ADD PARTITION (j=2) CACHED");
1778 ParsesOk(
"ALTER TABLE Foo ADD PARTITION (j=2) CACHED IN 'pool' WITH replication = 3");
1779 ParserError(
"ALTER TABLE Foo ADD PARTITION (j=2) CACHED IN 'pool' " +
1780 "with replication = -1");
1781 ParsesOk(
"ALTER TABLE Foo ADD PARTITION (j=2) UNCACHED");
1782 ParsesOk(
"ALTER TABLE Foo ADD PARTITION (j=2) LOCATION 'a/b' UNCACHED");
1783 ParsesOk(
"ALTER TABLE Foo ADD PARTITION (j=2) LOCATION 'a/b' CACHED IN 'pool'");
1784 ParsesOk(
"ALTER TABLE Foo ADD PARTITION (j=2) LOCATION 'a/b' CACHED IN 'pool' " +
1785 "with replication = 3");
1786 ParserError(
"ALTER TABLE Foo ADD PARTITION (j=2) CACHED IN 'pool' LOCATION 'a/b'");
1787 ParserError(
"ALTER TABLE Foo ADD PARTITION (j=2) UNCACHED LOCATION 'a/b'");
1789 ParserError(
"ALTER TABLE Foo ADD IF EXISTS PARTITION (i=1, s='Hello')");
1790 ParserError(
"ALTER TABLE TestDb.Foo ADD (i=1, s='Hello')");
1793 ParserError(
"ALTER TABLE TestDb.Foo PARTITION (i=1)");
1795 ParserError(
"ALTER TABLE TestDb.Foo ADD PARTITION ()");
1805 String[] columnKw = {
"COLUMN",
""};
1806 for (String kw: columnKw) {
1807 ParsesOk(String.format(
"ALTER TABLE Foo DROP %s col1", kw));
1808 ParsesOk(String.format(
"ALTER TABLE TestDb.Foo DROP %s col1", kw));
1811 ParserError(String.format(
"ALTER TABLE TestDb.Foo DROP %s col1, col2", kw));
1812 ParserError(String.format(
"ALTER TABLE TestDb.Foo DROP %s", kw));
1813 ParserError(String.format(
"ALTER TABLE Foo DROP %s 'col1'", kw));
1814 ParserError(String.format(
"ALTER Foo DROP %s col1", kw));
1815 ParserError(String.format(
"ALTER TABLE DROP %s col1", kw));
1816 ParserError(String.format(
"ALTER TABLE DROP %s", kw));
1822 ParsesOk(
"ALTER TABLE Foo DROP PARTITION (i=1)");
1823 ParsesOk(
"ALTER TABLE TestDb.Foo DROP IF EXISTS PARTITION (i=1, s='Hello')");
1824 ParsesOk(
"ALTER TABLE Foo DROP PARTITION (i=NULL)");
1825 ParsesOk(
"ALTER TABLE Foo DROP PARTITION (i=NULL, j=2, k=NULL)");
1826 ParsesOk(
"ALTER TABLE Foo DROP PARTITION (i=abc, j=(5*8+10), k=!true and false)");
1829 ParserError(
"ALTER TABLE Foo DROP PARTITION (partcol)");
1830 ParserError(
"ALTER TABLE Foo DROP PARTITION (i=1, j)");
1832 ParserError(
"ALTER TABLE Foo DROP IF NOT EXISTS PARTITION (i=1, s='Hello')");
1833 ParserError(
"ALTER TABLE TestDb.Foo DROP (i=1, s='Hello')");
1836 ParserError(
"ALTER TABLE TestDb.Foo PARTITION (i=1)");
1838 ParserError(
"ALTER TABLE TestDb.Foo DROP PARTITION ()");
1846 String[] columnKw = {
"COLUMN",
""};
1847 for (String kw: columnKw) {
1848 ParsesOk(String.format(
"ALTER TABLE Foo.Bar CHANGE %s c1 c2 int", kw));
1849 ParsesOk(String.format(
"ALTER TABLE Foo CHANGE %s c1 c2 int comment 'hi'", kw));
1852 ParserError(String.format(
"ALTER TABLE Foo CHANGE %s c1 int c2", kw));
1853 ParserError(String.format(
"ALTER TABLE Foo CHANGE %s col1 int", kw));
1854 ParserError(String.format(
"ALTER TABLE Foo CHANGE %s col1", kw));
1855 ParserError(String.format(
"ALTER TABLE Foo CHANGE %s", kw));
1856 ParserError(String.format(
"ALTER TABLE CHANGE %s c1 c2 int", kw));
1863 String [] supportedFileFormats =
1864 {
"TEXTFILE",
"SEQUENCEFILE",
"PARQUET",
"PARQUETFILE",
"RCFILE",
"AVRO"};
1865 for (String format: supportedFileFormats) {
1866 ParsesOk(
"ALTER TABLE Foo SET FILEFORMAT " + format);
1867 ParsesOk(
"ALTER TABLE TestDb.Foo SET FILEFORMAT " + format);
1868 ParsesOk(
"ALTER TABLE TestDb.Foo PARTITION (a=1) SET FILEFORMAT " + format);
1869 ParsesOk(
"ALTER TABLE Foo PARTITION (s='str') SET FILEFORMAT " + format);
1870 ParserError(
"ALTER TABLE TestDb.Foo PARTITION (i=5) SET " + format);
1871 ParserError(
"ALTER TABLE TestDb.Foo SET " + format);
1874 ParserError(
"ALTER TABLE TestDb.Foo SET FILEFORMAT");
1876 ParsesOk(
"ALTER TABLE Foo SET LOCATION '/a/b/c'");
1877 ParsesOk(
"ALTER TABLE TestDb.Foo SET LOCATION '/a/b/c'");
1879 ParsesOk(
"ALTER TABLE Foo PARTITION (i=1,s='str') SET LOCATION '/a/i=1/s=str'");
1880 ParsesOk(
"ALTER TABLE Foo PARTITION (s='str') SET LOCATION '/a/i=1/s=str'");
1882 ParserError(
"ALTER TABLE Foo PARTITION (s) SET LOCATION '/a'");
1883 ParserError(
"ALTER TABLE Foo PARTITION () SET LOCATION '/a'");
1884 ParserError(
"ALTER TABLE Foo PARTITION ('str') SET FILEFORMAT TEXTFILE");
1885 ParserError(
"ALTER TABLE Foo PARTITION (a=1, 5) SET FILEFORMAT TEXTFILE");
1886 ParserError(
"ALTER TABLE Foo PARTITION () SET FILEFORMAT PARQUETFILE");
1887 ParserError(
"ALTER TABLE Foo PARTITION (,) SET FILEFORMAT PARQUET");
1888 ParserError(
"ALTER TABLE Foo PARTITION (a=1) SET FILEFORMAT");
1889 ParserError(
"ALTER TABLE Foo PARTITION (a=1) SET LOCATION");
1890 ParserError(
"ALTER TABLE TestDb.Foo SET LOCATION abc");
1891 ParserError(
"ALTER TABLE TestDb.Foo SET LOCATION");
1894 String[] tblPropTypes = {
"TBLPROPERTIES",
"SERDEPROPERTIES"};
1895 String[] partClauses = {
"",
"PARTITION(k1=10, k2=20)"};
1896 for (String propType: tblPropTypes) {
1897 for (String part: partClauses) {
1898 ParsesOk(String.format(
"ALTER TABLE Foo %s SET %s ('a'='b')", part, propType));
1899 ParsesOk(String.format(
"ALTER TABLE Foo %s SET %s ('abc'='123')",
1901 ParsesOk(String.format(
"ALTER TABLE Foo %s SET %s ('abc'='123', 'a'='1')",
1903 ParsesOk(String.format(
"ALTER TABLE Foo %s SET %s ('a'='1', 'b'='2', 'c'='3')",
1905 ParserError(String.format(
"ALTER TABLE Foo %s SET %s ( )", part, propType));
1906 ParserError(String.format(
"ALTER TABLE Foo %s SET %s ('a', 'b')",
1908 ParserError(String.format(
"ALTER TABLE Foo %s SET %s ('a'='b',)",
1910 ParserError(String.format(
"ALTER TABLE Foo %s SET %s ('a'=b)", part, propType));
1911 ParserError(String.format(
"ALTER TABLE Foo %s SET %s (a='b')", part, propType));
1912 ParserError(String.format(
"ALTER TABLE Foo %s SET %s (a=b)", part, propType));
1916 for (String cacheClause: Lists.newArrayList(
"UNCACHED",
"CACHED in 'pool'",
1917 "CACHED in 'pool' with replication = 4")) {
1918 ParsesOk(
"ALTER TABLE Foo SET " + cacheClause);
1919 ParsesOk(
"ALTER TABLE Foo PARTITION(j=0) SET " + cacheClause);
1920 ParserError(
"ALTER TABLE Foo PARTITION(j=0) " + cacheClause);
1926 for (String entity: Lists.newArrayList(
"TABLE",
"VIEW")) {
1927 ParsesOk(String.format(
"ALTER %s TestDb.Foo RENAME TO TestDb.Foo2", entity));
1928 ParsesOk(String.format(
"ALTER %s Foo RENAME TO TestDb.Foo2", entity));
1929 ParsesOk(String.format(
"ALTER %s TestDb.Foo RENAME TO Foo2", entity));
1930 ParsesOk(String.format(
"ALTER %s Foo RENAME TO Foo2", entity));
1931 ParserError(String.format(
"ALTER %s Foo RENAME TO 'Foo2'", entity));
1932 ParserError(String.format(
"ALTER %s Foo RENAME Foo2", entity));
1933 ParserError(String.format(
"ALTER %s Foo RENAME TO", entity));
1934 ParserError(String.format(
"ALTER %s Foo TO Foo2", entity));
1935 ParserError(String.format(
"ALTER %s Foo TO Foo2", entity));
1942 ParsesOk(
"CREATE TABLE Foo (i int)");
1943 ParsesOk(
"CREATE TABLE Foo.Bar (i int)");
1944 ParsesOk(
"CREATE TABLE IF NOT EXISTS Foo.Bar (i int)");
1945 ParsesOk(
"CREATE TABLE Foo.Bar2 LIKE Foo.Bar1");
1946 ParsesOk(
"CREATE TABLE IF NOT EXISTS Bar2 LIKE Bar1");
1947 ParsesOk(
"CREATE EXTERNAL TABLE IF NOT EXISTS Bar2 LIKE Bar1");
1948 ParsesOk(
"CREATE EXTERNAL TABLE IF NOT EXISTS Bar2 LIKE Bar1 LOCATION '/a/b'");
1949 ParsesOk(
"CREATE TABLE Foo2 LIKE Foo COMMENT 'sdafsdf'");
1950 ParsesOk(
"CREATE TABLE Foo2 LIKE Foo COMMENT ''");
1951 ParsesOk(
"CREATE TABLE Foo2 LIKE Foo STORED AS PARQUETFILE");
1952 ParsesOk(
"CREATE TABLE Foo2 LIKE Foo COMMENT 'tbl' " +
1953 "STORED AS PARQUETFILE LOCATION '/a/b'");
1954 ParsesOk(
"CREATE TABLE Foo2 LIKE Foo STORED AS TEXTFILE LOCATION '/a/b'");
1957 ParsesOk(
"CREATE TABLE 01_Foo (01_i int, 02_j string)");
1960 ParsesOk(
"CREATE TABLE Foo (i int, s string)");
1961 ParsesOk(
"CREATE EXTERNAL TABLE Foo (i int, s string)");
1962 ParsesOk(
"CREATE EXTERNAL TABLE Foo (i int, s string) LOCATION '/test-warehouse/'");
1963 ParsesOk(
"CREATE TABLE Foo (i int, s string) COMMENT 'hello' LOCATION '/a/b/'");
1964 ParsesOk(
"CREATE TABLE Foo (i int, s string) COMMENT 'hello' LOCATION '/a/b/' " +
1965 "TBLPROPERTIES ('123'='1234')");
1967 ParsesOk(
"CREATE TABLE Foo COMMENT 'hello' LOCATION '/a/b/' " +
1968 "TBLPROPERTIES ('123'='1234')");
1971 ParsesOk(
"CREATE TABLE Foo (i int) PARTITIONED BY (j string)");
1972 ParsesOk(
"CREATE TABLE Foo (i int) PARTITIONED BY (s string, d double)");
1973 ParsesOk(
"CREATE TABLE Foo (i int, s string) PARTITIONED BY (s string, d double)" +
1974 " COMMENT 'hello' LOCATION '/a/b/'");
1976 ParsesOk(
"CREATE TABLE Foo PARTITIONED BY (s string, d double)" +
1977 " COMMENT 'hello' LOCATION '/a/b/'");
1978 ParserError(
"CREATE TABLE Foo (i int) PARTITIONED BY (int)");
1979 ParserError(
"CREATE TABLE Foo (i int) PARTITIONED BY ()");
1980 ParserError(
"CREATE TABLE Foo (i int) PARTITIONED BY");
1983 ParsesOk(
"CREATE TABLE Foo (i int COMMENT 'hello', s string)");
1984 ParsesOk(
"CREATE TABLE Foo (i int COMMENT 'hello', s string COMMENT 'hi')");
1985 ParsesOk(
"CREATE TABLE T (i int COMMENT 'hi') PARTITIONED BY (j int COMMENT 'bye')");
1988 String [] supportedFileFormats =
1989 {
"TEXTFILE",
"SEQUENCEFILE",
"PARQUET",
"PARQUETFILE",
"RCFILE",
"AVRO"};
1990 for (String format: supportedFileFormats) {
1991 ParsesOk(
"CREATE TABLE Foo (i int, s string) STORED AS " + format);
1992 ParsesOk(
"CREATE EXTERNAL TABLE Foo (i int, s string) STORED AS " + format);
1994 "CREATE TABLE Foo (i int, s string) STORED AS %s LOCATION '/b'", format));
1996 "CREATE EXTERNAL TABLE Foo (f float) COMMENT 'c' STORED AS %s LOCATION '/b'",
2000 "CREATE EXTERNAL TABLE Foo COMMENT 'c' STORED AS %s LOCATION '/b'", format));
2004 String[] tblPropTypes = {
"TBLPROPERTIES",
"WITH SERDEPROPERTIES"};
2005 for (String propType: tblPropTypes) {
2007 "CREATE TABLE Foo (i int) %s ('a'='b', 'c'='d', 'e'='f')", propType));
2008 ParserError(String.format(
"CREATE TABLE Foo (i int) %s", propType));
2009 ParserError(String.format(
"CREATE TABLE Foo (i int) %s ()", propType));
2010 ParserError(String.format(
"CREATE TABLE Foo (i int) %s ('a')", propType));
2011 ParserError(String.format(
"CREATE TABLE Foo (i int) %s ('a'=)", propType));
2012 ParserError(String.format(
"CREATE TABLE Foo (i int) %s ('a'=c)", propType));
2013 ParserError(String.format(
"CREATE TABLE Foo (i int) %s (a='c')", propType));
2015 ParsesOk(
"CREATE TABLE Foo (i int) WITH SERDEPROPERTIES ('a'='b') " +
2016 "TBLPROPERTIES ('c'='d', 'e'='f')");
2018 ParserError(
"CREATE TABLE Foo (i int) TBLPROPERTIES ('c'='d', 'e'='f') " +
2019 "WITH SERDEPROPERTIES ('a'='b')");
2021 ParserError(
"CREATE TABLE Foo (i int) SERDEPROPERTIES ('a'='b')");
2023 ParserError(
"CREATE TABLE Foo (i int, s string) STORED AS SEQFILE");
2024 ParserError(
"CREATE TABLE Foo (i int, s string) STORED TEXTFILE");
2025 ParserError(
"CREATE TABLE Foo LIKE Bar STORED AS TEXT");
2027 ParserError(
"CREATE TABLE Foo LIKE Bar STORED TEXTFILE");
2028 ParserError(
"CREATE TABLE Foo LIKE Bar STORED AS");
2029 ParserError(
"CREATE TABLE Foo LIKE Bar LOCATION");
2032 ParsesOk(
"CREATE TABLE T (i int) ROW FORMAT DELIMITED");
2033 ParsesOk(
"CREATE TABLE T (i int) ROW FORMAT DELIMITED FIELDS TERMINATED BY '|'");
2034 ParsesOk(
"CREATE TABLE T (i int) ROW FORMAT DELIMITED LINES TERMINATED BY '|'");
2035 ParsesOk(
"CREATE TABLE T (i int) ROW FORMAT DELIMITED ESCAPED BY '\'");
2036 ParsesOk(
"CREATE TABLE T (i int) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\0'" +
2037 " ESCAPED BY '\3' LINES TERMINATED BY '\1'");
2038 ParsesOk(
"CREATE TABLE T (i int) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\0'" +
2039 " LINES TERMINATED BY '\1' STORED AS TEXTFILE");
2040 ParsesOk(
"CREATE TABLE T (i int) COMMENT 'hi' ROW FORMAT DELIMITED STORED AS RCFILE");
2041 ParsesOk(
"CREATE TABLE T (i int) COMMENT 'hello' ROW FORMAT DELIMITED FIELDS " +
2042 "TERMINATED BY '\0' LINES TERMINATED BY '\1' STORED AS TEXTFILE LOCATION '/a'");
2045 ParserError(
"CREATE TABLE T (i int) ROW FORMAT DELIMITED TERMINATED BY '\0'");
2046 ParserError(
"CREATE TABLE T (i int) ROW FORMAT DELIMITED FIELDS TERMINATED BY");
2047 ParserError(
"CREATE TABLE T (i int) ROW FORMAT DELIMITED LINES TERMINATED BY");
2048 ParserError(
"CREATE TABLE T (i int) ROW FORMAT DELIMITED ESCAPED BY");
2049 ParserError(
"CREATE TABLE T (i int) ROW FORMAT DELIMITED FIELDS TERMINATED '|'");
2050 ParserError(
"CREATE TABLE T (i int) ROW FORMAT DELIMITED FIELDS TERMINATED BY |");
2051 ParserError(
"CREATE TABLE T (i int) ROW FORMAT DELIMITED FIELDS BY '\0'");
2052 ParserError(
"CREATE TABLE T (i int) ROW FORMAT DELIMITED LINES BY '\n'");
2053 ParserError(
"CREATE TABLE T (i int) FIELDS TERMINATED BY '\0'");
2054 ParserError(
"CREATE TABLE T (i int) ROWS TERMINATED BY '\0'");
2055 ParserError(
"CREATE TABLE T (i int) ESCAPED BY '\0'");
2059 ParserError(
"CREATE TABLE Foo (d double) COMMENT 'c' PARTITIONED BY (i int)");
2060 ParserError(
"CREATE TABLE Foo (d double) STORED AS TEXTFILE COMMENT 'c'");
2061 ParserError(
"CREATE TABLE Foo (d double) STORED AS TEXTFILE ROW FORMAT DELIMITED");
2062 ParserError(
"CREATE TABLE Foo (d double) ROW FORMAT DELIMITED COMMENT 'c'");
2063 ParserError(
"CREATE TABLE Foo (d double) LOCATION 'a' COMMENT 'c'");
2064 ParserError(
"CREATE TABLE Foo (d double) UNCACHED LOCATION '/a/b'");
2065 ParserError(
"CREATE TABLE Foo (d double) CACHED IN 'pool' LOCATION '/a/b'");
2066 ParserError(
"CREATE TABLE Foo (d double) CACHED IN 'pool' REPLICATION = 8 " +
2068 ParserError(
"CREATE TABLE Foo (d double) LOCATION 'a' COMMENT 'c' STORED AS RCFILE");
2069 ParserError(
"CREATE TABLE Foo (d double) LOCATION 'a' STORED AS RCFILE");
2070 ParserError(
"CREATE TABLE Foo (d double) TBLPROPERTIES('a'='b') LOCATION 'a'");
2071 ParserError(
"CREATE TABLE Foo (i int) LOCATION 'a' WITH SERDEPROPERTIES('a'='b')");
2074 ParserError(
"CREATE TABLE Foo (d double) LOCATION a");
2075 ParserError(
"CREATE TABLE Foo (d double) COMMENT c");
2076 ParserError(
"CREATE TABLE Foo (d double COMMENT c)");
2077 ParserError(
"CREATE TABLE Foo (d double COMMENT 'c') PARTITIONED BY (j COMMENT hi)");
2078 ParserError(
"CREATE TABLE Foo (d double) STORED AS 'TEXTFILE'");
2081 ParsesOk(
"CREATE TABLE Foo (i int) CACHED IN 'myPool'");
2082 ParsesOk(
"CREATE TABLE Foo (i int) CACHED IN 'myPool' WITH REPLICATION = 4");
2083 ParsesOk(
"CREATE TABLE Foo (i int) PARTITIONED BY(j int) CACHED IN 'myPool'");
2084 ParsesOk(
"CREATE TABLE Foo (i int) PARTITIONED BY(j int) CACHED IN 'myPool'" +
2085 " WITH REPLICATION = 4");
2086 ParsesOk(
"CREATE TABLE Foo (i int) PARTITIONED BY(j int) CACHED IN 'myPool'");
2087 ParsesOk(
"CREATE TABLE Foo (i int) PARTITIONED BY(j int) LOCATION '/a' " +
2088 "CACHED IN 'myPool'");
2089 ParserError(
"CREATE TABLE Foo (i int) CACHED IN myPool");
2090 ParserError(
"CREATE TABLE Foo (i int) PARTITIONED BY(j int) CACHED IN");
2091 ParserError(
"CREATE TABLE Foo (i int) CACHED 'myPool'");
2092 ParserError(
"CREATE TABLE Foo (i int) IN 'myPool'");
2093 ParserError(
"CREATE TABLE Foo (i int) PARTITIONED BY(j int) CACHED IN 'myPool' " +
2095 ParserError(
"CREATE TABLE Foo (i int) CACHED IN 'myPool' WITH REPLICATION = -1");
2096 ParserError(
"CREATE TABLE Foo (i int) CACHED IN 'myPool' WITH REPLICATION = 1.0");
2097 ParserError(
"CREATE TABLE Foo (i int) CACHED IN 'myPool' " +
2098 "WITH REPLICATION = cast(1 as double)");
2101 ParserError(
"CREATE TABLE IF EXISTS Foo.Bar (i int)");
2102 ParserError(
"CREATE TABLE Bar LIKE Bar2 (i int)");
2103 ParserError(
"CREATE IF NOT EXISTS TABLE Foo.Bar (i int)");
2104 ParserError(
"CREATE TABLE Foo (d double) STORED TEXTFILE");
2105 ParserError(
"CREATE TABLE Foo (d double) AS TEXTFILE");
2115 ParsesOk(
"CREATE TABLE Foo (i int, s string) PRODUCED BY DATA SOURCE Bar");
2116 ParsesOk(
"CREATE TABLE Foo (i int, s string) PRODUCED BY DATA SOURCE Bar(\"\")");
2117 ParsesOk(
"CREATE TABLE Foo (i int) PRODUCED BY DATA SOURCE " +
2118 "Bar(\"Foo \\!@#$%^&*()\")");
2119 ParsesOk(
"CREATE TABLE IF NOT EXISTS Foo (i int) PRODUCED BY DATA SOURCE Bar(\"\")");
2122 ParserError(
"CREATE TABLE Foo (i int) PRODUCED BY DATA Foo");
2123 ParserError(
"CREATE TABLE Foo (i int) PRODUCED BY DATA SRC Foo");
2124 ParserError(
"CREATE TABLE Foo (i int) PRODUCED BY DATA SOURCE Foo.Bar");
2125 ParserError(
"CREATE TABLE Foo (i int) PRODUCED BY DATA SOURCE Foo()");
2126 ParserError(
"CREATE EXTERNAL TABLE Foo (i int) PRODUCED BY DATA SOURCE Foo(\"\")");
2127 ParserError(
"CREATE TABLE Foo (i int) PRODUCED BY DATA SOURCE Foo(\"\") " +
2129 ParserError(
"CREATE TABLE Foo (i int) PRODUCED BY DATA SOURCE Foo(\"\") " +
2130 "ROW FORMAT DELIMITED");
2131 ParserError(
"CREATE TABLE Foo (i int) PARTITIONED BY (j string) PRODUCED BY DATA " +
2132 "SOURCE Foo(\"\")");
2137 ParsesOk(
"CREATE DATA SOURCE foo LOCATION '/foo.jar' CLASS 'com.bar.Foo' " +
2138 "API_VERSION 'V1'");
2139 ParsesOk(
"CREATE DATA SOURCE foo LOCATION \"/foo.jar\" CLASS \"com.bar.Foo\" " +
2140 "API_VERSION \"V1\"");
2141 ParsesOk(
"CREATE DATA SOURCE foo LOCATION '/x/foo@hi_^!#.jar' CLASS 'com.bar.Foo' " +
2142 "API_VERSION 'V1'");
2144 ParserError(
"CREATE DATA foo LOCATION '/foo.jar' CLASS 'com.bar.Foo' " +
2145 "API_VERSION 'V1'");
2146 ParserError(
"CREATE DATA SRC foo.bar LOCATION '/foo.jar' CLASS 'com.bar.Foo' " +
2147 "API_VERSION 'V1'");
2148 ParserError(
"CREATE DATA SOURCE foo.bar LOCATION '/x/foo.jar' CLASS 'com.bar.Foo' " +
2149 "API_VERSION 'V1'");
2150 ParserError(
"CREATE DATA SOURCE foo LOCATION /x/foo.jar CLASS 'com.bar.Foo' " +
2151 "API_VERSION 'V1'");
2152 ParserError(
"CREATE DATA SOURCE foo LOCATION '/x/foo.jar' CLASS com.bar.Foo " +
2153 "API_VERSION 'V1'");
2154 ParserError(
"CREATE DATA SOURCE foo LOCATION '/x/foo.jar' CLASS 'com.bar.Foo' " +
2156 ParserError(
"CREATE DATA SOURCE LOCATION '/x/foo.jar' CLASS 'com.bar.Foo' " +
2157 "API_VERSION 'V1'");
2158 ParserError(
"CREATE DATA SOURCE foo CLASS 'com.bar.Foo' " +
2159 "API_VERSION 'V1'");
2160 ParserError(
"CREATE DATA SOURCE foo LOCATION CLASS 'com.bar.Foo' " +
2161 "API_VERSION 'V1'");
2162 ParserError(
"CREATE DATA SOURCE foo LOCATION '/foo.jar' API_VERSION 'V1'");
2163 ParserError(
"CREATE DATA SOURCE foo LOCATION '/foo.jar' CLASS API_VERSION 'V1'");
2164 ParserError(
"CREATE DATA SOURCE foo LOCATION '/foo.jar' CLASS 'com.bar.Foo'");
2165 ParserError(
"CREATE DATA SOURCE foo LOCATION '/foo.jar' CLASS 'Foo' API_VERSION");
2166 ParserError(
"CREATE DATA SOURCE foo CLASS 'com.bar.Foo' LOCATION '/x/foo.jar' " +
2167 "API_VERSION 'V1'");
2168 ParserError(
"CREATE DATA SOURCE foo CLASS 'com.bar.Foo' API_VERSION 'V1' " +
2169 "LOCATION '/x/foo.jar' ");
2170 ParserError(
"CREATE DATA SOURCE foo API_VERSION 'V1' LOCATION '/x/foo.jar' " +
2171 "CLASS 'com.bar.Foo'");
2186 ParsesOk(
"CREATE VIEW Bar AS SELECT a, b, c from t");
2187 ParsesOk(
"CREATE VIEW Bar COMMENT 'test' AS SELECT a, b, c from t");
2188 ParsesOk(
"CREATE VIEW Bar (x, y, z) AS SELECT a, b, c from t");
2189 ParsesOk(
"CREATE VIEW Bar (x, y COMMENT 'foo', z) AS SELECT a, b, c from t");
2190 ParsesOk(
"CREATE VIEW Bar (x, y, z) COMMENT 'test' AS SELECT a, b, c from t");
2191 ParsesOk(
"CREATE VIEW IF NOT EXISTS Bar AS SELECT a, b, c from t");
2193 ParsesOk(
"CREATE VIEW Foo.Bar AS SELECT a, b, c from t");
2194 ParsesOk(
"CREATE VIEW Foo.Bar COMMENT 'test' AS SELECT a, b, c from t");
2195 ParsesOk(
"CREATE VIEW Foo.Bar (x, y, z) AS SELECT a, b, c from t");
2196 ParsesOk(
"CREATE VIEW Foo.Bar (x, y, z COMMENT 'foo') AS SELECT a, b, c from t");
2197 ParsesOk(
"CREATE VIEW Foo.Bar (x, y, z) COMMENT 'test' AS SELECT a, b, c from t");
2198 ParsesOk(
"CREATE VIEW IF NOT EXISTS Foo.Bar AS SELECT a, b, c from t");
2201 ParsesOk(
"CREATE VIEW Bar AS SELECT 1, 2, 3");
2202 ParsesOk(
"CREATE VIEW Bar AS VALUES(1, 2, 3)");
2203 ParsesOk(
"CREATE VIEW Bar AS SELECT 1, 2, 3 UNION ALL select 4, 5, 6");
2204 ParsesOk(
"CREATE VIEW Bar AS WITH t AS (SELECT 1, 2, 3) SELECT * FROM t");
2207 ParsesOk(
"CREATE VIEW Bar (x, y) AS SELECT 1, 2, 3");
2214 ParserError(
"CREATE VIEW Foo.Bar () AS SELECT c FROM t");
2216 ParserError(
"CREATE VIEW Foo.Bar (x int) AS SELECT c FROM t");
2217 ParserError(
"CREATE VIEW Foo.Bar (x int COMMENT 'x') AS SELECT c FROM t");
2219 ParserError(
"CREATE VIEW Foo.Bar (int COMMENT 'x') AS SELECT c FROM t");
2223 ParserError(
"CREATE VIEW Foo.Bar (x) AS INSERT INTO t select * from t");
2224 ParserError(
"CREATE VIEW Foo.Bar (x) AS CREATE TABLE Wrong (i int)");
2225 ParserError(
"CREATE VIEW Foo.Bar (x) AS ALTER TABLE Foo COLUMNS (i int, s string)");
2226 ParserError(
"CREATE VIEW Foo.Bar (x) AS CREATE VIEW Foo.Bar AS SELECT 1");
2227 ParserError(
"CREATE VIEW Foo.Bar (x) AS ALTER VIEW Foo.Bar AS SELECT 1");
2232 ParsesOk(
"ALTER VIEW Bar AS SELECT 1, 2, 3");
2233 ParsesOk(
"ALTER VIEW Bar AS SELECT a, b, c FROM t");
2234 ParsesOk(
"ALTER VIEW Bar AS VALUES(1, 2, 3)");
2235 ParsesOk(
"ALTER VIEW Bar AS SELECT 1, 2, 3 UNION ALL select 4, 5, 6");
2237 ParsesOk(
"ALTER VIEW Foo.Bar AS SELECT 1, 2, 3");
2238 ParsesOk(
"ALTER VIEW Foo.Bar AS SELECT a, b, c FROM t");
2239 ParsesOk(
"ALTER VIEW Foo.Bar AS VALUES(1, 2, 3)");
2240 ParsesOk(
"ALTER VIEW Foo.Bar AS SELECT 1, 2, 3 UNION ALL select 4, 5, 6");
2241 ParsesOk(
"ALTER VIEW Foo.Bar AS WITH t AS (SELECT 1, 2, 3) SELECT * FROM t");
2244 ParserError(
"ALTER TABLE Foo.Bar AS SELECT 1, 2, 3");
2252 ParserError(
"ALTER VIEW Foo.Bar AS INSERT INTO t select * from t");
2253 ParserError(
"ALTER VIEW Foo.Bar AS CREATE TABLE Wrong (i int)");
2254 ParserError(
"ALTER VIEW Foo.Bar AS ALTER TABLE Foo COLUMNS (i int, s string)");
2255 ParserError(
"ALTER VIEW Foo.Bar AS CREATE VIEW Foo.Bar AS SELECT 1, 2, 3");
2256 ParserError(
"ALTER VIEW Foo.Bar AS ALTER VIEW Foo.Bar AS SELECT 1, 2, 3");
2261 ParsesOk(
"CREATE TABLE Foo AS SELECT 1, 2, 3");
2262 ParsesOk(
"CREATE TABLE Foo AS SELECT * from foo.bar");
2263 ParsesOk(
"CREATE TABLE Foo.Bar AS SELECT int_col, bool_col from tbl limit 10");
2264 ParsesOk(
"CREATE TABLE Foo.Bar LOCATION '/a/b' AS SELECT * from foo");
2265 ParsesOk(
"CREATE TABLE IF NOT EXISTS Foo.Bar LOCATION '/a/b' AS SELECT * from foo");
2266 ParsesOk(
"CREATE TABLE Foo STORED AS PARQUET AS SELECT 1");
2267 ParsesOk(
"CREATE TABLE Foo ROW FORMAT DELIMITED STORED AS PARQUETFILE AS SELECT 1");
2268 ParsesOk(
"CREATE TABLE Foo TBLPROPERTIES ('a'='b', 'c'='d') AS SELECT * from bar");
2271 ParsesOk(
"CREATE TABLE Foo AS with t1 as (select 1) select * from t1");
2274 ParserError(
"CREATE TABLE Foo ROW FORMAT DELIMITED STORED AS PARQUET AS SELECT");
2275 ParserError(
"CREATE TABLE Foo ROW FORMAT DELIMITED STORED AS PARQUET AS WITH");
2276 ParserError(
"CREATE TABLE Foo ROW FORMAT DELIMITED STORED AS PARQUET AS");
2279 ParserError(
"CREATE TABLE Foo AS INSERT INTO Foo SELECT 1");
2282 ParserError(
"CREATE TABLE Foo(i int) AS SELECT 1");
2283 ParserError(
"CREATE TABLE Foo PARTITIONED BY(i int) AS SELECT 1");
2290 ParsesOk(
"DROP TABLE IF EXISTS Foo.Bar");
2293 ParsesOk(
"DROP VIEW IF EXISTS Foo.Bar");
2296 ParsesOk(
"DROP DATABASE IF EXISTS Foo");
2297 ParsesOk(
"DROP SCHEMA IF EXISTS Foo");
2299 ParsesOk(
"DROP AGGREGATE FUNCTION Foo(INT)");
2300 ParsesOk(
"DROP FUNCTION Foo.Foo(INT)");
2301 ParsesOk(
"DROP AGGREGATE FUNCTION IF EXISTS Foo()");
2302 ParsesOk(
"DROP FUNCTION IF EXISTS Foo(INT)");
2303 ParsesOk(
"DROP FUNCTION IF EXISTS Foo(INT...)");
2325 ParserError(
"DROP FUNCTION Foo(INT) RETURNS INT");
2326 ParserError(
"DROP FUNCTION Foo.(INT) RETURNS INT");
2327 ParserError(
"DROP FUNCTION Foo..(INT) RETURNS INT");
2328 ParserError(
"DROP FUNCTION Foo(NULL) RETURNS INT");
2329 ParserError(
"DROP FUNCTION Foo(INT) RETURNS NULL");
2330 ParserError(
"DROP BLAH FUNCTION IF EXISTS Foo.A.Foo(INT)");
2336 ParsesOk(
"LOAD DATA INPATH '/a/b' INTO TABLE Foo");
2337 ParsesOk(
"LOAD DATA INPATH '/a/b' INTO TABLE Foo.Bar");
2338 ParsesOk(
"LOAD DATA INPATH '/a/b' OVERWRITE INTO TABLE Foo.Bar");
2339 ParsesOk(
"LOAD DATA INPATH '/a/b' INTO TABLE Foo PARTITION(a=1, b='asdf')");
2340 ParsesOk(
"LOAD DATA INPATH '/a/b' INTO TABLE Foo PARTITION(a=1)");
2342 ParserError(
"LOAD DATA INPATH '/a/b' INTO Foo PARTITION(a=1)");
2343 ParserError(
"LOAD DATA INPATH '/a/b' INTO Foo PARTITION(a)");
2344 ParserError(
"LOAD DATA INPATH '/a/b' INTO Foo PARTITION");
2349 ParserError(
"LOAD DATA LOCAL INPATH '/a/b' INTO TABLE Foo");
2357 for (String typeDefStr: typeDefs) {
2358 ParsesOk(String.format(
"CREATE TABLE t (i %s)", typeDefStr));
2359 ParsesOk(String.format(
"SELECT CAST (i AS %s)", typeDefStr));
2361 ParsesOk(String.format(
"CREATE TABLE t (i MAP<%s, %s>)", typeDefStr, typeDefStr));
2362 ParsesOk(String.format(
"CREATE TABLE t (i ARRAY<%s>)", typeDefStr));
2363 ParsesOk(String.format(
"CREATE TABLE t (i STRUCT<f:%s>)", typeDefStr));
2371 for (String typeDefStr: typeDefs) {
2372 ParserError(String.format(
"CREATE TABLE t (i %s)", typeDefStr));
2373 ParserError(String.format(
"SELECT CAST (i AS %s)", typeDefStr));
2413 TypeDefsParseOk(
"STRUCT<a:TINYINT COMMENT 'x', b:BIGINT, c:DOUBLE COMMENT 'y'>");
2431 ParsesOk(
"invalidate metadata Foo");
2432 ParsesOk(
"invalidate metadata Foo.S");
2444 String[] prefixes = {
"compute",
"drop"};
2446 for (String prefix: prefixes) {
2449 ParsesOk(prefix +
" stats foo.bar");
2450 ParsesOk(prefix +
" stats `foo`.`bar`");
2468 "Syntax error in line 1:\n" +
2469 "c, b, c from t\n" +
2471 "Encountered: IDENTIFIER\n" +
2472 "Expected: ALTER, COMPUTE, CREATE, DESCRIBE, DROP, EXPLAIN, GRANT, " +
2473 "INSERT, INVALIDATE, LOAD, REFRESH, REVOKE, SELECT, SET, SHOW, USE, " +
2478 "Syntax error in line 1:\n" +
2481 "Encountered: FROM\n" +
2482 "Expected: ALL, CASE, CAST, DISTINCT, EXISTS, " +
2483 "FALSE, IF, INTERVAL, NOT, NULL, " +
2484 "STRAIGHT_JOIN, TRUE, IDENTIFIER\n");
2488 "Syntax error in line 1:\n" +
2489 "select c, b, c where a = 5\n" +
2491 "Encountered: WHERE\n" +
2492 "Expected: AND, AS, BETWEEN, DIV, FROM, IN, IS, LIKE, LIMIT, NOT, OR, " +
2493 "ORDER, REGEXP, RLIKE, UNION, COMMA, IDENTIFIER\n");
2497 "Syntax error in line 1:\n" +
2498 "select c, b, c from where a = 5\n" +
2500 "Encountered: WHERE\n" +
2501 "Expected: IDENTIFIER\n");
2505 "Syntax error in line 1:\n" +
2506 "select c, b, c from t where\n" +
2508 "Encountered: EOF\n" +
2509 "Expected: CASE, CAST, EXISTS, FALSE, " +
2510 "IF, INTERVAL, NOT, NULL, TRUE, IDENTIFIER\n");
2513 ParserError(
"select c, b, c from t where group by a, b",
2514 "Syntax error in line 1:\n" +
2515 "select c, b, c from t where group by a, b\n" +
2517 "Encountered: GROUP\n" +
2518 "Expected: CASE, CAST, EXISTS, FALSE, " +
2519 "IF, INTERVAL, NOT, NULL, TRUE, IDENTIFIER\n");
2523 "Unmatched string literal in line 1:\n" +
2524 "select c, \"b, c from t\n" +
2529 "Unmatched string literal in line 1:\n" +
2530 "select c, 'b, c from t\n" +
2535 "Syntax error in line 1:\n" +
2536 "select (i + 5)(1 - i) from t\n" +
2538 "Encountered: (\n" +
2542 "Syntax error in line 2:\n" +
2543 "(1 - i) from t\n" +
2545 "Encountered: (\n" +
2549 "Syntax error in line 2:\n" +
2552 "Encountered: (\n" +
2556 ParserError(
"select c, b, c,c,c,c,c,c,c,c,c,a a a,c,c,c,c,c,c,c,cd,c,d,d,,c, from t",
2557 "Syntax error in line 1:\n" +
2558 "... b, c,c,c,c,c,c,c,c,c,a a a,c,c,c,c,c,c,c,cd,c,d,d,,c,...\n" +
2560 "Encountered: IDENTIFIER\n" +
2561 "Expected: CROSS, FROM, FULL, GROUP, HAVING, INNER, JOIN, LEFT, LIMIT, OFFSET, " +
2562 "ON, ORDER, RIGHT, UNION, USING, WHERE, COMMA\n");
2565 ParserError(
"select a a a, b, c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,cd,c,d,d,,c, from t",
2566 "Syntax error in line 1:\n" +
2567 "select a a a, b, c,c,c,c,c,c,c,c,c,c,c,...\n" +
2569 "Encountered: IDENTIFIER\n" +
2570 "Expected: CROSS, FROM, FULL, GROUP, HAVING, INNER, JOIN, LEFT, LIMIT, OFFSET, " +
2571 "ON, ORDER, RIGHT, UNION, USING, WHERE, COMMA\n");
2574 ParserError(
"select a, b, c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,cd,c,d,d, ,c, from t",
2575 "Syntax error in line 1:\n" +
2576 "...c,c,c,c,c,c,c,c,cd,c,d,d, ,c, from t\n" +
2578 "Encountered: COMMA\n" +
2579 "Expected: CASE, CAST, EXISTS, FALSE, " +
2580 "IF, INTERVAL, NOT, NULL, TRUE, IDENTIFIER\n");
2584 "Syntax error in line 1:\n" +
2585 "DROP DATA SRC foo\n" +
2587 "Encountered: IDENTIFIER\n" +
2588 "Expected: SOURCE\n");
2590 "Syntax error in line 1:\n" +
2591 "SHOW DATA SRCS\n" +
2593 "Encountered: IDENTIFIER\n" +
2594 "Expected: SOURCES\n");
2596 "Syntax error in line 1:\n" +
2599 "Encountered: EMPTY IDENTIFIER\n" +
2600 "Expected: IDENTIFIER\n");
2604 "Syntax error in line 1:\n" +
2607 "Encountered: EOF\n" +
2613 ParsesOk(
"explain select a from tbl");
2614 ParsesOk(
"explain insert into tbl select a, b, c, d from tbl");
2625 String subquery =
"(SELECT count(*) FROM bar)";
2626 String[] operators = {
"=",
"!=",
"<>",
">",
">=",
"<",
"<="};
2627 for (String op: operators) {
2628 ParsesOk(String.format(
"SELECT * FROM foo WHERE a %s %s", op, subquery));
2629 ParsesOk(String.format(
"SELECT * FROM foo WHERE %s %s a", subquery, op));
2632 ParsesOk(
"SELECT * FROM foo WHERE a+1 > (SELECT count(a) FROM bar)");
2633 ParsesOk(
"SELECT * FROM foo WHERE (SELECT count(a) FROM bar) < a+1");
2636 ParsesOk(
"SELECT * FROM foo WHERE a IN (SELECT a FROM bar)");
2637 ParsesOk(
"SELECT * FROM foo WHERE a NOT IN (SELECT a FROM bar)");
2640 ParsesOk(
"SELECT * FROM foo WHERE EXISTS (SELECT a FROM bar WHERE b > 0)");
2641 ParsesOk(
"SELECT * FROM foo WHERE NOT EXISTS (SELECT a FROM bar WHERE b > 0)");
2642 ParsesOk(
"SELECT * FROM foo WHERE NOT (EXISTS (SELECT a FROM bar))");
2645 ParsesOk(
"SELECT * FROM foo WHERE a = (SELECT count(a) FROM bar) AND " +
2646 "b != (SELECT count(b) FROM baz) and c IN (SELECT c FROM qux)");
2647 ParsesOk(
"SELECT * FROM foo WHERE EXISTS (SELECT a FROM bar WHERE b < 0) AND " +
2648 "NOT EXISTS (SELECT a FROM baz WHERE b > 0)");
2649 ParsesOk(
"SELECT * FROM foo WHERE EXISTS (SELECT a from bar) AND " +
2650 "NOT EXISTS (SELECT a FROM baz) AND b IN (SELECT b FROM bar) AND " +
2651 "c NOT IN (SELECT c FROM qux) AND d = (SELECT max(d) FROM quux)");
2654 ParsesOk(
"SELECT * FROM foo WHERE EXISTS ((SELECT * FROM bar))");
2655 ParsesOk(
"SELECT * FROM foo WHERE EXISTS (((SELECT * FROM bar)))");
2656 ParsesOk(
"SELECT * FROM foo WHERE a IN ((SELECT a FROM bar))");
2657 ParsesOk(
"SELECT * FROM foo WHERE a = ((SELECT max(a) FROM bar))");
2660 ParsesOk(
"SELECT * FROM foo WHERE a IN (SELECT a FROM bar WHERE b IN " +
2661 "(SELECT b FROM baz))");
2662 ParsesOk(
"SELECT * FROM foo WHERE EXISTS (SELECT a FROM bar WHERE b NOT IN " +
2663 "(SELECT b FROM baz WHERE c < 10 AND d = (SELECT max(d) FROM qux)))");
2666 for (String op: operators) {
2667 ParsesOk(String.format(
"SELECT * FROM foo WHERE %s %s %s", subquery, op,
2673 ParserError(
"SELECT * FROM foo WHERE a IN SELECT a FROM bar");
2674 ParserError(
"SELECT * FROM foo WHERE a = SELECT count(*) FROM bar");
2675 ParserError(
"SELECT * FROM foo WHERE EXISTS SELECT * FROM bar");
2676 ParserError(
"SELECT * FROM foo WHERE a IN (SELECT a FROM bar");
2677 ParserError(
"SELECT * FROM foo WHERE a IN SELECT a FROM bar)");
2678 ParserError(
"SELECT * FROM foo WHERE a IN (SELECT) a FROM bar");
2681 ParserError(
"SELECT * FROM foo WHERE a EXISTS (SELECT * FROM bar)");
2682 ParserError(
"SELECT * FROM foo WHERE a NOT EXISTS (SELECT * FROM bar)");
2685 ParserError(
"SELECT * FROM foo WHERE EXISTS ((SELECT a FROM bar) UNION " +
2686 "(SELECT a FROM baz))");
2689 ParsesOk(
"SELECT a, count(*) FROM foo GROUP BY a HAVING count(*) > " +
2690 "(SELECT count(*) FROM bar)");
2691 ParsesOk(
"SELECT a, count(*) FROM foo GROUP BY a HAVING 10 > " +
2692 "(SELECT count(*) FROM bar)");
2695 ParsesOk(
"SELECT a, b, (SELECT c FROM foo) FROM foo");
2696 ParsesOk(
"SELECT (SELECT a FROM foo), b, c FROM bar");
2697 ParsesOk(
"SELECT (SELECT (SELECT a FROM foo) FROM bar) FROM baz");
2698 ParsesOk(
"SELECT (SELECT a FROM foo)");
2702 ParserError(
"SELECT (SELECT a FROM foo FROM bar");
2703 ParserError(
"SELECT SELECT a FROM foo) FROM bar");
2707 ParsesOk(
"SELECT a, count(*) FROM foo GROUP BY (SELECT a FROM bar)");
2708 ParsesOk(
"SELECT a, count(*) FROM foo GROUP BY a, (SELECT b FROM bar)");
2711 ParserError(
"SELECT a, count(*) FROM foo GROUP BY SELECT a FROM bar");
2712 ParserError(
"SELECT a, count(*) FROM foo GROUP BY (SELECT) a FROM bar");
2713 ParserError(
"SELECT a, count(*) FROM foo GROUP BY (SELECT a FROM bar");
2716 ParsesOk(
"SELECT a, b FROM foo ORDER BY (SELECT a FROM bar)");
2717 ParsesOk(
"SELECT a, b FROM foo ORDER BY (SELECT a FROM bar) DESC");
2718 ParsesOk(
"SELECT a, b FROM foo ORDER BY a ASC, (SELECT a FROM bar) DESC");
2721 ParserError(
"SELECT a, count(*) FROM foo ORDER BY SELECT a FROM bar");
2722 ParserError(
"SELECT a, count(*) FROM foo ORDER BY (SELECT) a FROM bar DESC");
2723 ParserError(
"SELECT a, count(*) FROM foo ORDER BY (SELECT a FROM bar ASC");
2763 ParsesOk(
"GRANT ROLE foo TO GROUP bar");
2764 ParsesOk(
"REVOKE ROLE foo FROM GROUP bar");
2765 ParsesOk(
"GRANT ROLE `foo` TO GROUP `bar`");
2776 Object[][] grantRevFormatStrs = {{
"GRANT",
"TO"}, {
"REVOKE",
"FROM"}};
2777 for (Object[] formatStr: grantRevFormatStrs) {
2778 ParsesOk(String.format(
"%s ALL ON TABLE foo %s myRole", formatStr));
2781 ParsesOk(String.format(
"%s ALL ON TABLE foo %s ROLE myRole", formatStr));
2783 ParsesOk(String.format(
"%s ALL ON DATABASE foo %s myRole", formatStr));
2784 ParsesOk(String.format(
"%s ALL ON URI 'foo' %s myRole", formatStr));
2786 ParsesOk(String.format(
"%s INSERT ON TABLE foo %s myRole", formatStr));
2787 ParsesOk(String.format(
"%s INSERT ON DATABASE foo %s myRole", formatStr));
2788 ParsesOk(String.format(
"%s INSERT ON URI 'foo' %s myRole", formatStr));
2790 ParsesOk(String.format(
"%s SELECT ON TABLE foo %s myRole", formatStr));
2791 ParsesOk(String.format(
"%s SELECT ON DATABASE foo %s myRole", formatStr));
2792 ParsesOk(String.format(
"%s SELECT ON URI 'foo' %s myRole", formatStr));
2795 ParsesOk(String.format(
"%s ALL ON SERVER %s myRole", formatStr));
2796 ParsesOk(String.format(
"%s INSERT ON SERVER %s myRole", formatStr));
2797 ParsesOk(String.format(
"%s SELECT ON SERVER %s myRole", formatStr));
2800 ParserError(String.format(
"%s ALL ON URI foo %s myRole", formatStr));
2801 ParserError(String.format(
"%s ALL ON DATABASE 'foo' %s myRole", formatStr));
2802 ParserError(String.format(
"%s ALL ON TABLE 'foo' %s myRole", formatStr));
2805 ParserError(String.format(
"GRANT ALL ON TABLE FROM myrole", formatStr));
2806 ParserError(String.format(
"GRANT ALL ON DATABASE FROM myrole", formatStr));
2807 ParserError(String.format(
"GRANT ALL ON URI FROM myrole", formatStr));
2810 ParserError(String.format(
"%s ALL ON TABLE foo %s", formatStr));
2812 ParserError(String.format(
"%s FAKE ON TABLE foo %s myRole", formatStr));
2814 ParsesOk(
"GRANT ALL ON TABLE foo TO myRole WITH GRANT OPTION");
2815 ParsesOk(
"GRANT ALL ON DATABASE foo TO myRole WITH GRANT OPTION");
2816 ParsesOk(
"GRANT ALL ON SERVER TO myRole WITH GRANT OPTION");
2817 ParsesOk(
"GRANT ALL ON URI '/abc/' TO myRole WITH GRANT OPTION");
2818 ParserError(
"GRANT ALL ON TABLE foo TO myRole WITH GRANT");
2819 ParserError(
"GRANT ALL ON TABLE foo TO myRole WITH");
2823 ParsesOk(
"REVOKE GRANT OPTION FOR ALL ON TABLE foo FROM myRole");
2824 ParsesOk(
"REVOKE GRANT OPTION FOR ALL ON DATABASE foo FROM myRole");
2825 ParsesOk(
"REVOKE GRANT OPTION FOR ALL ON SERVER FROM myRole");
2826 ParsesOk(
"REVOKE GRANT OPTION FOR ALL ON URI '/abc/' FROM myRole");
2827 ParserError(
"REVOKE GRANT OPTION ALL ON URI '/abc/' FROM myRole");
2828 ParserError(
"REVOKE GRANT ALL ON URI '/abc/' FROM myRole");
2833 ParserError(
"GRANT ALL ON TABLE foo FROM myrole");
2841 ParsesOk(
"SHOW ROLE GRANT GROUP myGroup");
2855 ParsesOk(
"SHOW GRANT ROLE foo ON SERVER");
2856 ParsesOk(
"SHOW GRANT ROLE foo ON DATABASE foo");
2857 ParsesOk(
"SHOW GRANT ROLE foo ON TABLE foo");
2858 ParsesOk(
"SHOW GRANT ROLE foo ON TABLE foo.bar");
2859 ParsesOk(
"SHOW GRANT ROLE foo ON URI '/abc/123'");
2870 ParsesOk(
"COMPUTE STATS functional.alltypes");
2872 ParserError(
"COMPUTE STATS ON functional.alltypes");
2878 ParsesOk(
"COMPUTE INCREMENTAL STATS functional.alltypes");
2879 ParserError(
"COMPUTE INCREMENTAL functional.alltypes");
2882 "COMPUTE INCREMENTAL STATS functional.alltypes PARTITION(month=10, year=2010)");
2884 ParserError(
"COMPUTE INCREMENTAL STATS functional.alltypes PARTITION(month, year)");
2888 ParsesOk(
"DROP INCREMENTAL STATS functional.alltypes PARTITION(month=10, year=2010)");
2889 ParserError(
"DROP INCREMENTAL STATS functional.alltypes PARTITION(month, year)");
2890 ParserError(
"DROP INCREMENTAL STATS functional.alltypes");
2900 "Syntax error in line 1:\n" +
2901 "SELECT 1; SELECT 2;\n" +
2903 "Encountered: SELECT\n" +
2906 ParsesOk(
"SELECT 1 FROM functional.alltypestiny WHERE 1 = (SELECT 1);");
2907 ParserError(
"SELECT 1 FROM functional.alltypestiny WHERE 1 = (SELECT 1;)",
2909 ParserError(
"SELECT 1 FROM functional.alltypestiny WHERE 1 = (SELECT 1;);",
2911 ParsesOk(
"CREATE TABLE functional.test_table (col INT);");
2912 ParsesOk(
"DESCRIBE functional.alltypes;");
void TestCompoundPredicates()
void TestSinglelineComment()
void TestCreateTableAsSelect()
void TestInsertHints(String stmt, String...expectedHints)
void ParserError(String stmt, String expectedErrorString)
List< TableRef > getTableRefs()
Object ParsesOk(String stmt)
void ParserError(String stmt)
void TestVariadicCreateFunctions()
void TestCreateDropRole()
void TestAggregateExprs()
void TestFunctionCallExprs()
void TestConditionalExprs()
void TestAlterTableDropPartition()
void TestNumericLiteralMinMaxValues()
void TestMultilineComment()
void TestGrantRevokeRole()
void TestAlterTableOrViewRename()
void TestComputeStatsIncremental()
void TestCreateAggregate()
void TestCreateDatabase()
void TestSelectListHints(String stmt, String...expectedHints)
void TestGrantRevokePrivilege()
static final String[] operands_
void TestTimestampArithmeticExprs()
void TestAlterTableChangeColumn()
public< C extends Expr > Object ParsesOk(String selectStmtSql, Class< C > cl)
void TestShowCreateTable()
void TestBetweenPredicate()
uint64_t Test(T *ht, const ProbeTuple *input, uint64_t num_tuples)
void TestCreateFunction()
void TestAlterTableAddReplaceColumns()
void TestComputeDropStats()
void TestAlterTableDropColumn()
void TestArithmeticExprs()
void testStringLiteral(String s)
void TypeDefsError(String...typeDefs)
void TestJoinHints(String stmt, String...expectedHints)
void TestCreateDataSource()
void TestAlterTableAddPartition()
void testLiteralTruthValues(String andStr, String orStr, String notStr)
void TypeDefsParseOk(String...typeDefs)
void TestDropDataSource()
void testCompoundPredicates(String andStr, String orStr, String notStr)