Search in sources :

Example 1 with ExpressionProfiler

use of io.trino.sql.gen.ExpressionProfiler in project trino by trinodb.

the class TestPageProcessor method testExpressionProfiler.

@Test
public void testExpressionProfiler() {
    TestingFunctionResolution functionResolution = new TestingFunctionResolution();
    CallExpression add10Expression = call(functionResolution.resolveOperator(ADD, ImmutableList.of(BIGINT, BIGINT)), field(0, BIGINT), constant(10L, BIGINT));
    TestingTicker testingTicker = new TestingTicker();
    PageFunctionCompiler functionCompiler = functionResolution.getPageFunctionCompiler();
    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 : TestingFunctionResolution(io.trino.metadata.TestingFunctionResolution) TestingTicker(io.airlift.testing.TestingTicker) PageFunctionCompiler(io.trino.sql.gen.PageFunctionCompiler) LazyBlock(io.trino.spi.block.LazyBlock) Block(io.trino.spi.block.Block) BlockAssertions.createLongSequenceBlock(io.trino.block.BlockAssertions.createLongSequenceBlock) BlockAssertions.createStringsBlock(io.trino.block.BlockAssertions.createStringsBlock) BlockAssertions.createSlicesBlock(io.trino.block.BlockAssertions.createSlicesBlock) VariableWidthBlock(io.trino.spi.block.VariableWidthBlock) DriverYieldSignal(io.trino.operator.DriverYieldSignal) Page(io.trino.spi.Page) CallExpression(io.trino.sql.relational.CallExpression) ExpressionProfiler(io.trino.sql.gen.ExpressionProfiler) Test(org.testng.annotations.Test)

Example 2 with ExpressionProfiler

use of io.trino.sql.gen.ExpressionProfiler in project trino by trinodb.

the class TestPageProcessor method testDecreasingBatchSize.

@Test
public void testDecreasingBatchSize() {
    int rows = 1024;
    // We set the expensive expression threshold to 0, so the expression is always considered expensive and the batch size gets halved until it becomes 1
    TestingTicker testingTicker = new TestingTicker();
    ExpressionProfiler profiler = new ExpressionProfiler(testingTicker, new Duration(0, MILLISECONDS));
    PageProcessor pageProcessor = new PageProcessor(Optional.empty(), ImmutableList.of(new InputPageProjection(0, BIGINT)), OptionalInt.of(512), profiler);
    Slice[] slices = new Slice[rows];
    Arrays.fill(slices, Slices.allocate(rows));
    Page inputPage = new Page(createSlicesBlock(slices));
    Iterator<Optional<Page>> output = processAndAssertRetainedPageSize(pageProcessor, inputPage);
    long previousPositionCount = 1;
    long totalPositionCount = 0;
    while (totalPositionCount < rows) {
        Optional<Page> page = output.next();
        assertTrue(page.isPresent());
        long positionCount = page.get().getPositionCount();
        totalPositionCount += positionCount;
        // the batch size doesn't get smaller than 1
        if (positionCount > 1 && previousPositionCount != 1) {
            assertEquals(positionCount, previousPositionCount / 2);
        }
        previousPositionCount = positionCount;
    }
}
Also used : TestingTicker(io.airlift.testing.TestingTicker) Optional(java.util.Optional) Duration(io.airlift.units.Duration) Page(io.trino.spi.Page) ExpressionProfiler(io.trino.sql.gen.ExpressionProfiler) Slice(io.airlift.slice.Slice) Test(org.testng.annotations.Test)

Example 3 with ExpressionProfiler

use of io.trino.sql.gen.ExpressionProfiler in project trino by trinodb.

the class TestPageProcessor method testIncreasingBatchSize.

@Test
public void testIncreasingBatchSize() {
    int rows = 1024;
    // We deliberately do not set the ticker, so that the expression is always cheap and the batch size gets doubled until other limits are hit
    TestingTicker testingTicker = new TestingTicker();
    ExpressionProfiler profiler = new ExpressionProfiler(testingTicker, SPLIT_RUN_QUANTA);
    PageProcessor pageProcessor = new PageProcessor(Optional.empty(), ImmutableList.of(new InputPageProjection(0, BIGINT)), OptionalInt.of(1), profiler);
    Slice[] slices = new Slice[rows];
    Arrays.fill(slices, Slices.allocate(rows));
    Page inputPage = new Page(createSlicesBlock(slices));
    Iterator<Optional<Page>> output = processAndAssertRetainedPageSize(pageProcessor, inputPage);
    long previousPositionCount = 1;
    long totalPositionCount = 0;
    while (totalPositionCount < rows) {
        Optional<Page> page = output.next();
        assertTrue(page.isPresent());
        long positionCount = page.get().getPositionCount();
        totalPositionCount += positionCount;
        // skip the first read && skip the last read, which can be a partial page
        if (positionCount > 1 && totalPositionCount != rows) {
            assertEquals(positionCount, previousPositionCount * 2);
        }
        previousPositionCount = positionCount;
    }
}
Also used : TestingTicker(io.airlift.testing.TestingTicker) Optional(java.util.Optional) Slice(io.airlift.slice.Slice) Page(io.trino.spi.Page) ExpressionProfiler(io.trino.sql.gen.ExpressionProfiler) Test(org.testng.annotations.Test)

Aggregations

TestingTicker (io.airlift.testing.TestingTicker)3 Page (io.trino.spi.Page)3 ExpressionProfiler (io.trino.sql.gen.ExpressionProfiler)3 Test (org.testng.annotations.Test)3 Slice (io.airlift.slice.Slice)2 Optional (java.util.Optional)2 Duration (io.airlift.units.Duration)1 BlockAssertions.createLongSequenceBlock (io.trino.block.BlockAssertions.createLongSequenceBlock)1 BlockAssertions.createSlicesBlock (io.trino.block.BlockAssertions.createSlicesBlock)1 BlockAssertions.createStringsBlock (io.trino.block.BlockAssertions.createStringsBlock)1 TestingFunctionResolution (io.trino.metadata.TestingFunctionResolution)1 DriverYieldSignal (io.trino.operator.DriverYieldSignal)1 Block (io.trino.spi.block.Block)1 LazyBlock (io.trino.spi.block.LazyBlock)1 VariableWidthBlock (io.trino.spi.block.VariableWidthBlock)1 PageFunctionCompiler (io.trino.sql.gen.PageFunctionCompiler)1 CallExpression (io.trino.sql.relational.CallExpression)1