Search in sources :

Example 6 with DriverYieldSignal

use of io.prestosql.operator.DriverYieldSignal in project hetu-core by openlookeng.

the class TestPageProcessor method testFilterNoColumns.

@Test
public void testFilterNoColumns() {
    PageProcessor pageProcessor = new PageProcessor(Optional.of(new TestingPageFilter(positionsRange(0, 50))), ImmutableList.of());
    Page inputPage = new Page(createLongSequenceBlock(0, 100));
    LocalMemoryContext memoryContext = newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName());
    Iterator<Optional<Page>> output = pageProcessor.process(SESSION, new DriverYieldSignal(), memoryContext, inputPage);
    assertEquals(memoryContext.getBytes(), 0);
    List<Optional<Page>> outputPages = ImmutableList.copyOf(output);
    assertEquals(outputPages.size(), 1);
    Page outputPage = outputPages.get(0).orElse(null);
    assertEquals(outputPage.getChannelCount(), 0);
    assertEquals(outputPage.getPositionCount(), 50);
}
Also used : LocalMemoryContext(io.prestosql.memory.context.LocalMemoryContext) Optional(java.util.Optional) DriverYieldSignal(io.prestosql.operator.DriverYieldSignal) Page(io.prestosql.spi.Page) Test(org.testng.annotations.Test)

Example 7 with DriverYieldSignal

use of io.prestosql.operator.DriverYieldSignal in project hetu-core by openlookeng.

the class TestPageProcessor method testAdaptiveBatchSize.

@Test
public void testAdaptiveBatchSize() {
    PageProcessor pageProcessor = new PageProcessor(Optional.empty(), ImmutableList.of(new InputPageProjection(0, VARCHAR)), OptionalInt.of(MAX_BATCH_SIZE));
    // process large page which will reduce batch size
    Slice[] slices = new Slice[(int) (MAX_BATCH_SIZE * 2.5)];
    Arrays.fill(slices, Slices.allocate(1024));
    Page inputPage = new Page(createSlicesBlock(slices));
    Iterator<Optional<Page>> output = processAndAssertRetainedPageSize(pageProcessor, new DriverYieldSignal(), inputPage);
    List<Optional<Page>> outputPages = ImmutableList.copyOf(output);
    int batchSize = MAX_BATCH_SIZE;
    for (Optional<Page> actualPage : outputPages) {
        Page expectedPage = new Page(createSlicesBlock(Arrays.copyOfRange(slices, 0, batchSize)));
        assertPageEquals(ImmutableList.of(VARCHAR), actualPage.orElse(null), expectedPage);
        if (actualPage.orElseThrow(() -> new AssertionError("page is not present")).getSizeInBytes() > MAX_PAGE_SIZE_IN_BYTES) {
            batchSize = batchSize / 2;
        }
    }
    // process small page which will increase batch size
    Arrays.fill(slices, Slices.allocate(128));
    inputPage = new Page(createSlicesBlock(slices));
    output = processAndAssertRetainedPageSize(pageProcessor, new DriverYieldSignal(), inputPage);
    outputPages = ImmutableList.copyOf(output);
    int offset = 0;
    for (Optional<Page> actualPage : outputPages) {
        Page expectedPage = new Page(createSlicesBlock(Arrays.copyOfRange(slices, 0, Math.min(inputPage.getPositionCount() - offset, batchSize))));
        assertPageEquals(ImmutableList.of(VARCHAR), actualPage.orElse(null), expectedPage);
        offset += actualPage.orElseThrow(() -> new AssertionError("page is not present")).getPositionCount();
        if (actualPage.orElseThrow(() -> new AssertionError("page is not present")).getSizeInBytes() < MIN_PAGE_SIZE_IN_BYTES) {
            batchSize = batchSize * 2;
        }
    }
}
Also used : Optional(java.util.Optional) Slice(io.airlift.slice.Slice) DriverYieldSignal(io.prestosql.operator.DriverYieldSignal) Page(io.prestosql.spi.Page) Test(org.testng.annotations.Test)

Example 8 with DriverYieldSignal

use of io.prestosql.operator.DriverYieldSignal in project hetu-core by openlookeng.

the class TestTupleFilterProcessor method testFilter.

@Test
public void testFilter() {
    Page tuplePage = Iterables.getOnlyElement(rowPagesBuilder(BIGINT, VARCHAR, DOUBLE).row(1L, "a", 0.1).build());
    List<Type> outputTypes = ImmutableList.of(VARCHAR, BIGINT, BOOLEAN, DOUBLE, DOUBLE);
    Page inputPage = Iterables.getOnlyElement(rowPagesBuilder(outputTypes).row("a", 1L, true, 0.1, 0.0).row("b", 1L, true, 0.1, 2.0).row("a", 1L, false, 0.1, 2.0).row("a", 0L, false, 0.2, 0.2).build());
    DynamicTupleFilterFactory filterFactory = new DynamicTupleFilterFactory(42, new PlanNodeId("42"), new int[] { 0, 1, 2 }, new int[] { 1, 0, 3 }, outputTypes, new PageFunctionCompiler(createTestMetadataManager(), 0));
    PageProcessor tupleFilterProcessor = filterFactory.createPageProcessor(tuplePage, OptionalInt.of(MAX_BATCH_SIZE)).get();
    Page actualPage = getOnlyElement(tupleFilterProcessor.process(SESSION, new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), inputPage)).orElseThrow(() -> new AssertionError("page is not present"));
    Page expectedPage = Iterables.getOnlyElement(rowPagesBuilder(outputTypes).row("a", 1L, true, 0.1, 0.0).row("a", 1L, false, 0.1, 2.0).build());
    assertPageEquals(outputTypes, actualPage, expectedPage);
}
Also used : PlanNodeId(io.prestosql.spi.plan.PlanNodeId) Type(io.prestosql.spi.type.Type) PageFunctionCompiler(io.prestosql.sql.gen.PageFunctionCompiler) PageProcessor(io.prestosql.operator.project.PageProcessor) DriverYieldSignal(io.prestosql.operator.DriverYieldSignal) Page(io.prestosql.spi.Page) Test(org.testng.annotations.Test)

