diff --git hcatalog/webhcat/java-client/src/test/java/org/apache/hive/hcatalog/api/TestHCatClient.java hcatalog/webhcat/java-client/src/test/java/org/apache/hive/hcatalog/api/TestHCatClient.java index 8992d552c..891322a 100644 --- hcatalog/webhcat/java-client/src/test/java/org/apache/hive/hcatalog/api/TestHCatClient.java +++ hcatalog/webhcat/java-client/src/test/java/org/apache/hive/hcatalog/api/TestHCatClient.java @@ -90,7 +90,6 @@ private static HiveConf replicationTargetHCatConf; private static SecurityManager securityManager; private static boolean useExternalMS = false; - private static boolean useExternalMSForReplication = false; public static class RunMS implements Runnable { @@ -1056,14 +1055,14 @@ public void testTableSchemaPropagation() throws Exception { HCatTable targetTable = targetMetaStore.deserializeTable(tableStringRep); assertEquals("Table after deserialization should have been identical to sourceTable.", - sourceTable.diff(targetTable), HCatTable.NO_DIFF); + HCatTable.NO_DIFF, sourceTable.diff(targetTable)); // Create table on Target. targetMetaStore.createTable(HCatCreateTableDesc.create(targetTable).build()); // Verify that the created table is identical to sourceTable. targetTable = targetMetaStore.getTable(dbName, tableName); assertEquals("Table after deserialization should have been identical to sourceTable.", - sourceTable.diff(targetTable), HCatTable.NO_DIFF); + HCatTable.NO_DIFF, sourceTable.diff(targetTable)); // Modify sourceTable. List newColumnSchema = new ArrayList(columnSchema); @@ -1098,7 +1097,7 @@ public void testTableSchemaPropagation() throws Exception { targetTable = targetMetaStore.getTable(dbName, tableName); assertEquals("After propagating schema changes, source and target tables should have been equivalent.", - targetTable.diff(sourceTable), HCatTable.NO_DIFF); + HCatTable.NO_DIFF, targetTable.diff(sourceTable)); } catch (Exception unexpected) { @@ -1157,14 +1156,14 @@ public void testPartitionRegistrationWithCustomSchema() throws Exception { sourceMetaStore.addPartition(HCatAddPartitionDesc.create(sourcePartition_1).build()); assertEquals("Unexpected number of partitions. ", - sourceMetaStore.getPartitions(dbName, tableName).size(), 1); + 1, sourceMetaStore.getPartitions(dbName, tableName).size()); // Verify that partition_1 was added correctly, and properties were inherited from the HCatTable. HCatPartition addedPartition_1 = sourceMetaStore.getPartition(dbName, tableName, partitionSpec_1); - assertEquals("Column schema doesn't match.", addedPartition_1.getColumns(), sourceTable.getCols()); - assertEquals("InputFormat doesn't match.", addedPartition_1.getInputFormat(), sourceTable.getInputFileFormat()); - assertEquals("OutputFormat doesn't match.", addedPartition_1.getOutputFormat(), sourceTable.getOutputFileFormat()); - assertEquals("SerDe doesn't match.", addedPartition_1.getSerDe(), sourceTable.getSerdeLib()); - assertEquals("SerDe params don't match.", addedPartition_1.getSerdeParams(), sourceTable.getSerdeParams()); + assertEquals("Column schema doesn't match.", sourceTable.getCols(), addedPartition_1.getColumns()); + assertEquals("InputFormat doesn't match.", sourceTable.getInputFileFormat(), addedPartition_1.getInputFormat()); + assertEquals("OutputFormat doesn't match.", sourceTable.getOutputFileFormat(), addedPartition_1.getOutputFormat()); + assertEquals("SerDe doesn't match.", sourceTable.getSerdeLib(), addedPartition_1.getSerDe()); + assertEquals("SerDe params don't match.", sourceTable.getSerdeParams(), addedPartition_1.getSerdeParams()); // Replicate table definition. @@ -1177,8 +1176,7 @@ public void testPartitionRegistrationWithCustomSchema() throws Exception { targetMetaStore.createTable(HCatCreateTableDesc.create(targetTable).build()); targetTable = targetMetaStore.getTable(dbName, tableName); - assertEquals("Created table doesn't match the source.", - targetTable.diff(sourceTable), HCatTable.NO_DIFF); + assertEquals("Created table doesn't match the source.", HCatTable.NO_DIFF, targetTable.diff(sourceTable)); // Modify Table schema at the source. List newColumnSchema = new ArrayList(columnSchema); @@ -1215,7 +1213,7 @@ public void testPartitionRegistrationWithCustomSchema() throws Exception { List targetPartitions = targetMetaStore.getPartitions(dbName, tableName); - assertEquals("Expected the same number of partitions. ", targetPartitions.size(), sourcePartitions.size()); + assertEquals("Expected the same number of partitions. ", sourcePartitions.size(), targetPartitions.size()); for (int i=0; i newColumnSchema = new ArrayList(columnSchema); diff --git metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java index 12f3f16..2e65190 100644 --- metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java +++ metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java @@ -185,11 +185,20 @@ public static boolean updateTableStatsFast(Database db, Table tbl, Warehouse wh, public static boolean updateTableStatsFast(Database db, Table tbl, Warehouse wh, boolean madeDir, boolean forceRecompute) throws MetaException { - FileStatus[] fileStatuses = {}; - if (tbl.getPartitionKeysSize() == 0) { // Update stats only when unpartitioned - fileStatuses = wh.getFileStatusesForUnpartitionedTable(db, tbl); + if (tbl.getPartitionKeysSize() == 0) { + // Update stats only when unpartitioned + FileStatus[] fileStatuses = wh.getFileStatusesForUnpartitionedTable(db, tbl); + return updateTableStatsFast(tbl, fileStatuses, madeDir, forceRecompute); + } else { + return false; } - return updateTableStatsFast(tbl, fileStatuses, madeDir, forceRecompute); + } + + /** + * Check whether given files array is null or empty. + */ + private static boolean isEmpty(FileStatus[] files) { + return files == null || files.length == 0; } /** @@ -204,6 +213,10 @@ public static boolean updateTableStatsFast(Database db, Table tbl, Warehouse wh, */ public static boolean updateTableStatsFast(Table tbl, FileStatus[] fileStatus, boolean newDir, boolean forceRecompute) throws MetaException { + if (isEmpty(fileStatus)) { + // no files given, don't write zero values for fast stats + return false; + } Map params = tbl.getParameters();