Search in sources :

Example 21 with DriverYieldSignal

use of com.facebook.presto.operator.DriverYieldSignal in project presto by prestodb.

the class TestDictionaryAwarePageProjection method testProjectFastReturnIgnoreYield.

private static void testProjectFastReturnIgnoreYield(Block block, DictionaryAwarePageProjection projection) {
    DriverYieldSignal yieldSignal = new DriverYieldSignal();
    Work<List<Block>> work = projection.project(null, yieldSignal, new Page(block), SelectedPositions.positionsRange(5, 10));
    yieldSignal.setWithDelay(1, executor);
    yieldSignal.forceYieldForTesting();
    // yield signal is ignored given the block has already been loaded
    assertTrue(work.process());
    Block result = work.getResult().get(0);
    yieldSignal.reset();
    assertBlockEquals(BIGINT, result, block.getRegion(5, 10));
    assertInstanceOf(result, DictionaryBlock.class);
}
Also used : DriverYieldSignal(com.facebook.presto.operator.DriverYieldSignal) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) BlockAssertions.createLongSequenceBlock(com.facebook.presto.block.BlockAssertions.createLongSequenceBlock) LongArrayBlock(com.facebook.presto.common.block.LongArrayBlock) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) Block(com.facebook.presto.common.block.Block) LazyBlock(com.facebook.presto.common.block.LazyBlock) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Page(com.facebook.presto.common.Page)

Example 22 with DriverYieldSignal

use of com.facebook.presto.operator.DriverYieldSignal in project presto by prestodb.

the class TestPageProcessor method testProjectEmptyPage.

@Test
public void testProjectEmptyPage() {
    PageProcessor pageProcessor = new PageProcessor(Optional.of(new SelectAllFilter()), ImmutableList.of(createInputPageProjectionWithOutputs(0, BIGINT, 0)));
    Page inputPage = new Page(createLongSequenceBlock(0, 0));
    LocalMemoryContext memoryContext = newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName());
    Iterator<Optional<Page>> output = pageProcessor.process(SESSION.getSqlFunctionProperties(), new DriverYieldSignal(), memoryContext, inputPage);
    assertEquals(memoryContext.getBytes(), 0);
    // output should be one page containing no columns (only a count)
    List<Optional<Page>> outputPages = ImmutableList.copyOf(output);
    assertEquals(outputPages.size(), 0);
}
Also used : LocalMemoryContext(com.facebook.presto.memory.context.LocalMemoryContext) Optional(java.util.Optional) DriverYieldSignal(com.facebook.presto.operator.DriverYieldSignal) Page(com.facebook.presto.common.Page) Test(org.testng.annotations.Test)

Example 23 with DriverYieldSignal

use of com.facebook.presto.operator.DriverYieldSignal in project presto by prestodb.

the class TestMergeSortedPages method testMergeSortYieldingProgresses.

@Test
public void testMergeSortYieldingProgresses() throws Exception {
    DriverYieldSignal yieldSignal = new DriverYieldSignal();
    yieldSignal.forceYieldForTesting();
    List<Type> types = ImmutableList.of(INTEGER);
    WorkProcessor<Page> mergedPages = MergeSortedPages.mergeSortedPages(ImmutableList.of(WorkProcessor.fromIterable(rowPagesBuilder(types).build())), new SimplePageWithPositionComparator(types, ImmutableList.of(0), ImmutableList.of(DESC_NULLS_LAST)), ImmutableList.of(0), types, (pageBuilder, pageWithPosition) -> pageBuilder.isFull(), false, newSimpleAggregatedMemoryContext().newAggregatedMemoryContext(), yieldSignal);
    // yield signal is on
    assertFalse(mergedPages.process());
    // processor finishes computations (yield signal is still on, but previous process() call yielded)
    assertTrue(mergedPages.process());
    assertTrue(mergedPages.isFinished());
}
Also used : Type(com.facebook.presto.common.type.Type) DriverYieldSignal(com.facebook.presto.operator.DriverYieldSignal) Page(com.facebook.presto.common.Page) SimplePageWithPositionComparator(com.facebook.presto.operator.SimplePageWithPositionComparator) Test(org.testng.annotations.Test)

Example 24 with DriverYieldSignal

use of com.facebook.presto.operator.DriverYieldSignal in project presto by prestodb.

the class TestMergeSortedPages method testSortingYields.

