Search in sources :

Example 1 with CursorProcessor

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

the class TestScanFilterAndProjectOperator method testPageSourceLazyLoad.

@Test
public void testPageSourceLazyLoad() {
    Block inputBlock = BlockAssertions.createLongSequenceBlock(0, 100);
    // If column 1 is loaded, test will fail
    Page input = new Page(100, inputBlock, new LazyBlock(100, lazyBlock -> {
        throw new AssertionError("Lazy block should not be loaded");
    }));
    DriverContext driverContext = newDriverContext();
    List<RowExpression> projections = ImmutableList.of(field(0, VARCHAR));
    Supplier<CursorProcessor> cursorProcessor = expressionCompiler.compileCursorProcessor(driverContext.getSession().getSqlFunctionProperties(), Optional.empty(), projections, "key");
    PageProcessor pageProcessor = new PageProcessor(Optional.of(new SelectAllFilter()), ImmutableList.of(new PageProjectionWithOutputs(new LazyPagePageProjection(), new int[] { 0 })));
    ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory factory = new ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory(0, new PlanNodeId("test"), new PlanNodeId("0"), (session, split, table, columns) -> new SinglePagePageSource(input), cursorProcessor, () -> pageProcessor, TESTING_TABLE_HANDLE, ImmutableList.of(), ImmutableList.of(BIGINT), Optional.empty(), new DataSize(0, BYTE), 0);
    SourceOperator operator = factory.createOperator(driverContext);
    operator.addSplit(new Split(new ConnectorId("test"), TestingTransactionHandle.create(), TestingSplit.createLocalSplit()));
    operator.noMoreSplits();
    MaterializedResult expected = toMaterializedResult(driverContext.getSession(), ImmutableList.of(BIGINT), ImmutableList.of(new Page(inputBlock)));
    MaterializedResult actual = toMaterializedResult(driverContext.getSession(), ImmutableList.of(BIGINT), toPages(operator));
    assertEquals(actual.getRowCount(), expected.getRowCount());
    assertEquals(actual, expected);
}
Also used : FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) RecordPageSource(com.facebook.presto.spi.RecordPageSource) Page(com.facebook.presto.common.Page) MetadataManager(com.facebook.presto.metadata.MetadataManager) Test(org.testng.annotations.Test) FixedPageSource(com.facebook.presto.spi.FixedPageSource) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) Expressions.constant(com.facebook.presto.sql.relational.Expressions.constant) BlockAssertions(com.facebook.presto.block.BlockAssertions) Expressions.field(com.facebook.presto.sql.relational.Expressions.field) CursorProcessor(com.facebook.presto.operator.project.CursorProcessor) Executors.newScheduledThreadPool(java.util.concurrent.Executors.newScheduledThreadPool) EQUAL(com.facebook.presto.common.function.OperatorType.EQUAL) KILOBYTE(io.airlift.units.DataSize.Unit.KILOBYTE) PageFunctionCompiler(com.facebook.presto.sql.gen.PageFunctionCompiler) PageProcessor(com.facebook.presto.operator.project.PageProcessor) PageProjectionWithOutputs(com.facebook.presto.operator.project.PageProjectionWithOutputs) Assert.assertNotNull(org.testng.Assert.assertNotNull) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Threads.daemonThreadsNamed(com.facebook.airlift.concurrent.Threads.daemonThreadsNamed) DataSize(io.airlift.units.DataSize) List(java.util.List) LazyBlockLoader(com.facebook.presto.common.block.LazyBlockLoader) Optional(java.util.Optional) LazyPagePageProjection(com.facebook.presto.operator.project.TestPageProcessor.LazyPagePageProjection) ConnectorId(com.facebook.presto.spi.ConnectorId) RowPagesBuilder.rowPagesBuilder(com.facebook.presto.RowPagesBuilder.rowPagesBuilder) LazyBlock(com.facebook.presto.common.block.LazyBlock) ExpressionCompiler(com.facebook.presto.sql.gen.ExpressionCompiler) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) SequencePageBuilder(com.facebook.presto.SequencePageBuilder) Assert.assertNull(org.testng.Assert.assertNull) Assert.assertEquals(com.facebook.presto.testing.assertions.Assert.assertEquals) 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) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) PageRecordSet(com.facebook.presto.operator.index.PageRecordSet) Supplier(java.util.function.Supplier) TypeSignatureProvider.fromTypes(com.facebook.presto.sql.analyzer.TypeSignatureProvider.fromTypes) Expressions.call(com.facebook.presto.sql.relational.Expressions.call) Iterators(com.google.common.collect.Iterators) TestingSplit(com.facebook.presto.testing.TestingSplit) TEST_SESSION(com.facebook.presto.SessionTestUtils.TEST_SESSION) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) BOOLEAN(com.facebook.presto.common.type.BooleanType.BOOLEAN) TableHandle(com.facebook.presto.spi.TableHandle) ExecutorService(java.util.concurrent.ExecutorService) RowExpression(com.facebook.presto.spi.relation.RowExpression) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) SelectAllFilter(com.facebook.presto.operator.project.TestPageProcessor.SelectAllFilter) Iterator(java.util.Iterator) TestingTaskContext.createTaskContext(com.facebook.presto.testing.TestingTaskContext.createTaskContext) SqlScalarFunction(com.facebook.presto.metadata.SqlScalarFunction) AbstractTestFunctions(com.facebook.presto.operator.scalar.AbstractTestFunctions) OperatorAssertion.toMaterializedResult(com.facebook.presto.operator.OperatorAssertion.toMaterializedResult) TestingTransactionHandle(com.facebook.presto.testing.TestingTransactionHandle) MaterializedResult(com.facebook.presto.testing.MaterializedResult) ConnectorPageSource(com.facebook.presto.spi.ConnectorPageSource) MetadataManager.createTestMetadataManager(com.facebook.presto.metadata.MetadataManager.createTestMetadataManager) Executors.newCachedThreadPool(java.util.concurrent.Executors.newCachedThreadPool) BlockAssertions.toValues(com.facebook.presto.block.BlockAssertions.toValues) Split(com.facebook.presto.metadata.Split) Assert.assertTrue(org.testng.Assert.assertTrue) Block(com.facebook.presto.common.block.Block) BYTE(io.airlift.units.DataSize.Unit.BYTE) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Metadata(com.facebook.presto.metadata.Metadata) CursorProcessor(com.facebook.presto.operator.project.CursorProcessor) RowExpression(com.facebook.presto.spi.relation.RowExpression) Page(com.facebook.presto.common.Page) PageProjectionWithOutputs(com.facebook.presto.operator.project.PageProjectionWithOutputs) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) LazyBlock(com.facebook.presto.common.block.LazyBlock) PageProcessor(com.facebook.presto.operator.project.PageProcessor) LazyPagePageProjection(com.facebook.presto.operator.project.TestPageProcessor.LazyPagePageProjection) DataSize(io.airlift.units.DataSize) LazyBlock(com.facebook.presto.common.block.LazyBlock) Block(com.facebook.presto.common.block.Block) SelectAllFilter(com.facebook.presto.operator.project.TestPageProcessor.SelectAllFilter) TestingSplit(com.facebook.presto.testing.TestingSplit) Split(com.facebook.presto.metadata.Split) OperatorAssertion.toMaterializedResult(com.facebook.presto.operator.OperatorAssertion.toMaterializedResult) MaterializedResult(com.facebook.presto.testing.MaterializedResult) ConnectorId(com.facebook.presto.spi.ConnectorId) Test(org.testng.annotations.Test)

