Search in sources :

Example 11 with DriverYieldSignal

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

the class FunctionAssertions method assertCachedInstanceHasBoundedRetainedSize.

public void assertCachedInstanceHasBoundedRetainedSize(String projection) {
    requireNonNull(projection, "projection is null");
    Expression projectionExpression = createExpression(session, projection, metadata, TypeProvider.copyOf(INPUT_TYPES));
    RowExpression projectionRowExpression = toRowExpression(session, projectionExpression);
    PageProcessor processor = compiler.compilePageProcessor(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.toConnectorSession(), 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(io.prestosql.operator.project.PageProcessor) Optional(java.util.Optional) Expression(io.prestosql.sql.tree.Expression) DereferenceExpression(io.prestosql.sql.tree.DereferenceExpression) RowExpression(io.prestosql.spi.relation.RowExpression) RowExpression(io.prestosql.spi.relation.RowExpression) DriverYieldSignal(io.prestosql.operator.DriverYieldSignal)

Example 12 with DriverYieldSignal

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

the class TestPageProcessorCompiler method testNonDeterministicProject.

@Test
public void testNonDeterministicProject() {
    Signature lessThan = internalOperator(LESS_THAN, BOOLEAN, ImmutableList.of(BIGINT, BIGINT));
    CallExpression random = new CallExpression(QualifiedObjectName.valueOfDefaultFunction("random").getObjectName(), new BuiltInFunctionHandle(new Signature(QualifiedObjectName.valueOfDefaultFunction("random"), SCALAR, parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature(StandardTypes.BIGINT))), BIGINT, singletonList(constant(10L, BIGINT)), Optional.empty());
    InputReferenceExpression col0 = field(0, BIGINT);
    CallExpression lessThanRandomExpression = new CallExpression(lessThan.getName().getObjectName(), new BuiltInFunctionHandle(lessThan), BOOLEAN, ImmutableList.of(col0, random), Optional.empty());
    PageProcessor processor = compiler.compilePageProcessor(Optional.empty(), ImmutableList.of(lessThanRandomExpression), MAX_BATCH_SIZE).get();
    assertFalse(new RowExpressionDeterminismEvaluator(metadata).isDeterministic(lessThanRandomExpression));
    Page page = new Page(createLongDictionaryBlock(1, 100));
    Page outputPage = getOnlyElement(processor.process(null, new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), page)).orElseThrow(() -> new AssertionError("page is not present"));
    assertFalse(outputPage.getBlock(0) instanceof DictionaryBlock);
}
Also used : RowExpressionDeterminismEvaluator(io.prestosql.sql.relational.RowExpressionDeterminismEvaluator) InputReferenceExpression(io.prestosql.spi.relation.InputReferenceExpression) PageProcessor(io.prestosql.operator.project.PageProcessor) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) BlockAssertions.createLongDictionaryBlock(io.prestosql.block.BlockAssertions.createLongDictionaryBlock) DriverYieldSignal(io.prestosql.operator.DriverYieldSignal) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) Page(io.prestosql.spi.Page) CallExpression(io.prestosql.spi.relation.CallExpression) Test(org.testng.annotations.Test)

Example 13 with DriverYieldSignal

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

the class TestPageProcessor method testProjectEmptyPage.