@Test
public void testSortingYields() throws Exception {
    DriverYieldSignal yieldSignal = new DriverYieldSignal();
    yieldSignal.forceYieldForTesting();
    List<Type> types = ImmutableList.of(INTEGER);
    WorkProcessor<Page> mergedPages = MergeSortedPages.mergeSortedPages(ImmutableList.of(WorkProcessor.fromIterable(rowPagesBuilder(types).row(1).build())), new SimplePageWithPositionComparator(types, ImmutableList.of(0), ImmutableList.of(DESC_NULLS_LAST)), ImmutableList.of(0), types, (pageBuilder, pageWithPosition) -> pageBuilder.isFull(), false, newSimpleAggregatedMemoryContext().newAggregatedMemoryContext(), yieldSignal);
    // yield signal is on
    assertFalse(mergedPages.process());
    yieldSignal.resetYieldForTesting();
    // page is produced
    assertTrue(mergedPages.process());
    assertFalse(mergedPages.isFinished());
    Page page = mergedPages.getResult();
    MaterializedResult expected = resultBuilder(TEST_SESSION, types).row(1).build();
    assertEquals(toMaterializedResult(TEST_SESSION, types, ImmutableList.of(page)), expected);
    // merge source finished
    assertTrue(mergedPages.process());
    assertTrue(mergedPages.isFinished());
}
Also used : Type(com.facebook.presto.common.type.Type) DriverYieldSignal(com.facebook.presto.operator.DriverYieldSignal) Page(com.facebook.presto.common.Page) SimplePageWithPositionComparator(com.facebook.presto.operator.SimplePageWithPositionComparator) OperatorAssertion.toMaterializedResult(com.facebook.presto.operator.OperatorAssertion.toMaterializedResult) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 25 with DriverYieldSignal

use of com.facebook.presto.operator.DriverYieldSignal in project presto by prestodb.

the class TestPageProcessorCompiler method testSanityFilterOnRLE.

@Test
public void testSanityFilterOnRLE() {
    FunctionAndTypeManager functionAndTypeManager = createTestMetadataManager().getFunctionAndTypeManager();
    FunctionHandle lessThan = functionAndTypeManager.resolveOperator(LESS_THAN, fromTypes(BIGINT, BIGINT));
    CallExpression filter = new CallExpression(LESS_THAN.name(), lessThan, BOOLEAN, ImmutableList.of(field(0, BIGINT), constant(10L, BIGINT)));
    PageProcessor processor = compiler.compilePageProcessor(TEST_SESSION.getSqlFunctionProperties(), Optional.of(filter), ImmutableList.of(field(0, BIGINT)), false, MAX_BATCH_SIZE).get();
    Page page = new Page(createRLEBlock(5L, 100));
    Page outputPage = getOnlyElement(processor.process(null, new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), page)).orElseThrow(() -> new AssertionError("page is not present"));
    assertEquals(outputPage.getPositionCount(), 100);
    assertTrue(outputPage.getBlock(0) instanceof RunLengthEncodedBlock);
    RunLengthEncodedBlock rle = (RunLengthEncodedBlock) outputPage.getBlock(0);
    assertEquals(BIGINT.getLong(rle.getValue(), 0), 5L);
}
Also used : PageProcessor(com.facebook.presto.operator.project.PageProcessor) FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) DriverYieldSignal(com.facebook.presto.operator.DriverYieldSignal) Page(com.facebook.presto.common.Page) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) FunctionHandle(com.facebook.presto.spi.function.FunctionHandle) CallExpression(com.facebook.presto.spi.relation.CallExpression) Test(org.testng.annotations.Test)

Aggregations

DriverYieldSignal (com.facebook.presto.operator.DriverYieldSignal)27 Page (com.facebook.presto.common.Page)23 Test (org.testng.annotations.Test)19 ImmutableList (com.google.common.collect.ImmutableList)9 Optional (java.util.Optional)9 List (java.util.List)8 Type (com.facebook.presto.common.type.Type)7 PageProcessor (com.facebook.presto.operator.project.PageProcessor)7 BlockAssertions.createLongSequenceBlock (com.facebook.presto.block.BlockAssertions.createLongSequenceBlock)6 Block (com.facebook.presto.common.block.Block)6 DictionaryBlock (com.facebook.presto.common.block.DictionaryBlock)6 LazyBlock (com.facebook.presto.common.block.LazyBlock)6 CallExpression (com.facebook.presto.spi.relation.CallExpression)6 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)6 LocalMemoryContext (com.facebook.presto.memory.context.LocalMemoryContext)5 Slice (io.airlift.slice.Slice)5 RunLengthEncodedBlock (com.facebook.presto.common.block.RunLengthEncodedBlock)4 VariableWidthBlock (com.facebook.presto.common.block.VariableWidthBlock)4 AggregatedMemoryContext (com.facebook.presto.memory.context.AggregatedMemoryContext)4 AggregatedMemoryContext.newSimpleAggregatedMemoryContext (com.facebook.presto.memory.context.AggregatedMemoryContext.newSimpleAggregatedMemoryContext)4