You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ke...@apache.org on 2012/06/01 18:52:03 UTC

svn commit: r1345274 - in /hive/trunk/ql/src: java/org/apache/hadoop/hive/ql/parse/ java/org/apache/hadoop/hive/ql/plan/ test/queries/clientpositive/ test/results/clientpositive/

Author: kevinwilfong
Date: Fri Jun  1 16:52:02 2012
New Revision: 1345274

URL: http://svn.apache.org/viewvc?rev=1345274&view=rev
Log:
HIVE-3076. drop partition does not work for non-partition columns (njain via kevinwilfong)

Added:
    hive/trunk/ql/src/test/queries/clientpositive/drop_partitions_filter3.q
    hive/trunk/ql/src/test/results/clientpositive/drop_partitions_filter3.q.out
Modified:
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/PartitionSpec.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/PlanUtils.java

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java?rev=1345274&r1=1345273&r2=1345274&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java Fri Jun  1 16:52:02 2012
@@ -53,6 +53,7 @@ import org.apache.hadoop.hive.ql.metadat
 import org.apache.hadoop.hive.ql.metadata.InvalidTableException;
 import org.apache.hadoop.hive.ql.metadata.Partition;
 import org.apache.hadoop.hive.ql.metadata.Table;
+import org.apache.hadoop.hive.ql.plan.PlanUtils;
 import org.apache.hadoop.hive.ql.session.SessionState.LogHelper;
 import org.apache.hadoop.hive.serde.Constants;
 import org.apache.hadoop.hive.serde2.columnar.ColumnarSerDe;
@@ -271,12 +272,8 @@ public abstract class BaseSemanticAnalyz
     rootTasks = new ArrayList<Task<? extends Serializable>>();
   }
 
