15 package com.cloudera.impala.analysis;
17 import static org.junit.Assert.assertEquals;
18 import static org.junit.Assert.fail;
20 import java.lang.reflect.Field;
21 import java.util.List;
23 import junit.framework.Assert;
31 import com.google.common.base.Preconditions;
32 import com.google.common.collect.ImmutableList;
33 import com.google.common.collect.Lists;
46 TblsAnalyzeOk(String.format(
"select %s from $TBL, allcomplextypes.%s",
47 collectionField, collectionTable), tbl);
49 TblsAnalyzeOk(String.format(
"select %s from $TBL, functional.allcomplextypes.%s",
50 collectionField, collectionTable), tbl);
53 collectionField, collectionTable), tbl);
56 TblsAnalyzeOk(String.format(
"select b.%s from $TBL a, a.%s b, a.int_map_col c",
57 collectionField, collectionTable), tbl);
58 TblsAnalyzeOk(String.format(
"select c.%s from $TBL a, a.int_array_col b, a.%s c",
59 collectionField, collectionTable), tbl);
63 if (joinOp.isNullAwareLeftAntiJoin())
continue;
64 TblsAnalyzeOk(String.format(
"select 1 from $TBL %s allcomplextypes.%s",
65 joinOp, collectionTable), tbl);
67 joinOp, collectionTable), tbl);
71 TblsAnalyzeOk(String.format(
"select %s from $TBL a, functional.allcomplextypes.%s",
72 collectionField, collectionTable), tbl);
73 TblsAnalyzeOk(String.format(
"select %s from $TBL.%s, functional.allcomplextypes",
74 collectionField, collectionTable), tbl);
75 TblsAnalyzeOk(String.format(
"select %s from functional.allcomplextypes a, $TBL.%s",
76 collectionField, collectionTable), tbl);
77 TblsAnalyzeOk(String.format(
"select %s from functional.allcomplextypes.%s, $TBL",
78 collectionField, collectionTable), tbl);
81 if (joinOp.isNullAwareLeftAntiJoin()
82 || joinOp.isCrossJoin()
83 || joinOp.isInnerJoin()) {
87 "select 1 from functional.allcomplextypes.%s %s functional.allcomplextypes",
88 collectionTable, joinOp),
89 String.format(
"%s requires an ON or USING clause", joinOp));
94 collectionField, collectionTable), tbl,
95 "Duplicate table alias: 'a'");
97 collectionField, collectionTable, collectionTable), tbl,
98 "Duplicate table alias: 'b'");
100 String[] childTblPath = collectionTable.split(
"\\.");
101 String childTblAlias = childTblPath[childTblPath.length - 1];
103 collectionField, collectionTable, collectionTable), tbl,
104 String.format(
"Duplicate table alias: '%s'", childTblAlias));
106 "select 1 from $TBL, allcomplextypes.%s, functional.allcomplextypes.%s",
107 collectionTable, collectionTable), tbl,
108 String.format(
"Duplicate table alias: '%s'", childTblAlias));
111 "select %s from $TBL, functional.allcomplextypes.%s allcomplextypes",
112 collectionField, collectionTable), tbl,
113 "Duplicate table alias: 'allcomplextypes'");
117 "select %s from allcomplextypes, %s", collectionField, collectionTable),
119 String.format(
"Could not resolve table reference: '%s'", collectionTable));
121 "select %s from functional.allcomplextypes, %s",
122 collectionField, collectionTable),
123 String.format(
"Could not resolve table reference: '%s'", collectionTable));
127 "select %s from functional.allcomplextypes, " +
128 "functional_parquet.allcomplextypes, allcomplextypes.%s",
129 collectionField, collectionTable),
130 "Unqualified table alias is ambiguous: 'allcomplextypes'");
134 return tableName.split(
"\\.").length > 0;
144 for (String tbl: tables) {
146 String uqAlias = tbl.substring(tbl.lastIndexOf(
".") + 1);
147 String fqAlias =
"functional." + tbl;
151 for (String col: columns) {
153 TblsAnalyzeOk(String.format(
"select %s from $TBL", col), tblName);
154 TblsAnalyzeOk(String.format(
"select %s.%s from $TBL", uqAlias, col), tblName);
156 if (!isCollectionTblRef) {
157 TblsAnalyzeOk(String.format(
"select %s.%s from $TBL", fqAlias, col), tblName);
161 TblsAnalyzeOk(String.format(
"select %s from $TBL a", col), tblName);
162 TblsAnalyzeOk(String.format(
"select a.%s from $TBL a", col), tblName);
164 String errRefStr =
"column/field reference";
165 if (col.endsWith(
"*")) errRefStr =
"star expression";
168 uqAlias, col, tbl), tblName,
169 String.format(
"Could not resolve %s: '%s.%s'",
170 errRefStr, uqAlias, col));
172 fqAlias, col, tbl), tblName,
173 String.format(
"Could not resolve %s: '%s.%s'",
174 errRefStr, fqAlias, col));
179 for (String t1: tables) {
180 for (String t2: tables) {
181 if (t1.equals(t2))
continue;
184 for (String col: columns) {
186 "select functional.%s.%s, functional.%s.%s " +
187 "from functional.%s, functional.%s", t1, col, t2, col, t1, t2));
192 String col = columns[0];
193 for (String tbl: tables) {
197 "Could not resolve column/field reference: 'alltypessmall.int_col'");
200 String.format(
"select a.%s from $TBL a, functional.testtbl a", col),
201 tblName,
"Duplicate table alias");
204 "Duplicate table alias");
206 String uqAlias = tbl.substring(tbl.lastIndexOf(
".") + 1);
208 "select %s.%s from $TBL, functional.testtbl %s", tbl, col, uqAlias), tblName,
209 "Duplicate table alias");
217 "allcomplextypes.int_array_col"},
220 "allcomplextypes.struct_array_col"},
221 new String[] {
"f1",
"f2",
"*"});
225 "allcomplextypes.int_map_col"},
228 "allcomplextypes.struct_map_col"},
233 "allcomplextypes.complex_nested_struct_col.f2.f12"},
243 AnalysisError(
"select 1 from functional.allcomplextypes a, a",
244 "Illegal table reference to non-collection type: 'a'");
247 AnalysisError(
"select 1 from functional.allcomplextypes.int_struct_col",
248 "Illegal table reference to non-collection type: " +
249 "'functional.allcomplextypes.int_struct_col'\n" +
250 "Path resolved to type: STRUCT<f1:INT,f2:INT>");
251 AnalysisError(
"select 1 from functional.allcomplextypes a, a.int_struct_col",
252 "Illegal table reference to non-collection type: 'a.int_struct_col'\n" +
253 "Path resolved to type: STRUCT<f1:INT,f2:INT>");
254 AnalysisError(
"select 1 from functional.allcomplextypes.int_array_col.item",
255 "Illegal table reference to non-collection type: " +
256 "'functional.allcomplextypes.int_array_col.item'\n" +
257 "Path resolved to type: INT");
258 AnalysisError(
"select 1 from functional.allcomplextypes.int_array_col a, a.pos",
259 "Illegal table reference to non-collection type: 'a.pos'\n" +
260 "Path resolved to type: BIGINT");
261 AnalysisError(
"select 1 from functional.allcomplextypes.int_map_col.key",
262 "Illegal table reference to non-collection type: " +
263 "'functional.allcomplextypes.int_map_col.key'\n" +
264 "Path resolved to type: STRING");
265 AnalysisError(
"select 1 from functional.allcomplextypes.int_map_col a, a.key",
266 "Illegal table reference to non-collection type: 'a.key'\n" +
267 "Path resolved to type: STRING");
271 if (joinOp.isNullAwareLeftAntiJoin())
continue;
273 "select 1 from functional.allcomplextypes a %s a.int_array_col b", joinOp));
275 "select 1 from functional.allcomplextypes a %s a.struct_array_col b", joinOp));
277 "select 1 from functional.allcomplextypes a %s a.int_map_col b", joinOp));
279 "select 1 from functional.allcomplextypes a %s a.struct_map_col", joinOp));
285 String[] tables =
new String[] {
"alltypes",
"alltypes_view" };
286 String[] columns =
new String[] {
"int_col",
"*" };
290 AnalyzesOk(
"select * from functional.alltypes " +
291 "cross join functional_parquet.alltypes");
295 "cross join functional_parquet.alltypes",
296 "Column/field reference is ambiguous: 'int_col'");
298 AnalysisError(
"select alltypes.int_col from functional.alltypes " +
299 "cross join functional_parquet.alltypes",
300 "Unqualified table alias is ambiguous: 'alltypes'");
301 AnalysisError(
"select alltypes.* from functional.alltypes " +
302 "cross join functional_parquet.alltypes",
303 "Unqualified table alias is ambiguous: 'alltypes'");
308 AnalysisError(
"select alltypes.smallint_col, functional.alltypes.int_col " +
309 "from alltypes inner join functional.alltypes " +
310 "on (alltypes.id = functional.alltypes.id)",
312 "Duplicate table alias: 'functional.alltypes'");
319 private List<Integer>
path(Integer... p) {
return Lists.newArrayList(p); }
330 Preconditions.checkState(e instanceof
SlotRef);
332 List<Integer> actualPhysPath = slotRef.getDesc().getAbsolutePath();
333 Assert.assertTrue(String.format(
"Expected path: %s\nActual path:%s",
334 expectedPhysPath, actualPhysPath),
335 actualPhysPath.equals(expectedPhysPath));
343 private void testStarPath(String sql, List<Integer>... expectedPhysPaths) {
345 List<List<Integer>> actualPaths = Lists.newArrayList();
346 for (
int i = 0; i < stmt.getResultExprs().size(); ++i) {
347 Expr e = stmt.getResultExprs().
get(i);
348 Preconditions.checkState(e instanceof
SlotRef);
350 actualPaths.add(slotRef.getDesc().getAbsolutePath());
352 List<List<Integer>> expectedPaths = Lists.newArrayList(expectedPhysPaths);
353 Assert.assertTrue(String.format(
"Expected paths: %s\nActual paths:%s",
354 expectedPaths, actualPaths),
355 actualPaths.equals(expectedPaths));
365 List<Integer> actualPhysPath = lastTblRef.getDesc().getPath().getAbsolutePath();
366 Assert.assertTrue(String.format(
"Expected path: %s\nActual path:%s",
367 expectedPhysPath, actualPhysPath),
368 actualPhysPath.equals(expectedPhysPath));
371 @SuppressWarnings(
"unchecked")
377 for (String field: implicitFieldNames) {
378 AnalysisError(String.format(
"select %s from functional.alltypes", field),
379 String.format(
"Could not resolve column/field reference: '%s'", field));
389 "Could not resolve column/field reference: 'item.item'");
391 "Could not resolve column/field reference: 'item.pos'");
398 addTestTable(
"create table d.t2 (c array<struct<f:int>>)");
403 "Expr 'item' in select list returns a complex type 'STRUCT<f:INT>'.\n" +
404 "Only scalar types are allowed in the select list.");
406 "Could not resolve column/field reference: 'item.pos'");
413 addTestTable(
"create table d.t3 (c array<struct<f:int,item:int,pos:int>>)");
420 "Expr 'item' in select list returns a complex type " +
421 "'STRUCT<f:INT,item:INT,pos:INT>'.\n" +
422 "Only scalar types are allowed in the select list.");
432 "Could not resolve column/field reference: 'value.value'");
439 addTestTable(
"create table d.t5 (c map<int,struct<f:int>>)");
444 "Could not resolve column/field reference: 'value.value'");
446 "Expr 'value' in select list returns a complex type " +
447 "'STRUCT<f:INT>'.\n" +
448 "Only scalar types are allowed in the select list.");
455 addTestTable(
"create table d.t6 (c map<int,struct<f:int,key:int,value:int>>)");
462 "Expr 'value' in select list returns a complex type " +
463 "'STRUCT<f:INT,key:INT,value:INT>'.\n" +
464 "Only scalar types are allowed in the select list.");
467 path(0, 0),
path(0, 1, 0),
path(0, 1, 1),
path(0, 1, 2));
469 path(0, 0),
path(0, 1, 0),
path(0, 1, 1),
path(0, 1, 2));
474 "c2 decimal(10, 4), " +
475 "c3 array<struct<a1:array<int>,a2:array<struct<x:int,y:int,a3:array<int>>>>>, " +
477 "c5 map<int,struct<m1:map<int,string>," +
478 " m2:map<int,struct<x:int,y:int,m3:map<int,int>>>>>)");
496 path(2, 0, 1, 0, 2));
500 testSlotRefPath(
"select a1.item from d.t7, t7.c3, c3.a1, c3.a2, a2.a3",
522 path(4, 1, 1, 1, 2, 1));
526 path(4, 1, 1, 1, 2));
528 path(4, 1, 1, 1, 1));
530 path(4, 1, 1, 1, 0));
532 path(4, 1, 1, 1, 1));
539 String[] tables =
new String[] {
"allcomplextypes" };
540 String[] columns =
new String[] {
"id",
"int_struct_col.f1",
541 "nested_struct_col.f2.f12.f21" };
545 AnalysisError(
"select nested_struct_col.badfield from functional.allcomplextypes",
546 "Could not resolve column/field reference: 'nested_struct_col.badfield'");
547 AnalysisError(
"select nested_struct_col.f2.badfield from functional.allcomplextypes",
548 "Could not resolve column/field reference: 'nested_struct_col.f2.badfield'");
549 AnalysisError(
"select nested_struct_col.badfield.f2 from functional.allcomplextypes",
550 "Could not resolve column/field reference: 'nested_struct_col.badfield.f2'");
553 AnalysisError(
"select int_array_col.item from functional.allcomplextypes",
554 "Illegal column/field reference 'int_array_col.item' with intermediate " +
555 "collection 'int_array_col' of type 'ARRAY<INT>'");
556 AnalysisError(
"select struct_array_col.f1 from functional.allcomplextypes",
557 "Illegal column/field reference 'struct_array_col.f1' with intermediate " +
558 "collection 'struct_array_col' of type 'ARRAY<STRUCT<f1:BIGINT,f2:STRING>>'");
559 AnalysisError(
"select int_map_col.key from functional.allcomplextypes",
560 "Illegal column/field reference 'int_map_col.key' with intermediate " +
561 "collection 'int_map_col' of type 'MAP<STRING,INT>'");
562 AnalysisError(
"select struct_map_col.f1 from functional.allcomplextypes",
563 "Illegal column/field reference 'struct_map_col.f1' with intermediate " +
564 "collection 'struct_map_col' of type 'MAP<STRING,STRUCT<f1:BIGINT,f2:STRING>>'");
566 "select complex_nested_struct_col.f2.f11 from functional.allcomplextypes",
567 "Illegal column/field reference 'complex_nested_struct_col.f2.f11' with " +
568 "intermediate collection 'f2' of type " +
569 "'ARRAY<STRUCT<f11:BIGINT,f12:MAP<STRING,STRUCT<f21:BIGINT>>>>'");
571 "select complex_nested_struct_col.f2.f11 from functional.allcomplextypes",
572 "Illegal column/field reference 'complex_nested_struct_col.f2.f11' with " +
573 "intermediate collection 'f2' of type " +
574 "'ARRAY<STRUCT<f11:BIGINT,f12:MAP<STRING,STRUCT<f21:BIGINT>>>>'");
580 addTestTable(
"create table a.a (a struct<a:struct<a:int>>)");
588 "Expr 'a' in select list returns a complex type 'STRUCT<a:STRUCT<a:INT>>'.\n" +
589 "Only scalar types are allowed in the select list.");
591 "Expr 't.a' in select list returns a complex type 'STRUCT<a:STRUCT<a:INT>>'.\n" +
592 "Only scalar types are allowed in the select list.");
594 "Expr 't.a.a' in select list returns a complex type 'STRUCT<a:INT>'.\n" +
595 "Only scalar types are allowed in the select list.");
601 "Column/field reference is ambiguous: 'a.a'");
603 "Column/field reference is ambiguous: 'a.a.a'");
605 "Column/field reference is ambiguous: 'a.a.a.a'");
609 "Could not resolve column/field reference: 'a.a.a.a.a.a'");
611 "Could not resolve column/field reference: 't.a.a.a.a'");
615 addTestTable(
"create table a.array_test (a array<int>)");
616 addTestTable(
"create table a.map_test (a map<int, int>)");
617 AnalyzesOk(
"select a.item from a.array_test t, t.a");
618 AnalyzesOk(
"select a.key, a.value from a.map_test t, t.a");
624 addTestTable(
"create table a.a (a struct<a:struct<a:int>>)");
632 "Cannot expand star in 'a.a.a.a.a.*' because path 'a.a.a.a.a' " +
633 "resolved to type 'INT'.");
635 "Cannot expand star in 't.a.a.a.*' because path 't.a.a.a' " +
636 "resolved to type 'INT'.");
638 "Expr 't.a' in select list returns a complex type 'STRUCT<a:STRUCT<a:INT>>'.\n" +
639 "Only scalar types are allowed in the select list.");
643 "Star expression is ambiguous: 'a.*'");
645 "Star expression is ambiguous: 'a.a.*'");
647 "Star expression is ambiguous: 'a.a.a.*'");
651 "Could not resolve star expression: 'a.a.a.a.a.a.*'");
653 "Could not resolve star expression: 't.a.a.a.a.*'");
657 addTestTable(
"create table a.array_test (a array<int>)");
658 addTestTable(
"create table a.map_test (a map<int, int>)");
659 AnalyzesOk(
"select a.* from a.array_test t, t.a");
660 AnalyzesOk(
"select a.* from a.map_test t, t.a");
666 addTestTable(
"create table a.a (a array<struct<a:array<int>>>)");
677 "Table reference is ambiguous: 'a.a'");
679 "Table reference is ambiguous: 'a.a.a'");
682 addTestTable(
"create table a.t1 (x array<struct<y:array<int>>>)");
685 "Table reference is ambiguous: 'a.x.y'");
690 AnalyzesOk(
"select int_col from functional.alltypes");
692 "Could not resolve table reference: 'badtbl'");
695 AnalyzesOk(
"SELECT INT_COL FROM FUNCTIONAL.ALLTYPES");
696 AnalyzesOk(
"SELECT INT_COL FROM functional.alltypes");
697 AnalyzesOk(
"SELECT INT_COL FROM functional.aLLTYPES");
698 AnalyzesOk(
"SELECT INT_COL FROM Functional.ALLTYPES");
699 AnalyzesOk(
"SELECT INT_COL FROM FUNCTIONAL.ALLtypes");
700 AnalyzesOk(
"SELECT INT_COL FROM FUNCTIONAL.alltypes");
701 AnalyzesOk(
"select functional.AllTypes.Int_Col from functional.alltypes");
707 AnalyzesOk(
"select 1 + 1, -128, 'two', 1.28");
708 AnalyzesOk(
"select -1, 1 - 1, 10 - -1, 1 - - - 1");
709 AnalyzesOk(
"select -1.0, 1.0 - 1.0, 10.0 - -1.0, 1.0 - - - 1.0");
710 AnalysisError(
"select a + 1",
"Could not resolve column/field reference: 'a'");
722 AnalyzesOk(
"select int_col is not null from functional.alltypes");
727 AnalyzesOk(
"select * from functional.AllTypes");
728 AnalyzesOk(
"select functional.alltypes.* from functional.AllTypes");
730 AnalyzesOk(
"select functional_seq.alltypes.* from functional_seq.alltypes");
732 AnalyzesOk(
"select functional.alltypes.*, functional_seq.alltypes.* " +
733 "from functional.alltypes, functional_seq.alltypes");
734 AnalyzesOk(
"select * from functional.alltypes, functional_seq.alltypes");
736 AnalyzesOk(
"select int_struct_col.* from functional.allcomplextypes");
737 AnalyzesOk(
"select a.int_struct_col.* from functional.allcomplextypes a");
738 AnalyzesOk(
"select allcomplextypes.int_struct_col.* from functional.allcomplextypes");
739 AnalyzesOk(
"select functional.allcomplextypes.int_struct_col.* " +
740 "from functional.allcomplextypes");
743 AnalysisError(
"select *",
"'*' expression in select list requires FROM clause.");
745 "'*' expression in select list requires FROM clause.");
746 AnalysisError(
"select a.*",
"Could not resolve star expression: 'a.*'");
749 AnalysisError(
"select functional.* from functional.alltypes",
750 "Could not resolve star expression: 'functional.*'");
752 "Cannot expand star in 'int_col.*' because " +
753 "path 'int_col' resolved to type 'INT'.\n" +
754 "Star expansion is only valid for paths to a struct type.");
755 AnalysisError(
"select complex_struct_col.f2.* from functional.allcomplextypes",
756 "Cannot expand star in 'complex_struct_col.f2.*' because " +
757 "path 'complex_struct_col.f2' resolved to type 'ARRAY<INT>'.\n" +
758 "Star expansion is only valid for paths to a struct type.");
760 for (String joinType:
new String[] {
"left semi join",
"left anti join" }) {
763 "select * from functional.alltypes a " +
764 "%s functional.testtbl b on (a.id = b.id)", joinType));
769 AnalysisError(String.format(
"select a.*, b.* from functional.alltypes a " +
770 "%s functional.alltypes b on (a.id = b.id)", joinType),
771 "Illegal star expression 'b.*' of semi-/anti-joined table 'b'");
773 for (String joinType:
new String[] {
"right semi join",
"right anti join" }) {
776 "select * from functional.alltypes a " +
777 "%s functional.testtbl b on (a.id = b.id)", joinType));
782 AnalysisError(String.format(
"select a.*, b.* from functional.alltypes a " +
783 "%s functional.alltypes b on (a.id = b.id)", joinType),
784 "Illegal star expression 'a.*' of semi-/anti-joined table 'a'");
794 AnalysisError(
"select int_struct_col from functional.allcomplextypes",
795 "Expr 'int_struct_col' in select list returns a " +
796 "complex type 'STRUCT<f1:INT,f2:INT>'.\n" +
797 "Only scalar types are allowed in the select list.");
799 AnalysisError(
"select int_struct_col from functional.allcomplextypes " +
800 "union all select int_struct_col from functional.allcomplextypes",
801 "Expr 'int_struct_col' in select list returns a " +
802 "complex type 'STRUCT<f1:INT,f2:INT>'.\n" +
803 "Only scalar types are allowed in the select list.");
806 "(select int_struct_col from functional.allcomplextypes) v",
807 "Expr 'int_struct_col' in select list returns a " +
808 "complex type 'STRUCT<f1:INT,f2:INT>'.\n" +
809 "Only scalar types are allowed in the select list.");
812 "select int_struct_col from functional.allcomplextypes",
813 "Expr 'int_struct_col' in select list returns a " +
814 "complex type 'STRUCT<f1:INT,f2:INT>'.\n" +
815 "Only scalar types are allowed in the select list.");
818 "select int_struct_col from functional.allcomplextypes",
819 "Expr 'int_struct_col' in select list returns a " +
820 "complex type 'STRUCT<f1:INT,f2:INT>'.\n" +
821 "Only scalar types are allowed in the select list.");
824 "cross join functional_parquet.alltypes",
825 "Expr 'functional.allcomplextypes.int_array_col' in select list returns a " +
826 "complex type 'ARRAY<INT>'.\n" +
827 "Only scalar types are allowed in the select list.");
828 AnalysisError(
"select complex_struct_col.* from functional.allcomplextypes",
829 "Expr 'functional.allcomplextypes.complex_struct_col.f2' in select list " +
830 "returns a complex type 'ARRAY<INT>'.\n" +
831 "Only scalar types are allowed in the select list.");
836 AnalysisError(
"select * from functional.alltypes group by 1",
837 "cannot combine '*' in select list with GROUP BY");
838 AnalysisError(
"select * from functional.alltypes order by 14",
839 "ORDER BY: ordinal exceeds number of items in select list: 14");
840 AnalyzesOk(
"select t.* from functional.alltypes t order by 1");
841 AnalyzesOk(
"select t2.* from functional.alltypes t1, " +
842 "functional.alltypes t2 order by 1");
843 AnalyzesOk(
"select * from (select max(id) from functional.testtbl) t1 order by 1");
844 AnalysisError(
"select * from (select max(id) from functional.testtbl) t1 order by 2",
845 "ORDER BY: ordinal exceeds number of items in select list: 2");
850 AnalyzesOk(
"select y x from (select id y from functional_hbase.alltypessmall) a");
851 AnalyzesOk(
"select id from (select id from functional_hbase.alltypessmall) a");
852 AnalyzesOk(
"select * from (select id+2 from functional_hbase.alltypessmall) a");
854 "(select c t1 from (select id c from functional_hbase.alltypessmall) t1) a");
855 AnalysisError(
"select id from (select id+2 from functional_hbase.alltypessmall) a",
856 "Could not resolve column/field reference: 'id'");
857 AnalyzesOk(
"select a.* from (select id+2 from functional_hbase.alltypessmall) a");
860 AnalyzesOk(
"select * from (select id+2 id from functional_hbase.alltypessmall) a " +
861 "join (select * from functional.AllTypes where true) b");
862 AnalyzesOk(
"select a.x from (select count(id) x from functional.AllTypes) a");
863 AnalyzesOk(
"select a.* from (select count(id) from functional.AllTypes) a");
864 AnalysisError(
"select a.id from (select id y from functional_hbase.alltypessmall) a",
865 "Could not resolve column/field reference: 'a.id'");
866 AnalyzesOk(
"select * from (select * from functional.AllTypes) a where year = 2009");
867 AnalyzesOk(
"select * from (select * from functional.alltypesagg) a right outer join" +
868 " (select * from functional.alltypessmall) b using (id, int_col) " +
869 " where a.day >= 6 and b.month > 2 and a.tinyint_col = 15 and " +
870 " b.string_col = '15' and a.tinyint_col + b.tinyint_col < 15");
871 AnalyzesOk(
"select * from (select a.smallint_col+b.smallint_col c1" +
872 " from functional.alltypesagg a join functional.alltypessmall b " +
873 " using (id, int_col)) x " +
874 " where x.c1 > 100");
876 " (select * from (select id+2 from functional_hbase.alltypessmall) b) a");
878 "(select * from functional.alltypes a join " +
879 "functional.alltypes b on (a.int_col = b.int_col)) x",
880 "duplicated inline view column alias: 'id' in inline view 'x'");
884 " from functional.alltypessmall c join " +
885 " (select a.smallint_col smallint_col, a.tinyint_col tinyint_col, " +
886 " a.int_col int_col, b.float_col float_col" +
887 " from (select * from functional.alltypesagg a where month=1) a join " +
888 " functional.alltypessmall b on (a.smallint_col = b.id)) x " +
889 " on (x.tinyint_col = c.id)");
892 AnalyzesOk(
"select count(*) from (select count(id) from " +
893 "functional.AllTypes group by id) a");
894 AnalyzesOk(
"select count(a.x) from (select id+2 x " +
895 "from functional_hbase.alltypessmall) a");
897 " from (select * from functional.testtbl) x " +
898 " group by zip, id having count(*) > 0) x");
900 AnalysisError(
"select zip + count(*) from functional.testtbl",
901 "select list expression not produced by aggregation output " +
902 "(missing from GROUP BY clause?)");
906 "(select rank() over(order by string_col) from functional.alltypes " +
908 " select tinyint_col from functional.alltypessmall) a");
910 "(select int_col from functional.alltypes " +
912 " select tinyint_col from functional.alltypessmall) a " +
914 "select smallint_col from functional.alltypes");
916 "(select int_col from functional.alltypes " +
918 " select b.smallint_col from " +
919 " (select smallint_col from functional.alltypessmall" +
921 " select tinyint_col from functional.alltypes) b) a");
924 "(select int_col from functional.alltypes " +
926 " select tinyint_col from functional.alltypessmall) a",
927 "Could not resolve column/field reference: 'tinyint_col'");
931 "(select id, zip from functional.testtbl group by id having count(*) > 0) x",
932 "select list expression not produced by aggregation output " +
933 "(missing from GROUP BY clause?)");
935 "(select id from functional.testtbl group by id having zip + count(*) > 0) x",
936 "HAVING clause not produced by aggregation output " +
937 "(missing from GROUP BY clause?)");
939 "(select zip, count(*) from functional.testtbl group by 3) x",
940 "GROUP BY: ordinal exceeds number of items in select list");
942 "(select * from functional.alltypes group by 1) x",
943 "cannot combine '*' in select list with GROUP BY");
945 "(select zip, count(*) from functional.testtbl group by count(*)) x",
946 "GROUP BY expression must not contain aggregate functions");
948 "(select zip, count(*) from functional.testtbl group by count(*) + min(zip)) x",
949 "GROUP BY expression must not contain aggregate functions");
951 "(select zip, count(*) from functional.testtbl group by 2) x",
952 "GROUP BY expression must not contain aggregate functions");
955 AnalyzesOk(
"select * from (select zip, count(*) " +
956 " from (select * from functional.testtbl) x " +
957 " group by 1 order by count(*) + min(zip) limit 5) x");
958 AnalyzesOk(
"select * from (select zip, count(*) " +
959 " from (select * from functional.testtbl) x " +
960 " group by 1 order by count(*) + min(zip)) x");
962 " from (select * from functional.testtbl) x " +
963 " group by 1 offset 5) x",
964 "OFFSET requires an ORDER BY clause: OFFSET 5");
966 " from (select * from functional.testtbl) x " +
967 " group by 1 order by count(*) + min(zip) offset 5) x",
968 "Order-by with offset without limit not supported in nested queries");
969 AnalyzesOk(
"select c1, c2 from (select zip c1 , count(*) c2 " +
970 " from (select * from functional.testtbl) x group by 1) x " +
971 " order by 2, 1 limit 5");
972 AnalyzesOk(
"select c1, c2 from (select zip c1 , count(*) c2 " +
973 " from (select * from functional.testtbl) x group by 1) x " +
975 AnalyzesOk(
"select c1, c2 from (select zip c1 , count(*) c2 " +
976 " from (select * from functional.testtbl) x group by 1) x " +
977 " order by 2, 1 offset 5");
983 AnalyzesOk(
"select `int_col * 1`, a, int_col, `NOT bool_col` from " +
984 "(select int_col * 1, int_col as a, int_col, !bool_col, concat(string_col) " +
985 "from functional.alltypes) t");
987 AnalyzesOk(
"select _c0, a, int_col, _c3 from " +
988 "(select int_col * 1, int_col as a, int_col, !bool_col, concat(string_col) " +
991 AnalyzesOk(
"select _c0, count(a), count(int_col), _c3 from " +
992 "(select int_col * 1, int_col as a, int_col, !bool_col, concat(string_col) " +
993 "from functional.alltypes) t group by _c0, _c3 order by _c0 limit 10",
996 AnalyzesOk(
"select x.front, x._c1, x._c2 from " +
997 "(select y.back as front, y._c0 * 10, y._c2 + 2 from " +
998 "(select int_col * 10, int_col as back, int_col + 2 from " +
999 "functional.alltypestiny) y) x",
1004 "(select int_col * 2, id from functional.alltypes) a inner join " +
1005 "(select int_col + 6, id from functional.alltypes) b " +
1008 "Column/field reference is ambiguous: '_c0'");
1011 "(select int_col * 1, int_col as a, int_col, !bool_col, concat(string_col) " +
1012 "from functional.alltypes) t",
1014 "Could not resolve column/field reference: '_c2'");
1018 "FROM functional.decimal_tbl AS t1 LEFT JOIN " +
1019 "(SELECT SUM(t1.d2) - SUM(t1.d3) as double_col_3, " +
1020 "SUM(t1.d2) IS NULL " +
1021 "FROM functional.decimal_tbl AS t1) AS t3 " +
1022 "ON t3.double_col_3 = t1.d3");
1026 AnalyzesOk(
"select 1 from functional.alltypes a left outer join " +
1027 "(select id, upper(decode(string_col, NULL, date_string_col)) " +
1028 "from functional.alltypes) v on (a.id = v.id)");
1032 "(select id y from functional.alltypestiny where id in " +
1033 "(select id from functional.alltypessmall)) a");
1039 "select a.int_col from functional.alltypes a " +
1040 "join functional.alltypes b on (a.int_col = b.int_col)");
1042 "select a.int_col " +
1043 "from functional.alltypes a join functional.alltypes b on " +
1044 "(a.int_col = b.int_col and a.string_col = b.string_col)");
1046 "select a.int_col from functional.alltypes a " +
1047 "join functional.alltypes b on (a.bool_col)");
1049 "select a.int_col from functional.alltypes a " +
1050 "join functional.alltypes b on (NULL)");
1052 AnalyzesOk(
"select a.int_col from functional.alltypes a join functional.alltypes b");
1055 "select a.int_col from functional.alltypes a " +
1056 "join functional.alltypes b on trim(a.string_col)",
1057 "ON clause 'trim(a.string_col)' requires return type 'BOOLEAN'. " +
1058 "Actual type is 'STRING'.");
1060 "select a.int_col from functional.alltypes a " +
1061 "join functional.alltypes b on a.int_col * b.float_col",
1062 "ON clause 'a.int_col * b.float_col' requires return type 'BOOLEAN'. " +
1063 "Actual type is 'DOUBLE'.");
1066 "select a.int_col from functional.alltypes a " +
1067 "join functional.alltypes b on (a.bigint_col = sum(b.int_col))",
1068 "aggregate function not allowed in ON clause");
1070 "select a.int_col from functional.alltypes a " +
1071 "join functional.alltypes b on (a.bigint_col = " +
1072 "lag(b.int_col) over(order by a.bigint_col))",
1073 "analytic expression not allowed in ON clause");
1076 "select a.int_col from functional.alltypes a " +
1077 "join functional.alltypes b on (a.int_col = b.badcol)",
1078 "Could not resolve column/field reference: 'b.badcol'");
1081 "select a.int_col from functional.alltypes a " +
1082 "join functional.alltypes b on (int_col = int_col)",
1083 "Column/field reference is ambiguous: 'int_col'");
1086 "select a.int_col from functional.alltypes a join functional.alltypes b on " +
1087 "(a.int_col = badalias.int_col)",
1088 "Could not resolve column/field reference: 'badalias.int_col'");
1091 "select a.int_col from functional.alltypes a join " +
1092 "functional.alltypes b on a.bool_col = b.string_col",
1093 "operands of type BOOLEAN and STRING are not comparable: " +
1094 "a.bool_col = b.string_col");
1096 "select a.int_col, b.int_col, c.int_col " +
1097 "from functional.alltypes a join functional.alltypes b on " +
1098 "(a.int_col = b.int_col and a.string_col = b.string_col)" +
1099 "join functional.alltypes c on " +
1100 "(b.int_col = c.int_col and b.string_col = c.string_col " +
1101 "and b.bool_col = c.bool_col)");
1104 "select a.int_col, b.int_col, c.int_col " +
1105 "from functional.alltypes a join functional.alltypes b on " +
1106 "(c.int_col = b.int_col and a.string_col = b.string_col)" +
1107 "join functional.alltypes c on " +
1108 "(b.int_col = c.int_col and b.string_col = c.string_col " +
1109 "and b.bool_col = c.bool_col)",
1110 "Could not resolve column/field reference: 'c.int_col'");
1113 AnalyzesOk(
"select * from functional.alltypes a left outer join " +
1114 "functional.alltypes b on (a.id = b.id)");
1115 AnalyzesOk(
"select * from functional.alltypes a left outer join " +
1116 "functional.alltypes b using (id)");
1118 "left outer join functional.alltypes b",
1119 "LEFT OUTER JOIN requires an ON or USING clause");
1120 AnalyzesOk(
"select * from functional.alltypes a right outer join " +
1121 "functional.alltypes b on (a.id = b.id)");
1122 AnalyzesOk(
"select * from functional.alltypes a right outer join " +
1123 "functional.alltypes b using (id)");
1125 "right outer join functional.alltypes b",
1126 "RIGHT OUTER JOIN requires an ON or USING clause");
1127 AnalyzesOk(
"select * from functional.alltypes a full outer join " +
1128 "functional.alltypes b on (a.id = b.id)");
1129 AnalyzesOk(
"select * from functional.alltypes a full outer join " +
1130 "functional.alltypes b using (id)");
1131 AnalysisError(
"select * from functional.alltypes a full outer join " +
1132 "functional.alltypes b",
1133 "FULL OUTER JOIN requires an ON or USING clause");
1138 AnalyzesOk(
"select a.int_col, b.int_col from functional.alltypes a join " +
1139 "functional.alltypes b using (int_col)");
1140 AnalyzesOk(
"select a.int_col, b.int_col from " +
1141 "functional.alltypes a join functional.alltypes b " +
1142 "using (int_col, string_col)");
1144 "select a.int_col, b.int_col, c.int_col " +
1145 "from functional.alltypes a " +
1146 "join functional.alltypes b using (int_col, string_col) " +
1147 "join functional.alltypes c using (int_col, string_col, bool_col)");
1149 AnalysisError(
"select a.int_col from functional.alltypes a " +
1150 "join functional.alltypes b using (badcol)",
1151 "unknown column badcol for alias a");
1153 "select a.int_col from functional.alltypes a " +
1154 "join functional.alltypes b using (int_col, badcol)",
1155 "unknown column badcol for alias a ");
1164 for (String joinType:
new String[] {
"left semi join",
"left anti join" }) {
1166 AnalyzesOk(String.format(
"select a.id from functional.alltypes a " +
1167 "%s functional.alltypes b on (a.id = b.id)", joinType));
1168 AnalyzesOk(String.format(
"select a.id from functional.alltypes a " +
1169 "%s functional.alltypes b on (a.id = b.id) " +
1170 "%s functional.alltypes c on (a.id = c.id)", joinType, joinType));
1171 AnalyzesOk(String.format(
"select a.id from functional.alltypes a %s " +
1172 "functional.alltypes b using (id)", joinType));
1175 AnalyzesOk(String.format(
"select int_col from functional.alltypes a " +
1176 "%s functional.alltypes b on (a.id = b.id)", joinType));
1177 AnalysisError(String.format(
"select * from functional.alltypes a " +
1178 "%s functional.alltypes b on (a.id = b.id and a.int_col = int_col)", joinType),
1179 "Column/field reference is ambiguous: 'int_col'");
1181 AnalyzesOk(String.format(
"select int_col from functional.alltypes b " +
1182 "%s functional.alltypes a on (b.id = a.id)", joinType));
1183 AnalysisError(String.format(
"select * from functional.alltypes b " +
1184 "%s functional.alltypes a on (b.id = a.id and b.int_col = int_col)", joinType),
1185 "Column/field reference is ambiguous: 'int_col'");
1188 AnalyzesOk(String.format(
"select int_col from functional.alltypes c " +
1189 "%s functional.alltypes b on (c.id = b.id) " +
1190 "%s functional.jointbl a on (test_id = c.id)", joinType, joinType));
1191 AnalyzesOk(String.format(
"select int_col from functional.alltypes c " +
1192 "%s functional.alltypes b on (c.id = b.id) " +
1193 "%s functional.jointbl a on (test_id = id)", joinType, joinType));
1194 AnalysisError(String.format(
"select int_col from functional.alltypes c " +
1195 "%s functional.alltypes b on (c.id = b.id) " +
1196 "%s functional.jointbl a on (test_id = b.id)", joinType, joinType),
1197 "Illegal column/field reference 'b.id' of semi-/anti-joined table 'b'");
1199 AnalysisError(String.format(
"select a.id, b.id from functional.alltypes a " +
1200 "%s functional.alltypes b on (a.id = b.id)", joinType),
1201 "Illegal column/field reference 'b.id' of semi-/anti-joined table 'b'");
1202 AnalysisError(String.format(
"select a.id from functional.alltypes a " +
1203 "%s (select * from functional.alltypes) b " +
1204 "on (a.id = b.id) where b.int_col > 10", joinType),
1205 "Illegal column/field reference 'b.int_col' of semi-/anti-joined table 'b'");
1206 AnalysisError(String.format(
"select a.id from functional.alltypes a " +
1207 "%s functional.alltypes b on (a.id = b.id) group by b.bool_col", joinType),
1208 "Illegal column/field reference 'b.bool_col' of semi-/anti-joined table 'b'");
1209 AnalysisError(String.format(
"select a.id from functional.alltypes a " +
1210 "%s (select * from functional.alltypes) b " +
1211 "on (a.id = b.id) order by b.string_col", joinType),
1212 "Illegal column/field reference 'b.string_col' of " +
1213 "semi-/anti-joined table 'b'");
1215 AnalysisError(String.format(
"select a.id from functional.alltypes a " +
1216 "%s functional.alltypes b on (a.id = b.id)" +
1217 "left outer join functional.testtbl c on (b.id = c.id)", joinType),
1218 "Illegal column/field reference 'b.id' of semi-/anti-joined table 'b'");
1220 AnalysisError(String.format(
"select a.id from functional.alltypes a " +
1221 "%s functional.alltypes b on (a.id = b.id)" +
1222 "%s functional.testtbl c on (b.id = c.id)", joinType, joinType),
1223 "Illegal column/field reference 'b.id' of semi-/anti-joined table 'b'");
1225 AnalysisError(String.format(
"select a.id from functional.alltypes a " +
1226 "%s functional.alltypes b using(id) " +
1227 "%s functional.alltypes c using(int_col)", joinType, joinType),
1228 "Illegal column/field reference 'b.int_col' of semi-/anti-joined table 'b'");
1230 AnalysisError(String.format(
"select * from functional.alltypes a " +
1231 "%s functional.alltypes b on (a.id = b.id and a.int_col = int_col)", joinType),
1232 "Column/field reference is ambiguous: 'int_col'");
1234 AnalysisError(String.format(
"select test_id from functional.alltypes a " +
1235 "%s functional.jointbl b on (a.id = b.alltypes_id)", joinType),
1236 "Illegal column/field reference 'test_id' of semi-/anti-joined table 'b'");
1238 AnalysisError(String.format(
"select alltypes.int_col from functional.alltypes " +
1239 "%s functional_parquet.alltypes " +
1240 "on (functional.alltypes.id = functional_parquet.alltypes.id)", joinType),
1241 "Unqualified table alias is ambiguous: 'alltypes'");
1243 AnalysisError(String.format(
"select 1 from functional.allcomplextypes a " +
1244 "%s functional.allcomplextypes b on (a.id = b.id) " +
1245 "inner join b.int_array_col", joinType),
1246 "Illegal table reference 'b.int_array_col' of semi-/anti-joined table 'b'");
1251 for (String joinType:
new String[] {
"right semi join",
"right anti join" }) {
1253 AnalyzesOk(String.format(
"select b.id from functional.alltypes a " +
1254 "%s functional.alltypes b on (a.id = b.id)", joinType));
1255 AnalyzesOk(String.format(
"select c.id from functional.alltypes a " +
1256 "%s functional.alltypes b on (a.id = b.id) " +
1257 "%s functional.alltypes c on (b.id = c.id)", joinType, joinType));
1258 AnalyzesOk(String.format(
"select b.id from functional.alltypes a %s " +
1259 "functional.alltypes b using (id)", joinType));
1262 AnalyzesOk(String.format(
"select int_col from functional.alltypes a " +
1263 "%s functional.alltypes b on (a.id = b.id)", joinType));
1264 AnalysisError(String.format(
"select * from functional.alltypes a " +
1265 "%s functional.alltypes b on (a.id = b.id and a.int_col = int_col)", joinType),
1266 "Column/field reference is ambiguous: 'int_col'");
1268 AnalyzesOk(String.format(
"select int_col from functional.alltypes b " +
1269 "%s functional.alltypes a on (b.id = a.id)", joinType));
1270 AnalysisError(String.format(
"select * from functional.alltypes b " +
1271 "%s functional.alltypes a on (b.id = a.id and b.int_col = int_col)", joinType),
1272 "Column/field reference is ambiguous: 'int_col'");
1275 AnalyzesOk(String.format(
"select int_col from functional.jointbl c " +
1276 "%s functional.alltypes b on (test_id = b.id) " +
1277 "%s functional.alltypes a on (b.id = a.id)", joinType, joinType));
1278 AnalyzesOk(String.format(
"select int_col from functional.jointbl c " +
1279 "%s functional.alltypes b on (test_id = id) " +
1280 "%s functional.alltypes a on (b.id = a.id)", joinType, joinType));
1281 AnalysisError(String.format(
"select int_col from functional.jointbl c " +
1282 "%s functional.alltypes b on (test_id = a.id) " +
1283 "%s functional.alltypes a on (c.id = b.id)", joinType, joinType),
1284 "Could not resolve column/field reference: 'a.id'");
1286 AnalysisError(String.format(
"select a.id, b.id from functional.alltypes a " +
1287 "%s functional.alltypes b on (a.id = b.id)", joinType),
1288 "Illegal column/field reference 'a.id' of semi-/anti-joined table 'a'");
1289 AnalysisError(String.format(
"select b.id from functional.alltypes a " +
1290 "%s (select * from functional.alltypes) b " +
1291 "on (a.id = b.id) where a.int_col > 10", joinType),
1292 "Illegal column/field reference 'a.int_col' of semi-/anti-joined table 'a'");
1293 AnalysisError(String.format(
"select b.id from functional.alltypes a " +
1294 "%s functional.alltypes b on (a.id = b.id) group by a.bool_col", joinType),
1295 "Illegal column/field reference 'a.bool_col' of semi-/anti-joined table 'a'");
1296 AnalysisError(String.format(
"select b.id from functional.alltypes a " +
1297 "%s (select * from functional.alltypes) b " +
1298 "on (a.id = b.id) order by a.string_col", joinType),
1299 "Illegal column/field reference 'a.string_col' of " +
1300 "semi-/anti-joined table 'a'");
1302 AnalysisError(String.format(
"select b.id from functional.alltypes a " +
1303 "%s functional.alltypes b on (a.id = b.id)" +
1304 "left outer join functional.testtbl c on (a.id = c.id)", joinType),
1305 "Illegal column/field reference 'a.id' of semi-/anti-joined table 'a'");
1307 AnalysisError(String.format(
"select b.id from functional.alltypes a " +
1308 "%s functional.alltypes b on (a.id = b.id)" +
1309 "%s functional.testtbl c on (a.id = c.id)", joinType, joinType),
1310 "Illegal column/field reference 'a.id' of semi-/anti-joined table 'a'");
1312 AnalysisError(String.format(
"select b.id from functional.alltypes a " +
1313 "%s functional.alltypes b using(id) " +
1314 "%s functional.alltypes c using(int_col)", joinType, joinType),
1315 "Illegal column/field reference 'b.id' of semi-/anti-joined table 'b'");
1317 AnalysisError(String.format(
"select * from functional.alltypes a " +
1318 "%s functional.alltypes b on (a.id = b.id and a.int_col = int_col)", joinType),
1319 "Column/field reference is ambiguous: 'int_col'");
1321 AnalysisError(String.format(
"select test_id from functional.jointbl a " +
1322 "%s functional.alltypes b on (a.alltypes_id = b.id)", joinType),
1323 "Illegal column/field reference 'test_id' of semi-/anti-joined table 'a'");
1325 AnalysisError(String.format(
"select alltypes.int_col from functional.alltypes " +
1326 "%s functional_parquet.alltypes " +
1327 "on (functional.alltypes.id = functional_parquet.alltypes.id)", joinType),
1328 "Unqualified table alias is ambiguous: 'alltypes'");
1330 AnalysisError(String.format(
"select 1 from functional.allcomplextypes a " +
1331 "%s functional.allcomplextypes b on (a.id = b.id) " +
1332 "inner join a.int_array_col", joinType),
1333 "Illegal table reference 'a.int_array_col' of semi-/anti-joined table 'a'");
1339 String[][] hintStyles =
new String[][] {
1340 new String[] {
"/* +",
"*/" },
1341 new String[] {
"\n-- +",
"\n" },
1342 new String[] {
"[",
"]" }
1344 for (String[] hintStyle: hintStyles) {
1345 String prefix = hintStyle[0];
1346 String suffix = hintStyle[1];
1348 String.format(
"select * from functional.alltypes a join %sbroadcast%s " +
1349 "functional.alltypes b using (int_col)", prefix, suffix));
1351 String.format(
"select * from functional.alltypes a join %sshuffle%s " +
1352 "functional.alltypes b using (int_col)", prefix, suffix));
1354 String.format(
"select * from functional.alltypes a cross join %sbroadcast%s " +
1355 "functional.alltypes b", prefix, suffix));
1358 String.format(
"select * from functional.alltypes a join %sbadhint%s " +
1359 "functional.alltypes b using (int_col)", prefix, suffix),
1360 "JOIN hint not recognized: badhint");
1363 if (!prefix.contains(
"[")) {
1365 "select * from functional.alltypes a join %sbroadcast broadcast%s " +
1366 "functional.alltypes b using (int_col)", prefix, suffix),
1367 "JOIN hint not recognized: broadcast broadcast");
1370 String.format(
"select * from functional.alltypes a cross join %sshuffle%s " +
1371 "functional.alltypes b", prefix, suffix),
1372 "CROSS JOIN does not support SHUFFLE.");
1374 "select * from functional.alltypes a right outer join %sbroadcast%s " +
1375 "functional.alltypes b using (int_col)", prefix, suffix),
1376 "RIGHT OUTER JOIN does not support BROADCAST.");
1378 "select * from functional.alltypes a full outer join %sbroadcast%s " +
1379 "functional.alltypes b using (int_col)", prefix, suffix),
1380 "FULL OUTER JOIN does not support BROADCAST.");
1382 "select * from functional.alltypes a right semi join %sbroadcast%s " +
1383 "functional.alltypes b using (int_col)", prefix, suffix),
1384 "RIGHT SEMI JOIN does not support BROADCAST.");
1386 "select * from functional.alltypes a right anti join %sbroadcast%s " +
1387 "functional.alltypes b using (int_col)", prefix, suffix),
1388 "RIGHT ANTI JOIN does not support BROADCAST.");
1391 "select * from functional.alltypes a join %sbroadcast,shuffle%s " +
1392 "functional.alltypes b using (int_col)", prefix, suffix),
1393 "Conflicting JOIN hint: shuffle");
1399 String[][] hintStyles =
new String[][] {
1400 new String[] {
"/* +",
"*/" },
1401 new String[] {
"\n-- +",
"\n" },
1402 new String[] {
"",
"" }
1404 for (String[] hintStyle: hintStyles) {
1405 String prefix = hintStyle[0];
1406 String suffix = hintStyle[1];
1408 "select %sstraight_join%s * from functional.alltypes", prefix, suffix));
1410 "select %sStrAigHt_jOiN%s * from functional.alltypes", prefix, suffix));
1411 if (!prefix.equals(
"")) {
1415 "select %sbadhint%s * from functional.alltypes", prefix, suffix),
1416 "PLAN hint not recognized: badhint");
1419 "select %sstraight_join,straight_join%s * from functional.alltypes",
1427 String[][] hintStyles =
new String[][] {
1428 new String[] {
"/* +",
"*/" },
1429 new String[] {
"\n-- +",
"\n" },
1430 new String[] {
"[",
"]" }
1432 for (String[] hintStyle: hintStyles) {
1433 String prefix = hintStyle[0];
1434 String suffix = hintStyle[1];
1436 AnalyzesOk(String.format(
"insert into functional.alltypessmall " +
1437 "partition (year, month) %sshuffle%s select * from functional.alltypes",
1439 AnalyzesOk(String.format(
"insert into table functional.alltypessmall " +
1440 "partition (year, month) %snoshuffle%s select * from functional.alltypes",
1443 AnalyzesOk(String.format(
"insert into functional.alltypessmall " +
1444 "partition (year, month) %sbadhint%s select * from functional.alltypes",
1446 "INSERT hint not recognized: badhint");
1449 "insert into table functional.alltypesnopart %sshuffle%s " +
1450 "select * from functional.alltypesnopart", prefix, suffix),
1451 "INSERT hints are only supported for inserting into partitioned Hdfs tables.");
1454 "insert into table functional_hbase.alltypes %sshuffle%s " +
1455 "select * from functional_hbase.alltypes", prefix, suffix),
1456 "INSERT hints are only supported for inserting into partitioned Hdfs tables.");
1458 AnalysisError(
"insert into table functional.alltypessmall " +
1459 "partition (year, month) /* +shuffle,noshuffle */ " +
1460 "select * from functional.alltypes",
1461 "Conflicting INSERT hint: noshuffle");
1465 AnalyzesOk(
"insert into table functional.alltypessmall " +
1466 "partition (year, month) /* +shuffle, ShUfFlE */ " +
1467 "select * from functional.alltypes");
1468 AnalyzesOk(
"insert into table functional.alltypessmall " +
1469 "partition (year, month) [shuffle, ShUfFlE] " +
1470 "select * from functional.alltypes");
1475 AnalyzesOk(
"select zip, name from functional.testtbl where id > 15");
1476 AnalysisError(
"select zip, name from functional.testtbl where badcol > 15",
1477 "Could not resolve column/field reference: 'badcol'");
1478 AnalyzesOk(
"select * from functional.testtbl where true");
1479 AnalysisError(
"select * from functional.testtbl where count(*) > 0",
1480 "aggregate function not allowed in WHERE clause");
1483 AnalyzesOk(
"select id from functional.testtbl where id " +
1484 op.toString() +
" true");
1485 AnalyzesOk(
"select id from functional.testtbl where id " +
1486 op.toString() +
" false");
1487 AnalyzesOk(
"select id from functional.testtbl where id " +
1488 op.toString() +
" NULL");
1491 AnalyzesOk(
"select id from functional.alltypes where bool_col");
1493 AnalysisError(
"select id from functional.alltypes where int_col",
1494 "WHERE clause requires return type 'BOOLEAN'. Actual type is 'INT'.");
1495 AnalysisError(
"select id from functional.alltypes where trim('abc')",
1496 "WHERE clause requires return type 'BOOLEAN'. Actual type is 'STRING'.");
1497 AnalysisError(
"select id from functional.alltypes where (int_col + float_col) * 10",
1498 "WHERE clause requires return type 'BOOLEAN'. Actual type is 'DOUBLE'.");
1504 AnalyzesOk(
"select year(timestamp_col), count(*) " +
1505 "from functional.alltypes group by 1");
1506 AnalyzesOk(
"select year(timestamp_col), count(*) " +
1507 "from functional.alltypes group by year(timestamp_col)");
1511 AnalyzesOk(
"select now() + interval abs(cast(1 as int)) days");
1512 AnalyzesOk(
"select now() + interval abs(cast(1 as smallint)) days");
1513 AnalyzesOk(
"select now() + interval abs(cast(1 as tinyint)) days");
1515 AnalyzesOk(
"select round(c1) from functional.decimal_tiny");
1516 AnalyzesOk(
"select round(c1, 2) from functional.decimal_tiny");
1517 AnalysisError(
"select round(c1, cast(c3 as int)) from functional.decimal_tiny",
1518 "round() must be called with a constant second argument.");
1519 AnalysisError(
"select truncate(c1, cast(c3 as int)) from functional.decimal_tiny",
1520 "truncate() must be called with a constant second argument.");
1538 AnalyzesOk(
"select aggfn(int_col) from functional.alltypesagg");
1540 "aggregation without a FROM clause is not allowed");
1542 "select aggfn(int_col) over (partition by int_col) from functional.alltypesagg",
1543 "Aggregate function 'default.aggfn(int_col)' not supported with OVER clause.");
1544 AnalysisError(
"select aggfn(distinct int_col) from functional.alltypesagg",
1545 "User defined aggregates do not support DISTINCT.");
1546 AnalyzesOk(
"select default.aggfn(int_col) from functional.alltypes");
1547 AnalyzesOk(
"select count(*) from functional.testtbl");
1548 AnalyzesOk(
"select min(id), max(id), sum(id) from functional.testtbl");
1549 AnalyzesOk(
"select avg(id) from functional.testtbl");
1551 AnalyzesOk(
"select count(*), min(id), max(id), sum(id), avg(id), aggfn(id) " +
1552 "from functional.testtbl");
1553 AnalyzesOk(
"select AggFn(tinyint_col), AggFn(int_col), AggFn(bigint_col), " +
1554 "AggFn(double_col) from functional.alltypes");
1555 AnalysisError(
"select AggFn(string_col) from functional.alltypes",
1556 "No matching function with signature: default.aggfn(STRING)");
1557 AnalyzesOk(
"select AggFn(string_col, string_col) from functional.alltypes");
1559 AnalyzesOk(
"select count(NULL), min(NULL), max(NULL), sum(NULL), avg(NULL), " +
1560 "group_concat(NULL), group_concat(name, NULL) from functional.testtbl");
1561 AnalysisError(
"select id, zip from functional.testtbl where count(*) > 0",
1562 "aggregate function not allowed in WHERE clause");
1563 AnalysisError(
"select 1 from functional.alltypes where aggfn(1)",
1564 "aggregate function not allowed in WHERE clause");
1567 "count() is not allowed.");
1569 "No matching function with signature: min().");
1570 AnalysisError(
"select int_col from functional.alltypes order by count(*)",
1571 "select list expression not produced by aggregation output (missing from "
1572 +
"GROUP BY clause?): int_col");
1576 "'*' can only be used in conjunction with COUNT");
1578 "'*' can only be used in conjunction with COUNT");
1580 "'*' can only be used in conjunction with COUNT");
1581 AnalysisError(
"select group_concat(*) from functional.testtbl",
1582 "'*' can only be used in conjunction with COUNT");
1585 AnalysisError(
"select count(id, zip) from functional.testtbl",
1586 "COUNT must have DISTINCT for multiple arguments: count(id, zip)");
1587 AnalysisError(
"select min(id, zip) from functional.testtbl",
1588 "No matching function with signature: min(BIGINT, INT).");
1589 AnalysisError(
"select group_concat(name, '-', ',') from functional.testtbl",
1590 "No matching function with signature: group_concat(STRING, STRING, STRING)");
1593 AnalysisError(
"select sum(count(*)) from functional.testtbl",
1594 "aggregate function must not contain aggregate parameters");
1595 AnalysisError(
"select sum(rank() over (order by id)) from functional.testtbl",
1596 "aggregate function must not contain analytic parameters");
1597 AnalysisError(
"select min(aggfn(int_col)) from functional.alltypes",
1598 "aggregate function must not contain aggregate parameters: " +
1599 "min(default.aggfn(int_col))");
1602 AnalysisError(
"select sum(timestamp_col) from functional.alltypes",
1603 "SUM requires a numeric parameter: sum(timestamp_col)");
1604 AnalysisError(
"select sum(string_col) from functional.alltypes",
1605 "SUM requires a numeric parameter: sum(string_col)");
1606 AnalysisError(
"select avg(string_col) from functional.alltypes",
1607 "AVG requires a numeric or timestamp parameter: avg(string_col)");
1610 AnalysisError(
"select count(*)",
"aggregation without a FROM clause is not allowed");
1611 AnalysisError(
"select min(1)",
"aggregation without a FROM clause is not allowed");
1613 "aggregation without a FROM clause is not allowed");
1616 AnalyzesOk(
"select group_concat(string_col) from functional.alltypes");
1617 AnalyzesOk(
"select group_concat(string_col, '-') from functional.alltypes");
1618 AnalyzesOk(
"select group_concat(string_col, string_col) from functional.alltypes");
1621 String literal = typeToLiteralValue_.get(type);
1622 String query1 = String.format(
1623 "select group_concat(%s) from functional.alltypes", literal);
1624 String query2 = String.format(
1625 "select group_concat(string_col, %s) from functional.alltypes", literal);
1626 if (type.getPrimitiveType() == PrimitiveType.STRING || type.isNull()) {
1631 "No matching function with signature: group_concat(");
1633 "No matching function with signature: group_concat(");
1640 "select ndv(%s) from functional.alltypes",
1645 AnalyzesOk(
"select min(d1), max(d2), count(d3), sum(d4) "
1646 +
"from functional.decimal_tbl");
1647 AnalyzesOk(
"select ndv(d1), distinctpc(d2), distinctpcsa(d3), count(distinct d4) "
1648 +
"from functional.decimal_tbl");
1649 AnalyzesOk(
"select avg(d5) from functional.decimal_tbl");
1650 AnalysisError(
"select group_concat(d5) from functional.decimal_tbl",
1651 "No matching function with signature: group_concat(DECIMAL(10,5))");
1654 AnalyzesOk(
"select cast(avg(c1) as decimal(10,4)) as c from " +
1655 "functional.decimal_tiny group by c3 having c = 5.1106 order by 1");
1658 checkExprType(
"select min(cast('foo' as char(5))) from functional.chars_tiny",
1660 checkExprType(
"select max(cast('foo' as varchar(5))) from functional.chars_tiny",
1664 checkExprType(
"select max(lower(cs)) from functional.chars_tiny",
1670 AnalyzesOk(
"select count(distinct id) as sum_id from functional.testtbl");
1671 AnalyzesOk(
"select count(distinct id) as sum_id from " +
1672 "functional.testtbl order by sum_id");
1673 AnalyzesOk(
"select count(distinct id) as sum_id from " +
1674 "functional.testtbl order by max(id)");
1675 AnalyzesOk(
"select distinct id, zip from functional.testtbl");
1676 AnalyzesOk(
"select distinct * from functional.testtbl");
1677 AnalysisError(
"select distinct count(*) from functional.testtbl",
1678 "cannot combine SELECT DISTINCT with aggregate functions or GROUP BY");
1679 AnalysisError(
"select distinct id, zip from functional.testtbl group by 1, 2",
1680 "cannot combine SELECT DISTINCT with aggregate functions or GROUP BY");
1682 "functional.testtbl group by 1, 2",
1683 "cannot combine SELECT DISTINCT with aggregate functions or GROUP BY");
1684 AnalyzesOk(
"select count(distinct id, zip) from functional.testtbl");
1685 AnalysisError(
"select count(distinct id, zip), count(distinct zip) " +
1686 "from functional.testtbl",
1687 "all DISTINCT aggregate functions need to have the same set of parameters");
1688 AnalyzesOk(
"select tinyint_col, count(distinct int_col, bigint_col) "
1689 +
"from functional.alltypesagg group by 1");
1690 AnalyzesOk(
"select tinyint_col, count(distinct int_col),"
1691 +
"sum(distinct int_col) from functional.alltypesagg group by 1");
1692 AnalyzesOk(
"select avg(DISTINCT(tinyint_col)) from functional.alltypesagg");
1695 AnalyzesOk(
"select sum(distinct t1.bigint_col), avg(distinct t1.bigint_col) " +
1696 "from functional.alltypes t1 group by t1.int_col, t1.int_col");
1698 AnalysisError(
"select tinyint_col, count(distinct int_col),"
1699 +
"sum(distinct bigint_col) from functional.alltypesagg group by 1",
1700 "all DISTINCT aggregate functions need to have the same set of parameters");
1702 AnalyzesOk(
"select tinyint_col, count(distinct int_col),"
1703 +
"min(distinct smallint_col), max(distinct string_col) "
1704 +
"from functional.alltypesagg group by 1");
1705 AnalysisError(
"select group_concat(distinct name) from functional.testtbl",
1706 "GROUP_CONCAT() does not support DISTINCT");
1713 "(select distinct id, zip from (select * from functional.testtbl) x) y");
1715 "(select distinct * from (Select * from functional.testtbl) x) y");
1716 AnalyzesOk(
"select distinct * from (select count(*) from functional.testtbl) x");
1717 AnalyzesOk(
"select count(distinct id, zip) " +
1718 "from (select * from functional.testtbl) x");
1719 AnalyzesOk(
"select * from (select tinyint_col, count(distinct int_col, bigint_col) "
1720 +
"from (select * from functional.alltypesagg) x group by 1) y");
1721 AnalyzesOk(
"select tinyint_col, count(distinct int_col),"
1722 +
"sum(distinct int_col) from " +
1723 "(select * from functional.alltypesagg) x group by 1");
1727 "(select distinct count(*) from functional.testtbl) x",
1728 "cannot combine SELECT DISTINCT with aggregate functions or GROUP BY");
1730 "(select distinct id, zip from functional.testtbl group by 1, 2) x",
1731 "cannot combine SELECT DISTINCT with aggregate functions or GROUP BY");
1733 "(select distinct id, zip, count(*) from functional.testtbl group by 1, 2) x",
1734 "cannot combine SELECT DISTINCT with aggregate functions or GROUP BY");
1736 "(select count(distinct id, zip), count(distinct zip) " +
1737 "from functional.testtbl) x",
1738 "all DISTINCT aggregate functions need to have the same set of parameters");
1739 AnalysisError(
"select * from " +
"(select tinyint_col, count(distinct int_col),"
1740 +
"sum(distinct bigint_col) from functional.alltypesagg group by 1) x",
1741 "all DISTINCT aggregate functions need to have the same set of parameters");
1744 AnalysisError(
"select distinct count(*) from (select * from functional.testtbl) x",
1745 "cannot combine SELECT DISTINCT with aggregate functions or GROUP BY");
1747 "(select * from functional.testtbl) x group by 1, 2",
1748 "cannot combine SELECT DISTINCT with aggregate functions or GROUP BY");
1750 "(select * from functional.testtbl) x group by 1, 2",
1751 "cannot combine SELECT DISTINCT with aggregate functions or GROUP BY");
1752 AnalyzesOk(
"select count(distinct id, zip) " +
1753 "from (select * from functional.testtbl) x");
1754 AnalysisError(
"select count(distinct id, zip), count(distinct zip) " +
1755 " from (select * from functional.testtbl) x",
1756 "all DISTINCT aggregate functions need to have the same set of parameters");
1757 AnalyzesOk(
"select tinyint_col, count(distinct int_col, bigint_col) "
1758 +
"from (select * from functional.alltypesagg) x group by 1");
1759 AnalyzesOk(
"select tinyint_col, count(distinct int_col),"
1760 +
"sum(distinct int_col) from " +
1761 "(select * from functional.alltypesagg) x group by 1");
1762 AnalysisError(
"select tinyint_col, count(distinct int_col),"
1763 +
"sum(distinct bigint_col) from " +
1764 "(select * from functional.alltypesagg) x group by 1",
1765 "all DISTINCT aggregate functions need to have the same set of parameters");
1770 AnalyzesOk(
"select zip, count(*) from functional.testtbl group by zip");
1771 AnalyzesOk(
"select zip + count(*) from functional.testtbl group by zip");
1773 AnalyzesOk(
"select count(*) from functional.testtbl group by 2*3+4");
1774 AnalyzesOk(
"select count(*) from functional.testtbl " +
1775 "group by true, false, NULL");
1777 AnalyzesOk(
"select true, NULL, 1*2+5 as a, zip, count(*) from functional.testtbl " +
1779 AnalyzesOk(
"select d1, d2, count(*) from functional.decimal_tbl " +
1783 AnalysisError(
"select zip, count(*) from functional.testtbl",
1784 "select list expression not produced by aggregation output " +
1785 "(missing from GROUP BY clause?)");
1786 AnalysisError(
"select zip + count(*) from functional.testtbl",
1787 "select list expression not produced by aggregation output " +
1788 "(missing from GROUP BY clause?)");
1791 AnalyzesOk(
"select id, zip from functional.testtbl " +
1792 "group by zip, id having count(*) > 0");
1793 AnalyzesOk(
"select count(*) from functional.alltypes " +
1794 "group by bool_col having bool_col");
1797 "group by bool_col having 5 + 10 * 5.6",
1798 "HAVING clause '5 + 10 * 5.6' requires return type 'BOOLEAN'. " +
1799 "Actual type is 'DOUBLE'.");
1801 "group by bool_col having int_col",
1802 "HAVING clause 'int_col' requires return type 'BOOLEAN'. Actual type is 'INT'.");
1804 "group by id having count(*) > 0",
1805 "select list expression not produced by aggregation output " +
1806 "(missing from GROUP BY clause?)");
1808 "group by id having zip + count(*) > 0",
1809 "HAVING clause not produced by aggregation output " +
1810 "(missing from GROUP BY clause?)");
1812 AnalyzesOk(
"select zip, count(*) from functional.testtbl group by 1");
1813 AnalyzesOk(
"select count(*), zip from functional.testtbl group by 2");
1814 AnalysisError(
"select zip, count(*) from functional.testtbl group by 3",
1815 "GROUP BY: ordinal exceeds number of items in select list: 3");
1816 AnalysisError(
"select * from functional.alltypes group by 1",
1817 "cannot combine '*' in select list with GROUP BY");
1819 AnalyzesOk(
"select zip z, id iD1, id ID2, count(*) " +
1820 "from functional.testtbl group by z, ID1, id2");
1822 AnalyzesOk(
"select int_col, INT_COL from functional.alltypes group by int_col");
1823 AnalyzesOk(
"select bool_col a, bool_col A from functional.alltypes group by a");
1824 AnalyzesOk(
"select int_col A, bool_col b, int_col a, bool_col B " +
1825 "from functional.alltypes group by a, b");
1827 AnalysisError(
"select zip a, id a, count(*) from functional.testtbl group by a",
1828 "Column 'a' in GROUP BY clause is ambiguous");
1829 AnalysisError(
"select zip id, id, count(*) from functional.testtbl group by id",
1830 "Column 'id' in GROUP BY clause is ambiguous");
1833 AnalysisError(
"select zip, count(*) from functional.testtbl group by count(*)",
1834 "GROUP BY expression must not contain aggregate functions");
1836 "from functional.testtbl group by count(*) + min(zip)",
1837 "GROUP BY expression must not contain aggregate functions");
1838 AnalysisError(
"select zip, count(*) from functional.testtbl group by 2",
1839 "GROUP BY expression must not contain aggregate functions");
1842 AnalyzesOk(
"select int_col, string_col, bigint_col, count(*) " +
1843 "from functional.alltypes group by string_col, int_col, bigint_col");
1844 AnalyzesOk(
"select int_col, string_col, bigint_col, count(*) " +
1845 "from functional.alltypes group by 2, 1, 3");
1846 AnalysisError(
"select int_col, string_col, bigint_col, count(*) " +
1847 "from functional.alltypes group by 2, 1, 4",
1848 "GROUP BY expression must not contain aggregate functions");
1851 AnalyzesOk(
"select float_col, double_col, count(*) " +
1852 "from functional.alltypes group by 1, 2");
1854 AnalyzesOk(
"select int_col + 0.5, count(*) from functional.alltypes group by 1");
1855 AnalyzesOk(
"select cast(int_col as double), count(*)" +
1856 "from functional.alltypes group by 1");
1861 AnalyzesOk(
"select zip, id from functional.testtbl order by zip");
1862 AnalyzesOk(
"select zip, id from functional.testtbl order by zip asc");
1863 AnalyzesOk(
"select zip, id from functional.testtbl order by zip desc");
1864 AnalyzesOk(
"select zip, id from functional.testtbl " +
1865 "order by true asc, false desc, NULL asc");
1866 AnalyzesOk(
"select d1, d2 from functional.decimal_tbl order by d1");
1869 AnalyzesOk(
"select zip, id from functional.testtbl order by 1");
1870 AnalyzesOk(
"select zip, id from functional.testtbl order by 2 desc, 1 asc");
1872 AnalysisError(
"select zip, id from functional.testtbl order by 0",
1873 "ORDER BY: ordinal must be >= 1");
1874 AnalysisError(
"select zip, id from functional.testtbl order by 3",
1875 "ORDER BY: ordinal exceeds number of items in select list: 3");
1876 AnalyzesOk(
"select * from functional.alltypes order by 1");
1878 AnalyzesOk(
"select zip z, id C, id D from functional.testtbl order by z, C, d");
1881 AnalyzesOk(
"select zip, count(*) from functional.testtbl group by 1 " +
1882 " order by count(*)");
1883 AnalyzesOk(
"select zip, count(*) from functional.testtbl " +
1884 "group by 1 order by count(*) + min(zip)");
1885 AnalysisError(
"select zip, count(*) from functional.testtbl group by 1 order by id",
1886 "ORDER BY expression not produced by aggregation output " +
1887 "(missing from GROUP BY clause?)");
1890 AnalyzesOk(
"select int_col, string_col, bigint_col from functional.alltypes " +
1891 "order by string_col, 15.7 * float_col, int_col + bigint_col");
1892 AnalyzesOk(
"select int_col, string_col, bigint_col from functional.alltypes " +
1893 "order by 2, 1, 3");
1896 AnalyzesOk(
"select float_col, int_col + 0.5 from functional.alltypes order by 1, 2");
1897 AnalyzesOk(
"select float_col, int_col + 0.5 from functional.alltypes order by 2, 1");
1900 AnalyzesOk(
"select t1.int_col from functional.alltypes t1, " +
1901 "functional.alltypes t2 where t1.id = t2.id order by int_col");
1904 AnalyzesOk(
"select int_col, INT_COL from functional.alltypes order by int_col");
1905 AnalyzesOk(
"select bool_col a, bool_col A from functional.alltypes order by a");
1906 AnalyzesOk(
"select int_col A, bool_col b, int_col a, bool_col B " +
1907 "from functional.alltypes order by a, b");
1910 "functional.alltypessmall order by a limit 1",
1911 "Column 'a' in ORDER BY clause is ambiguous");
1913 "functional.alltypessmall order by a limit 1",
1914 "Column 'a' in ORDER BY clause is ambiguous");
1917 AnalyzesOk(
"select * from (select * from functional.alltypes order by int_col) A",
1918 "Ignoring ORDER BY clause without LIMIT or OFFSET: " +
1919 "ORDER BY int_col ASC");
1920 AnalyzesOk(
"select * from functional.alltypes order by int_col desc union all " +
1921 "select * from functional.alltypes",
1922 "Ignoring ORDER BY clause without LIMIT or OFFSET: " +
1923 "ORDER BY int_col DESC");
1924 AnalyzesOk(
"insert into functional.alltypes partition (year, month) " +
1925 "select * from functional.alltypes order by int_col",
1926 "Ignoring ORDER BY clause without LIMIT or OFFSET: " +
1927 "ORDER BY int_col ASC");
1928 AnalyzesOk(
"create table functional.alltypescopy as " +
1929 "select * from functional.alltypes order by int_col",
1930 "Ignoring ORDER BY clause without LIMIT or OFFSET: " +
1931 "ORDER BY int_col ASC");
1937 AnalyzesOk(
"select rank() over (order by int_col) from functional.alltypes union " +
1938 "select int_col from functional.alltypessmall");
1940 AnalyzesOk(
"select int_col from functional.alltypes union " +
1941 "select int_col from functional.alltypes");
1943 AnalyzesOk(
"select int_col from functional.alltypes union " +
1944 "select int_col from functional.alltypes " +
1945 "union select int_col from functional.alltypes union " +
1946 "select int_col from functional.alltypes");
1948 AnalyzesOk(
"select id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
1949 "float_col, double_col, date_string_col, string_col, timestamp_col, year," +
1950 "month from functional.alltypes union " +
1951 "select id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
1952 "float_col, double_col, date_string_col, string_col, timestamp_col, year," +
1953 "month from functional.alltypes");
1955 AnalyzesOk(
"select a.smallint_col from functional.alltypes a " +
1956 "union select a.int_col from functional.alltypessmall a");
1958 AnalyzesOk(
"select id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
1959 "float_col, double_col, date_string_col, string_col, timestamp_col, year," +
1960 "month from functional.alltypes union " +
1961 "select NULL, NULL, NULL, NULL, NULL, NULL, " +
1962 "NULL, NULL, NULL, NULL, NULL, NULL," +
1963 "NULL from functional.alltypes");
1967 "union select NULL, NULL, NULL " +
1968 "union select 1.0, NULL, 3 " +
1969 "union select NULL, 10, NULL");
1971 AnalyzesOk(
"select tinyint_col from functional.alltypes " +
1972 "union select smallint_col from functional.alltypes " +
1973 "union select int_col from functional.alltypes " +
1974 "union select bigint_col from functional.alltypes");
1976 AnalyzesOk(
"select float_col from functional.alltypes union " +
1977 "select double_col from functional.alltypes");
1979 AnalyzesOk(
"select tinyint_col, double_col from functional.alltypes " +
1980 "union select smallint_col, float_col from functional.alltypes " +
1981 "union select int_col, bigint_col from functional.alltypes " +
1982 "union select bigint_col, int_col from functional.alltypes " +
1983 "union select float_col, smallint_col from functional.alltypes " +
1984 "union select double_col, tinyint_col from functional.alltypes");
1987 AnalyzesOk(
"(select int_col from functional.alltypes) " +
1988 "union (select tinyint_col from functional.alltypessmall) " +
1989 "order by int_col limit 1");
1990 AnalyzesOk(
"(select int_col from functional.alltypes) " +
1991 "union (select tinyint_col from functional.alltypessmall) " +
1992 "order by int_col");
1993 AnalyzesOk(
"(select int_col from functional.alltypes) " +
1994 "union (select tinyint_col from functional.alltypessmall) " +
1995 "order by int_col offset 5");
1997 AnalyzesOk(
"select int_col from functional.alltypes order by int_col " +
1998 "union (select tinyint_col from functional.alltypessmall) ");
1999 AnalysisError(
"select int_col from functional.alltypes order by int_col offset 5 " +
2000 "union (select tinyint_col from functional.alltypessmall) ",
2001 "Order-by with offset without limit not supported in nested queries");
2002 AnalysisError(
"select int_col from functional.alltypes offset 5 " +
2003 "union (select tinyint_col from functional.alltypessmall) ",
2004 "OFFSET requires an ORDER BY clause: OFFSET 5");
2006 AnalyzesOk(
"select int_col from functional.alltypes " +
2007 "union (select tinyint_col from functional.alltypessmall " +
2008 "order by tinyint_col) ");
2010 "union (select tinyint_col from functional.alltypessmall " +
2011 "order by tinyint_col offset 5) ",
2012 "Order-by with offset without limit not supported in nested queries");
2014 "union (select tinyint_col from functional.alltypessmall offset 5) ",
2015 "OFFSET requires an ORDER BY clause: OFFSET 5");
2017 AnalyzesOk(
"(select tinyint_col, double_col from functional.alltypes) " +
2018 "union (select smallint_col, float_col from functional.alltypes) " +
2019 "union (select int_col, bigint_col from functional.alltypes) " +
2020 "union (select bigint_col, int_col from functional.alltypes) " +
2021 "order by double_col, tinyint_col");
2023 AnalyzesOk(
"select int_col from functional.alltypes order by int_col " +
2024 "union select int_col from functional.alltypes order by int_col limit 10 " +
2025 "union (select int_col from functional.alltypes " +
2026 "order by int_col limit 10 offset 5) order by int_col offset 5");
2028 AnalyzesOk(
"(select tinyint_col, double_col from functional.alltypes) " +
2029 "union (select smallint_col, float_col from functional.alltypes) " +
2030 "union (select int_col, bigint_col from functional.alltypes) " +
2031 "union (select bigint_col, int_col from functional.alltypes) " +
2036 "union select int_col, float_col from functional.alltypes",
2037 "Operands have unequal number of columns:\n" +
2038 "'SELECT int_col FROM functional.alltypes' has 1 column(s)\n" +
2039 "'SELECT int_col, float_col FROM functional.alltypes' has 2 column(s)");
2042 "union select tinyint_col from functional.alltypes " +
2043 "union select smallint_col from functional.alltypes " +
2044 "union select smallint_col, bigint_col from functional.alltypes",
2045 "Operands have unequal number of columns:\n" +
2046 "'SELECT int_col FROM functional.alltypes' has 1 column(s)\n" +
2047 "'SELECT smallint_col, bigint_col FROM functional.alltypes' has 2 column(s)");
2050 "union select lag(string_col) over(order by int_col) from functional.alltypes",
2051 "Incompatible return types 'BOOLEAN' and 'STRING' of exprs " +
2052 "'bool_col' and 'lag(string_col, 1, NULL)'.");
2054 AnalysisError(
"select int_col, string_col from functional.alltypes " +
2055 "union select tinyint_col, bool_col from functional.alltypes " +
2056 "union select smallint_col, int_col from functional.alltypes " +
2057 "union select smallint_col, bool_col from functional.alltypes",
2058 "Incompatible return types 'STRING' and 'BOOLEAN' of " +
2059 "exprs 'string_col' and 'bool_col'.");
2061 AnalysisError(
"(select int_col from functional.alltypes) " +
2062 "union (select int_col from functional.alltypessmall) order by 2",
2063 "ORDER BY: ordinal exceeds number of items in select list: 2");
2065 AnalysisError(
"(select int_col a, string_col a from functional.alltypes) " +
2066 "union (select int_col a, string_col a " +
2067 "from functional.alltypessmall) order by a",
2068 "Column 'a' in ORDER BY clause is ambiguous");
2070 AnalyzesOk(
"(select int_col a, string_col b from functional.alltypes) " +
2071 "union (select int_col a, string_col a " +
2072 "from functional.alltypessmall) order by a");
2075 AnalysisError(
"select int_col a, int_col a from functional.alltypes " +
2076 "union all (select 1, bigint_col from functional.alltypessmall) order by a",
2077 "Column 'a' in ORDER BY clause is ambiguous");
2081 AnalysisError(
"(select smallint_col from functional.alltypes) " +
2082 "union (select int_col from functional.alltypessmall) order by int_col",
2083 "Could not resolve column/field reference: 'int_col'");
2085 AnalysisError(
"select a.smallint_col from functional.alltypes a " +
2086 "union select a.int_col from functional.alltypessmall",
2087 "Could not resolve column/field reference: 'a.int_col'");
2091 AnalyzesOk(
"select cast(1 as bigint) union select cast(1 as decimal(19, 0))");
2098 AnalyzesOk(
"select * from (values('a', NULL, 'c')) as t");
2099 AnalyzesOk(
"values(1.0, 2, NULL) union all values(1, 2.0, 3)");
2100 AnalyzesOk(
"insert overwrite table functional.alltypes " +
2101 "partition (year=2009, month=10)" +
2102 "values(1, true, 1, 1, 1, 1, 1.0, 1.0, 'a', 'a', cast(0 as timestamp))");
2103 AnalyzesOk(
"insert overwrite table functional.alltypes " +
2104 "partition (year, month) " +
2105 "values(1, true, 1, 1, 1, 1, 1.0, 1.0, 'a', 'a', cast(0 as timestamp)," +
2109 AnalyzesOk(
"select * from (values('a', 'b', 'c')) as t");
2110 AnalyzesOk(
"select * from (values(('a', 'b', 'c'), ('d', 'e', 'f'))) as t");
2111 AnalyzesOk(
"values((1.0, 2, NULL), (2.0, 3, 4)) union all values(1, 2.0, 3)");
2112 AnalyzesOk(
"insert overwrite table functional.alltypes " +
2113 "partition (year=2009, month=10) " +
2115 "(1, true, 1, 1, 1, 1, 1.0, 1.0, 'a', 'a', cast(0 as timestamp))," +
2116 "(2, false, 2, 2, NULL, 2, 2.0, 2.0, 'b', 'b', cast(0 as timestamp))," +
2117 "(3, true, 3, 3, 3, 3, 3.0, 3.0, 'c', 'c', cast(0 as timestamp)))");
2118 AnalyzesOk(
"insert overwrite table functional.alltypes " +
2119 "partition (year, month) " +
2121 "(1, true, 1, 1, 1, 1, 1.0, 1.0, 'a', 'a', cast(0 as timestamp), 2009, 10)," +
2122 "(2, false, 2, 2, NULL, 2, 2.0, 2.0, 'b', 'b', cast(0 as timestamp), 2009, 2)," +
2123 "(3, true, 3, 3, 3, 3, 3.0, 3.0, 'c', 'c', cast(0 as timestamp), 2009, 3))");
2125 AnalyzesOk(
"values((1 as x, 'a' as y), (2 as k, 'b' as j))");
2127 AnalyzesOk(
"values(1 as x, 'a') order by 2 limit 10");
2128 AnalyzesOk(
"values(1 as x, 'a' as y), (2, 'b') order by y limit 10");
2129 AnalyzesOk(
"values((1, 'a'), (2, 'b')) order by 1 limit 10");
2130 AnalyzesOk(
"values((1, 'a'), (2, 'b')) order by 2");
2131 AnalyzesOk(
"values((1, 'a'), (2, 'b')) order by 1 offset 5");
2133 "OFFSET requires an ORDER BY clause: OFFSET 5");
2136 "'*' expression in select list requires FROM clause.");
2138 "aggregation without a FROM clause is not allowed");
2140 "Could not resolve column/field reference: 'id'");
2141 AnalysisError(
"values((1 as x, 'a' as y), (2, 'b')) order by c limit 1",
2142 "Could not resolve column/field reference: 'c'");
2144 "Operands have unequal number of columns:\n" +
2145 "'(1, 2)' has 2 column(s)\n" +
2146 "'(3, 4, 5)' has 3 column(s)");
2148 "Incompatible return types 'STRING' and 'TINYINT' of exprs ''a'' and '4'");
2149 AnalysisError(
"insert overwrite table functional.alltypes " +
2150 "partition (year, month) " +
2151 "values(1, true, 'a', 1, 1, 1, 1.0, 1.0, 'a', 'a', cast(0 as timestamp)," +
2153 "Target table 'functional.alltypes' is incompatible with SELECT / PARTITION " +
2155 "Expression ''a'' (type: STRING) is not compatible with column " +
2156 "'tinyint_col' (type: TINYINT)");
2162 AnalyzesOk(
"with t as (select int_col x, bigint_col y from functional.alltypes) " +
2163 "select x, y from t");
2165 AnalyzesOk(
"with t1 as (select int_col x, bigint_col y from functional.alltypes), " +
2166 "t2 as (select 1 x , 10 y), t3 as (values(2 x , 20 y), (3, 30)), " +
2167 "t4 as (select 4 x, 40 y union all select 5, 50), " +
2168 "t5 as (select * from (values(6 x, 60 y)) as a) " +
2169 "select x, y from t3");
2171 AnalyzesOk(
"with t1 as (select int_col x, bigint_col y from functional.alltypes), " +
2172 "t2 as (select 1 x , 10 y), t3 as (values(2 x , 20 y), (3, 30)), " +
2173 "t4 as (select 4 x, 40 y union all select 5, 50), " +
2174 "t5 as (select * from (values(6 x, 60 y)) as a) " +
2175 "select * from t1 union all select * from t2 union all select * from t3 " +
2176 "union all select * from t4 union all select * from t5");
2178 AnalyzesOk(
"with t1 as (select int_col x, bigint_col y from functional.alltypes), " +
2179 "t2 as (select 1 x , 10 y), t3 as (values(2 x , 20 y), (3, 30)), " +
2180 "t4 as (select 4 x, 40 y union all select 5, 50), " +
2181 "t5 as (select * from (values(6 x, 60 y)) as a) " +
2182 "select t1.y, t2.y, t3.y, t4.y, t5.y from t1, t2, t3, t4, t5 " +
2183 "where t1.y = t2.y and t2.y = t3.y and t3.y = t4.y and t4.y = t5.y");
2185 AnalyzesOk(
"with t1 as (select * from functional.alltypestiny)" +
2186 "insert into functional.alltypes partition(year, month) select * from t1");
2189 AnalyzesOk(
"with test_ctas_1 as (select * from functional.alltypestiny) insert " +
2190 "into functional.alltypes partition (year, month) with with_1 as " +
2191 "(select t1.* from test_ctas_1 as t1 right join (select 1 as int_col " +
2192 "from functional.alltypestiny as t1) as t2 ON t2.int_col = t1.int_col) " +
2193 "select * from with_1 limit 10");
2196 AnalyzesOk(
"insert into functional.alltypes partition (year, month) with " +
2197 "with_1 as (select t1.* from functional.alltypes as t1 right " +
2198 "join (select * from functional.alltypestiny as t1) t2 on t1.int_col = " +
2199 "t2.int_col) select * from with_1 limit 10");
2201 AnalyzesOk(
"with t1 as (select id from functional.alltypestiny) " +
2202 "insert into functional.alltypes partition(year, month) " +
2203 "with t1 as (select * from functional.alltypessmall) select * from t1");
2205 AnalyzesOk(
"with t1 as (select 'a') select * from (select * from t1) as t2");
2207 "select * from (select * from (select * from t1) as t2) as t3");
2209 AnalyzesOk(
"select * from (with t1 as (values(1 x, 10 y)) select * from t1) as t2");
2212 AnalyzesOk(
"with T1 as (select int_col x, bigint_col y from functional.alltypes)," +
2213 "t2 as (select 1 x , 10 y), T3 as (values(2 x , 20 y), (3, 30)), " +
2214 "t4 as (select 4 x, 40 y union all select 5, 50), " +
2215 "T5 as (select * from (values(6 x, 60 y)) as a) " +
2216 "select * from t1 union all select * from T2 union all select * from t3 " +
2217 "union all select * from T4 union all select * from t5");
2220 AnalyzesOk(
"with t1 as (values('a', 'b')) " +
2221 "(with t2 as (values('c', 'd')) select * from t2) union all" +
2222 "(with t3 as (values('e', 'f')) select * from t3) order by 1 limit 1");
2224 AnalyzesOk(
"with t1 as (select * from functional.alltypestiny) " +
2225 "insert into functional.alltypes partition(year, month) " +
2226 "with t2 as (select * from functional.alltypessmall) select * from t1");
2231 "select t2.* from (with t1 as (select 'b') select * from t1) as t2");
2233 AnalyzesOk(
"with t1 as (select 1), t2 as (select 2)" +
2234 "select * from functional.alltypes as t1");
2235 AnalyzesOk(
"with t1 as (select 1), t2 as (select 2) select * from t2 as t1");
2236 AnalyzesOk(
"with t1 as (select 1) select * from (select 2) as t1");
2238 AnalyzesOk(
"with alltypes as (select * from functional.alltypes) " +
2239 "select * from functional.alltypes union all select * from alltypes");
2245 AnalyzesOk(
"with t1 as (select int_col x, bigint_col y from alltypes), " +
2246 "alltypes as (select x a, y b from t1)" +
2247 "select a, b from alltypes",
2251 AnalyzesOk(
"with t1 as (select abc x, xyz y from complex_view), " +
2252 "complex_view as (select x a, y b from t1)" +
2253 "select a, b from complex_view",
2256 AnalyzesOk(
"with t1 as (with t1 as (select int_col x, bigint_col y from alltypes) " +
2257 "select x, y from t1), " +
2258 "alltypes as (select x a, y b from t1) " +
2259 "select a, b from alltypes",
2263 "(select * from (with t2 as (select * from functional.alltypes) " +
2264 "select * from t2) t3) " +
2265 "select * from t1");
2268 "(with t2 as (values('a', 'b')) select * from t2 union all select * from t2) " +
2269 "select * from t1");
2272 "(select 'x', 'y' union all (with t2 as (values('a', 'b')) select * from t2)) " +
2273 "select * from t1");
2277 "select x from t union all select x from t");
2280 "select t1.x, t2.x, t.x from t as t1, t as t2, t " +
2281 "where t1.x = t2.x and t2.x = t.x");
2284 AnalyzesOk(
"with t as (select int_col + 2, !bool_col from functional.alltypes) " +
2285 "select `int_col + 2`, `NOT bool_col` from t");
2289 AnalyzesOk(
"select 1 from (with w as (select 1 from functional.alltypes " +
2290 "where exists (select 1 from functional.alltypes)) select 1 from w) tt");
2291 AnalyzesOk(
"create table test_with as select 1 from (with w as " +
2292 "(select 1 from functional.alltypes where exists " +
2293 "(select 1 from functional.alltypes)) select 1 from w) tt");
2294 AnalyzesOk(
"insert into functional.alltypesnopart (id) select 1 from " +
2295 "(with w as (select 1 from functional.alltypes where exists " +
2296 "(select 1 from functional.alltypes)) select 1 from w) tt");
2299 AnalysisError(
"with t1 as (select 1), t1 as (select 2) select * from t1",
2300 "Duplicate table alias: 't1'");
2302 AnalysisError(
"with t1 as (select 1 x), t2 as (select 2 y)" +
2303 "select * from functional.alltypes as t1 inner join t1",
2304 "Duplicate table alias: 't1'");
2306 "select * from t2 as t1 inner join t1",
2307 "Duplicate table alias: 't1'");
2308 AnalysisError(
"with t1 as (select 1) select * from (select 2) as t1 inner join t1",
2309 "Duplicate table alias: 't1'");
2311 AnalysisError(
"with t1 as (select 'a' x) select * from t1 inner join t1",
2312 "Duplicate table alias: 't1'");
2314 AnalysisError(
"with t1 as (select 'a' x) select t1.x from t1 as t2",
2315 "Could not resolve column/field reference: 't1.x'");
2317 AnalysisError(
"with t1 as (select 'a' x) insert into t1 values('b' x)",
2318 "Table does not exist: default.t1");
2321 AnalyzesOk(
"with alltypes_view as (select int_col x from alltypes_view) " +
2322 "select x from alltypes_view",
2325 AnalysisError(
"with t as (select int_col x, bigint_col y from t1) " +
2326 "select x, y from t",
2327 "Could not resolve table reference: 't1'");
2328 AnalysisError(
"with t as (select 1 as x, 2 as y union all select * from t) " +
2329 "select x, y from t",
2330 "Could not resolve table reference: 't'");
2331 AnalysisError(
"with t as (select a.* from (select * from t) as a) " +
2332 "select x, y from t",
2333 "Could not resolve table reference: 't'");
2335 AnalysisError(
"with t1 as (with t2 as (select * from t1) select * from t2) " +
2336 "select * from t1 ",
2337 "Could not resolve table reference: 't1'");
2339 "(select * from (with t2 as (select * from t1) select * from t2) t3) " +
2341 "Could not resolve table reference: 't1'");
2344 "(with t2 as (select * from t1) select * from t2 union all select * from t2)" +
2346 "Could not resolve table reference: 't1'");
2348 "(select 'x', 'y' union all (with t2 as (select * from t1) select * from t2))" +
2350 "Could not resolve table reference: 't1'");
2352 AnalysisError(
"with t1 as (select int_col x, bigint_col y from t2), " +
2353 "t2 as (select int_col x, bigint_col y from t1) select x, y from t1",
2354 "Could not resolve table reference: 't2'");
2357 AnalyzesOk(
"with t as (select * from functional.alltypesagg where id in " +
2358 "(select id from functional.alltypes)) select int_col from t");
2359 AnalyzesOk(
"with t as (select * from functional.alltypes) select * from " +
2360 "functional.alltypesagg a where exists (select id from t where t.id = a.id)");
2361 AnalyzesOk(
"with t as (select * from functional.alltypes) select * from " +
2362 "functional.alltypesagg where 10 > (select count(*) from t) and " +
2363 "100 < (select max(int_col) from t)");
2364 AnalyzesOk(
"with t as (select * from functional.alltypes a where exists " +
2365 "(select * from functional.alltypesagg t where t.id = 1 and a.id = t.id) " +
2366 "and not exists (select * from functional.alltypesagg b where b.id = 1 " +
2367 "and b.int_col = a.int_col)) select * from t");
2370 AnalyzesOk(
"with with_1 as (select 1 as int_col_1), with_2 as " +
2371 "(select 1 as int_col_1 from (with with_3 as (select 1 as int_col_1 from " +
2372 "with_1) select 1 as int_col_1 from with_3) as t1) select 1 as int_col_1 " +
2374 AnalyzesOk(
"with with_1 as (select 1 as int_col_1), with_2 as (select 1 as " +
2375 "int_col_1 from (with with_3 as (select 1 as int_col_1 from with_1) " +
2376 "select 1 as int_col_1 from with_3) as t1), with_4 as (select 1 as " +
2377 "int_col_1 from with_2) select 1 as int_col_1 from with_4");
2378 AnalyzesOk(
"with with_1 as (select 1 as int_col_1), with_2 as (with with_3 " +
2379 "as (select 1 as int_col_1 from (with with_4 as (select 1 as int_col_1 " +
2380 "from with_1) select 1 as int_col_1 from with_4) as t1) select 1 as " +
2381 "int_col_1 from with_3) select 1 as int_col_1 from with_2");
2384 AnalyzesOk(
"with with_1 as (select int_col from functional.alltypestiny " +
2385 "where int_col between 0 and 10) select * from with_1");
2387 AnalyzesOk(
"with with_1 as (select int_col between 0 and 10 " +
2388 "from functional.alltypestiny) select * from with_1");
2391 AnalyzesOk(
"with with_1 as (select timestamp_col between " +
2392 "cast('2001-01-01' as timestamp) and " +
2393 "(cast('2001-01-01' as timestamp) + interval 10 days) " +
2394 "from functional.alltypestiny) select * from with_1");
2396 AnalyzesOk(
"with with_1 as (select * from functional.alltypestiny " +
2397 "where timestamp_col between cast('2001-01-01' as timestamp) and " +
2398 "(cast('2001-01-01' as timestamp) + interval 10 days)) " +
2399 "select * from with_1");
2405 AnalyzesOk(
"select * from functional.alltypes_view");
2406 AnalyzesOk(
"select x, y, z from functional.alltypes_view_sub");
2407 AnalyzesOk(
"select abc, xyz from functional.complex_view");
2409 AnalyzesOk(
"select * from functional.view_view");
2411 AnalyzesOk(
"select t.x, t.y, t.z from functional.alltypes_view_sub t");
2414 AnalyzesOk(
"select * from functional.alltypes_view_sub union all " +
2415 "select * from functional.alltypes_view_sub");
2417 AnalyzesOk(
"select t.* from (select * from functional.alltypes_view_sub) t");
2419 AnalyzesOk(
"with t as (select * from functional.complex_view) " +
2420 "select abc, xyz from t");
2423 AnalyzesOk(
"select sum(t1.abc), t2.xyz from functional.complex_view t1 " +
2424 "inner join functional.complex_view t2 on (t1.abc = t2.abc) " +
2428 AnalysisError(
"insert into functional.alltypes_view partition(year, month) " +
2429 "select * from functional.alltypes",
2430 "Impala does not support inserting into views: functional.alltypes_view");
2432 AnalysisError(
"load data inpath '/test-warehouse/tpch.lineitem/lineitem.tbl' " +
2433 "into table functional.alltypes_view",
2434 "LOAD DATA only supported for HDFS tables: functional.alltypes_view");
2436 AnalysisError(
"select * from functional.alltypes_view_sub " +
2437 "inner join functional.alltypes_view_sub",
2438 "Duplicate table alias: 'functional.alltypes_view_sub'");
2440 AnalysisError(
"select int_col from functional.alltypes_view_sub",
2441 "Could not resolve column/field reference: 'int_col'");
2446 for (String overwrite: Lists.newArrayList(
"",
"overwrite")) {
2448 AnalyzesOk(String.format(
"load data inpath '%s' %s into table tpch.lineitem",
2449 "/test-warehouse/tpch.lineitem/lineitem.tbl", overwrite));
2452 AnalyzesOk(String.format(
"load data inpath '%s' %s into table tpch.lineitem",
2453 "/test-warehouse/tpch.lineitem/", overwrite));
2456 AnalyzesOk(String.format(
"load data inpath '%s' %s into table " +
2457 "functional.alltypes partition(year=2009, month=12)",
2458 "/test-warehouse/tpch.lineitem/", overwrite));
2461 AnalysisError(String.format(
"load data inpath '%s' %s into table tpch.lineitem",
2462 "/test-warehouse/", overwrite),
2463 "INPATH location 'hdfs://localhost:20500/test-warehouse' cannot " +
2464 "contain subdirectories.");
2467 AnalysisError(String.format(
"load data inpath '%s' %s into table tpch.lineitem",
2468 "/test-warehouse/emptytable", overwrite),
2469 "INPATH location 'hdfs://localhost:20500/test-warehouse/emptytable' " +
2470 "contains no visible files.");
2473 AnalysisError(String.format(
"load data inpath '%s' %s into table tpch.lineitem",
2474 "/test-warehouse/alltypessmall/year=2009/month=1/.hidden", overwrite),
2475 "INPATH location 'hdfs://localhost:20500/test-warehouse/alltypessmall/" +
2476 "year=2009/month=1/.hidden' points to a hidden file.");
2477 AnalysisError(String.format(
"load data inpath '%s' %s into table tpch.lineitem",
2478 "/test-warehouse/alltypessmall/year=2009/month=1/_hidden", overwrite),
2479 "INPATH location 'hdfs://localhost:20500/test-warehouse/alltypessmall/" +
2480 "year=2009/month=1/_hidden' points to a hidden file.");
2483 AnalysisError(String.format(
"load data inpath '%s' %s into table tpch.lineitem",
2484 "/test-warehouse/does_not_exist", overwrite),
2485 "INPATH location 'hdfs://localhost:20500/test-warehouse/does_not_exist' " +
2488 AnalysisError(String.format(
"load data inpath '%s' %s into table tpch.lineitem",
2489 "", overwrite),
"URI path cannot be empty.");
2492 AnalysisError(String.format(
"load data inpath '%s' %s into table " +
2493 "functional.alltypes partition(year=123, month=10)",
2494 "/test-warehouse/tpch.lineitem/", overwrite),
2495 "Partition spec does not exist: (year=123, month=10)");
2498 AnalysisError(String.format(
"load data inpath '%s' %s into table " +
2499 "functional_hbase.alltypessmall",
2500 "/test-warehouse/tpch.lineitem/", overwrite),
2501 "LOAD DATA only supported for HDFS tables: functional_hbase.alltypessmall");
2504 AnalysisError(String.format(
"load data inpath '%s' %s into table " +
2505 "functional.alltypes",
2506 "/test-warehouse/tpch.lineitem/", overwrite),
2507 "Table is partitioned but no partition spec was specified: " +
2508 "functional.alltypes");
2511 AnalysisError(String.format(
"load data inpath '%s' %s into table " +
2513 "/test-warehouse/tpch.lineitem/", overwrite),
2514 "Database does not exist: nodb");
2515 AnalysisError(String.format(
"load data inpath '%s' %s into table " +
2517 "/test-warehouse/tpch.lineitem/", overwrite),
2518 "Table does not exist: functional.notbl");
2521 AnalysisError(String.format(
"load data inpath '%s' %s into table " +
2522 "tpch.lineitem",
"file:///test-warehouse/test.out", overwrite),
2523 "INPATH location 'file:/test-warehouse/test.out' must point to an " +
2525 AnalysisError(String.format(
"load data inpath '%s' %s into table " +
2526 "tpch.lineitem",
"s3n://bucket/test-warehouse/test.out", overwrite),
2527 "INPATH location 's3n://bucket/test-warehouse/test.out' must point to an " +
2531 AnalyzesOk(String.format(
"load data inpath '%s' %s into table " +
2533 "/test-warehouse/alltypes_text_lzo/year=2009/month=4", overwrite));
2536 AnalyzesOk(String.format(
"load data inpath '%s' %s into table " +
2537 "functional_text_lzo.alltypes partition(year=2009, month=4)",
2538 "/test-warehouse/alltypes_text_lzo/year=2009/month=4", overwrite));
2539 AnalyzesOk(String.format(
"load data inpath '%s' %s into table " +
2540 "functional_text_lzo.jointbl",
2541 "/test-warehouse/alltypes_text_lzo/year=2009/month=4", overwrite));
2544 AnalysisError(String.format(
"load data inpath '%s' into table " +
2545 "functional_seq.alltypes partition(year=2009, month=3)",
2546 "/test-warehouse/alltypes_seq/year=2009/month=5", overwrite),
2547 "Unable to LOAD DATA into target table (functional_seq.alltypes) because " +
2548 "Impala does not have WRITE access to HDFS location: " +
2549 "hdfs://localhost:20500/test-warehouse/alltypes_seq/year=2009/month=3");
2555 for (String qualifier: ImmutableList.of(
"INTO",
"OVERWRITE")) {
2563 AnalysisError(
"insert into functional_seq.alltypes partition(year, month)" +
2564 "select * from functional.alltypes",
2565 "Unable to INSERT into target table (functional_seq.alltypes) because Impala " +
2566 "does not have WRITE access to at least one HDFS path: " +
2567 "hdfs://localhost:20500/test-warehouse/alltypes_seq/year=2009/month=");
2570 AnalyzesOk(
"insert into functional.alltypessmall " +
2571 "partition (year, month) [shuffle] select * from functional.alltypes");
2572 AnalyzesOk(
"insert into table functional.alltypessmall " +
2573 "partition (year, month) [noshuffle] select * from functional.alltypes");
2575 AnalyzesOk(
"insert into table functional.alltypessmall " +
2576 "partition (year, month) [shuffle, ShUfFlE] select * from functional.alltypes");
2578 AnalyzesOk(
"insert into functional.alltypessmall " +
2579 "partition (year, month) [badhint] select * from functional.alltypes",
2580 "INSERT hint not recognized: badhint");
2582 AnalysisError(
"insert into table functional.alltypessmall " +
2583 "partition (year, month) [shuffle, noshuffle] select * from functional.alltypes",
2584 "Conflicting INSERT hint: noshuffle");
2586 AnalysisError(
"insert into table functional.alltypesnopart [shuffle] " +
2587 "select * from functional.alltypesnopart",
2588 "INSERT hints are only supported for inserting into partitioned Hdfs tables.");
2590 AnalysisError(
"insert into table functional_hbase.alltypes [shuffle] " +
2591 "select * from functional_hbase.alltypes",
2592 "INSERT hints are only supported for inserting into partitioned Hdfs tables.");
2600 AnalyzesOk(
"insert " + qualifier +
" table functional.alltypessmall " +
2601 "partition (year, month)" +
2602 "select id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
2603 "float_col, double_col, date_string_col, string_col, timestamp_col, year, " +
2604 "month from functional.alltypes");
2606 AnalyzesOk(
"insert " + qualifier +
" table functional.alltypessmall " +
2607 "partition (year, month)" +
2608 "select id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
2609 "float_col, double_col, date_string_col, " +
2610 "string_col, timestamp_col, NULL, NULL from functional.alltypes");
2612 AnalyzesOk(
"insert " + qualifier +
" table functional.alltypessmall " +
2613 "partition (year, month)" +
2614 "select NULL, NULL, NULL, NULL, NULL, NULL, " +
2615 "NULL, NULL, NULL, NULL, NULL, NULL, " +
2616 "NULL from functional.alltypes");
2619 AnalyzesOk(
"insert " + qualifier +
" table functional.alltypessmall " +
2620 "partition (year, month)" +
2621 "select id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
2622 "float_col, double_col, date_string_col, string_col, timestamp_col, month, " +
2623 "year from functional.alltypes");
2625 AnalyzesOk(
"insert " + qualifier +
" table functional.alltypessmall " +
2626 "partition (year=2009, month)" +
2627 "select id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
2628 "float_col, double_col, date_string_col, string_col, timestamp_col, month " +
2629 "from functional.alltypes");
2631 AnalyzesOk(
"insert " + qualifier +
" table functional.alltypessmall " +
2632 "partition (year=NULL, month)" +
2633 "select id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
2634 "float_col, double_col, date_string_col, string_col, timestamp_col, year from " +
2635 "functional.alltypes");
2637 AnalyzesOk(
"insert " + qualifier +
" table functional.alltypessmall " +
2638 "partition (year, month=4)" +
2639 "select id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
2640 "float_col, double_col, date_string_col, string_col, timestamp_col, year from " +
2641 "functional.alltypes");
2643 AnalyzesOk(
"insert " + qualifier +
" table functional.alltypessmall " +
2644 "partition (year, month=NULL)" +
2645 "select id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
2646 "float_col, double_col, date_string_col, string_col, timestamp_col, year from " +
2647 "functional.alltypes");
2649 AnalyzesOk(
"insert " + qualifier +
" table functional.alltypessmall " +
2650 "partition (year=2009, month)" +
2651 "select id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
2652 "float_col, double_col, date_string_col, string_col, timestamp_col, NULL from " +
2653 "functional.alltypes");
2655 AnalyzesOk(
"insert " + qualifier +
" table functional.alltypessmall " +
2656 "partition (year, month=4)" +
2657 "select id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
2658 "float_col, double_col, date_string_col, string_col, timestamp_col, NULL from " +
2659 "functional.alltypes");
2661 AnalyzesOk(
"insert " + qualifier +
" table functional.alltypessmall " +
2662 "Partition (year=2009, month=NULL)" +
2663 "select id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
2664 "float_col, double_col, date_string_col, string_col, timestamp_col " +
2665 "from functional.alltypes");
2667 AnalyzesOk(
"insert " + qualifier +
" table functional.alltypessmall " +
2668 "partition (year=NULL, month=4)" +
2669 "select id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
2670 "float_col, double_col, date_string_col, string_col, timestamp_col " +
2671 "from functional.alltypes");
2675 " table functional.alltypessmall partition (year, month)" +
2676 "select * from functional.alltypes");
2678 AnalysisError(
"insert " + qualifier +
" table functional.alltypessmall " +
2679 "partition (year, month)" +
2680 "select id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
2681 "float_col, double_col, date_string_col, string_col, timestamp_col " +
2682 "from functional.alltypes",
2683 "Target table 'functional.alltypessmall' has more columns (13) than the " +
2684 "SELECT / VALUES clause and PARTITION clause return (11)");
2686 AnalysisError(
"insert " + qualifier +
" table functional.alltypessmall " +
2687 "partition (year=2009, month)" +
2688 "select id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
2689 "float_col, double_col, date_string_col, string_col, timestamp_col " +
2690 "from functional.alltypes",
2691 "Target table 'functional.alltypessmall' has more columns (13) than the " +
2692 "SELECT / VALUES clause and PARTITION clause return (12)");
2694 AnalysisError(
"insert " + qualifier +
" table functional.alltypessmall " +
2695 "partition (year=rank() over(order by int_col), month)" +
2696 "select id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
2697 "float_col, double_col, date_string_col, string_col, timestamp_col, month " +
2698 "from functional.alltypes",
2699 "Non-constant expressions are not supported as static partition-key values " +
2700 "in 'year=rank() OVER (ORDER BY int_col ASC)'");
2703 AnalysisError(
"insert " + qualifier +
" table functional.alltypessmall " +
2704 "partition (year, month=4)" +
2705 "select id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
2706 "float_col, double_col, date_string_col, string_col, timestamp_col " +
2707 "from functional.alltypes",
2708 "Target table 'functional.alltypessmall' has more columns (13) than the " +
2709 "SELECT / VALUES clause and PARTITION clause return (12)");
2711 AnalysisError(
"insert " + qualifier +
" table functional.alltypessmall " +
2712 "partition (year=2009, month=4)" +
2713 "select * from functional.alltypes",
2714 "Target table 'functional.alltypessmall' has fewer columns (13) than the " +
2715 "SELECT / VALUES clause and PARTITION clause return (15)");
2724 "insert " + qualifier +
" table functional.alltypesnopart " +
2725 "select id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
2726 "float_col, double_col, date_string_col, string_col from functional.alltypes",
2727 "Target table 'functional.alltypesnopart' has more columns (11) than the SELECT" +
2728 " / VALUES clause returns (10)");
2731 if (!qualifier.contains(
"OVERWRITE")) {
2732 AnalysisError(
"INSERT " + qualifier +
" TABLE functional_hbase.alltypes " +
2733 "SELECT * FROM functional.alltypesagg",
2734 "Target table 'functional_hbase.alltypes' has fewer columns (13) than the " +
2735 "SELECT / VALUES clause returns (14)");
2738 AnalyzesOk(
"insert " + qualifier +
" table functional.alltypesnopart " +
2739 "select id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
2740 "float_col, double_col, date_string_col, string_col, timestamp_col from " +
2741 "functional.alltypes");
2743 AnalyzesOk(
"insert " + qualifier +
" table functional.alltypesnopart " +
2744 "select NULL, NULL, NULL, NULL, NULL, NULL, " +
2745 "NULL, NULL, NULL, NULL, NULL " +
2746 "from functional.alltypes");
2748 String hbaseQuery =
"INSERT " + qualifier +
" TABLE " +
2749 "functional_hbase.insertalltypesagg select id, bigint_col, bool_col, " +
2750 "date_string_col, day, double_col, float_col, int_col, month, smallint_col, " +
2751 "string_col, timestamp_col, tinyint_col, year from functional.alltypesagg";
2755 if (!qualifier.contains(
"OVERWRITE")) {
2758 AnalysisError(hbaseQuery,
"HBase doesn't have a way to perform INSERT OVERWRITE");
2763 " TABLE functional.alltypesnopart PARTITION(year=2009) " +
2764 "SELECT * FROM functional.alltypes",
"PARTITION clause is only valid for INSERT" +
2765 " into partitioned table. 'functional.alltypesnopart' is not partitioned");
2768 AnalysisError(
"INSERT " + qualifier +
" table UNKNOWNDB.alltypesnopart SELECT * " +
2769 "from functional.alltypesnopart",
"Database does not exist: UNKNOWNDB");
2777 AnalyzesOk(
"insert " + qualifier +
" table functional.alltypessmall " +
2778 "partition (year=2009, month=4)" +
2779 "select id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
2780 "float_col, double_col, date_string_col, string_col, timestamp_col " +
2781 "from functional.alltypes");
2784 AnalyzesOk(
"insert " + qualifier +
" table functional.alltypessmall " +
2785 "partition (year=NULL, month=NULL)" +
2786 "select id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
2787 "float_col, double_col, date_string_col, string_col, timestamp_col " +
2788 "from functional.alltypes");
2790 AnalyzesOk(
"insert " + qualifier +
" table functional.alltypessmall " +
2791 "partition (year=NULL, month=NULL)" +
2792 "select NULL, NULL, NULL, NULL, NULL, NULL, " +
2793 "NULL, NULL, NULL, NULL, NULL " +
2794 "from functional.alltypes");
2796 AnalyzesOk(
"insert " + qualifier +
" table functional.alltypessmall " +
2797 "partition (year=NULL, month=NULL)" +
2798 "select id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
2799 "float_col, double_col, date_string_col, string_col, timestamp_col " +
2800 "from functional.alltypes");
2802 AnalyzesOk(
"insert " + qualifier +
" table functional.alltypessmall " +
2803 "partition (year=2009, month=NULL)" +
2804 "select id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
2805 "float_col, double_col, date_string_col, string_col, timestamp_col " +
2806 "from functional.alltypes");
2808 AnalyzesOk(
"insert " + qualifier +
" table functional.alltypessmall " +
2809 "partition (year=NULL, month=4)" +
2810 "select id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
2811 "float_col, double_col, date_string_col, string_col, timestamp_col " +
2812 "from functional.alltypes");
2814 AnalyzesOk(
"insert " + qualifier +
" table functional.alltypessmall " +
2815 "partition (year=-1, month=cast(100*20+10 as INT))" +
2816 "select id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
2817 "float_col, double_col, date_string_col, string_col, timestamp_col " +
2818 "from functional.alltypes");
2822 AnalyzesOk(
"insert " + qualifier +
" table functional.alltypessmall " +
2823 "partition (year=2009, month=4)" +
2824 "select id, bool_col, tinyint_col, smallint_col, int_col, int_col, " +
2825 "float_col, float_col, date_string_col, string_col, timestamp_col " +
2826 "from functional.alltypes");
2828 AnalysisError(
"insert " + qualifier +
" table functional.alltypessmall " +
2829 "select id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
2830 "float_col, double_col, date_string_col, string_col, timestamp_col " +
2831 "from functional.alltypes",
2832 "Not enough partition columns mentioned in query. Missing columns are: year, " +
2835 AnalysisError(
"insert " + qualifier +
" table functional.alltypessmall " +
2836 "partition (year=2009, month=4)" +
2837 "select id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
2838 "float_col, double_col, date_string_col, timestamp_col from functional.alltypes",
2839 "Target table 'functional.alltypessmall' has more columns (13) than the " +
2840 "SELECT / VALUES clause and PARTITION clause return (12)");
2842 AnalysisError(
"insert " + qualifier +
" table functional.alltypessmall " +
2843 "partition (year=2009, month=4)" +
2844 "select id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
2845 "float_col, double_col, date_string_col, bool_col, timestamp_col " +
2846 "from functional.alltypes",
2847 "Target table 'functional.alltypessmall' is incompatible with SELECT / " +
2848 "PARTITION expressions.\nExpression 'bool_col' (type: BOOLEAN) is not " +
2849 "compatible with column 'string_col' (type: STRING)");
2851 AnalysisError(
"insert " + qualifier +
" table functional.alltypessmall " +
2852 "partition (year=2009, month=4, year=10)" +
2853 "select id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
2854 "float_col, double_col, date_string_col, string_col, timestamp_col " +
2855 "from functional.alltypes",
2856 "Duplicate column 'year' in partition clause");
2858 AnalysisError(
"insert " + qualifier +
" table functional.alltypessmall " +
2859 "partition (year=2009)" +
2860 "select id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
2861 "float_col, double_col, date_string_col, string_col, timestamp_col " +
2862 "from functional.alltypes",
2863 "Not enough partition columns mentioned in query. Missing columns are: month");
2865 AnalysisError(
"insert " + qualifier +
" table functional.alltypessmall " +
2866 "partition (year=2009, bigint_col=10)" +
2867 "select id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
2868 "float_col, double_col, date_string_col, string_col, timestamp_col " +
2869 "from functional.alltypes",
2870 "Column 'bigint_col' is not a partition column");
2872 AnalysisError(
"insert " + qualifier +
" table functional.alltypessmall " +
2873 "partition (year=2009, month=4)" +
2874 "select id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
2875 "double_col, double_col, date_string_col, string_col, timestamp_col " +
2876 "from functional.alltypes",
2877 "Possible loss of precision for target table 'functional.alltypessmall'.\n" +
2878 "Expression 'double_col' (type: DOUBLE) would need to be cast to FLOAT for " +
2879 "column 'float_col'");
2881 AnalysisError(
"insert " + qualifier +
" table functional.alltypessmall " +
2882 "partition (year=2009, month=4)" +
2883 "select * from functional.alltypes",
2884 "Target table 'functional.alltypessmall' has fewer columns (13) than the " +
2885 "SELECT / VALUES clause and PARTITION clause return (15)");
2887 AnalysisError(
"insert " + qualifier +
" table functional.alltypessmall " +
2888 "partition (year=\"should be an int\", month=4)" +
2889 "select id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
2890 "float_col, double_col, date_string_col, string_col, timestamp_col " +
2891 "from functional.alltypes",
2892 "Target table 'functional.alltypessmall' is incompatible with " +
2893 "SELECT / PARTITION expressions.");
2895 AnalysisError(
"insert " + qualifier +
" table functional.alltypessmall " +
2896 "partition (year=-1, month=int_col)" +
2897 "select id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
2898 "float_col, double_col, date_string_col, string_col, timestamp_col " +
2899 "from functional.alltypes",
2900 "Non-constant expressions are not supported as static partition-key values " +
2901 "in 'month=int_col'.");
2903 if (qualifier.contains(
"OVERWRITE")) {
2904 AnalysisError(
"insert " + qualifier +
" table functional_hbase.alltypessmall " +
2905 "partition(year, month) select * from functional.alltypessmall",
2906 "PARTITION clause is not valid for INSERT into HBase tables. " +
2907 "'functional_hbase.alltypessmall' is an HBase table");
2913 AnalysisError(
"insert " + qualifier +
" table functional.tinytable(a, a, b)" +
2914 "values(1, 2, 3)",
"Duplicate column 'a' in column permutation");
2917 AnalysisError(
"insert " + qualifier +
" table functional.tinytable" +
2918 "(a, c) values(1, 2)",
"Unknown column 'c' in column permutation");
2921 AnalyzesOk(
"insert " + qualifier +
" table functional.tinytable(a) values('hello')");
2924 AnalysisError(
"insert " + qualifier +
" table functional.tinytable(a, b)" +
2925 " select 'a', 'b', 'c' from functional.alltypes",
2926 "Column permutation mentions fewer columns (2) than the SELECT / VALUES clause" +
2930 AnalysisError(
"insert " + qualifier +
" table functional.tinytable(a, b)" +
2931 " select 'a' from functional.alltypes",
2932 "Column permutation mentions more columns (2) than the SELECT / VALUES clause" +
2937 AnalysisError(
"insert " + qualifier +
" table functional.alltypesnopart" +
2938 "(id, bool_col, string_col, smallint_col, int_col, bigint_col, " +
2939 "float_col, double_col, date_string_col, tinyint_col, timestamp_col)" +
2940 " select * from functional.alltypesnopart",
2941 "Target table 'functional.alltypesnopart' is incompatible with SELECT / " +
2942 "PARTITION expressions.\nExpression 'functional.alltypesnopart.tinyint_col' " +
2943 "(type: TINYINT) is not compatible with column 'string_col' (type: STRING)");
2946 AnalyzesOk(
"insert " + qualifier +
" table functional.alltypesnopart" +
2947 "(id, bool_col, string_col, smallint_col, int_col, bigint_col, " +
2948 "float_col, double_col, date_string_col, tinyint_col, timestamp_col)" +
2949 " select id, bool_col, string_col, smallint_col, int_col, bigint_col, " +
2950 "float_col, double_col, date_string_col, tinyint_col, timestamp_col" +
2951 " from functional.alltypesnopart");
2954 AnalyzesOk(
"insert " + qualifier +
" table functional.alltypes" +
2955 "(id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
2956 "float_col, double_col, date_string_col, string_col, timestamp_col, " +
2957 "year, month) select * from functional.alltypes");
2960 AnalysisError(
"insert " + qualifier +
" table functional.alltypes" +
2961 "(id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
2962 "float_col, double_col, date_string_col, string_col, timestamp_col, " +
2963 "year, month) PARTITION(year) select * from functional.alltypes",
2964 "Duplicate column 'year' in partition clause");
2969 AnalyzesOk(
"insert " + qualifier +
" table functional.alltypes" +
2970 "(id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
2971 "float_col, double_col, date_string_col, string_col, timestamp_col, " +
2972 "year) PARTITION(month) select * from functional.alltypes");
2976 AnalyzesOk(
"insert " + qualifier +
" table functional.alltypes(id, year)" +
2977 "PARTITION(month=2009) select 1, 2 from functional.alltypes");
2980 AnalyzesOk(
"insert " + qualifier +
" table functional.alltypesnopart" +
2981 "(id, bool_col) select id, bool_col from functional.alltypesnopart");
2984 AnalysisError(
"insert " + qualifier +
" table functional.alltypes(id)" +
2985 " select id from functional.alltypes",
2986 "Not enough partition columns mentioned in query. " +
2987 "Missing columns are: year, month");
2990 AnalysisError(
"insert " + qualifier +
" table functional.alltypes(year)" +
2991 " partition(year=2012, month=3) select 1 from functional.alltypes",
2992 "Duplicate column 'year' in partition clause");
2997 AnalysisError(
"insert " + qualifier +
" table functional.alltypes" +
2998 "(id, bool_col, string_col, smallint_col, int_col, bigint_col, " +
2999 "float_col, double_col, date_string_col, tinyint_col, timestamp_col) " +
3000 "PARTITION (year, month)" +
3001 " select id, bool_col, month, smallint_col, int_col, bigint_col, " +
3002 "float_col, double_col, date_string_col, tinyint_col, timestamp_col, " +
3003 "year, string_col from functional.alltypes",
3004 "Target table 'functional.alltypes' is incompatible with SELECT / PARTITION " +
3006 "Expression 'month' (type: INT) is not compatible with column 'string_col' " +
3010 AnalyzesOk(
"insert " + qualifier +
" table functional.alltypesnopart()");
3012 AnalysisError(
"insert " + qualifier +
" table functional.alltypesnopart() select 1",
3013 "Column permutation mentions fewer columns (0) than the SELECT / VALUES clause " +
3016 AnalyzesOk(
"insert " + qualifier +
" table functional.alltypes() " +
3017 "partition(year=2012, month=1)");
3019 AnalysisError(
"insert " + qualifier +
" table functional.alltypes() " +
3020 "partition(year=2012, month=1) select 1",
3021 "Column permutation and PARTITION clause mention fewer columns (0) than the " +
3022 "SELECT / VALUES clause and PARTITION clause return (1)");
3024 AnalysisError(
"insert " + qualifier +
" table functional.alltypes() " +
3025 "partition(year, month)",
3026 "Column permutation and PARTITION clause mention more columns (2) than the " +
3027 "SELECT / VALUES clause and PARTITION clause return (0)");
3030 AnalyzesOk(
"insert " + qualifier +
" table functional.alltypes() " +
3031 "partition(year, month) select 1,2 from functional.alltypes");
3033 if (!qualifier.contains(
"OVERWRITE")) {
3035 AnalyzesOk(
"insert " + qualifier +
" table functional_hbase.alltypesagg" +
3036 "(id, bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
3037 "float_col, double_col, date_string_col, string_col, timestamp_col) " +
3038 "select * from functional.alltypesnopart");
3040 AnalysisError(
"insert " + qualifier +
" table functional_hbase.alltypesagg" +
3041 "(id, tinyint_col, smallint_col, int_col, bigint_col, " +
3042 "float_col, double_col, date_string_col, string_col) " +
3043 "select * from functional.alltypesnopart",
3044 "Column permutation mentions fewer columns (9) than the SELECT /" +
3045 " VALUES clause returns (11)");
3047 AnalysisError(
"insert " + qualifier +
" table functional_hbase.alltypesagg" +
3048 "(bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
3049 "float_col, double_col, date_string_col, string_col, timestamp_col) " +
3050 "select bool_col, tinyint_col, smallint_col, int_col, bigint_col, " +
3051 "float_col, double_col, date_string_col, string_col, timestamp_col from " +
3052 "functional.alltypesnopart",
3053 "Row-key column 'id' must be explicitly mentioned in column permutation.");
3076 @SuppressWarnings(
"rawtypes")
3078 int actualNumMembers = 0;
3079 for (Field f: cl.getDeclaredFields()) {
3081 if (!f.isSynthetic()) ++actualNumMembers;
3083 if (actualNumMembers != expectedNumMembers) {
3084 fail(String.format(
"The number of members in %s have changed.\n" +
3085 "Expected %s but found %s. Please modify clone() accordingly and " +
3086 "change the expected number of members in this test.",
3087 cl.getSimpleName(), expectedNumMembers, actualNumMembers));
void testCollectionTableRefs(String collectionTable, String collectionField)
List< Integer > path(Integer...p)
void testInsertWithPermutation(String qualifier)
List< TableRef > getTableRefs()
void testStarPath(String sql, List< Integer >...expectedPhysPaths)
void TestSetQueryOption()
void TblsAnalyzeOk(String query, TableName tbl)
static final ScalarType BIGINT
void TestStarPathAmbiguity()
Db addTestDb(String dbName)
void TestDistinctInlineView()
static final ScalarType STRING
static Map< ScalarType, String > typeToLiteralValue_
Analyzer createAnalyzer(String defaultDb)
void checkExprType(String query, Type type)
Analyzer createAnalyzerUsingHiveColLabels()
ArrayList< Expr > getResultExprs()
void TblsAnalysisError(String query, TableName tbl, String expectedError)
void TestImplicitAndExplicitPaths()
ParseNode AnalyzesOk(String stmt)
void addTestUda(String name, Type retType, Type...argTypes)
void TestSelectListHints()
static final ScalarType DOUBLE
void TestCollectionTableRefs()
void TestSlotRefPathAmbiguity()
Table addTestTable(String createTableSql)
static final ScalarType INT
uint64_t Test(T *ht, const ProbeTuple *input, uint64_t num_tuples)
static final String MAP_VALUE_FIELD_NAME
void testAllTableAliases(String[] tables, String[] columns)
boolean isCollectionTableRef(String tableName)
void testSlotRefPath(String sql, List< Integer > expectedPhysPath)
static final String ARRAY_POS_FIELD_NAME
void testNumberOfMembers(Class cl, int expectedNumMembers)
void TestTableRefPathAmbiguity()
static final String ARRAY_ITEM_FIELD_NAME
void testInsertUnpartitioned(String qualifier)
void AnalysisError(String stmt)
void testInsertDynamic(String qualifier)
void TestCatalogTableRefs()
void testTableRefPath(String sql, List< Integer > expectedPhysPath)
void testInsertStatic(String qualifier)
void TestComplexTypesInSelectList()
static final String MAP_KEY_FIELD_NAME