Search in sources :

Example 11 with PageProcessor

use of io.trino.operator.project.PageProcessor 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)

Example 12 with PageProcessor

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

the class TestPageProcessorCompiler method testNoCaching.

@Test
public void testNoCaching() {
    ImmutableList.Builder<RowExpression> projectionsBuilder = ImmutableList.builder();
    ArrayType arrayType = new ArrayType(VARCHAR);
    ResolvedFunction resolvedFunction = functionResolution.resolveFunction(QualifiedName.of("concat"), fromTypes(arrayType, arrayType));
    projectionsBuilder.add(new CallExpression(resolvedFunction, ImmutableList.of(field(0, arrayType), field(1, arrayType))));
    ImmutableList<RowExpression> projections = projectionsBuilder.build();
    PageProcessor pageProcessor = compiler.compilePageProcessor(Optional.empty(), projections).get();
    PageProcessor pageProcessor2 = compiler.compilePageProcessor(Optional.empty(), projections).get();
    assertTrue(pageProcessor != pageProcessor2);
}
Also used : ArrayType(io.trino.spi.type.ArrayType) PageProcessor(io.trino.operator.project.PageProcessor) ImmutableList(com.google.common.collect.ImmutableList) ResolvedFunction(io.trino.metadata.ResolvedFunction) RowExpression(io.trino.sql.relational.RowExpression) CallExpression(io.trino.sql.relational.CallExpression) Test(org.testng.annotations.Test)

Example 13 with PageProcessor

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

the class TestPageProcessorCompiler method testSanityRLE.

@Test
public void testSanityRLE() {
    PageProcessor processor = compiler.compilePageProcessor(Optional.empty(), ImmutableList.of(field(0, BIGINT), field(1, VARCHAR)), MAX_BATCH_SIZE).get();
    Slice varcharValue = Slices.utf8Slice("hello");
    Page page = new Page(RunLengthEncodedBlock.create(BIGINT, 123L, 100), RunLengthEncodedBlock.create(VARCHAR, varcharValue, 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 RunLengthEncodedBlock);
    assertTrue(outputPage.getBlock(1) instanceof RunLengthEncodedBlock);
    RunLengthEncodedBlock rleBlock = (RunLengthEncodedBlock) outputPage.getBlock(0);
    assertEquals(BIGINT.getLong(rleBlock.getValue(), 0), 123L);
    RunLengthEncodedBlock rleBlock1 = (RunLengthEncodedBlock) outputPage.getBlock(1);
    assertEquals(VARCHAR.getSlice(rleBlock1.getValue(), 0), varcharValue);
}
Also used : PageProcessor(io.trino.operator.project.PageProcessor) Slice(io.airlift.slice.Slice) DriverYieldSignal(io.trino.operator.DriverYieldSignal) Page(io.trino.spi.Page) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) Test(org.testng.annotations.Test)

Example 14 with PageProcessor

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

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, () -> {
        throw new AssertionError("Lazy block should not be loaded");
    }));
    DriverContext driverContext = newDriverContext();
    List<RowExpression> projections = ImmutableList.of(field(0, VARCHAR));
    Supplier<CursorProcessor> cursorProcessor = functionAssertions.getExpressionCompiler().compileCursorProcessor(Optional.empty(), projections, "key");
    PageProcessor pageProcessor = new PageProcessor(Optional.of(new SelectAllFilter()), ImmutableList.of(new LazyPagePageProjection()));
    ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory factory = new ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory(0, new PlanNodeId("test"), new PlanNodeId("0"), (session, split, table, columns, dynamicFilter) -> new SinglePagePageSource(input), cursorProcessor, () -> pageProcessor, TEST_TABLE_HANDLE, ImmutableList.of(), DynamicFilter.EMPTY, ImmutableList.of(BIGINT), DataSize.ofBytes(0), 0);
    SourceOperator operator = factory.createOperator(driverContext);
    operator.addSplit(new Split(new CatalogName("test"), TestingSplit.createLocalSplit(), Lifespan.taskWide()));
    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 : CursorProcessor(io.trino.operator.project.CursorProcessor) RowExpression(io.trino.sql.relational.RowExpression) Page(io.trino.spi.Page) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) LazyBlock(io.trino.spi.block.LazyBlock) PageProcessor(io.trino.operator.project.PageProcessor) LazyPagePageProjection(io.trino.operator.project.TestPageProcessor.LazyPagePageProjection) LazyBlock(io.trino.spi.block.LazyBlock) Block(io.trino.spi.block.Block) SelectAllFilter(io.trino.operator.project.TestPageProcessor.SelectAllFilter) CatalogName(io.trino.connector.CatalogName) Split(io.trino.metadata.Split) TestingSplit(io.trino.testing.TestingSplit) MaterializedResult(io.trino.testing.MaterializedResult) OperatorAssertion.toMaterializedResult(io.trino.operator.OperatorAssertion.toMaterializedResult) Test(org.testng.annotations.Test)