-  public static String stripQuotes(String val) throws SemanticException {
-    if ((val.charAt(0) == '\'' && val.charAt(val.length() - 1) == '\'')
-        || (val.charAt(0) == '\"' && val.charAt(val.length() - 1) == '\"')) {
-      val = val.substring(1, val.length() - 1);
-    }
-    return val;
+  public static String stripQuotes(String val) {
+    return PlanUtils.stripQuotes(val);
   }
 
   public static String charSetString(String charSetName, String charSetString)

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/PartitionSpec.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/PartitionSpec.java?rev=1345274&r1=1345273&r2=1345274&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/PartitionSpec.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/PartitionSpec.java Fri Jun  1 16:52:02 2012
@@ -18,7 +18,6 @@
 
 package org.apache.hadoop.hive.ql.plan;
 
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.Map;
@@ -110,9 +109,9 @@ public class PartitionSpec {
   // For compatibility with other non-string partition columns, this function
   // returns the key, value mapping assuming that the operator is equality.
   public Map<String, String> getPartSpecWithoutOperator() {
-    Map<String, String> partSpec = new HashMap<String, String>();
+    Map<String, String> partSpec = new LinkedHashMap<String, String>();
     for (Map.Entry<String, PredicateSpec> entry: this.partSpec.entrySet()) {
-      partSpec.put(entry.getKey(), entry.getValue().getValue());
+      partSpec.put(entry.getKey(), PlanUtils.stripQuotes(entry.getValue().getValue()));
     }
 
     return partSpec;

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/PlanUtils.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/PlanUtils.java?rev=1345274&r1=1345273&r2=1345274&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/PlanUtils.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/PlanUtils.java Fri Jun  1 16:52:02 2012
@@ -724,6 +724,14 @@ public final class PlanUtils {
     }
   }
 
+  public static String stripQuotes(String val) {
+    if ((val.charAt(0) == '\'' && val.charAt(val.length() - 1) == '\'')
+        || (val.charAt(0) == '\"' && val.charAt(val.length() - 1) == '\"')) {
+      val = val.substring(1, val.length() - 1);
+    }
+    return val;
+  }
+
   private PlanUtils() {
     // prevent instantiation
   }

Added: hive/trunk/ql/src/test/queries/clientpositive/drop_partitions_filter3.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientpositive/drop_partitions_filter3.q?rev=1345274&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientpositive/drop_partitions_filter3.q (added)
+++ hive/trunk/ql/src/test/queries/clientpositive/drop_partitions_filter3.q Fri Jun  1 16:52:02 2012
@@ -0,0 +1,20 @@
+create table ptestfilter (a string, b int) partitioned by (c string, d int);
+describe ptestfilter;
+
+alter table ptestfilter add partition (c='1', d=1);
+alter table ptestfilter add partition (c='1', d=2);
+alter table ptestFilter add partition (c='2', d=1);
+alter table ptestfilter add partition (c='2', d=2);
+alter table ptestfilter add partition (c='3', d=1);
+alter table ptestfilter add partition (c='3', d=2);
+show partitions ptestfilter;
+
+alter table ptestfilter drop partition (c='1', d=1);
+show partitions ptestfilter;
+
+alter table ptestfilter drop partition (c='2');
+show partitions ptestfilter;
+
+drop table ptestfilter;
+
+

Added: hive/trunk/ql/src/test/results/clientpositive/drop_partitions_filter3.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/drop_partitions_filter3.q.out?rev=1345274&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/drop_partitions_filter3.q.out (added)
+++ hive/trunk/ql/src/test/results/clientpositive/drop_partitions_filter3.q.out Fri Jun  1 16:52:02 2012
@@ -0,0 +1,107 @@
+PREHOOK: query: create table ptestfilter (a string, b int) partitioned by (c string, d int)
+PREHOOK: type: CREATETABLE
+POSTHOOK: query: create table ptestfilter (a string, b int) partitioned by (c string, d int)
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: default@ptestfilter
+PREHOOK: query: describe ptestfilter
+PREHOOK: type: DESCTABLE
+POSTHOOK: query: describe ptestfilter
+POSTHOOK: type: DESCTABLE
+a	string	
+b	int	
+c	string	
+d	int	
+PREHOOK: query: alter table ptestfilter add partition (c='1', d=1)
+PREHOOK: type: ALTERTABLE_ADDPARTS
+PREHOOK: Input: default@ptestfilter
+POSTHOOK: query: alter table ptestfilter add partition (c='1', d=1)
+POSTHOOK: type: ALTERTABLE_ADDPARTS
+POSTHOOK: Input: default@ptestfilter
+POSTHOOK: Output: default@ptestfilter@c=1/d=1
+PREHOOK: query: alter table ptestfilter add partition (c='1', d=2)
+PREHOOK: type: ALTERTABLE_ADDPARTS
+PREHOOK: Input: default@ptestfilter
+POSTHOOK: query: alter table ptestfilter add partition (c='1', d=2)
+POSTHOOK: type: ALTERTABLE_ADDPARTS
+POSTHOOK: Input: default@ptestfilter
+POSTHOOK: Output: default@ptestfilter@c=1/d=2
+PREHOOK: query: alter table ptestFilter add partition (c='2', d=1)
+PREHOOK: type: ALTERTABLE_ADDPARTS
+PREHOOK: Input: default@ptestfilter
+POSTHOOK: query: alter table ptestFilter add partition (c='2', d=1)
+POSTHOOK: type: ALTERTABLE_ADDPARTS
+POSTHOOK: Input: default@ptestfilter
+POSTHOOK: Output: default@ptestfilter@c=2/d=1
+PREHOOK: query: alter table ptestfilter add partition (c='2', d=2)
+PREHOOK: type: ALTERTABLE_ADDPARTS
+PREHOOK: Input: default@ptestfilter
+POSTHOOK: query: alter table ptestfilter add partition (c='2', d=2)
+POSTHOOK: type: ALTERTABLE_ADDPARTS
+POSTHOOK: Input: default@ptestfilter
+POSTHOOK: Output: default@ptestfilter@c=2/d=2
+PREHOOK: query: alter table ptestfilter add partition (c='3', d=1)
+PREHOOK: type: ALTERTABLE_ADDPARTS
+PREHOOK: Input: default@ptestfilter
+POSTHOOK: query: alter table ptestfilter add partition (c='3', d=1)
+POSTHOOK: type: ALTERTABLE_ADDPARTS
+POSTHOOK: Input: default@ptestfilter
+POSTHOOK: Output: default@ptestfilter@c=3/d=1
+PREHOOK: query: alter table ptestfilter add partition (c='3', d=2)
+PREHOOK: type: ALTERTABLE_ADDPARTS
+PREHOOK: Input: default@ptestfilter
+POSTHOOK: query: alter table ptestfilter add partition (c='3', d=2)
+POSTHOOK: type: ALTERTABLE_ADDPARTS
+POSTHOOK: Input: default@ptestfilter
+POSTHOOK: Output: default@ptestfilter@c=3/d=2
+PREHOOK: query: show partitions ptestfilter
+PREHOOK: type: SHOWPARTITIONS
+POSTHOOK: query: show partitions ptestfilter
+POSTHOOK: type: SHOWPARTITIONS
+c=1/d=1
+c=1/d=2
+c=2/d=1
+c=2/d=2
+c=3/d=1
+c=3/d=2
+PREHOOK: query: alter table ptestfilter drop partition (c='1', d=1)
+PREHOOK: type: ALTERTABLE_DROPPARTS
+PREHOOK: Input: default@ptestfilter
+PREHOOK: Output: default@ptestfilter@c=1/d=1
+POSTHOOK: query: alter table ptestfilter drop partition (c='1', d=1)
+POSTHOOK: type: ALTERTABLE_DROPPARTS
+POSTHOOK: Input: default@ptestfilter
+POSTHOOK: Output: default@ptestfilter@c=1/d=1
+PREHOOK: query: show partitions ptestfilter
+PREHOOK: type: SHOWPARTITIONS
+POSTHOOK: query: show partitions ptestfilter
+POSTHOOK: type: SHOWPARTITIONS
+c=1/d=2
+c=2/d=1
+c=2/d=2
+c=3/d=1
+c=3/d=2
+PREHOOK: query: alter table ptestfilter drop partition (c='2')
+PREHOOK: type: ALTERTABLE_DROPPARTS
+PREHOOK: Input: default@ptestfilter
+PREHOOK: Output: default@ptestfilter@c=2/d=1
+PREHOOK: Output: default@ptestfilter@c=2/d=2
+POSTHOOK: query: alter table ptestfilter drop partition (c='2')
+POSTHOOK: type: ALTERTABLE_DROPPARTS
+POSTHOOK: Input: default@ptestfilter
+POSTHOOK: Output: default@ptestfilter@c=2/d=1
+POSTHOOK: Output: default@ptestfilter@c=2/d=2
+PREHOOK: query: show partitions ptestfilter
+PREHOOK: type: SHOWPARTITIONS
+POSTHOOK: query: show partitions ptestfilter
+POSTHOOK: type: SHOWPARTITIONS
+c=1/d=2
+c=3/d=1
+c=3/d=2
+PREHOOK: query: drop table ptestfilter
+PREHOOK: type: DROPTABLE
+PREHOOK: Input: default@ptestfilter
+PREHOOK: Output: default@ptestfilter
+POSTHOOK: query: drop table ptestfilter
+POSTHOOK: type: DROPTABLE
+POSTHOOK: Input: default@ptestfilter
+POSTHOOK: Output: default@ptestfilter