Search in sources :

Example 1 with OrcReaderSettings

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

the class TestSelectiveOrcReader method testHiddenConstantColumns.

@Test
public void testHiddenConstantColumns() throws Exception {
    Type type = BIGINT;
    List<Type> types = ImmutableList.of(type);
    List<List<?>> values = ImmutableList.of(ImmutableList.of(1L, 2L));
    TempFile tempFile = new TempFile();
    writeOrcColumnsPresto(tempFile.getFile(), DWRF, ZSTD, Optional.empty(), types, values, new OrcWriterStats());
    // Hidden columns like partition columns use negative indices (-13).
    int hiddenColumnIndex = -13;
    Map<Integer, Type> includedColumns = ImmutableMap.of(hiddenColumnIndex, VARCHAR, 0, BIGINT);
    List<Integer> outputColumns = ImmutableList.of(hiddenColumnIndex, 0);
    Slice constantSlice = Slices.utf8Slice("partition_value");
    Map<Integer, Object> constantValues = ImmutableMap.of(hiddenColumnIndex, constantSlice);
    OrcAggregatedMemoryContext systemMemoryUsage = new TestingHiveOrcAggregatedMemoryContext();
    TupleDomainFilter filter = BigintRange.of(1, 1, false);
    Map<Subfield, TupleDomainFilter> subFieldFilter = toSubfieldFilter(filter);
    OrcReaderSettings readerSettings = OrcTester.OrcReaderSettings.builder().setColumnFilters(ImmutableMap.of(0, subFieldFilter)).build();
    try (OrcSelectiveRecordReader recordReader = createCustomOrcSelectiveRecordReader(tempFile.getFile(), DWRF.getOrcEncoding(), OrcPredicate.TRUE, types, 1, readerSettings.getColumnFilters(), readerSettings.getFilterFunctions(), readerSettings.getFilterFunctionInputMapping(), readerSettings.getRequiredSubfields(), constantValues, ImmutableMap.of(), includedColumns, outputColumns, false, systemMemoryUsage, false)) {
        Page page = recordReader.getNextPage();
        assertEquals(page.getPositionCount(), 1);
        Block partitionValueBlock = page.getBlock(0);
        int length = partitionValueBlock.getSliceLength(0);
        Slice varcharSlice = partitionValueBlock.getSlice(0, 0, length);
        assertEquals(varcharSlice, constantSlice);
        Block bigintBlock = page.getBlock(1);
        assertEquals(bigintBlock.getLong(0), 1);
        assertNull(recordReader.getNextPage());
    }
}
Also used : OrcTester.createCustomOrcSelectiveRecordReader(com.facebook.presto.orc.OrcTester.createCustomOrcSelectiveRecordReader) OrcReaderSettings(com.facebook.presto.orc.OrcTester.OrcReaderSettings) Page(com.facebook.presto.common.Page) TupleDomainFilter(com.facebook.presto.common.predicate.TupleDomainFilter) BigInteger(java.math.BigInteger) CharType.createCharType(com.facebook.presto.common.type.CharType.createCharType) OrcTester.mapType(com.facebook.presto.orc.OrcTester.mapType) DecimalType(com.facebook.presto.common.type.DecimalType) CharType(com.facebook.presto.common.type.CharType) Type(com.facebook.presto.common.type.Type) OrcTester.arrayType(com.facebook.presto.orc.OrcTester.arrayType) OrcTester.rowType(com.facebook.presto.orc.OrcTester.rowType) Slice(io.airlift.slice.Slice) Block(com.facebook.presto.common.block.Block) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) Subfield(com.facebook.presto.common.Subfield) Test(org.testng.annotations.Test)

Aggregations

Page (com.facebook.presto.common.Page)1 Subfield (com.facebook.presto.common.Subfield)1 Block (com.facebook.presto.common.block.Block)1 TupleDomainFilter (com.facebook.presto.common.predicate.TupleDomainFilter)1 CharType (com.facebook.presto.common.type.CharType)1 CharType.createCharType (com.facebook.presto.common.type.CharType.createCharType)1 DecimalType (com.facebook.presto.common.type.DecimalType)1 Type (com.facebook.presto.common.type.Type)1 OrcReaderSettings (com.facebook.presto.orc.OrcTester.OrcReaderSettings)1 OrcTester.arrayType (com.facebook.presto.orc.OrcTester.arrayType)1 OrcTester.createCustomOrcSelectiveRecordReader (com.facebook.presto.orc.OrcTester.createCustomOrcSelectiveRecordReader)1 OrcTester.mapType (com.facebook.presto.orc.OrcTester.mapType)1 OrcTester.rowType (com.facebook.presto.orc.OrcTester.rowType)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 Slice (io.airlift.slice.Slice)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1