Search in sources :

Example 6 with DriverYieldSignal

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

the class TestPageProcessorCompiler method testSanityColumnarDictionary.

@Test
public void testSanityColumnarDictionary() {
    PageProcessor processor = compiler.compilePageProcessor(TEST_SESSION.getSqlFunctionProperties(), Optional.empty(), ImmutableList.of(field(0, VARCHAR)), false, 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(com.facebook.presto.operator.project.PageProcessor) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) BlockAssertions.createLongDictionaryBlock(com.facebook.presto.block.BlockAssertions.createLongDictionaryBlock) DriverYieldSignal(com.facebook.presto.operator.DriverYieldSignal) Page(com.facebook.presto.common.Page) Test(org.testng.annotations.Test)

Example 7 with DriverYieldSignal

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

the class TestPageProcessor method testProjectLazyLoad.

@Test
public void testProjectLazyLoad() {
    PageProcessor pageProcessor = new PageProcessor(Optional.of(new SelectAllFilter()), ImmutableList.of(new PageProjectionWithOutputs(new LazyPagePageProjection(), new int[] { 0 })), OptionalInt.of(MAX_BATCH_SIZE));
    // 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);
    List<Optional<Page>> outputPages = ImmutableList.copyOf(output);
    assertEquals(outputPages.size(), 1);
    assertPageEquals(ImmutableList.of(BIGINT), outputPages.get(0).orElse(null), new Page(createLongSequenceBlock(0, 100)));
}
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) Optional(java.util.Optional) DriverYieldSignal(com.facebook.presto.operator.DriverYieldSignal) Page(com.facebook.presto.common.Page) LazyBlock(com.facebook.presto.common.block.LazyBlock) Test(org.testng.annotations.Test)

Example 8 with DriverYieldSignal

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

the class TestPageProcessor method testExpressionProfiler.

@Test
public void testExpressionProfiler() {
    MetadataManager metadata = createTestMetadataManager();
    CallExpression add10Expression = call(ADD.name(), metadata.getFunctionAndTypeManager().resolveOperator(ADD, fromTypes(BIGINT, BIGINT)), BIGINT, field(0, BIGINT), constant(10L, BIGINT));
    TestingTicker testingTicker = new TestingTicker();
    PageFunctionCompiler functionCompiler = new PageFunctionCompiler(metadata, 0);
    Supplier<PageProjection> projectionSupplier = functionCompiler.compileProjection(SESSION.getSqlFunctionProperties(), 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<List<Block>> work = projection.project(SESSION.getSqlFunctionProperties(), 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 : MetadataManager(com.facebook.presto.metadata.MetadataManager) MetadataManager.createTestMetadataManager(com.facebook.presto.metadata.MetadataManager.createTestMetadataManager) TestingTicker(com.facebook.airlift.testing.TestingTicker) PageFunctionCompiler(com.facebook.presto.sql.gen.PageFunctionCompiler) DriverYieldSignal(com.facebook.presto.operator.DriverYieldSignal) Page(com.facebook.presto.common.Page) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) SelectedPositions.positionsList(com.facebook.presto.operator.project.SelectedPositions.positionsList) CallExpression(com.facebook.presto.spi.relation.CallExpression) ExpressionProfiler(com.facebook.presto.sql.gen.ExpressionProfiler) Test(org.testng.annotations.Test)

Example 9 with DriverYieldSignal

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

the class TestPageProcessor method testAdaptiveBatchSize.

@Test
public void testAdaptiveBatchSize() {
    PageProcessor pageProcessor = new PageProcessor(Optional.empty(), ImmutableList.of(createInputPageProjectionWithOutputs(0, VARCHAR, 0)), 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(com.facebook.presto.operator.DriverYieldSignal) Page(com.facebook.presto.common.Page) Test(org.testng.annotations.Test)

Example 10 with DriverYieldSignal

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

the class TestPageProcessor method testSelectNoneFilter.

@Test
public void testSelectNoneFilter() {
    PageProcessor pageProcessor = new PageProcessor(Optional.of(new SelectNoneFilter()), ImmutableList.of(createInputPageProjectionWithOutputs(0, BIGINT, 0)));
    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(), 0);
}
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)

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