@Test
public void testProjectEmptyPage() {
    PageProcessor pageProcessor = new PageProcessor(Optional.of(new SelectAllFilter()), ImmutableList.of(new InputPageProjection(0, BIGINT)));
    Page inputPage = new Page(createLongSequenceBlock(0, 0));
    LocalMemoryContext memoryContext = newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName());
    Iterator<Optional<Page>> output = pageProcessor.process(SESSION, 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(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 14 with DriverYieldSignal

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

the class TestPageProcessor method testSelectNoneFilterLazyLoad.

@Test
public void testSelectNoneFilterLazyLoad() {
    PageProcessor pageProcessor = new PageProcessor(Optional.of(new SelectNoneFilter()), ImmutableList.of(new InputPageProjection(1, BIGINT)));
    // if channel 1 is loaded, test will fail
    Page inputPage = new Page(createLongSequenceBlock(0, 100), new LazyBlock(100, lazyBlock -> {
        throw new AssertionError("Lazy block should not be loaded");
    }));
    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(), 0);
}
Also used : TestingTicker(io.airlift.testing.TestingTicker) ADD(io.prestosql.spi.function.OperatorType.ADD) Arrays(java.util.Arrays) MIN_PAGE_SIZE_IN_BYTES(io.prestosql.operator.project.PageProcessor.MIN_PAGE_SIZE_IN_BYTES) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) Test(org.testng.annotations.Test) Duration(io.airlift.units.Duration) CallExpression(io.prestosql.spi.relation.CallExpression) MAX_BATCH_SIZE(io.prestosql.operator.project.PageProcessor.MAX_BATCH_SIZE) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) Expressions.call(io.prestosql.sql.relational.Expressions.call) SelectedPositions.positionsRange(io.prestosql.operator.project.SelectedPositions.positionsRange) Signature.internalOperator(io.prestosql.spi.function.Signature.internalOperator) Slices(io.airlift.slice.Slices) BlockAssertions.createSlicesBlock(io.prestosql.block.BlockAssertions.createSlicesBlock) AggregatedMemoryContext(io.prestosql.memory.context.AggregatedMemoryContext) PageFunctionCompiler(io.prestosql.sql.gen.PageFunctionCompiler) Type(io.prestosql.spi.type.Type) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) Assert.assertFalse(org.testng.Assert.assertFalse) BlockAssertions.createStringsBlock(io.prestosql.block.BlockAssertions.createStringsBlock) MetadataManager.createTestMetadataManager(io.prestosql.metadata.MetadataManager.createTestMetadataManager) Collections.nCopies(java.util.Collections.nCopies) LazyBlock(io.prestosql.spi.block.LazyBlock) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Assert.assertNotNull(org.testng.Assert.assertNotNull) List(java.util.List) ClassLayout(org.openjdk.jol.info.ClassLayout) SPLIT_RUN_QUANTA(io.prestosql.execution.executor.PrioritizedSplitRunner.SPLIT_RUN_QUANTA) Optional(java.util.Optional) Work(io.prestosql.operator.Work) AggregatedMemoryContext.newSimpleAggregatedMemoryContext(io.prestosql.memory.context.AggregatedMemoryContext.newSimpleAggregatedMemoryContext) Slice(io.airlift.slice.Slice) Assert.assertNull(org.testng.Assert.assertNull) SESSION(io.prestosql.testing.TestingConnectorSession.SESSION) VariableWidthBlock(io.prestosql.spi.block.VariableWidthBlock) NANOSECONDS(java.util.concurrent.TimeUnit.NANOSECONDS) DriverYieldSignal(io.prestosql.operator.DriverYieldSignal) Assert.assertEquals(org.testng.Assert.assertEquals) CompletedWork(io.prestosql.operator.CompletedWork) OptionalInt(java.util.OptionalInt) Supplier(java.util.function.Supplier) VARCHAR(io.prestosql.spi.type.VarcharType.VARCHAR) ImmutableList(com.google.common.collect.ImmutableList) String.join(java.lang.String.join) Threads.daemonThreadsNamed(io.airlift.concurrent.Threads.daemonThreadsNamed) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Block(io.prestosql.spi.block.Block) AfterClass(org.testng.annotations.AfterClass) MAX_PAGE_SIZE_IN_BYTES(io.prestosql.operator.project.PageProcessor.MAX_PAGE_SIZE_IN_BYTES) LocalMemoryContext(io.prestosql.memory.context.LocalMemoryContext) Iterator(java.util.Iterator) Expressions.constant(io.prestosql.sql.relational.Expressions.constant) Page(io.prestosql.spi.Page) ExpressionProfiler(io.prestosql.sql.gen.ExpressionProfiler) Expressions.field(io.prestosql.sql.relational.Expressions.field) BlockAssertions.createLongSequenceBlock(io.prestosql.block.BlockAssertions.createLongSequenceBlock) Assert.assertTrue(org.testng.Assert.assertTrue) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) PageAssertions.assertPageEquals(io.prestosql.operator.PageAssertions.assertPageEquals) LocalMemoryContext(io.prestosql.memory.context.LocalMemoryContext) LazyBlock(io.prestosql.spi.block.LazyBlock) Optional(java.util.Optional) DriverYieldSignal(io.prestosql.operator.DriverYieldSignal) Page(io.prestosql.spi.Page) Test(org.testng.annotations.Test)

Example 15 with DriverYieldSignal

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

the class TestPageProcessor method testExpressionProfiler.

@Test
public void testExpressionProfiler() {
    CallExpression add10Expression = call(ADD.getFunctionName().toString(), new BuiltInFunctionHandle(internalOperator(ADD, BIGINT.getTypeSignature(), ImmutableList.of(BIGINT.getTypeSignature(), BIGINT.getTypeSignature()))), BIGINT, field(0, BIGINT), constant(10L, BIGINT));
    TestingTicker testingTicker = new TestingTicker();
    PageFunctionCompiler functionCompiler = new PageFunctionCompiler(createTestMetadataManager(), 0);
    Supplier<PageProjection> projectionSupplier = functionCompiler.compileProjection(add10Expression, Optional.empty());
    PageProjection projection = projectionSupplier.get();
    Page page = new Page(createLongSequenceBlock(1, 11));
    ExpressionProfiler profiler = new ExpressionProfiler(testingTicker, SPLIT_RUN_QUANTA);
    for (int i = 0; i < 100; i++) {
        profiler.start();
        Work<Block> work = projection.project(SESSION, new DriverYieldSignal(), page, SelectedPositions.positionsRange(0, page.getPositionCount()));
        if (i < 10) {
            // increment the ticker with a large value to mark the expression as expensive
            testingTicker.increment(10, SECONDS);
            profiler.stop(page.getPositionCount());
            assertTrue(profiler.isExpressionExpensive());
        } else {
            testingTicker.increment(0, NANOSECONDS);
            profiler.stop(page.getPositionCount());
            assertFalse(profiler.isExpressionExpensive());
        }
        work.process();
    }
}
Also used : TestingTicker(io.airlift.testing.TestingTicker) PageFunctionCompiler(io.prestosql.sql.gen.PageFunctionCompiler) BlockAssertions.createSlicesBlock(io.prestosql.block.BlockAssertions.createSlicesBlock) BlockAssertions.createStringsBlock(io.prestosql.block.BlockAssertions.createStringsBlock) LazyBlock(io.prestosql.spi.block.LazyBlock) VariableWidthBlock(io.prestosql.spi.block.VariableWidthBlock) Block(io.prestosql.spi.block.Block) BlockAssertions.createLongSequenceBlock(io.prestosql.block.BlockAssertions.createLongSequenceBlock) DriverYieldSignal(io.prestosql.operator.DriverYieldSignal) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) Page(io.prestosql.spi.Page) CallExpression(io.prestosql.spi.relation.CallExpression) ExpressionProfiler(io.prestosql.sql.gen.ExpressionProfiler) Test(org.testng.annotations.Test)

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