hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r1051694 - in /hive/trunk: ./ common/src/java/org/apache/hadoop/hive/conf/ conf/ ql/src/java/org/apache/hadoop/hive/ql/parse/ ql/src/test/queries/clientnegative/ ql/src/test/queries/clientpositive/ ql/src/test/results/clientnegative/ ql/src...
Date Tue, 21 Dec 2010 23:18:23 GMT
Author: jvs
Date: Tue Dec 21 23:18:23 2010
New Revision: 1051694

URL: http://svn.apache.org/viewvc?rev=1051694&view=rev
Log:
HIVE-1856 Implement DROP TABLE/VIEW IF EXISTS
(Marcel Kornacker via jvs)


Added:
    hive/trunk/ql/src/test/queries/clientnegative/drop_table_failure1.q
    hive/trunk/ql/src/test/queries/clientnegative/drop_table_failure2.q
    hive/trunk/ql/src/test/queries/clientpositive/drop_table.q
    hive/trunk/ql/src/test/queries/clientpositive/drop_view.q
    hive/trunk/ql/src/test/results/clientnegative/drop_table_failure1.q.out
    hive/trunk/ql/src/test/results/clientnegative/drop_table_failure2.q.out
    hive/trunk/ql/src/test/results/clientpositive/drop_table.q.out
    hive/trunk/ql/src/test/results/clientpositive/drop_view.q.out
Modified:
    hive/trunk/CHANGES.txt
    hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java
    hive/trunk/conf/hive-default.xml
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g
    hive/trunk/ql/src/test/queries/clientnegative/drop_view_failure2.q
    hive/trunk/ql/src/test/results/clientnegative/drop_view_failure2.q.out

Modified: hive/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hive/trunk/CHANGES.txt?rev=1051694&r1=1051693&r2=1051694&view=diff
==============================================================================
--- hive/trunk/CHANGES.txt (original)
+++ hive/trunk/CHANGES.txt Tue Dec 21 23:18:23 2010
@@ -132,6 +132,9 @@ Trunk -  Unreleased
     HIVE-1835 Better auto-complete for Hive
     (Paul Butler via Ning Zhang)
 
+    HIVE-1856 Implement DROP TABLE/VIEW IF EXISTS
+    (Marcel Kornacker via jvs)
+
   IMPROVEMENTS
 
     HIVE-1712. Migrating metadata from derby to mysql thrown NullPointerException (Jake Farrell
via pauly)

Modified: hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java
URL: http://svn.apache.org/viewvc/hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java?rev=1051694&r1=1051693&r2=1051694&view=diff
==============================================================================
--- hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java (original)
+++ hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java Tue Dec 21 23:18:23
2010
@@ -106,6 +106,9 @@ public class HiveConf extends Configurat
     // run in local mode only if number of tasks (for map and reduce each) is
     // less than this
     LOCALMODEMAXTASKS("hive.exec.mode.local.auto.tasks.max", 4),
+    // if true, DROP TABLE/VIEW does not fail if table/view doesn't exist and IF EXISTS is
+    // not specified
+    DROPIGNORESNONEXISTENT("hive.exec.drop.ignorenonexistent", true),
 
     // hadoop stuff
     HADOOPBIN("hadoop.bin.path", System.getenv("HADOOP_HOME") + "/bin/hadoop"),

Modified: hive/trunk/conf/hive-default.xml
URL: http://svn.apache.org/viewvc/hive/trunk/conf/hive-default.xml?rev=1051694&r1=1051693&r2=1051694&view=diff
==============================================================================
--- hive/trunk/conf/hive-default.xml (original)
+++ hive/trunk/conf/hive-default.xml Tue Dec 21 23:18:23 2010
@@ -796,6 +796,14 @@
 </property>
 
 <property>