Example 9 with DriverYieldSignal

use of io.prestosql.operator.DriverYieldSignal in project hetu-core by openlookeng.

the class TestDictionaryAwarePageProjection method testProjectList.

private static void testProjectList(Block block, Class<? extends Block> expectedResultType, DictionaryAwarePageProjection projection, boolean forceYield) {
    DriverYieldSignal yieldSignal = new DriverYieldSignal();
    int[] positions = { 0, 2, 4, 6, 8, 10 };
    Work<Block> work = projection.project(null, yieldSignal, new Page(block), SelectedPositions.positionsList(positions, 0, positions.length));
    Block result;
    if (forceYield) {
        result = projectWithYield(work, yieldSignal);
    } else {
        assertTrue(work.process());
        result = work.getResult();
    }
    assertBlockEquals(BIGINT, result, block.copyPositions(positions, 0, positions.length));
    assertInstanceOf(result, expectedResultType);
}
Also used : DriverYieldSignal(io.prestosql.operator.DriverYieldSignal) RunLengthEncodedBlock(io.prestosql.spi.block.RunLengthEncodedBlock) LongArrayBlock(io.prestosql.spi.block.LongArrayBlock) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) Block(io.prestosql.spi.block.Block) LazyBlock(io.prestosql.spi.block.LazyBlock) BlockAssertions.createLongSequenceBlock(io.prestosql.block.BlockAssertions.createLongSequenceBlock) Page(io.prestosql.spi.Page)

Example 10 with DriverYieldSignal

use of io.prestosql.operator.DriverYieldSignal in project hetu-core by openlookeng.

the class TestDictionaryAwarePageProjection method testProjectRange.

private static void testProjectRange(Block block, Class<? extends Block> expectedResultType, DictionaryAwarePageProjection projection, boolean forceYield) {
    DriverYieldSignal yieldSignal = new DriverYieldSignal();
    Work<Block> work = projection.project(null, yieldSignal, new Page(block), SelectedPositions.positionsRange(5, 10));
    Block result;
    if (forceYield) {
        result = projectWithYield(work, yieldSignal);
    } else {
        assertTrue(work.process());
        result = work.getResult();
    }
    assertBlockEquals(BIGINT, result, block.getRegion(5, 10));
    assertInstanceOf(result, expectedResultType);
}
Also used : DriverYieldSignal(io.prestosql.operator.DriverYieldSignal) RunLengthEncodedBlock(io.prestosql.spi.block.RunLengthEncodedBlock) LongArrayBlock(io.prestosql.spi.block.LongArrayBlock) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) Block(io.prestosql.spi.block.Block) LazyBlock(io.prestosql.spi.block.LazyBlock) BlockAssertions.createLongSequenceBlock(io.prestosql.block.BlockAssertions.createLongSequenceBlock) Page(io.prestosql.spi.Page)

Aggregations

DriverYieldSignal (io.prestosql.operator.DriverYieldSignal)26 Page (io.prestosql.spi.Page)22 Test (org.testng.annotations.Test)18 Block (io.prestosql.spi.block.Block)9 Optional (java.util.Optional)9 BlockAssertions.createLongSequenceBlock (io.prestosql.block.BlockAssertions.createLongSequenceBlock)7 PageProcessor (io.prestosql.operator.project.PageProcessor)7 LazyBlock (io.prestosql.spi.block.LazyBlock)7 DictionaryBlock (io.prestosql.spi.block.DictionaryBlock)6 BuiltInFunctionHandle (io.prestosql.spi.function.BuiltInFunctionHandle)6 CallExpression (io.prestosql.spi.relation.CallExpression)6 Slice (io.airlift.slice.Slice)5 LocalMemoryContext (io.prestosql.memory.context.LocalMemoryContext)5 RunLengthEncodedBlock (io.prestosql.spi.block.RunLengthEncodedBlock)5 VariableWidthBlock (io.prestosql.spi.block.VariableWidthBlock)5 Type (io.prestosql.spi.type.Type)5 BlockAssertions.createSlicesBlock (io.prestosql.block.BlockAssertions.createSlicesBlock)4 BlockAssertions.createStringsBlock (io.prestosql.block.BlockAssertions.createStringsBlock)4 AggregatedMemoryContext (io.prestosql.memory.context.AggregatedMemoryContext)4 AggregatedMemoryContext.newSimpleAggregatedMemoryContext (io.prestosql.memory.context.AggregatedMemoryContext.newSimpleAggregatedMemoryContext)4