diff --git ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java index 51838ae..552f24f 100644 --- ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java +++ ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java @@ -10335,6 +10335,19 @@ private void validateCreateView(CreateViewDesc createVwDesc) try { Table oldView = getTableWithQN(createVwDesc.getViewName(), false); + // Do not allow view to be defined on temp table + Set tableAliases = qb.getTabAliases(); + for (String alias : tableAliases) { + try { + Table table = db.getTable(qb.getTabNameForAlias(alias)); + if (table.isTemporary()) { + throw new SemanticException("View definition references temporary table " + alias); + } + } catch (HiveException ex) { + throw new SemanticException(ex); + } + } + // ALTER VIEW AS SELECT requires the view must exist if (createVwDesc.getIsAlterViewAs() && oldView == null) { String viewNotExistErrorMsg = diff --git ql/src/test/queries/clientnegative/create_view_failure10.q ql/src/test/queries/clientnegative/create_view_failure10.q new file mode 100644 index 0000000..13acfd0 --- /dev/null +++ ql/src/test/queries/clientnegative/create_view_failure10.q @@ -0,0 +1,3 @@ +-- CREATE VIEW should fail if it references a temp table +create temporary table tmp1 (c1 string, c2 string); +create view tmp1_view as select c1, count(*) from tmp1 group by c1; diff --git ql/src/test/results/clientnegative/create_view_failure10.q.out ql/src/test/results/clientnegative/create_view_failure10.q.out new file mode 100644 index 0000000..872a331 --- /dev/null +++ ql/src/test/results/clientnegative/create_view_failure10.q.out @@ -0,0 +1,10 @@ +PREHOOK: query: -- CREATE VIEW should fail if it references a temp table +create temporary table tmp1 (c1 string, c2 string) +PREHOOK: type: CREATETABLE +PREHOOK: Output: database:default +POSTHOOK: query: -- CREATE VIEW should fail if it references a temp table +create temporary table tmp1 (c1 string, c2 string) +POSTHOOK: type: CREATETABLE +POSTHOOK: Output: database:default +POSTHOOK: Output: default@tmp1 +FAILED: SemanticException org.apache.hadoop.hive.ql.parse.SemanticException: View definition references temporary table tmp1