Search in sources :

Example 11 with DriverYieldSignal

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

the class TestDictionaryAwarePageProjection method testProjectRange.

private static void testProjectRange(Block block, Class<? extends Block> expectedResultType, DictionaryAwarePageProjection projection, boolean forceYield) {
    DriverYieldSignal yieldSignal = new DriverYieldSignal();
    Work<List<Block>> work = projection.project(null, yieldSignal, new Page(block), SelectedPositions.positionsRange(5, 10));
    List<Block> result;
    if (forceYield) {
        result = projectWithYield(work, yieldSignal);
    } else {
        assertTrue(work.process());
        result = work.getResult();
    }
    assertBlockEquals(BIGINT, result.get(0), block.getRegion(5, 10));
    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)

Example 12 with DriverYieldSignal

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

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(), IntStream.range(0, 20).mapToObj(i -> new PageProjectionWithOutputs(new YieldPageProjection(new InputPageProjection(0)), new int[] { i })).collect(toImmutableList()), 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) DriverYieldSignal(com.facebook.presto.operator.DriverYieldSignal) Page(com.facebook.presto.common.Page) Slice(io.airlift.slice.Slice) LazyBlock(com.facebook.presto.common.block.LazyBlock) BlockAssertions.createSlicesBlock(com.facebook.presto.block.BlockAssertions.createSlicesBlock) VariableWidthBlock(com.facebook.presto.common.block.VariableWidthBlock) BlockAssertions.createLongSequenceBlock(com.facebook.presto.block.BlockAssertions.createLongSequenceBlock) BlockAssertions.createStringsBlock(com.facebook.presto.block.BlockAssertions.createStringsBlock) Block(com.facebook.presto.common.block.Block) Test(org.testng.annotations.Test)

Example 13 with DriverYieldSignal

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

the class TestPageProcessor method testFilterNoColumns.

@Test
public void testFilterNoColumns() {
    PageProcessor pageProcessor = new PageProcessor(Optional.of(new TestingPageFilter(positionsRange(0, 50))), ImmutableList.of());
    Page inputPage = new Page(createLongSequenceBlock(0, 100));
    LocalMemoryContext memoryContext = newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName());
    Iterator<Optional<Page>> output = pageProcessor.process(SESSION.getSqlFunctionProperties(), new DriverYieldSignal(), memoryContext, inputPage);
    assertEquals(memoryContext.getBytes(), 0);
    List<Optional<Page>> outputPages = ImmutableList.copyOf(output);
    assertEquals(outputPages.size(), 1);
    Page outputPage = outputPages.get(0).orElse(null);
    assertEquals(outputPage.getChannelCount(), 0);
    assertEquals(outputPage.getPositionCount(), 50);
}
Also used : LocalMemoryContext(com.facebook.presto.memory.context.LocalMemoryContext) Optional(java.util.Optional) DriverYieldSignal(com.facebook.presto.operator.DriverYieldSignal) Page(com.facebook.presto.common.Page) Test(org.testng.annotations.Test)

Example 14 with DriverYieldSignal

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

the class TestPageProcessor method testRetainedSize.

@Test
public void testRetainedSize() {
    PageProcessor pageProcessor = new PageProcessor(Optional.of(new SelectAllFilter()), ImmutableList.of(createInputPageProjectionWithOutputs(0, VARCHAR, 0), createInputPageProjectionWithOutputs(1, VARCHAR, 1)), OptionalInt.of(MAX_BATCH_SIZE));
    // create 2 columns X 800 rows of strings with each string's size = 10KB
    // this can force previouslyComputedResults to be saved given the page is 16MB in size
    String value = join("", nCopies(10_000, "a"));
    List<String> values = nCopies(800, value);
    Page inputPage = new Page(createStringsBlock(values), createStringsBlock(values));
    AggregatedMemoryContext memoryContext = newSimpleAggregatedMemoryContext();
    Iterator<Optional<Page>> output = processAndAssertRetainedPageSize(pageProcessor, new DriverYieldSignal(), memoryContext, inputPage);
    // force a compute
    // one block of previouslyComputedResults will be saved given the first column is with 8MB
    output.hasNext();
    // verify we do not count block sizes twice
    // comparing with the input page, the output page also contains an extra instance size for previouslyComputedResults
    assertEquals(memoryContext.getBytes() - ClassLayout.parseClass(VariableWidthBlock.class).instanceSize(), inputPage.getRetainedSizeInBytes());
}
Also used : Optional(java.util.Optional) DriverYieldSignal(com.facebook.presto.operator.DriverYieldSignal) Page(com.facebook.presto.common.Page) AggregatedMemoryContext.newSimpleAggregatedMemoryContext(com.facebook.presto.memory.context.AggregatedMemoryContext.newSimpleAggregatedMemoryContext) AggregatedMemoryContext(com.facebook.presto.memory.context.AggregatedMemoryContext) VariableWidthBlock(com.facebook.presto.common.block.VariableWidthBlock) Test(org.testng.annotations.Test)

Example 15 with DriverYieldSignal

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

the class TestPageProcessor method testSelectNoneFilterLazyLoad.

