hadoop-hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zs...@apache.org
Subject svn commit: r903961 - in /hadoop/hive/branches/branch-0.5: ./ ql/src/java/org/apache/hadoop/hive/ql/exec/ ql/src/java/org/apache/hadoop/hive/ql/parse/ ql/src/java/org/apache/hadoop/hive/ql/plan/ ql/src/test/queries/clientpositive/ ql/src/test/results/c...
Date Thu, 28 Jan 2010 05:13:54 GMT
Author: zshao
Date: Thu Jan 28 05:13:53 2010
New Revision: 903961

URL: http://svn.apache.org/viewvc?rev=903961&view=rev
Log:
HIVE-1106. Support ALTER TABLE t ADD IF NOT EXIST PARTITION. (Paul Yang via zshao)

Added:
    hadoop/hive/branches/branch-0.5/ql/src/test/queries/clientpositive/add_part_exist.q
    hadoop/hive/branches/branch-0.5/ql/src/test/results/clientpositive/add_part_exist.q.out
Modified:
    hadoop/hive/branches/branch-0.5/CHANGES.txt
    hadoop/hive/branches/branch-0.5/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java
    hadoop/hive/branches/branch-0.5/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java
    hadoop/hive/branches/branch-0.5/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g
    hadoop/hive/branches/branch-0.5/ql/src/java/org/apache/hadoop/hive/ql/plan/AddPartitionDesc.java
    hadoop/hive/branches/branch-0.5/ql/src/test/results/clientnegative/addpart1.q.out

Modified: hadoop/hive/branches/branch-0.5/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hive/branches/branch-0.5/CHANGES.txt?rev=903961&r1=903960&r2=903961&view=diff
==============================================================================
--- hadoop/hive/branches/branch-0.5/CHANGES.txt (original)
+++ hadoop/hive/branches/branch-0.5/CHANGES.txt Thu Jan 28 05:13:53 2010
@@ -104,6 +104,9 @@
     HIVE-1036. Add API Method to Query HiveConf Values of the Metastore.
     (Paul Yang via zshao)
 
+    HIVE-1106. Support ALTER TABLE t ADD IF NOT EXIST PARTITION.
+    (Paul Yang via zshao)
+
   IMPROVEMENTS
 
     HIVE-760. Add version info to META-INF/MANIFEST.MF.

Modified: hadoop/hive/branches/branch-0.5/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java
URL: http://svn.apache.org/viewvc/hadoop/hive/branches/branch-0.5/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java?rev=903961&r1=903960&r2=903961&view=diff
==============================================================================
--- hadoop/hive/branches/branch-0.5/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java
(original)
+++ hadoop/hive/branches/branch-0.5/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java
Thu Jan 28 05:13:53 2010
@@ -203,6 +203,13 @@
     Table tbl = db.getTable(addPartitionDesc.getDbName(),
         addPartitionDesc.getTableName());
 
+    // If the add partition was created with IF NOT EXISTS, then we should
+    // not throw an error if the specified part does exist.
+    Partition checkPart = db.getPartition(tbl, addPartitionDesc.getPartSpec(), false);
+    if(checkPart != null && addPartitionDesc.getIfNotExists()) {
+      return 0;
+    }
+    
     if(addPartitionDesc.getLocation() == null) {
       db.createPartition(tbl, addPartitionDesc.getPartSpec());
     } else {

Modified: hadoop/hive/branches/branch-0.5/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java
URL: http://svn.apache.org/viewvc/hadoop/hive/branches/branch-0.5/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java?rev=903961&r1=903960&r2=903961&view=diff
==============================================================================
--- hadoop/hive/branches/branch-0.5/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java
(original)
+++ hadoop/hive/branches/branch-0.5/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java
Thu Jan 28 05:13:53 2010
@@ -491,16 +491,20 @@
 
     String currentLocation = null;
     Map<String, String> currentPart = null;
-
+    boolean ifNotExists = false;
+    
     int numCh = ast.getChildCount();
     for (int num = 1; num < numCh; num++) {
       CommonTree child = (CommonTree)ast.getChild(num);
       switch (child.getToken().getType()) {
+      case HiveParser.TOK_IFNOTEXISTS:
+        ifNotExists = true;
+        break;
       case HiveParser.TOK_PARTSPEC:
         if(currentPart != null) {
           AddPartitionDesc addPartitionDesc =
             new AddPartitionDesc(MetaStoreUtils.DEFAULT_DATABASE_NAME,
-                tblName, currentPart, currentLocation);
+                tblName, currentPart, currentLocation, ifNotExists);
           rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(), addPartitionDesc),
conf));
         }
         //create new partition, set values
@@ -520,7 +524,7 @@
     if(currentPart != null) {
       AddPartitionDesc addPartitionDesc =
         new AddPartitionDesc(MetaStoreUtils.DEFAULT_DATABASE_NAME,
-            tblName, currentPart, currentLocation);
+            tblName, currentPart, currentLocation, ifNotExists);
       rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(), addPartitionDesc),
conf));
     }
   }

