diff --git a/java/core/src/java/org/apache/orc/impl/ReaderImpl.java b/java/core/src/java/org/apache/orc/impl/ReaderImpl.java index a354ea1ed3..602e5c303a 100644 --- a/java/core/src/java/org/apache/orc/impl/ReaderImpl.java +++ b/java/core/src/java/org/apache/orc/impl/ReaderImpl.java @@ -792,6 +792,22 @@ public long getRawDataSizeFromColIndices(List colIndices) { return getRawDataSizeFromColIndices(include, schema, fileStats); } + public static long getRawDataSizeFromColIndices( + List colIndices, + List types, + List stats) + throws FileFormatException { + TypeDescription schema = OrcUtils.convertTypeFromProtobuf(types, 0); + boolean[] include = new boolean[schema.getMaximumId() + 1]; + for(Integer rootId: colIndices) { + TypeDescription root = schema.findSubtype(rootId); + for(int c = root.getId(); c <= root.getMaximumId(); ++c) { + include[c] = true; + } + } + return getRawDataSizeFromColIndices(include, schema, stats); + } + static long getRawDataSizeFromColIndices(boolean[] include, TypeDescription schema, List stats) { diff --git a/java/core/src/test/org/apache/orc/impl/TestReaderImpl.java b/java/core/src/test/org/apache/orc/impl/TestReaderImpl.java index 5e8c9cf723..8e5085b9ff 100644 --- a/java/core/src/test/org/apache/orc/impl/TestReaderImpl.java +++ b/java/core/src/test/org/apache/orc/impl/TestReaderImpl.java @@ -44,11 +44,13 @@ import org.apache.orc.FileFormatException; import org.apache.orc.OrcFile; import org.apache.orc.OrcProto; +import org.apache.orc.OrcUtils; import org.apache.orc.Reader; import org.apache.orc.RecordReader; import org.apache.orc.StripeStatistics; import org.apache.orc.TestVectorOrcFile; import org.apache.orc.TimestampColumnStatistics; +import org.apache.orc.TypeDescription; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -368,4 +370,26 @@ public void testOrcTailStripeStats() throws Exception { assertEquals(-28550000, tsStats.getMaximumUtc()); } } + + @Test + public void testGetRawDataSizeFromColIndices() throws Exception { + Configuration conf = new Configuration(); + Path path = new Path(workDir, "orc_split_elim_new.orc"); + FileSystem fs = path.getFileSystem(conf); + try (ReaderImpl reader = (ReaderImpl) OrcFile.createReader(path, + OrcFile.readerOptions(conf).filesystem(fs))) { + TypeDescription schema = reader.getSchema(); + List types = OrcUtils.getOrcTypes(schema); + boolean[] include = new boolean[schema.getMaximumId() + 1]; + List list = new ArrayList(); + for (int i = 0; i < include.length; i++) { + include[i] = true; + list.add(i); + } + List stats = reader.getFileTail().getFooter().getStatisticsList(); + assertEquals( + ReaderImpl.getRawDataSizeFromColIndices(include, schema, stats), + ReaderImpl.getRawDataSizeFromColIndices(list, types, stats)); + } + } }