diff --git a/ql/src/java/org/apache/hadoop/hive/ql/io/orc/FixAcidKeyIndex.java b/ql/src/java/org/apache/hadoop/hive/ql/io/orc/FixAcidKeyIndex.java index 6920938fd4..8a7437e893 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/io/orc/FixAcidKeyIndex.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/io/orc/FixAcidKeyIndex.java @@ -108,6 +108,10 @@ public static void main(String[] args) throws Exception { } static boolean isAcidKeyIndexValid(Reader reader) { + if (reader.getNumberOfRows() == 0) { + return true; + } + // The number of stripes should match the key index count List stripes = reader.getStripes(); RecordIdentifier[] keyIndex = OrcRecordUpdater.parseKeyIndex(reader); diff --git a/ql/src/test/org/apache/hadoop/hive/ql/io/orc/TestFixAcidKeyIndex.java b/ql/src/test/org/apache/hadoop/hive/ql/io/orc/TestFixAcidKeyIndex.java index bf478cc09e..c4d569eb82 100644 --- a/ql/src/test/org/apache/hadoop/hive/ql/io/orc/TestFixAcidKeyIndex.java +++ b/ql/src/test/org/apache/hadoop/hive/ql/io/orc/TestFixAcidKeyIndex.java @@ -211,6 +211,12 @@ void fixValidIndex(Path orcFile) throws Exception { @Test public void testValidKeyIndex() throws Exception { + // Try with 0 row file. + createTestAcidFile(testFilePath, 0, new GoodKeyIndexBuilder()); + checkValidKeyIndex(testFilePath); + // Attempting to fix a valid - should not result in a new file. + fixValidIndex(testFilePath); + // Try single stripe createTestAcidFile(testFilePath, 100, new GoodKeyIndexBuilder()); checkValidKeyIndex(testFilePath);