Example 2 with CursorProcessor

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

the class TestScanFilterAndProjectOperator method testPageSource.

@Test
public void testPageSource() {
    final Page input = SequencePageBuilder.createSequencePage(ImmutableList.of(VARCHAR), 10_000, 0);
    DriverContext driverContext = newDriverContext();
    List<RowExpression> projections = ImmutableList.of(field(0, VARCHAR));
    Supplier<CursorProcessor> cursorProcessor = expressionCompiler.compileCursorProcessor(driverContext.getSession().getSqlFunctionProperties(), Optional.empty(), projections, "key");
    Supplier<PageProcessor> pageProcessor = expressionCompiler.compilePageProcessor(driverContext.getSession().getSqlFunctionProperties(), Optional.empty(), projections);
    ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory factory = new ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory(0, new PlanNodeId("test"), new PlanNodeId("0"), (session, split, table, columns) -> new FixedPageSource(ImmutableList.of(input)), cursorProcessor, pageProcessor, TESTING_TABLE_HANDLE, ImmutableList.of(), ImmutableList.of(VARCHAR), Optional.empty(), new DataSize(0, BYTE), 0);
    SourceOperator operator = factory.createOperator(driverContext);
    operator.addSplit(new Split(new ConnectorId("test"), TestingTransactionHandle.create(), TestingSplit.createLocalSplit()));
    operator.noMoreSplits();
    MaterializedResult expected = toMaterializedResult(driverContext.getSession(), ImmutableList.of(VARCHAR), ImmutableList.of(input));
    MaterializedResult actual = toMaterializedResult(driverContext.getSession(), ImmutableList.of(VARCHAR), toPages(operator));
    assertEquals(actual.getRowCount(), expected.getRowCount());
    assertEquals(actual, expected);
}
Also used : CursorProcessor(com.facebook.presto.operator.project.CursorProcessor) RowExpression(com.facebook.presto.spi.relation.RowExpression) Page(com.facebook.presto.common.Page) FixedPageSource(com.facebook.presto.spi.FixedPageSource) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) PageProcessor(com.facebook.presto.operator.project.PageProcessor) DataSize(io.airlift.units.DataSize) TestingSplit(com.facebook.presto.testing.TestingSplit) Split(com.facebook.presto.metadata.Split) OperatorAssertion.toMaterializedResult(com.facebook.presto.operator.OperatorAssertion.toMaterializedResult) MaterializedResult(com.facebook.presto.testing.MaterializedResult) ConnectorId(com.facebook.presto.spi.ConnectorId) Test(org.testng.annotations.Test)