+  <name>hive.exec.drop.ignorenonexistent</name>
+  <value>true</value>
+  <description>
+    Do not report an error if DROP TABLE/VIEW specifies a non-existent table/view
+  </description>
+</property>
+
+<property>
   <name>hive.exec.show.job.failure.debug.info</name>
   <value>false</value>
   <description>

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java?rev=1051694&r1=1051693&r2=1051694&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java Tue Dec
21 23:18:23 2010
@@ -319,9 +319,13 @@ public class DDLSemanticAnalyzer extends
   private void analyzeDropTable(ASTNode ast, boolean expectView)
       throws SemanticException {
     String tableName = unescapeIdentifier(ast.getChild(0).getText());
+    boolean ifExists = (ast.getFirstChildWithType(TOK_IFEXISTS) != null);
+    // we want to signal an error if the table/view doesn't exist and we're
+    // configured not to fail silently
+    boolean throwException =
+      !ifExists && !HiveConf.getBoolVar(conf, ConfVars.DROPIGNORESNONEXISTENT);
     try {
-      Table tab = db.getTable(db.getCurrentDatabase(), tableName, false);
-      // Ignore if table does not exist
+      Table tab = db.getTable(db.getCurrentDatabase(), tableName, throwException);
       if (tab != null) {
         inputs.add(new ReadEntity(tab));
         outputs.add(new WriteEntity(tab));

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g?rev=1051694&r1=1051693&r2=1051694&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g Tue Dec 21 23:18:23 2010
@@ -434,7 +434,7 @@ dropIndexStatement
 dropTableStatement
 @init { msgs.push("drop statement"); }
 @after { msgs.pop(); }
-    : KW_DROP KW_TABLE Identifier  -> ^(TOK_DROPTABLE Identifier)
+    : KW_DROP KW_TABLE ifExists? Identifier -> ^(TOK_DROPTABLE Identifier ifExists?)
     ;
 
 alterStatement
@@ -763,8 +763,7 @@ createViewStatement
 dropViewStatement
 @init { msgs.push("drop view statement"); }
 @after { msgs.pop(); }
-    : KW_DROP KW_VIEW Identifier
-    -> ^(TOK_DROPVIEW Identifier)
+    : KW_DROP KW_VIEW ifExists? Identifier -> ^(TOK_DROPVIEW Identifier ifExists?)
     ;
 
 showStmtIdentifier

Added: hive/trunk/ql/src/test/queries/clientnegative/drop_table_failure1.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientnegative/drop_table_failure1.q?rev=1051694&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientnegative/drop_table_failure1.q (added)
+++ hive/trunk/ql/src/test/queries/clientnegative/drop_table_failure1.q Tue Dec 21 23:18:23
2010
@@ -0,0 +1,3 @@
+set hive.exec.drop.ignorenonexistent=false;
+-- Can't use DROP TABLE if the table doesn't exist and IF EXISTS isn't specified
+DROP TABLE UnknownTable;

Added: hive/trunk/ql/src/test/queries/clientnegative/drop_table_failure2.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientnegative/drop_table_failure2.q?rev=1051694&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientnegative/drop_table_failure2.q (added)
+++ hive/trunk/ql/src/test/queries/clientnegative/drop_table_failure2.q Tue Dec 21 23:18:23
2010
@@ -0,0 +1,3 @@
+CREATE VIEW xxx6 AS SELECT key FROM src;
+-- Can't use DROP TABLE on a view
+DROP TABLE xxx6;

Modified: hive/trunk/ql/src/test/queries/clientnegative/drop_view_failure2.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientnegative/drop_view_failure2.q?rev=1051694&r1=1051693&r2=1051694&view=diff
==============================================================================
--- hive/trunk/ql/src/test/queries/clientnegative/drop_view_failure2.q (original)
+++ hive/trunk/ql/src/test/queries/clientnegative/drop_view_failure2.q Tue Dec 21 23:18:23
2010
@@ -1,5 +1,3 @@
-DROP VIEW xxx6;
-
--- Can't use DROP TABLE on a view
-CREATE VIEW xxx6 AS SELECT key FROM src;
-DROP TABLE xxx6;
+SET hive.exec.drop.ignorenonexistent=false;
+-- Can't use DROP VIEW if the view doesn't exist and IF EXISTS isn't specified
+DROP VIEW UnknownView;

Added: hive/trunk/ql/src/test/queries/clientpositive/drop_table.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientpositive/drop_table.q?rev=1051694&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientpositive/drop_table.q (added)
+++ hive/trunk/ql/src/test/queries/clientpositive/drop_table.q Tue Dec 21 23:18:23 2010
@@ -0,0 +1,2 @@
+SET hive.exec.dropfailssilently=false;
+DROP TABLE IF EXISTS UnknownTable;

Added: hive/trunk/ql/src/test/queries/clientpositive/drop_view.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientpositive/drop_view.q?rev=1051694&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientpositive/drop_view.q (added)
+++ hive/trunk/ql/src/test/queries/clientpositive/drop_view.q Tue Dec 21 23:18:23 2010
@@ -0,0 +1,2 @@
+SET hive.exec.dropfailssilently=false;
+DROP VIEW IF EXISTS UnknownView;

Added: hive/trunk/ql/src/test/results/clientnegative/drop_table_failure1.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientnegative/drop_table_failure1.q.out?rev=1051694&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientnegative/drop_table_failure1.q.out (added)
+++ hive/trunk/ql/src/test/results/clientnegative/drop_table_failure1.q.out Tue Dec 21 23:18:23
2010
@@ -0,0 +1 @@
+FAILED: Error in semantic analysis: Table not found UnknownTable

Added: hive/trunk/ql/src/test/results/clientnegative/drop_table_failure2.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientnegative/drop_table_failure2.q.out?rev=1051694&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientnegative/drop_table_failure2.q.out (added)
+++ hive/trunk/ql/src/test/results/clientnegative/drop_table_failure2.q.out Tue Dec 21 23:18:23
2010
@@ -0,0 +1,14 @@
+PREHOOK: query: CREATE VIEW xxx6 AS SELECT key FROM src
+PREHOOK: type: CREATEVIEW
+PREHOOK: Output: file:/var/folders/zs/zslcAnKJHzGpoX+3OhC8UU+++TI/-Tmp-/mkornacker/hive_2010-12-16_16-00-37_558_8494052575804500264/-mr-10000
+POSTHOOK: query: CREATE VIEW xxx6 AS SELECT key FROM src
+POSTHOOK: type: CREATEVIEW
+POSTHOOK: Output: default@xxx6
+POSTHOOK: Output: file:/var/folders/zs/zslcAnKJHzGpoX+3OhC8UU+++TI/-Tmp-/mkornacker/hive_2010-12-16_16-00-37_558_8494052575804500264/-mr-10000
+PREHOOK: query: -- Can't use DROP TABLE on a view
+DROP TABLE xxx6
+PREHOOK: type: DROPTABLE
+PREHOOK: Input: default@xxx6
+PREHOOK: Output: default@xxx6
+FAILED: Error in metadata: Cannot drop a view with DROP TABLE
+FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask

Modified: hive/trunk/ql/src/test/results/clientnegative/drop_view_failure2.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientnegative/drop_view_failure2.q.out?rev=1051694&r1=1051693&r2=1051694&view=diff
==============================================================================
--- hive/trunk/ql/src/test/results/clientnegative/drop_view_failure2.q.out (original)
+++ hive/trunk/ql/src/test/results/clientnegative/drop_view_failure2.q.out Tue Dec 21 23:18:23
2010
@@ -1,19 +1 @@
-PREHOOK: query: DROP VIEW xxx6
-PREHOOK: type: DROPVIEW
-POSTHOOK: query: DROP VIEW xxx6
-POSTHOOK: type: DROPVIEW
-PREHOOK: query: -- Can't use DROP TABLE on a view
-CREATE VIEW xxx6 AS SELECT key FROM src
-PREHOOK: type: CREATEVIEW
-PREHOOK: Output: file:/tmp/njain/hive_2010-08-16_23-08-27_750_3628035822001608649/-mr-10000
-POSTHOOK: query: -- Can't use DROP TABLE on a view
-CREATE VIEW xxx6 AS SELECT key FROM src
-POSTHOOK: type: CREATEVIEW
-POSTHOOK: Output: file:/tmp/njain/hive_2010-08-16_23-08-27_750_3628035822001608649/-mr-10000
-POSTHOOK: Output: default@xxx6
-PREHOOK: query: DROP TABLE xxx6
-PREHOOK: type: DROPTABLE
-PREHOOK: Input: default@xxx6
-PREHOOK: Output: default@xxx6
-FAILED: Error in metadata: Cannot drop a view with DROP TABLE
-FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask
+FAILED: Error in semantic analysis: Table not found UnknownView

Added: hive/trunk/ql/src/test/results/clientpositive/drop_table.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/drop_table.q.out?rev=1051694&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/drop_table.q.out (added)
+++ hive/trunk/ql/src/test/results/clientpositive/drop_table.q.out Tue Dec 21 23:18:23 2010
@@ -0,0 +1,4 @@
+PREHOOK: query: DROP TABLE IF EXISTS UnknownTable
+PREHOOK: type: DROPTABLE
+POSTHOOK: query: DROP TABLE IF EXISTS UnknownTable
+POSTHOOK: type: DROPTABLE

Added: hive/trunk/ql/src/test/results/clientpositive/drop_view.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/drop_view.q.out?rev=1051694&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/drop_view.q.out (added)
+++ hive/trunk/ql/src/test/results/clientpositive/drop_view.q.out Tue Dec 21 23:18:23 2010
@@ -0,0 +1,4 @@
+PREHOOK: query: DROP VIEW IF EXISTS UnknownView
+PREHOOK: type: DROPVIEW
+POSTHOOK: query: DROP VIEW IF EXISTS UnknownView
+POSTHOOK: type: DROPVIEW



Mime
View raw message