You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by jd...@apache.org on 2014/08/20 22:15:04 UTC

svn commit: r1619219 - in /hive/trunk/ql/src: java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java test/queries/clientnegative/create_view_failure10.q test/results/clientnegative/create_view_failure10.q.out

Author: jdere
Date: Wed Aug 20 20:15:04 2014
New Revision: 1619219

URL: http://svn.apache.org/r1619219
Log:
HIVE-7638: Disallow CREATE VIEW when created with a temporary table (Jason Dere, reviewed by Thejas Nair)

Added:
    hive/trunk/ql/src/test/queries/clientnegative/create_view_failure10.q
    hive/trunk/ql/src/test/results/clientnegative/create_view_failure10.q.out
Modified:
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java?rev=1619219&r1=1619218&r2=1619219&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java Wed Aug 20 20:15:04 2014
@@ -10337,6 +10337,19 @@ public class SemanticAnalyzer extends Ba
     try {
       Table oldView = getTable(createVwDesc.getViewName(), false);
 
+      // Do not allow view to be defined on temp table
+      Set<String> 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 =

Added: hive/trunk/ql/src/test/queries/clientnegative/create_view_failure10.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientnegative/create_view_failure10.q?rev=1619219&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientnegative/create_view_failure10.q (added)
+++ hive/trunk/ql/src/test/queries/clientnegative/create_view_failure10.q Wed Aug 20 20:15:04 2014
@@ -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;

Added: hive/trunk/ql/src/test/results/clientnegative/create_view_failure10.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientnegative/create_view_failure10.q.out?rev=1619219&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientnegative/create_view_failure10.q.out (added)
+++ hive/trunk/ql/src/test/results/clientnegative/create_view_failure10.q.out Wed Aug 20 20:15:04 2014
@@ -0,0 +1,11 @@
+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
+PREHOOK: Output: default@tmp1
+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