Example 3 with CursorProcessor

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

the class TestScanFilterAndProjectOperator method testRecordCursorSource.

@Test
public void testRecordCursorSource() {
    final Page input = SequencePageBuilder.createSequencePage(ImmutableList.of(VARCHAR), 10_000, 0);
    DriverContext driverContext = newDriverContext();
    List<RowExpression> projections = ImmutableList.of(field(0, VARCHAR));
    Supplier<CursorProcessor> cursorProcessor = expressionCompiler.compileCursorProcessor(driverContext.getSession().getSqlFunctionProperties(), Optional.empty(), projections, "key");
    Supplier<PageProcessor> pageProcessor = expressionCompiler.compilePageProcessor(driverContext.getSession().getSqlFunctionProperties(), Optional.empty(), projections);
    ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory factory = new ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory(0, new PlanNodeId("test"), new PlanNodeId("0"), (session, split, table, columns) -> new RecordPageSource(new PageRecordSet(ImmutableList.of(VARCHAR), input)), cursorProcessor, pageProcessor, TESTING_TABLE_HANDLE, ImmutableList.of(), ImmutableList.of(VARCHAR), Optional.empty(), new DataSize(0, BYTE), 0);
    SourceOperator operator = factory.createOperator(driverContext);
    operator.addSplit(new Split(new ConnectorId("test"), TestingTransactionHandle.create(), TestingSplit.createLocalSplit()));
    operator.noMoreSplits();
    MaterializedResult expected = toMaterializedResult(driverContext.getSession(), ImmutableList.of(VARCHAR), ImmutableList.of(input));
    MaterializedResult actual = toMaterializedResult(driverContext.getSession(), ImmutableList.of(VARCHAR), toPages(operator));
    assertEquals(actual.getRowCount(), expected.getRowCount());
    assertEquals(actual, expected);
}
Also used : CursorProcessor(com.facebook.presto.operator.project.CursorProcessor) RowExpression(com.facebook.presto.spi.relation.RowExpression) Page(com.facebook.presto.common.Page) PageRecordSet(com.facebook.presto.operator.index.PageRecordSet) RecordPageSource(com.facebook.presto.spi.RecordPageSource) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) PageProcessor(com.facebook.presto.operator.project.PageProcessor) DataSize(io.airlift.units.DataSize) TestingSplit(com.facebook.presto.testing.TestingSplit) Split(com.facebook.presto.metadata.Split) OperatorAssertion.toMaterializedResult(com.facebook.presto.operator.OperatorAssertion.toMaterializedResult) MaterializedResult(com.facebook.presto.testing.MaterializedResult) ConnectorId(com.facebook.presto.spi.ConnectorId) Test(org.testng.annotations.Test)