Modified: hadoop/hive/branches/branch-0.5/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g
URL: http://svn.apache.org/viewvc/hadoop/hive/branches/branch-0.5/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g?rev=903961&r1=903960&r2=903961&view=diff
==============================================================================
--- hadoop/hive/branches/branch-0.5/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g (original)
+++ hadoop/hive/branches/branch-0.5/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g Thu
Jan 28 05:13:53 2010
@@ -303,8 +303,8 @@
 alterStatementSuffixAddPartitions
 @init { msgs.push("add partition statement"); }
 @after { msgs.pop(); }
-    : Identifier KW_ADD partitionSpec partitionLocation? (partitionSpec partitionLocation?)*
-    -> ^(TOK_ALTERTABLE_ADDPARTS Identifier (partitionSpec partitionLocation?)+)
+    : Identifier KW_ADD ifNotExists? partitionSpec partitionLocation? (partitionSpec partitionLocation?)*
+    -> ^(TOK_ALTERTABLE_ADDPARTS Identifier ifNotExists? (partitionSpec partitionLocation?)+)
     ;
 
 partitionLocation

Modified: hadoop/hive/branches/branch-0.5/ql/src/java/org/apache/hadoop/hive/ql/plan/AddPartitionDesc.java
URL: http://svn.apache.org/viewvc/hadoop/hive/branches/branch-0.5/ql/src/java/org/apache/hadoop/hive/ql/plan/AddPartitionDesc.java?rev=903961&r1=903960&r2=903961&view=diff
==============================================================================
--- hadoop/hive/branches/branch-0.5/ql/src/java/org/apache/hadoop/hive/ql/plan/AddPartitionDesc.java
(original)
+++ hadoop/hive/branches/branch-0.5/ql/src/java/org/apache/hadoop/hive/ql/plan/AddPartitionDesc.java
Thu Jan 28 05:13:53 2010
@@ -27,6 +27,7 @@
   String tableName;
   String dbName;
   String location;
+  boolean ifNotExists;
   Map<String, String> partSpec;
   
   /**
@@ -34,14 +35,16 @@
    * @param tableName table to add to.
    * @param partSpec partition specification.
    * @param location partition location, relative to table location. 
+   * @param ifNotExists if true, the partition is only added if it doesn't exist
    */
   public AddPartitionDesc(String dbName, String tableName,
-      Map<String, String> partSpec, String location) {
+      Map<String, String> partSpec, String location, boolean ifNotExists) {
     super();
     this.dbName = dbName;
     this.tableName = tableName;
     this.partSpec = partSpec;
     this.location = location;
+    this.ifNotExists = ifNotExists;
   }
 
   /**
@@ -100,4 +103,17 @@
     this.partSpec = partSpec;
   }
 
+  /**
+   * @return if the partition should only be added if it doesn't exist already
+   */
+  public boolean getIfNotExists() {
+    return this.ifNotExists;
+  }
+  
+  /**
+   * @param ifNotExists if the part should be added only if it doesn't exist
+   */
+  public void setIfNotExists(boolean ifNotExists) {
+    this.ifNotExists = ifNotExists;
+  }
 }
\ No newline at end of file

Added: hadoop/hive/branches/branch-0.5/ql/src/test/queries/clientpositive/add_part_exist.q
URL: http://svn.apache.org/viewvc/hadoop/hive/branches/branch-0.5/ql/src/test/queries/clientpositive/add_part_exist.q?rev=903961&view=auto
==============================================================================
--- hadoop/hive/branches/branch-0.5/ql/src/test/queries/clientpositive/add_part_exist.q (added)
+++ hadoop/hive/branches/branch-0.5/ql/src/test/queries/clientpositive/add_part_exist.q Thu
Jan 28 05:13:53 2010
@@ -0,0 +1,16 @@
+CREATE TABLE add_part_test (key STRING, value STRING) PARTITIONED BY (ds STRING);
+SHOW PARTITIONS add_part_test;
+
+ALTER TABLE add_part_test ADD PARTITION (ds='2010-01-01');
+SHOW PARTITIONS add_part_test;
+
+ALTER TABLE add_part_test ADD IF NOT EXISTS PARTITION (ds='2010-01-01');
+SHOW PARTITIONS add_part_test;
+
+ALTER TABLE add_part_test ADD IF NOT EXISTS PARTITION (ds='2010-01-02');
+SHOW PARTITIONS add_part_test;
+
+ALTER TABLE add_part_test ADD IF NOT EXISTS PARTITION (ds='2010-01-01') PARTITION (ds='2010-01-02')
PARTITION (ds='2010-01-03');
+SHOW PARTITIONS add_part_test;
+
+DROP TABLE add_part_test;

Modified: hadoop/hive/branches/branch-0.5/ql/src/test/results/clientnegative/addpart1.q.out
URL: http://svn.apache.org/viewvc/hadoop/hive/branches/branch-0.5/ql/src/test/results/clientnegative/addpart1.q.out?rev=903961&r1=903960&r2=903961&view=diff
==============================================================================
--- hadoop/hive/branches/branch-0.5/ql/src/test/results/clientnegative/addpart1.q.out (original)
+++ hadoop/hive/branches/branch-0.5/ql/src/test/results/clientnegative/addpart1.q.out Thu
Jan 28 05:13:53 2010
@@ -19,5 +19,5 @@
 b=f/c=s
 PREHOOK: query: alter table addpart1 add partition (b='f', c='')
 PREHOOK: type: ALTERTABLE_ADDPARTS
