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 @@ void alterTableUpdateTableColumnStats(RawStore msdb, Table oldTable, Table newTa // 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 @@ private ColumnStatistics updateOrGetPartitionColumnStats( || !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 oldColNames = new ArrayList(oldCols.size()); 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 @@ static boolean areSameColumns(List oldCols, List newCo return true; } - static boolean columnsIncluded(List oldCols, List 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 oldCols, List newCols) { if (oldCols.size() > newCols.size()) { return false; } - Set newColsSet = new HashSet(newCols); + Map columnNameTypePairMap = new HashMap(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; } } 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 @@ 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))); } }