Example 4 with CursorProcessor

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

the class TestScanFilterAndProjectOperator method testPageSourceLazyBlock.

@Test
public void testPageSourceLazyBlock() {
    // Tests that a page containing a LazyBlock is loaded and its bytes are counted by the operator.
    DriverContext driverContext = newDriverContext();
    List<RowExpression> projections = ImmutableList.of(field(0, BIGINT));
    Supplier<CursorProcessor> cursorProcessor = expressionCompiler.compileCursorProcessor(driverContext.getSession().getSqlFunctionProperties(), Optional.empty(), projections, "key");
    Supplier<PageProcessor> pageProcessor = expressionCompiler.compilePageProcessor(driverContext.getSession().getSqlFunctionProperties(), Optional.empty(), projections);
    // This Block will be wrapped in a LazyBlock inside the operator on call to getNextPage().
    Block inputBlock = BlockAssertions.createLongSequenceBlock(0, 10);
    CountingLazyPageSource pageSource = new CountingLazyPageSource(ImmutableList.of(new Page(inputBlock)));
    ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory factory = new ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory(0, new PlanNodeId("test"), new PlanNodeId("0"), (session, split, table, columns) -> pageSource, cursorProcessor, pageProcessor, TESTING_TABLE_HANDLE, ImmutableList.of(), ImmutableList.of(BIGINT), Optional.empty(), new DataSize(0, BYTE), 0);
    SourceOperator operator = factory.createOperator(driverContext);
    operator.addSplit(new Split(new ConnectorId("test"), TestingTransactionHandle.create(), TestingSplit.createLocalSplit()));
    operator.noMoreSplits();
    MaterializedResult expected = toMaterializedResult(driverContext.getSession(), ImmutableList.of(BIGINT), ImmutableList.of(new Page(inputBlock)));
    Page expectedPage = expected.toPage();
    MaterializedResult actual = toMaterializedResult(driverContext.getSession(), ImmutableList.of(BIGINT), toPages(operator));
    Page actualPage = actual.toPage();
    // Assert expected page and actual page are equal.
    assertPageEquals(actual.getTypes(), actualPage, expectedPage);
    // PageSource counting isn't flawed, assert on the test implementation
    assertEquals(pageSource.getCompletedBytes(), expectedPage.getSizeInBytes());
    assertEquals(pageSource.getCompletedPositions(), expectedPage.getPositionCount());
    // Assert operator stats match the expected values
    assertEquals(operator.getOperatorContext().getOperatorStats().getRawInputDataSize().toBytes(), expectedPage.getSizeInBytes());
    assertEquals(operator.getOperatorContext().getOperatorStats().getInputPositions(), expected.getRowCount());
}
Also used : CursorProcessor(com.facebook.presto.operator.project.CursorProcessor) RowExpression(com.facebook.presto.spi.relation.RowExpression) Page(com.facebook.presto.common.Page) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) PageProcessor(com.facebook.presto.operator.project.PageProcessor) DataSize(io.airlift.units.DataSize) LazyBlock(com.facebook.presto.common.block.LazyBlock) Block(com.facebook.presto.common.block.Block) TestingSplit(com.facebook.presto.testing.TestingSplit) Split(com.facebook.presto.metadata.Split) OperatorAssertion.toMaterializedResult(com.facebook.presto.operator.OperatorAssertion.toMaterializedResult) MaterializedResult(com.facebook.presto.testing.MaterializedResult) ConnectorId(com.facebook.presto.spi.ConnectorId) Test(org.testng.annotations.Test)