-FAILED: Error in metadata: add partition: Value for key c is null or empty
+FAILED: Error in metadata: get partition: Value for key c is null or empty
 FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask

Added: hadoop/hive/branches/branch-0.5/ql/src/test/results/clientpositive/add_part_exist.q.out
URL: http://svn.apache.org/viewvc/hadoop/hive/branches/branch-0.5/ql/src/test/results/clientpositive/add_part_exist.q.out?rev=903961&view=auto
==============================================================================
--- hadoop/hive/branches/branch-0.5/ql/src/test/results/clientpositive/add_part_exist.q.out
(added)
+++ hadoop/hive/branches/branch-0.5/ql/src/test/results/clientpositive/add_part_exist.q.out
Thu Jan 28 05:13:53 2010
@@ -0,0 +1,56 @@
+PREHOOK: query: CREATE TABLE add_part_test (key STRING, value STRING) PARTITIONED BY (ds
STRING)
+PREHOOK: type: CREATETABLE
+POSTHOOK: query: CREATE TABLE add_part_test (key STRING, value STRING) PARTITIONED BY (ds
STRING)
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: default@add_part_test
+PREHOOK: query: SHOW PARTITIONS add_part_test
+PREHOOK: type: SHOWPARTITIONS
+POSTHOOK: query: SHOW PARTITIONS add_part_test
+POSTHOOK: type: SHOWPARTITIONS
+PREHOOK: query: ALTER TABLE add_part_test ADD PARTITION (ds='2010-01-01')
+PREHOOK: type: ALTERTABLE_ADDPARTS
+POSTHOOK: query: ALTER TABLE add_part_test ADD PARTITION (ds='2010-01-01')
+POSTHOOK: type: ALTERTABLE_ADDPARTS
+POSTHOOK: Output: default@add_part_test@ds=2010-01-01
+PREHOOK: query: SHOW PARTITIONS add_part_test
+PREHOOK: type: SHOWPARTITIONS
+POSTHOOK: query: SHOW PARTITIONS add_part_test
+POSTHOOK: type: SHOWPARTITIONS
+ds=2010-01-01
+PREHOOK: query: ALTER TABLE add_part_test ADD IF NOT EXISTS PARTITION (ds='2010-01-01')
+PREHOOK: type: ALTERTABLE_ADDPARTS
+POSTHOOK: query: ALTER TABLE add_part_test ADD IF NOT EXISTS PARTITION (ds='2010-01-01')
+POSTHOOK: type: ALTERTABLE_ADDPARTS
+PREHOOK: query: SHOW PARTITIONS add_part_test
+PREHOOK: type: SHOWPARTITIONS
+POSTHOOK: query: SHOW PARTITIONS add_part_test
+POSTHOOK: type: SHOWPARTITIONS
+ds=2010-01-01
+PREHOOK: query: ALTER TABLE add_part_test ADD IF NOT EXISTS PARTITION (ds='2010-01-02')
+PREHOOK: type: ALTERTABLE_ADDPARTS
+POSTHOOK: query: ALTER TABLE add_part_test ADD IF NOT EXISTS PARTITION (ds='2010-01-02')
+POSTHOOK: type: ALTERTABLE_ADDPARTS
+POSTHOOK: Output: default@add_part_test@ds=2010-01-02
+PREHOOK: query: SHOW PARTITIONS add_part_test
+PREHOOK: type: SHOWPARTITIONS
+POSTHOOK: query: SHOW PARTITIONS add_part_test
+POSTHOOK: type: SHOWPARTITIONS
+ds=2010-01-01
+ds=2010-01-02
+PREHOOK: query: ALTER TABLE add_part_test ADD IF NOT EXISTS PARTITION (ds='2010-01-01') PARTITION
(ds='2010-01-02') PARTITION (ds='2010-01-03')
+PREHOOK: type: ALTERTABLE_ADDPARTS
+POSTHOOK: query: ALTER TABLE add_part_test ADD IF NOT EXISTS PARTITION (ds='2010-01-01')
PARTITION (ds='2010-01-02') PARTITION (ds='2010-01-03')
+POSTHOOK: type: ALTERTABLE_ADDPARTS
+POSTHOOK: Output: default@add_part_test@ds=2010-01-03
+PREHOOK: query: SHOW PARTITIONS add_part_test
+PREHOOK: type: SHOWPARTITIONS
+POSTHOOK: query: SHOW PARTITIONS add_part_test
+POSTHOOK: type: SHOWPARTITIONS
+ds=2010-01-01
+ds=2010-01-02
+ds=2010-01-03
+PREHOOK: query: DROP TABLE add_part_test
+PREHOOK: type: DROPTABLE
+POSTHOOK: query: DROP TABLE add_part_test
+POSTHOOK: type: DROPTABLE
+POSTHOOK: Output: default@add_part_test



Mime
View raw message