FAQ
Author: cws
Date: Tue Jun 19 21:14:09 2012
New Revision: 1351859

URL: http://svn.apache.org/viewvc?rev=1351859&view=rev
Log:
Fixing bug in removing ProtectMode from a Table
(Bhushan Mandhani via Carl Steinbach)

Summary:
When ProtectMode has every member set to the default false value, the toString() method returns null. When this happens, we should realize that the PROTECT_MODE parameter is
no longer needed and should be removed for the Table or Partition. Currently, we try to persist this null value and get an error.

Test Plan: Ran Hive. Checked that "alter table some_table disable NO_DROP CASCADE" successfully removed the PROTECT_MODE parameter and did not give any error. Running unit tests.

Reviewers: njain, kevinwilfong, cwsteinbach

Reviewed By: cwsteinbach

Differential Revision: https://reviews.facebook.net/D3615

Modified:
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/metadata/Partition.java
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/metadata/Table.java
hive/trunk/ql/src/test/queries/clientpositive/protectmode2.q
hive/trunk/ql/src/test/results/clientpositive/protectmode2.q.out

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/metadata/Partition.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/metadata/Partition.java?rev=1351859&r1=1351858&r2=1351859&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/metadata/Partition.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/metadata/Partition.java Tue Jun 19 21:14:09 2012
@@ -544,7 +544,12 @@ public class Partition implements Serial
*/
public void setProtectMode(ProtectMode protectMode){
Map<String, String> parameters = tPartition.getParameters();
- parameters.put(ProtectMode.PARAMETER_NAME, protectMode.toString());
+ String pm = protectMode.toString();
+ if (pm != null) {
+ parameters.put(ProtectMode.PARAMETER_NAME, pm);
+ } else {
+ parameters.remove(ProtectMode.PARAMETER_NAME);
+ }
tPartition.setParameters(parameters);
}


Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/metadata/Table.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/metadata/Table.java?rev=1351859&r1=1351858&r2=1351859&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/metadata/Table.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/metadata/Table.java Tue Jun 19 21:14:09 2012
@@ -767,7 +767,12 @@ public class Table implements Serializab
*/
public void setProtectMode(ProtectMode protectMode){
Map<String, String> parameters = tTable.getParameters();
- parameters.put(ProtectMode.PARAMETER_NAME, protectMode.toString());
+ String pm = protectMode.toString();
+ if (pm != null) {
+ parameters.put(ProtectMode.PARAMETER_NAME, pm);
+ } else {
+ parameters.remove(ProtectMode.PARAMETER_NAME);
+ }
tTable.setParameters(parameters);
}


Modified: hive/trunk/ql/src/test/queries/clientpositive/protectmode2.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientpositive/protectmode2.q?rev=1351859&r1=1351858&r2=1351859&view=diff
==============================================================================
--- hive/trunk/ql/src/test/queries/clientpositive/protectmode2.q (original)
+++ hive/trunk/ql/src/test/queries/clientpositive/protectmode2.q Tue Jun 19 21:14:09 2012
@@ -17,6 +17,7 @@ alter table tbl2 add partition (p='p1');
alter table tbl2 add partition (p='p2');
alter table tbl2 add partition (p='p3');
alter table tbl2 enable no_drop cascade;
-desc extended tbl2;
+desc formatted tbl2;
alter table tbl2 disable no_drop cascade;
+desc formatted tbl2;
drop table tbl2;

Modified: hive/trunk/ql/src/test/results/clientpositive/protectmode2.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/protectmode2.q.out?rev=1351859&r1=1351858&r2=1351859&view=diff
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/protectmode2.q.out (original)
+++ hive/trunk/ql/src/test/results/clientpositive/protectmode2.q.out Tue Jun 19 21:14:09 2012
@@ -106,14 +106,40 @@ POSTHOOK: query: alter table tbl2 enable
POSTHOOK: type: ALTERTABLE_PROTECTMODE
POSTHOOK: Input: default@tbl2
POSTHOOK: Output: default@tbl2
-PREHOOK: query: desc extended tbl2
+PREHOOK: query: desc formatted tbl2
PREHOOK: type: DESCTABLE
-POSTHOOK: query: desc extended tbl2
+POSTHOOK: query: desc formatted tbl2
POSTHOOK: type: DESCTABLE
-col string
-p string
+# col_name data_type comment

+col string None
+
+# Partition Information
+# col_name data_type comment
+
+p string None
+
+# Detailed Table Information
+Database: default
+#### A masked pattern was here ####
+Protect Mode: NO_DROP_CASCADE
+Retention: 0
#### A masked pattern was here ####
+Table Type: MANAGED_TABLE
+Table Parameters:
+ PROTECT_MODE NO_DROP_CASCADE
+#### A masked pattern was here ####
+
+# Storage Information
+SerDe Library: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
+InputFormat: org.apache.hadoop.mapred.TextInputFormat
+OutputFormat: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
+Compressed: No
+Num Buckets: -1
+Bucket Columns: []
+Sort Columns: []
+Storage Desc Params:
+ serialization.format 1
PREHOOK: query: alter table tbl2 disable no_drop cascade
PREHOOK: type: ALTERTABLE_PROTECTMODE
PREHOOK: Input: default@tbl2
@@ -122,6 +148,39 @@ POSTHOOK: query: alter table tbl2 disabl
POSTHOOK: type: ALTERTABLE_PROTECTMODE
POSTHOOK: Input: default@tbl2
POSTHOOK: Output: default@tbl2
+PREHOOK: query: desc formatted tbl2
+PREHOOK: type: DESCTABLE
+POSTHOOK: query: desc formatted tbl2
+POSTHOOK: type: DESCTABLE
+# col_name data_type comment
+
+col string None
+
+# Partition Information
+# col_name data_type comment
+
+p string None
+
+# Detailed Table Information
+Database: default
+#### A masked pattern was here ####
+Protect Mode: None
+Retention: 0
+#### A masked pattern was here ####
+Table Type: MANAGED_TABLE
+Table Parameters:
+#### A masked pattern was here ####
+
+# Storage Information
+SerDe Library: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
+InputFormat: org.apache.hadoop.mapred.TextInputFormat
+OutputFormat: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
+Compressed: No
+Num Buckets: -1
+Bucket Columns: []
+Sort Columns: []
+Storage Desc Params:
+ serialization.format 1
PREHOOK: query: drop table tbl2
PREHOOK: type: DROPTABLE
PREHOOK: Input: default@tbl2

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 1 | next ›
Discussion Overview
groupcommits @
categorieshive, hadoop
postedJun 19, '12 at 9:14p
activeJun 19, '12 at 9:14p
posts1
users1
websitehive.apache.org

1 user in discussion

Cws: 1 post

People

Translate

site design / logo © 2021 Grokbase