diff --git a/java/core/src/java/org/apache/orc/impl/ConvertTreeReaderFactory.java b/java/core/src/java/org/apache/orc/impl/ConvertTreeReaderFactory.java index d3d8f3102f..9a42527e82 100644 --- a/java/core/src/java/org/apache/orc/impl/ConvertTreeReaderFactory.java +++ b/java/core/src/java/org/apache/orc/impl/ConvertTreeReaderFactory.java @@ -301,11 +301,13 @@ public void convertVector(ColumnVector fromColVector, resultColVector.reset(); if (fromColVector.isRepeating) { resultColVector.isRepeating = true; - if (fromColVector.noNulls || !fromColVector.isNull[0]) { - setConvertVectorElement(0); - } else { - resultColVector.noNulls = false; - resultColVector.isNull[0] = true; + if (batchSize > 0) { + if (fromColVector.noNulls || !fromColVector.isNull[0]) { + setConvertVectorElement(0); + } else { + resultColVector.noNulls = false; + resultColVector.isNull[0] = true; + } } } else if (fromColVector.noNulls) { for (int i = 0; i < batchSize; i++) { diff --git a/java/core/src/test/org/apache/orc/impl/TestConvertTreeReaderFactory.java b/java/core/src/test/org/apache/orc/impl/TestConvertTreeReaderFactory.java index bbec4516d9..804859f5b7 100644 --- a/java/core/src/test/org/apache/orc/impl/TestConvertTreeReaderFactory.java +++ b/java/core/src/test/org/apache/orc/impl/TestConvertTreeReaderFactory.java @@ -746,4 +746,38 @@ private void testDecimalConvertToDecimalInNullStripe() throws Exception { readDecimalInNullStripe("decimal(18,2)", DecimalColumnVector.class, new String[]{"null", "1024", "1"}); } + + @Test + public void testIntArrayToStringArrayFirstBatchAllEmpty() throws Exception { + TypeDescription fileSchema = TypeDescription.fromString("struct>"); + TypeDescription readerSchema = TypeDescription.fromString("struct>"); + + try (Writer w = OrcFile.createWriter(testFilePath, + OrcFile.writerOptions(conf).setSchema(fileSchema))) { + VectorizedRowBatch b = fileSchema.createRowBatch(3); + ListColumnVector lc = (ListColumnVector) b.cols[0]; + for (int i = 0; i < 3; i++) { + lc.offsets[i] = 0; + lc.lengths[i] = 0; + } + lc.childCount = 0; + b.size = 3; + w.addRowBatch(b); + } + + try (Reader reader = OrcFile.createReader(testFilePath, OrcFile.readerOptions(conf)); + RecordReader rows = reader.rows(reader.options().schema(readerSchema))) { + VectorizedRowBatch rb = readerSchema.createRowBatch(3); + assertTrue(rows.nextBatch(rb)); + ListColumnVector r = (ListColumnVector) rb.cols[0]; + // Cast verifies schema evolution took effect (would be LongColumnVector without evolution) + BytesColumnVector child = (BytesColumnVector) r.child; + assertEquals(0, r.childCount); + for (int i = 0; i < 3; i++) { + assertEquals(0, r.lengths[i], "row " + i + " should be empty array"); + } + } finally { + fs.delete(testFilePath, false); + } + } }