Search in sources :

Example 11 with DriverYieldSignal

use of io.trino.operator.DriverYieldSignal in project trino by trinodb.

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.trino.operator.DriverYieldSignal) Page(io.trino.spi.Page) Test(org.testng.annotations.Test)

Example 12 with DriverYieldSignal

use of io.trino.operator.DriverYieldSignal in project trino by trinodb.

the class TestDictionaryAwarePageProjection method testProjectFastReturnIgnoreYield.

private static void testProjectFastReturnIgnoreYield(Block block, DictionaryAwarePageProjection projection, boolean produceLazyBlock) {
    if (produceLazyBlock) {
        block = lazyWrapper(block);
    }
    DriverYieldSignal yieldSignal = new DriverYieldSignal();
    Work<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();
    yieldSignal.reset();
    if (produceLazyBlock) {
        assertInstanceOf(result, LazyBlock.class);
        assertFalse(result.isLoaded());
        assertFalse(block.isLoaded());
        result = result.getLoadedBlock();
    }
    assertBlockEquals(BIGINT, result, block.getRegion(5, 10));
    assertInstanceOf(result, DictionaryBlock.class);
}
Also used : DriverYieldSignal(io.trino.operator.DriverYieldSignal) BlockAssertions.createLongSequenceBlock(io.trino.block.BlockAssertions.createLongSequenceBlock) DictionaryBlock(io.trino.spi.block.DictionaryBlock) LazyBlock(io.trino.spi.block.LazyBlock) Block(io.trino.spi.block.Block) LongArrayBlock(io.trino.spi.block.LongArrayBlock) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) BlockAssertions.createLongsBlock(io.trino.block.BlockAssertions.createLongsBlock) Page(io.trino.spi.Page)

Example 13 with DriverYieldSignal

use of io.trino.operator.DriverYieldSignal in project trino by trinodb.

the class TestPageFunctionCompiler method testGeneratedClassName.

@Test
public void testGeneratedClassName() {
    PageFunctionCompiler functionCompiler = FUNCTION_RESOLUTION.getPageFunctionCompiler();
    String planNodeId = "7";
    String stageId = "20170707_223500_67496_zguwn.2";
    String classSuffix = stageId + "_" + planNodeId;
    Supplier<PageProjection> projectionSupplier = functionCompiler.compileProjection(ADD_10_EXPRESSION, Optional.of(classSuffix));
    PageProjection projection = projectionSupplier.get();
    Work<Block> work = projection.project(SESSION, new DriverYieldSignal(), createLongBlockPage(0), SelectedPositions.positionsRange(0, 1));
    // class name should look like PageProjectionOutput_20170707_223500_67496_zguwn_2_7_XX
    assertTrue(work.getClass().getSimpleName().startsWith("PageProjectionWork_" + stageId.replace('.', '_') + "_" + planNodeId));
}
Also used : PageProjection(io.trino.operator.project.PageProjection) Block(io.trino.spi.block.Block) DriverYieldSignal(io.trino.operator.DriverYieldSignal) Test(org.testng.annotations.Test)

Example 14 with DriverYieldSignal

use of io.trino.operator.DriverYieldSignal in project trino by trinodb.

the class TestPageProcessorCompiler method testSanityColumnarDictionary.

@Test
public void testSanityColumnarDictionary() {
    PageProcessor processor = compiler.compilePageProcessor(Optional.empty(), ImmutableList.of(field(0, VARCHAR)), MAX_BATCH_SIZE).get();
    Page page = new Page(createDictionaryBlock(createExpectedValues(10), 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 DictionaryBlock);
    DictionaryBlock dictionaryBlock = (DictionaryBlock) outputPage.getBlock(0);
    assertEquals(dictionaryBlock.getDictionary().getPositionCount(), 10);
}
Also used : PageProcessor(io.trino.operator.project.PageProcessor) DictionaryBlock(io.trino.spi.block.DictionaryBlock) BlockAssertions.createLongDictionaryBlock(io.trino.block.BlockAssertions.createLongDictionaryBlock) DriverYieldSignal(io.trino.operator.DriverYieldSignal) Page(io.trino.spi.Page) Test(org.testng.annotations.Test)

Example 15 with DriverYieldSignal

use of io.trino.operator.DriverYieldSignal in project trino by trinodb.

the class TestPageProcessorCompiler method testNonDeterministicProject.

@Test
public void testNonDeterministicProject() {
    ResolvedFunction lessThan = functionResolution.resolveOperator(LESS_THAN, ImmutableList.of(BIGINT, BIGINT));
    CallExpression random = new CallExpression(functionResolution.resolveFunction(QualifiedName.of("random"), fromTypes(BIGINT)), singletonList(constant(10L, BIGINT)));
    InputReferenceExpression col0 = field(0, BIGINT);
    CallExpression lessThanRandomExpression = new CallExpression(lessThan, ImmutableList.of(col0, random));
    PageProcessor processor = compiler.compilePageProcessor(Optional.empty(), ImmutableList.of(lessThanRandomExpression), MAX_BATCH_SIZE).get();
    assertFalse(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 : InputReferenceExpression(io.trino.sql.relational.InputReferenceExpression) PageProcessor(io.trino.operator.project.PageProcessor) ResolvedFunction(io.trino.metadata.ResolvedFunction) DictionaryBlock(io.trino.spi.block.DictionaryBlock) BlockAssertions.createLongDictionaryBlock(io.trino.block.BlockAssertions.createLongDictionaryBlock) DriverYieldSignal(io.trino.operator.DriverYieldSignal) Page(io.trino.spi.Page) CallExpression(io.trino.sql.relational.CallExpression) Test(org.testng.annotations.Test)

Aggregations

DriverYieldSignal (io.trino.operator.DriverYieldSignal)31 Page (io.trino.spi.Page)29 Test (org.testng.annotations.Test)21 Block (io.trino.spi.block.Block)12 LazyBlock (io.trino.spi.block.LazyBlock)10 Optional (java.util.Optional)10 BlockAssertions.createLongSequenceBlock (io.trino.block.BlockAssertions.createLongSequenceBlock)7 PageProcessor (io.trino.operator.project.PageProcessor)7 DictionaryBlock (io.trino.spi.block.DictionaryBlock)7 RunLengthEncodedBlock (io.trino.spi.block.RunLengthEncodedBlock)6 LocalMemoryContext (io.trino.memory.context.LocalMemoryContext)5 BlockAssertions.createLongsBlock (io.trino.block.BlockAssertions.createLongsBlock)4 LongArrayBlock (io.trino.spi.block.LongArrayBlock)4 Type (io.trino.spi.type.Type)4 CallExpression (io.trino.sql.relational.CallExpression)4 Slice (io.airlift.slice.Slice)3 BlockAssertions.createLongDictionaryBlock (io.trino.block.BlockAssertions.createLongDictionaryBlock)3 ResolvedFunction (io.trino.metadata.ResolvedFunction)3 SimplePageWithPositionComparator (io.trino.operator.SimplePageWithPositionComparator)3 VariableWidthBlock (io.trino.spi.block.VariableWidthBlock)3