Search in sources :

Example 1 with TempFile

use of com.facebook.presto.orc.OrcTester.TempFile in project presto by prestodb.

the class TestOrcReaderPositions method testStripeSkipping.

@Test
public void testStripeSkipping() throws Exception {
    try (TempFile tempFile = new TempFile()) {
        createMultiStripeFile(tempFile.getFile());
        // test reading second and fourth stripes
        OrcPredicate predicate = (numberOfRows, statisticsByColumnIndex) -> {
            if (numberOfRows == 100) {
                return true;
            }
            IntegerStatistics stats = statisticsByColumnIndex.get(0).getIntegerStatistics();
            return ((stats.getMin() == 60) && (stats.getMax() == 117)) || ((stats.getMin() == 180) && (stats.getMax() == 237));
        };
        OrcRecordReader reader = createCustomOrcRecordReader(tempFile, new OrcMetadataReader(), predicate, BIGINT);
        assertEquals(reader.getFileRowCount(), 100);
        assertEquals(reader.getReaderRowCount(), 40);
        assertEquals(reader.getFilePosition(), 0);
        assertEquals(reader.getReaderPosition(), 0);
        // second stripe
        assertEquals(reader.nextBatch(), 20);
        assertEquals(reader.getReaderPosition(), 0);
        assertEquals(reader.getFilePosition(), 20);
        assertCurrentBatch(reader, 1);
        // fourth stripe
        assertEquals(reader.nextBatch(), 20);
        assertEquals(reader.getReaderPosition(), 20);
        assertEquals(reader.getFilePosition(), 60);
        assertCurrentBatch(reader, 3);
        assertEquals(reader.nextBatch(), -1);
        assertEquals(reader.getReaderPosition(), 40);
        assertEquals(reader.getFilePosition(), 100);
        reader.close();
    }
}
Also used : OrcFile(org.apache.hadoop.hive.ql.io.orc.OrcFile) Block(com.facebook.presto.spi.block.Block) Slice(io.airlift.slice.Slice) OrcWriterOptions(org.apache.hadoop.hive.ql.io.orc.OrcWriterOptions) PrimitiveObjectInspectorFactory.javaLongObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaLongObjectInspector) Assert.assertEquals(org.testng.Assert.assertEquals) Writable(org.apache.hadoop.io.Writable) Test(org.testng.annotations.Test) ORC_12(com.facebook.presto.orc.OrcTester.Format.ORC_12) OrcSerde(org.apache.hadoop.hive.ql.io.orc.OrcSerde) ByteBuffer(java.nio.ByteBuffer) Writer(org.apache.hadoop.hive.ql.io.orc.Writer) BIGINT(com.facebook.presto.spi.type.BigintType.BIGINT) FileSinkOperator(org.apache.hadoop.hive.ql.exec.FileSinkOperator) IntegerStatistics(com.facebook.presto.orc.metadata.IntegerStatistics) TempFile(com.facebook.presto.orc.OrcTester.TempFile) Configuration(org.apache.hadoop.conf.Configuration) Map(java.util.Map) OrcTester.createOrcRecordWriter(com.facebook.presto.orc.OrcTester.createOrcRecordWriter) Path(org.apache.hadoop.fs.Path) ImmutableMap(com.google.common.collect.ImmutableMap) Footer(com.facebook.presto.orc.metadata.Footer) UTF_8(java.nio.charset.StandardCharsets.UTF_8) SNAPPY(org.apache.hadoop.hive.ql.io.orc.CompressionKind.SNAPPY) NullMemoryManager(org.apache.hadoop.hive.ql.io.orc.NullMemoryManager) OrcMetadataReader(com.facebook.presto.orc.metadata.OrcMetadataReader) IOException(java.io.IOException) Field(java.lang.reflect.Field) Maps(com.google.common.collect.Maps) File(java.io.File) SettableStructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.SettableStructObjectInspector) DataSize(io.airlift.units.DataSize) OrcTester.createCustomOrcRecordReader(com.facebook.presto.orc.OrcTester.createCustomOrcRecordReader) Serializer(org.apache.hadoop.hive.serde2.Serializer) OrcOutputFormat(org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat) SerDeException(org.apache.hadoop.hive.serde2.SerDeException) OrcTester.createSettableStructObjectInspector(com.facebook.presto.orc.OrcTester.createSettableStructObjectInspector) StructField(org.apache.hadoop.hive.serde2.objectinspector.StructField) TempFile(com.facebook.presto.orc.OrcTester.TempFile) OrcMetadataReader(com.facebook.presto.orc.metadata.OrcMetadataReader) OrcTester.createCustomOrcRecordReader(com.facebook.presto.orc.OrcTester.createCustomOrcRecordReader) IntegerStatistics(com.facebook.presto.orc.metadata.IntegerStatistics) Test(org.testng.annotations.Test)

Example 2 with TempFile

use of com.facebook.presto.orc.OrcTester.TempFile in project presto by prestodb.

the class TestOrcReaderPositions method testEntireFile.

@Test
public void testEntireFile() throws Exception {
    try (TempFile tempFile = new TempFile()) {
        createMultiStripeFile(tempFile.getFile());
        OrcRecordReader reader = createCustomOrcRecordReader(tempFile, new OrcMetadataReader(), OrcPredicate.TRUE, BIGINT);
        assertEquals(reader.getReaderRowCount(), 100);
        assertEquals(reader.getReaderPosition(), 0);
        assertEquals(reader.getFileRowCount(), reader.getReaderRowCount());
        assertEquals(reader.getFilePosition(), reader.getReaderPosition());
        for (int i = 0; i < 5; i++) {
            assertEquals(reader.nextBatch(), 20);
            assertEquals(reader.getReaderPosition(), i * 20L);
            assertEquals(reader.getFilePosition(), reader.getReaderPosition());
            assertCurrentBatch(reader, i);
        }
        assertEquals(reader.nextBatch(), -1);
        assertEquals(reader.getReaderPosition(), 100);
        assertEquals(reader.getFilePosition(), reader.getReaderPosition());
        reader.close();
    }
}
Also used : TempFile(com.facebook.presto.orc.OrcTester.TempFile) OrcMetadataReader(com.facebook.presto.orc.metadata.OrcMetadataReader) OrcTester.createCustomOrcRecordReader(com.facebook.presto.orc.OrcTester.createCustomOrcRecordReader) Test(org.testng.annotations.Test)

Aggregations

TempFile (com.facebook.presto.orc.OrcTester.TempFile)2 OrcTester.createCustomOrcRecordReader (com.facebook.presto.orc.OrcTester.createCustomOrcRecordReader)2 OrcMetadataReader (com.facebook.presto.orc.metadata.OrcMetadataReader)2 Test (org.testng.annotations.Test)2 ORC_12 (com.facebook.presto.orc.OrcTester.Format.ORC_12)1 OrcTester.createOrcRecordWriter (com.facebook.presto.orc.OrcTester.createOrcRecordWriter)1 OrcTester.createSettableStructObjectInspector (com.facebook.presto.orc.OrcTester.createSettableStructObjectInspector)1 Footer (com.facebook.presto.orc.metadata.Footer)1 IntegerStatistics (com.facebook.presto.orc.metadata.IntegerStatistics)1 Block (com.facebook.presto.spi.block.Block)1 BIGINT (com.facebook.presto.spi.type.BigintType.BIGINT)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Maps (com.google.common.collect.Maps)1 Slice (io.airlift.slice.Slice)1 DataSize (io.airlift.units.DataSize)1 File (java.io.File)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 ByteBuffer (java.nio.ByteBuffer)1 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)1