Example 15 with PageProcessor

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

the class TestScanFilterAndProjectOperator method testPageYield.

@Test
public void testPageYield() {
    int totalRows = 1000;
    Page input = SequencePageBuilder.createSequencePage(ImmutableList.of(BIGINT), totalRows, 1);
    DriverContext driverContext = newDriverContext();
    // 20 columns; each column is associated with a function that will force yield per projection
    int totalColumns = 20;
    ImmutableList.Builder<SqlScalarFunction> functions = ImmutableList.builder();
    for (int i = 0; i < totalColumns; i++) {
        functions.add(new GenericLongFunction("page_col" + i, value -> {
            driverContext.getYieldSignal().forceYieldForTesting();
            return value;
        }));
    }
    functionAssertions.addFunctions(new InternalFunctionBundle(functions.build()));
    // match each column with a projection
    ExpressionCompiler expressionCompiler = new ExpressionCompiler(functionAssertions.getFunctionManager(), new PageFunctionCompiler(functionAssertions.getFunctionManager(), 0));
    ImmutableList.Builder<RowExpression> projections = ImmutableList.builder();
    for (int i = 0; i < totalColumns; i++) {
        projections.add(call(functionAssertions.getMetadata().resolveFunction(session, QualifiedName.of("generic_long_page_col" + i), fromTypes(BIGINT)), field(0, BIGINT)));
    }
    Supplier<CursorProcessor> cursorProcessor = expressionCompiler.compileCursorProcessor(Optional.empty(), projections.build(), "key");
    Supplier<PageProcessor> pageProcessor = expressionCompiler.compilePageProcessor(Optional.empty(), projections.build(), MAX_BATCH_SIZE);
    ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory factory = new ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory(0, new PlanNodeId("test"), new PlanNodeId("0"), (session, split, table, columns, dynamicFilter) -> new FixedPageSource(ImmutableList.of(input)), cursorProcessor, pageProcessor, TEST_TABLE_HANDLE, ImmutableList.of(), DynamicFilter.EMPTY, ImmutableList.of(BIGINT), DataSize.ofBytes(0), 0);
    SourceOperator operator = factory.createOperator(driverContext);
    operator.addSplit(new Split(new CatalogName("test"), TestingSplit.createLocalSplit(), Lifespan.taskWide()));
    operator.noMoreSplits();
    // exactly 20 blocks (one for each column) and the PageProcessor will be able to create a Page out of it.
    for (int i = 1; i <= totalRows * totalColumns; i++) {
        driverContext.getYieldSignal().setWithDelay(SECONDS.toNanos(1000), driverContext.getYieldExecutor());
        Page page = operator.getOutput();
        if (i == totalColumns) {
            assertNotNull(page);
            assertEquals(page.getPositionCount(), totalRows);
            assertEquals(page.getChannelCount(), totalColumns);
            for (int j = 0; j < totalColumns; j++) {
                assertEquals(toValues(BIGINT, page.getBlock(j)), toValues(BIGINT, input.getBlock(0)));
            }
        } else {
            assertNull(page);
        }
        driverContext.getYieldSignal().reset();
    }
}
Also used : MaterializedResult(io.trino.testing.MaterializedResult) TypeSignatureProvider.fromTypes(io.trino.sql.analyzer.TypeSignatureProvider.fromTypes) BlockAssertions(io.trino.block.BlockAssertions) Test(org.testng.annotations.Test) Expressions.field(io.trino.sql.relational.Expressions.field) LazyPagePageProjection(io.trino.operator.project.TestPageProcessor.LazyPagePageProjection) SequencePageBuilder(io.trino.SequencePageBuilder) LazyBlock(io.trino.spi.block.LazyBlock) CatalogName(io.trino.connector.CatalogName) Block(io.trino.spi.block.Block) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) Executors.newScheduledThreadPool(java.util.concurrent.Executors.newScheduledThreadPool) CursorProcessor(io.trino.operator.project.CursorProcessor) TEST_SESSION(io.trino.SessionTestUtils.TEST_SESSION) PageRecordSet(io.trino.operator.index.PageRecordSet) RowPagesBuilder.rowPagesBuilder(io.trino.RowPagesBuilder.rowPagesBuilder) KILOBYTE(io.airlift.units.DataSize.Unit.KILOBYTE) EQUAL(io.trino.spi.function.OperatorType.EQUAL) ConnectorPageSource(io.trino.spi.connector.ConnectorPageSource) Assert.assertEquals(io.trino.testing.assertions.Assert.assertEquals) Expressions.constant(io.trino.sql.relational.Expressions.constant) PageFunctionCompiler(io.trino.sql.gen.PageFunctionCompiler) SelectAllFilter(io.trino.operator.project.TestPageProcessor.SelectAllFilter) Assert.assertNotNull(org.testng.Assert.assertNotNull) AbstractTestFunctions(io.trino.operator.scalar.AbstractTestFunctions) DataSize(io.airlift.units.DataSize) List(java.util.List) FixedPageSource(io.trino.spi.connector.FixedPageSource) BIGINT(io.trino.spi.type.BigintType.BIGINT) PageAssertions.assertPageEquals(io.trino.operator.PageAssertions.assertPageEquals) Split(io.trino.metadata.Split) DynamicFilter(io.trino.spi.connector.DynamicFilter) Optional(java.util.Optional) BlockAssertions.toValues(io.trino.block.BlockAssertions.toValues) Assert.assertNull(org.testng.Assert.assertNull) Page(io.trino.spi.Page) Supplier(java.util.function.Supplier) ExpressionCompiler(io.trino.sql.gen.ExpressionCompiler) MAX_BATCH_SIZE(io.trino.operator.project.PageProcessor.MAX_BATCH_SIZE) VARCHAR(io.trino.spi.type.VarcharType.VARCHAR) ImmutableList(com.google.common.collect.ImmutableList) Threads.daemonThreadsNamed(io.airlift.concurrent.Threads.daemonThreadsNamed) RecordPageSource(io.trino.spi.connector.RecordPageSource) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) PageProcessor(io.trino.operator.project.PageProcessor) TestingSplit(io.trino.testing.TestingSplit) Lifespan(io.trino.execution.Lifespan) ExecutorService(java.util.concurrent.ExecutorService) TestingTaskContext.createTaskContext(io.trino.testing.TestingTaskContext.createTaskContext) AfterClass(org.testng.annotations.AfterClass) SqlScalarFunction(io.trino.metadata.SqlScalarFunction) FunctionManager(io.trino.metadata.FunctionManager) QualifiedName(io.trino.sql.tree.QualifiedName) OperatorAssertion.toMaterializedResult(io.trino.operator.OperatorAssertion.toMaterializedResult) Expressions.call(io.trino.sql.relational.Expressions.call) RowExpression(io.trino.sql.relational.RowExpression) InternalFunctionBundle(io.trino.metadata.InternalFunctionBundle) TEST_TABLE_HANDLE(io.trino.testing.TestingHandles.TEST_TABLE_HANDLE) Executors.newCachedThreadPool(java.util.concurrent.Executors.newCachedThreadPool) Assert.assertTrue(org.testng.Assert.assertTrue) SECONDS(java.util.concurrent.TimeUnit.SECONDS) PageFunctionCompiler(io.trino.sql.gen.PageFunctionCompiler) CursorProcessor(io.trino.operator.project.CursorProcessor) ImmutableList(com.google.common.collect.ImmutableList) Page(io.trino.spi.Page) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) PageProcessor(io.trino.operator.project.PageProcessor) InternalFunctionBundle(io.trino.metadata.InternalFunctionBundle) RowExpression(io.trino.sql.relational.RowExpression) FixedPageSource(io.trino.spi.connector.FixedPageSource) SqlScalarFunction(io.trino.metadata.SqlScalarFunction) ExpressionCompiler(io.trino.sql.gen.ExpressionCompiler) CatalogName(io.trino.connector.CatalogName) Split(io.trino.metadata.Split) TestingSplit(io.trino.testing.TestingSplit) Test(org.testng.annotations.Test)

