Search in sources :

Example 21 with DriverYieldSignal

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

the class TestInputPageProjection method testLazyInputPage.

@Test
public void testLazyInputPage() {
    InputPageProjection projection = new InputPageProjection(0, BIGINT);
    Block block = createLongSequenceBlock(0, 100);
    Block result = projection.project(SESSION, new DriverYieldSignal(), new Page(block), SelectedPositions.positionsRange(0, 100)).getResult();
    assertFalse(result instanceof LazyBlock);
    block = lazyWrapper(block);
    result = projection.project(SESSION, new DriverYieldSignal(), new Page(block), SelectedPositions.positionsRange(0, 100)).getResult();
    assertTrue(result instanceof LazyBlock);
    assertFalse(result.isLoaded());
}
Also used : LazyBlock(io.trino.spi.block.LazyBlock) LazyBlock(io.trino.spi.block.LazyBlock) Block(io.trino.spi.block.Block) BlockAssertions.createLongSequenceBlock(io.trino.block.BlockAssertions.createLongSequenceBlock) DriverYieldSignal(io.trino.operator.DriverYieldSignal) Page(io.trino.spi.Page) Test(org.testng.annotations.Test)

Example 22 with DriverYieldSignal

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

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, () -> {
        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 : LocalMemoryContext(io.trino.memory.context.LocalMemoryContext) LazyBlock(io.trino.spi.block.LazyBlock) Optional(java.util.Optional) DriverYieldSignal(io.trino.operator.DriverYieldSignal) Page(io.trino.spi.Page) Test(org.testng.annotations.Test)

Example 23 with DriverYieldSignal

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

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.trino.memory.context.LocalMemoryContext) Optional(java.util.Optional) DriverYieldSignal(io.trino.operator.DriverYieldSignal) Page(io.trino.spi.Page) Test(org.testng.annotations.Test)

Example 24 with DriverYieldSignal

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

the class TestPageProcessor method testSelectNoneFilter.

@Test
public void testSelectNoneFilter() {
    PageProcessor pageProcessor = new PageProcessor(Optional.of(new SelectNoneFilter()), ImmutableList.of(new InputPageProjection(0, BIGINT)));
    Page inputPage = new Page(createLongSequenceBlock(0, 100));
    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 : LocalMemoryContext(io.trino.memory.context.LocalMemoryContext) Optional(java.util.Optional) DriverYieldSignal(io.trino.operator.DriverYieldSignal) Page(io.trino.spi.Page) Test(org.testng.annotations.Test)

Example 25 with DriverYieldSignal

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

the class TestPageProcessor method testYieldProjection.

@Test
public void testYieldProjection() {
    // each projection can finish without yield
    // while between two projections, there is a yield
    int rows = 128;
    int columns = 20;
    DriverYieldSignal yieldSignal = new DriverYieldSignal();
    PageProcessor pageProcessor = new PageProcessor(Optional.empty(), Collections.nCopies(columns, new YieldPageProjection(new InputPageProjection(0, VARCHAR))), OptionalInt.of(MAX_BATCH_SIZE));
    Slice[] slices = new Slice[rows];
    Arrays.fill(slices, Slices.allocate(rows));
    Page inputPage = new Page(createSlicesBlock(slices));
    Iterator<Optional<Page>> output = processAndAssertRetainedPageSize(pageProcessor, yieldSignal, inputPage);
    // Also, we would like to reset the yield signal before starting to process the next column in order NOT to yield per position inside the column.
    for (int i = 0; i < columns - 1; i++) {
        assertTrue(output.hasNext());
        assertNull(output.next().orElse(null));
        assertTrue(yieldSignal.isSet());
        yieldSignal.reset();
    }
    assertTrue(output.hasNext());
    Page actualPage = output.next().orElse(null);
    assertNotNull(actualPage);
    assertTrue(yieldSignal.isSet());
    yieldSignal.reset();
    Block[] blocks = new Block[columns];
    Arrays.fill(blocks, createSlicesBlock(Arrays.copyOfRange(slices, 0, rows)));
    Page expectedPage = new Page(blocks);
    assertPageEquals(Collections.nCopies(columns, VARCHAR), actualPage, expectedPage);
    assertFalse(output.hasNext());
}
Also used : Optional(java.util.Optional) Slice(io.airlift.slice.Slice) DriverYieldSignal(io.trino.operator.DriverYieldSignal) 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) Page(io.trino.spi.Page) 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