@Test
public void testSelectNoneFilterLazyLoad() {
    PageProcessor pageProcessor = new PageProcessor(Optional.of(new SelectNoneFilter()), ImmutableList.of(createInputPageProjectionWithOutputs(1, BIGINT, 0)));
    // 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.getSqlFunctionProperties(), new DriverYieldSignal(), memoryContext, inputPage);
    assertEquals(memoryContext.getBytes(), 0);
    List<Optional<Page>> outputPages = ImmutableList.copyOf(output);
    assertEquals(outputPages.size(), 0);
}
Also used : TestingTicker(com.facebook.airlift.testing.TestingTicker) Page(com.facebook.presto.common.Page) CompletedWork(com.facebook.presto.operator.CompletedWork) Arrays(java.util.Arrays) MetadataManager(com.facebook.presto.metadata.MetadataManager) Test(org.testng.annotations.Test) Expressions.constant(com.facebook.presto.sql.relational.Expressions.constant) BlockAssertions(com.facebook.presto.block.BlockAssertions) Duration(io.airlift.units.Duration) Expressions.field(com.facebook.presto.sql.relational.Expressions.field) ADD(com.facebook.presto.common.function.OperatorType.ADD) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) SESSION(com.facebook.presto.testing.TestingConnectorSession.SESSION) Slices(io.airlift.slice.Slices) CallExpression(com.facebook.presto.spi.relation.CallExpression) PageFunctionCompiler(com.facebook.presto.sql.gen.PageFunctionCompiler) Assert.assertFalse(org.testng.Assert.assertFalse) SPLIT_RUN_QUANTA(com.facebook.presto.execution.executor.PrioritizedSplitRunner.SPLIT_RUN_QUANTA) Collections.nCopies(java.util.Collections.nCopies) SqlFunctionProperties(com.facebook.presto.common.function.SqlFunctionProperties) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) LocalMemoryContext(com.facebook.presto.memory.context.LocalMemoryContext) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Assert.assertNotNull(org.testng.Assert.assertNotNull) Threads.daemonThreadsNamed(com.facebook.airlift.concurrent.Threads.daemonThreadsNamed) List(java.util.List) ClassLayout(org.openjdk.jol.info.ClassLayout) Optional(java.util.Optional) LazyBlock(com.facebook.presto.common.block.LazyBlock) IntStream(java.util.stream.IntStream) Slice(io.airlift.slice.Slice) Assert.assertNull(org.testng.Assert.assertNull) DriverYieldSignal(com.facebook.presto.operator.DriverYieldSignal) BlockAssertions.createSlicesBlock(com.facebook.presto.block.BlockAssertions.createSlicesBlock) RowType.withDefaultFieldNames(com.facebook.presto.common.type.RowType.withDefaultFieldNames) NANOSECONDS(java.util.concurrent.TimeUnit.NANOSECONDS) VARCHAR(com.facebook.presto.common.type.VarcharType.VARCHAR) MAX_BATCH_SIZE(com.facebook.presto.operator.project.PageProcessor.MAX_BATCH_SIZE) PageAssertions.assertPageEquals(com.facebook.presto.operator.PageAssertions.assertPageEquals) Assert.assertEquals(org.testng.Assert.assertEquals) VariableWidthBlock(com.facebook.presto.common.block.VariableWidthBlock) OptionalInt(java.util.OptionalInt) Supplier(java.util.function.Supplier) TypeSignatureProvider.fromTypes(com.facebook.presto.sql.analyzer.TypeSignatureProvider.fromTypes) Expressions.call(com.facebook.presto.sql.relational.Expressions.call) REAL(com.facebook.presto.common.type.RealType.REAL) ImmutableList(com.google.common.collect.ImmutableList) String.join(java.lang.String.join) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) MIN_PAGE_SIZE_IN_BYTES(com.facebook.presto.operator.project.PageProcessor.MIN_PAGE_SIZE_IN_BYTES) BOOLEAN(com.facebook.presto.common.type.BooleanType.BOOLEAN) SelectedPositions.positionsRange(com.facebook.presto.operator.project.SelectedPositions.positionsRange) ArrayType(com.facebook.presto.common.type.ArrayType) AggregatedMemoryContext.newSimpleAggregatedMemoryContext(com.facebook.presto.memory.context.AggregatedMemoryContext.newSimpleAggregatedMemoryContext) MAX_PAGE_SIZE_IN_BYTES(com.facebook.presto.operator.project.PageProcessor.MAX_PAGE_SIZE_IN_BYTES) Type(com.facebook.presto.common.type.Type) BlockAssertions.createLongSequenceBlock(com.facebook.presto.block.BlockAssertions.createLongSequenceBlock) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) PageAssertions.createPageWithRandomData(com.facebook.presto.operator.PageAssertions.createPageWithRandomData) BlockAssertions.createMapType(com.facebook.presto.block.BlockAssertions.createMapType) Iterator(java.util.Iterator) BlockAssertions.createStringsBlock(com.facebook.presto.block.BlockAssertions.createStringsBlock) AggregatedMemoryContext(com.facebook.presto.memory.context.AggregatedMemoryContext) SelectedPositions.positionsList(com.facebook.presto.operator.project.SelectedPositions.positionsList) MetadataManager.createTestMetadataManager(com.facebook.presto.metadata.MetadataManager.createTestMetadataManager) Work(com.facebook.presto.operator.Work) Assert.assertTrue(org.testng.Assert.assertTrue) ExpressionProfiler(com.facebook.presto.sql.gen.ExpressionProfiler) Block(com.facebook.presto.common.block.Block) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) LocalMemoryContext(com.facebook.presto.memory.context.LocalMemoryContext) LazyBlock(com.facebook.presto.common.block.LazyBlock) Optional(java.util.Optional) DriverYieldSignal(com.facebook.presto.operator.DriverYieldSignal) Page(com.facebook.presto.common.Page) Test(org.testng.annotations.Test)

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