HIVE-16803: Alter table change column comment should not try to get column 
stats for update (Chaoyu Tang, reviewed by Pengcheng Xiong)


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/690a9f8e
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/690a9f8e
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/690a9f8e

Branch: refs/heads/hive-14535
Commit: 690a9f8e2a2ce3ef773565e5ab3dc3b664e3412a
Parents: 0155a34
Author: Chaoyu Tang <[email protected]>
Authored: Fri Jun 2 14:25:17 2017 -0400
Committer: Chaoyu Tang <[email protected]>
Committed: Fri Jun 2 14:25:17 2017 -0400

----------------------------------------------------------------------
 .../hadoop/hive/metastore/HiveAlterHandler.java     |  4 ++--
 .../hadoop/hive/metastore/MetaStoreUtils.java       | 14 +++++++++++---
 .../hadoop/hive/metastore/TestMetaStoreUtils.java   | 16 +++++++++-------
 3 files changed, 22 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/690a9f8e/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java
----------------------------------------------------------------------
diff --git 
a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java 
b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java
index 7978a40..7c1be8c 100644
--- a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java
+++ b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java
@@ -727,7 +727,7 @@ public class HiveAlterHandler implements AlterHandler {
       // Nothing to update if everything is the same
         if (newDbName.equals(dbName) &&
             newTableName.equals(tableName) &&
-            MetaStoreUtils.columnsIncluded(oldCols, newCols)) {
+            MetaStoreUtils.columnsIncludedByNameType(oldCols, newCols)) {
           updateColumnStats = false;
         }
 
@@ -802,7 +802,7 @@ public class HiveAlterHandler implements AlterHandler {
           || !oldPartName.equals(newPartName);
 
       // do not need to update column stats if alter partition is not for 
rename or changing existing columns
-      if (!rename && MetaStoreUtils.columnsIncluded(oldCols, newCols)) {
+      if (!rename && MetaStoreUtils.columnsIncludedByNameType(oldCols, 
newCols)) {
         return newPartsColStats;
       }
       List<String> oldColNames = new ArrayList<String>(oldCols.size());

http://git-wip-us.apache.org/repos/asf/hive/blob/690a9f8e/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java
----------------------------------------------------------------------
diff --git 
a/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java 
b/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java
index 8328428..a8adb61 100644
--- a/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java
+++ b/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java
@@ -652,14 +652,22 @@ public class MetaStoreUtils {
     return true;
   }
 
-  static boolean columnsIncluded(List<FieldSchema> oldCols, List<FieldSchema> 
newCols) {
+  /*
+   * This method is to check if the new column list includes all the old 
columns with same name and
+   * type. The column comment does not count.
+   */
+  static boolean columnsIncludedByNameType(List<FieldSchema> oldCols, 
List<FieldSchema> newCols) {
     if (oldCols.size() > newCols.size()) {
       return false;
     }
 
-    Set<FieldSchema> newColsSet = new HashSet<FieldSchema>(newCols);
+    Map<String, String> columnNameTypePairMap = new HashMap<String, 
String>(newCols.size());
+    for (FieldSchema newCol : newCols) {
+      columnNameTypePairMap.put(newCol.getName().toLowerCase(), 
newCol.getType());
+    }
     for (final FieldSchema oldCol : oldCols) {
-      if (!newColsSet.contains(oldCol)) {
+      if (!columnNameTypePairMap.containsKey(oldCol.getName())
+          || 
!columnNameTypePairMap.get(oldCol.getName()).equalsIgnoreCase(oldCol.getType()))
 {
         return false;
       }
     }

http://git-wip-us.apache.org/repos/asf/hive/blob/690a9f8e/metastore/src/test/org/apache/hadoop/hive/metastore/TestMetaStoreUtils.java
----------------------------------------------------------------------
diff --git 
a/metastore/src/test/org/apache/hadoop/hive/metastore/TestMetaStoreUtils.java 
b/metastore/src/test/org/apache/hadoop/hive/metastore/TestMetaStoreUtils.java
index 21f9054..e5c8a40 100644
--- 
a/metastore/src/test/org/apache/hadoop/hive/metastore/TestMetaStoreUtils.java
+++ 
b/metastore/src/test/org/apache/hadoop/hive/metastore/TestMetaStoreUtils.java
@@ -27,15 +27,17 @@ import java.util.Arrays;
 public class TestMetaStoreUtils {
 
   @Test
-  public void testColumnsIncluded() {
+  public void testcolumnsIncludedByNameType() {
     FieldSchema col1 = new FieldSchema("col1", "string", "col1 comment");
+    FieldSchema col1a = new FieldSchema("col1", "string", "col1 but with a 
different comment");
     FieldSchema col2 = new FieldSchema("col2", "string", "col2 comment");
     FieldSchema col3 = new FieldSchema("col3", "string", "col3 comment");
-    Assert.assertTrue(MetaStoreUtils.columnsIncluded(Arrays.asList(col1), 
Arrays.asList(col1)));
-    Assert.assertTrue(MetaStoreUtils.columnsIncluded(Arrays.asList(col1, 
col2), Arrays.asList(col1, col2)));
-    Assert.assertTrue(MetaStoreUtils.columnsIncluded(Arrays.asList(col1, 
col2), Arrays.asList(col2, col1)));
-    Assert.assertTrue(MetaStoreUtils.columnsIncluded(Arrays.asList(col1, 
col2), Arrays.asList(col1, col2, col3)));
-    Assert.assertTrue(MetaStoreUtils.columnsIncluded(Arrays.asList(col1, 
col2), Arrays.asList(col3, col2, col1)));
-    Assert.assertFalse(MetaStoreUtils.columnsIncluded(Arrays.asList(col1, 
col2), Arrays.asList(col1)));
+    
Assert.assertTrue(MetaStoreUtils.columnsIncludedByNameType(Arrays.asList(col1), 
Arrays.asList(col1)));
+    
Assert.assertTrue(MetaStoreUtils.columnsIncludedByNameType(Arrays.asList(col1), 
Arrays.asList(col1a)));
+    
Assert.assertTrue(MetaStoreUtils.columnsIncludedByNameType(Arrays.asList(col1, 
col2), Arrays.asList(col1, col2)));
+    
Assert.assertTrue(MetaStoreUtils.columnsIncludedByNameType(Arrays.asList(col1, 
col2), Arrays.asList(col2, col1)));
+    
Assert.assertTrue(MetaStoreUtils.columnsIncludedByNameType(Arrays.asList(col1, 
col2), Arrays.asList(col1, col2, col3)));
+    
Assert.assertTrue(MetaStoreUtils.columnsIncludedByNameType(Arrays.asList(col1, 
col2), Arrays.asList(col3, col2, col1)));
+    
Assert.assertFalse(MetaStoreUtils.columnsIncludedByNameType(Arrays.asList(col1, 
col2), Arrays.asList(col1)));
   }
 }

Reply via email to