Aggregations

PageProcessor (io.trino.operator.project.PageProcessor)23 Page (io.trino.spi.Page)17 Test (org.testng.annotations.Test)17 RowExpression (io.trino.sql.relational.RowExpression)13 PlanNodeId (io.trino.sql.planner.plan.PlanNodeId)12 CursorProcessor (io.trino.operator.project.CursorProcessor)8 DriverYieldSignal (io.trino.operator.DriverYieldSignal)7 CatalogName (io.trino.connector.CatalogName)6 Split (io.trino.metadata.Split)6 PageFunctionCompiler (io.trino.sql.gen.PageFunctionCompiler)6 TestingSplit (io.trino.testing.TestingSplit)6 ExpressionCompiler (io.trino.sql.gen.ExpressionCompiler)5 MaterializedResult (io.trino.testing.MaterializedResult)5 ImmutableList (com.google.common.collect.ImmutableList)4 FunctionManager (io.trino.metadata.FunctionManager)4 ResolvedFunction (io.trino.metadata.ResolvedFunction)4 OperatorAssertion.toMaterializedResult (io.trino.operator.OperatorAssertion.toMaterializedResult)4 CallExpression (io.trino.sql.relational.CallExpression)4 BlockAssertions.createLongDictionaryBlock (io.trino.block.BlockAssertions.createLongDictionaryBlock)3 PageRecordSet (io.trino.operator.index.PageRecordSet)3