Search in sources :

Example 16 with DriverYieldSignal

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

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, SESSION.getSqlFunctionProperties(), SESSION.getSessionFunctions(), new PageFunctionCompiler(createTestMetadataManager(), 0));
    PageProcessor tupleFilterProcessor = filterFactory.createPageProcessor(tuplePage, OptionalInt.of(MAX_BATCH_SIZE)).get();
    Page actualPage = getOnlyElement(tupleFilterProcessor.process(SESSION.getSqlFunctionProperties(), 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(com.facebook.presto.spi.plan.PlanNodeId) Type(com.facebook.presto.common.type.Type) PageFunctionCompiler(com.facebook.presto.sql.gen.PageFunctionCompiler) PageProcessor(com.facebook.presto.operator.project.PageProcessor) DriverYieldSignal(com.facebook.presto.operator.DriverYieldSignal) Page(com.facebook.presto.common.Page) Test(org.testng.annotations.Test)

Example 17 with DriverYieldSignal

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

the class PagesSortBenchmark method runPagesMergeSortBenchmark.

@Benchmark
public List<Page> runPagesMergeSortBenchmark(MergeSortedBenchmarkData data) {
    WorkProcessor<Page> sortedPagesWork = mergeSortedPages(data.getSplitPages().stream().map(WorkProcessor::fromIterable).collect(toImmutableList()), ORDERING_COMPILER.compilePageWithPositionComparator(data.getSortTypes(), data.getSortChannels(), data.getSortOrders()), data.getOutputChannels(), data.getTypes(), (pageBuilder, pageWithPosition) -> pageBuilder.isFull(), false, newSimpleAggregatedMemoryContext(), new DriverYieldSignal());
    ImmutableList.Builder<Page> sortedPages = ImmutableList.builder();
    while (true) {
        sortedPagesWork.process();
        if (sortedPagesWork.isFinished()) {
            return sortedPages.build();
        }
        sortedPages.add(sortedPagesWork.getResult());
    }
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) WorkProcessor(com.facebook.presto.operator.WorkProcessor) DriverYieldSignal(com.facebook.presto.operator.DriverYieldSignal) Page(com.facebook.presto.common.Page) SequencePageBuilder.createSequencePage(com.facebook.presto.SequencePageBuilder.createSequencePage) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 18 with DriverYieldSignal

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

the class TestMergeSortedPages method mergeSortedPages.

private static MaterializedResult mergeSortedPages(List<Type> types, List<Integer> sortChannels, List<SortOrder> sortOrder, List<List<Page>> sortedPages) throws Exception {
    List<WorkProcessor<Page>> pageProducers = sortedPages.stream().map(WorkProcessor::fromIterable).collect(toImmutableList());
    PageWithPositionComparator comparator = new SimplePageWithPositionComparator(types, sortChannels, sortOrder);
    AggregatedMemoryContext memoryContext = newSimpleAggregatedMemoryContext().newAggregatedMemoryContext();
    WorkProcessor<Page> mergedPages = MergeSortedPages.mergeSortedPages(pageProducers, comparator, types, memoryContext, new DriverYieldSignal());
    assertTrue(mergedPages.process());
    if (mergedPages.isFinished()) {
        return toMaterializedResult(TEST_SESSION, types, ImmutableList.of());
    }
    Page page = mergedPages.getResult();
    assertTrue(mergedPages.process());
    assertTrue(mergedPages.isFinished());
    assertEquals(memoryContext.getBytes(), 0L);
    return toMaterializedResult(TEST_SESSION, types, ImmutableList.of(page));
}
Also used : WorkProcessor(com.facebook.presto.operator.WorkProcessor) DriverYieldSignal(com.facebook.presto.operator.DriverYieldSignal) SimplePageWithPositionComparator(com.facebook.presto.operator.SimplePageWithPositionComparator) Page(com.facebook.presto.common.Page) SimplePageWithPositionComparator(com.facebook.presto.operator.SimplePageWithPositionComparator) PageWithPositionComparator(com.facebook.presto.operator.PageWithPositionComparator) AggregatedMemoryContext.newSimpleAggregatedMemoryContext(com.facebook.presto.memory.context.AggregatedMemoryContext.newSimpleAggregatedMemoryContext) AggregatedMemoryContext(com.facebook.presto.memory.context.AggregatedMemoryContext)

Example 19 with DriverYieldSignal

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

the class FunctionAssertions method assertCachedInstanceHasBoundedRetainedSize.

public void assertCachedInstanceHasBoundedRetainedSize(String projection) {
    requireNonNull(projection, "projection is null");
    Expression projectionExpression = createExpression(session, projection, metadata, SYMBOL_TYPES);
    RowExpression projectionRowExpression = toRowExpression(session, projectionExpression);
    PageProcessor processor = compiler.compilePageProcessor(session.getSqlFunctionProperties(), Optional.empty(), ImmutableList.of(projectionRowExpression)).get();
    // This is a heuristic to detect whether the retained size of cachedInstance is bounded.
    // * The test runs at least 1000 iterations.
    // * The test passes if max retained size doesn't refresh after
    // 4x the number of iterations when max was last updated.
    // * The test fails if retained size reaches 1MB.
    // Note that 1MB is arbitrarily chosen and may be increased if a function implementation
    // legitimately needs more.
    long maxRetainedSize = 0;
    int maxIterationCount = 0;
    for (int iterationCount = 0; iterationCount < Math.max(1000, maxIterationCount * 4); iterationCount++) {
        Iterator<Optional<Page>> output = processor.process(session.getSqlFunctionProperties(), new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), SOURCE_PAGE);
        // consume the iterator
        Iterators.getOnlyElement(output);
        long retainedSize = processor.getProjections().stream().mapToLong(this::getRetainedSizeOfCachedInstance).sum();
        if (retainedSize > maxRetainedSize) {
            maxRetainedSize = retainedSize;
            maxIterationCount = iterationCount;
        }
        if (maxRetainedSize >= 1048576) {
            fail(format("The retained size of cached instance of function invocation is likely unbounded: %s", projection));
        }
    }
}
Also used : PageProcessor(com.facebook.presto.operator.project.PageProcessor) Optional(java.util.Optional) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) CanonicalizeExpressionRewriter.canonicalizeExpression(com.facebook.presto.sql.planner.iterative.rule.CanonicalizeExpressionRewriter.canonicalizeExpression) RowExpression(com.facebook.presto.spi.relation.RowExpression) DereferenceExpression(com.facebook.presto.sql.tree.DereferenceExpression) Expression(com.facebook.presto.sql.tree.Expression) RowExpression(com.facebook.presto.spi.relation.RowExpression) DriverYieldSignal(com.facebook.presto.operator.DriverYieldSignal)

Example 20 with DriverYieldSignal

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

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<List<Block>> work = projection.project(null, yieldSignal, new Page(block), SelectedPositions.positionsList(positions, 0, positions.length));
    List<Block> result;
    if (forceYield) {
        result = projectWithYield(work, yieldSignal);
    } else {
        assertTrue(work.process());
        result = work.getResult();
    }
    assertBlockEquals(BIGINT, result.get(0), block.copyPositions(positions, 0, positions.length));
    assertInstanceOf(result.get(0), expectedResultType);
}
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)

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