Example 5 with CursorProcessor

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

the class TestCursorProcessorCompiler method testCompilerWithCSE.

@Test
public void testCompilerWithCSE() {
    PageFunctionCompiler functionCompiler = new PageFunctionCompiler(METADATA, 0);
    ExpressionCompiler expressionCompiler = new ExpressionCompiler(METADATA, functionCompiler);
    RowExpression filter = new SpecialFormExpression(AND, BIGINT, ADD_X_Y_GREATER_THAN_2, ADD_X_Y_LESS_THAN_10);
    List<? extends RowExpression> projections = createIfProjectionList(5);
    Supplier<CursorProcessor> cseCursorProcessorSupplier = expressionCompiler.compileCursorProcessor(SESSION.getSqlFunctionProperties(), Optional.of(filter), projections, "key", true);
    Supplier<CursorProcessor> noCseSECursorProcessorSupplier = expressionCompiler.compileCursorProcessor(SESSION.getSqlFunctionProperties(), Optional.of(filter), projections, "key", false);
    Page input = createLongBlockPage(2, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
    List<Type> types = ImmutableList.of(BIGINT, BIGINT);
    PageBuilder pageBuilder = new PageBuilder(projections.stream().map(RowExpression::getType).collect(toList()));
    RecordSet recordSet = new PageRecordSet(types, input);
    cseCursorProcessorSupplier.get().process(SESSION.getSqlFunctionProperties(), new DriverYieldSignal(), recordSet.cursor(), pageBuilder);
    Page pageFromCSE = pageBuilder.build();
    pageBuilder.reset();
    noCseSECursorProcessorSupplier.get().process(SESSION.getSqlFunctionProperties(), new DriverYieldSignal(), recordSet.cursor(), pageBuilder);
    Page pageFromNoCSE = pageBuilder.build();
    checkPageEqual(pageFromCSE, pageFromNoCSE);
}
Also used : CursorProcessor(com.facebook.presto.operator.project.CursorProcessor) RowExpression(com.facebook.presto.spi.relation.RowExpression) DriverYieldSignal(com.facebook.presto.operator.DriverYieldSignal) Page(com.facebook.presto.common.Page) PageBuilder(com.facebook.presto.common.PageBuilder) PageRecordSet(com.facebook.presto.operator.index.PageRecordSet) Type(com.facebook.presto.common.type.Type) PageRecordSet(com.facebook.presto.operator.index.PageRecordSet) RecordSet(com.facebook.presto.spi.RecordSet) SpecialFormExpression(com.facebook.presto.spi.relation.SpecialFormExpression) Test(org.testng.annotations.Test)

Aggregations

CursorProcessor (com.facebook.presto.operator.project.CursorProcessor)9 Page (com.facebook.presto.common.Page)8 PageProcessor (com.facebook.presto.operator.project.PageProcessor)8 ConnectorId (com.facebook.presto.spi.ConnectorId)8 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)8 RowExpression (com.facebook.presto.spi.relation.RowExpression)8 DataSize (io.airlift.units.DataSize)8 Test (org.testng.annotations.Test)8 Split (com.facebook.presto.metadata.Split)7 TestingSplit (com.facebook.presto.testing.TestingSplit)7 OperatorAssertion.toMaterializedResult (com.facebook.presto.operator.OperatorAssertion.toMaterializedResult)5 PageRecordSet (com.facebook.presto.operator.index.PageRecordSet)5 FixedPageSource (com.facebook.presto.spi.FixedPageSource)4 RecordPageSource (com.facebook.presto.spi.RecordPageSource)4 MaterializedResult (com.facebook.presto.testing.MaterializedResult)4 Block (com.facebook.presto.common.block.Block)3 LazyBlock (com.facebook.presto.common.block.LazyBlock)3 FunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager)3 Metadata (com.facebook.presto.metadata.Metadata)3 Threads.daemonThreadsNamed (com.facebook.airlift.concurrent.Threads.daemonThreadsNamed)2