Search in sources :

Example 1 with FunctionManager

use of io.trino.metadata.FunctionManager in project trino by trinodb.

the class TestTupleFilterProcessor method testFilter.

@Test
public void testFilter() {
    Page tuplePage = Iterables.getOnlyElement(rowPagesBuilder(BIGINT, VARCHAR, DOUBLE).row(1L, "a", 0.1).build());
    List<Type> outputTypes = ImmutableList.of(VARCHAR, BIGINT, BOOLEAN, DOUBLE, DOUBLE);
    Page inputPage = Iterables.getOnlyElement(rowPagesBuilder(outputTypes).row("a", 1L, true, 0.1, 0.0).row("b", 1L, true, 0.1, 2.0).row("a", 1L, false, 0.1, 2.0).row("a", 0L, false, 0.2, 0.2).build());
    FunctionManager functionManager = createTestingFunctionManager();
    DynamicTupleFilterFactory filterFactory = new DynamicTupleFilterFactory(42, new PlanNodeId("42"), new int[] { 0, 1, 2 }, new int[] { 1, 0, 3 }, outputTypes, new PageFunctionCompiler(functionManager, 0), new BlockTypeOperators(new TypeOperators()));
    PageProcessor tupleFilterProcessor = filterFactory.createPageProcessor(tuplePage, OptionalInt.of(MAX_BATCH_SIZE)).get();
    Page actualPage = getOnlyElement(tupleFilterProcessor.process(SESSION, new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), inputPage)).orElseThrow(() -> new AssertionError("page is not present"));
    Page expectedPage = Iterables.getOnlyElement(rowPagesBuilder(outputTypes).row("a", 1L, true, 0.1, 0.0).row("a", 1L, false, 0.1, 2.0).build());
    assertPageEquals(outputTypes, actualPage, expectedPage);
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) Type(io.trino.spi.type.Type) PageFunctionCompiler(io.trino.sql.gen.PageFunctionCompiler) PageProcessor(io.trino.operator.project.PageProcessor) BlockTypeOperators(io.trino.type.BlockTypeOperators) DriverYieldSignal(io.trino.operator.DriverYieldSignal) Page(io.trino.spi.Page) FunctionManager.createTestingFunctionManager(io.trino.metadata.FunctionManager.createTestingFunctionManager) FunctionManager(io.trino.metadata.FunctionManager) TypeOperators(io.trino.spi.type.TypeOperators) BlockTypeOperators(io.trino.type.BlockTypeOperators) Test(org.testng.annotations.Test)

Example 2 with FunctionManager

use of io.trino.metadata.FunctionManager in project trino by trinodb.

the class TestScanFilterAndProjectOperator method testRecordCursorYield.

@Test
public void testRecordCursorYield() {
    // create a generic long function that yields for projection on every row
    // verify we will yield #row times totally
    // create a table with 15 rows
    int length = 15;
    Page input = SequencePageBuilder.createSequencePage(ImmutableList.of(BIGINT), length, 0);
    DriverContext driverContext = newDriverContext();
    // set up generic long function with a callback to force yield
    functionAssertions.addFunctions(new InternalFunctionBundle(new GenericLongFunction("record_cursor", value -> {
        driverContext.getYieldSignal().forceYieldForTesting();
        return value;
    })));
    FunctionManager functionManager = functionAssertions.getFunctionManager();
    ExpressionCompiler expressionCompiler = new ExpressionCompiler(functionManager, new PageFunctionCompiler(functionManager, 0));
    List<RowExpression> projections = ImmutableList.of(call(functionAssertions.getMetadata().resolveFunction(session, QualifiedName.of("generic_long_record_cursor"), fromTypes(BIGINT)), field(0, BIGINT)));
    Supplier<CursorProcessor> cursorProcessor = expressionCompiler.compileCursorProcessor(Optional.empty(), projections, "key");
    Supplier<PageProcessor> pageProcessor = expressionCompiler.compilePageProcessor(Optional.empty(), projections);
    ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory factory = new ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory(0, new PlanNodeId("test"), new PlanNodeId("0"), (session, split, table, columns, dynamicFilter) -> new RecordPageSource(new PageRecordSet(ImmutableList.of(BIGINT), 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();
    // start driver; get null value due to yield for the first 15 times
    for (int i = 0; i < length; i++) {
        driverContext.getYieldSignal().setWithDelay(SECONDS.toNanos(1000), driverContext.getYieldExecutor());
        assertNull(operator.getOutput());
        driverContext.getYieldSignal().reset();
    }
    // the 16th yield is not going to prevent the operator from producing a page
    driverContext.getYieldSignal().setWithDelay(SECONDS.toNanos(1000), driverContext.getYieldExecutor());
    Page output = operator.getOutput();
    driverContext.getYieldSignal().reset();
    assertNotNull(output);
    assertEquals(toValues(BIGINT, output.getBlock(0)), toValues(BIGINT, input.getBlock(0)));
}
Also used : PageFunctionCompiler(io.trino.sql.gen.PageFunctionCompiler) CursorProcessor(io.trino.operator.project.CursorProcessor) RowExpression(io.trino.sql.relational.RowExpression) Page(io.trino.spi.Page) PageRecordSet(io.trino.operator.index.PageRecordSet) RecordPageSource(io.trino.spi.connector.RecordPageSource) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) PageProcessor(io.trino.operator.project.PageProcessor) InternalFunctionBundle(io.trino.metadata.InternalFunctionBundle) ExpressionCompiler(io.trino.sql.gen.ExpressionCompiler) CatalogName(io.trino.connector.CatalogName) Split(io.trino.metadata.Split) TestingSplit(io.trino.testing.TestingSplit) FunctionManager(io.trino.metadata.FunctionManager) Test(org.testng.annotations.Test)

Example 3 with FunctionManager

use of io.trino.metadata.FunctionManager in project trino by trinodb.

the class BenchmarkPageProcessor2 method setup.

@Setup
public void setup() {
    Type type = TYPE_MAP.get(this.type);
    for (int i = 0; i < columnCount; i++) {
        Symbol symbol = new Symbol(type.getDisplayName().toLowerCase(ENGLISH) + i);
        symbolTypes.put(symbol, type);
        sourceLayout.put(symbol, i);
    }
    List<RowExpression> projections = getProjections(type);
    types = projections.stream().map(RowExpression::getType).collect(toList());
    FunctionManager functionManager = createTestingFunctionManager();
    PageFunctionCompiler pageFunctionCompiler = new PageFunctionCompiler(functionManager, 0);
    inputPage = createPage(types, dictionaryBlocks);
    pageProcessor = new ExpressionCompiler(functionManager, pageFunctionCompiler).compilePageProcessor(Optional.of(getFilter(type)), projections).get();
    recordSet = new PageRecordSet(types, inputPage);
    cursorProcessor = new ExpressionCompiler(functionManager, pageFunctionCompiler).compileCursorProcessor(Optional.of(getFilter(type)), projections, "key").get();
}
Also used : Type(io.trino.spi.type.Type) Symbol(io.trino.sql.planner.Symbol) RowExpression(io.trino.sql.relational.RowExpression) PageRecordSet(io.trino.operator.index.PageRecordSet) FunctionManager.createTestingFunctionManager(io.trino.metadata.FunctionManager.createTestingFunctionManager) FunctionManager(io.trino.metadata.FunctionManager) Setup(org.openjdk.jmh.annotations.Setup)

Aggregations

FunctionManager (io.trino.metadata.FunctionManager)3 FunctionManager.createTestingFunctionManager (io.trino.metadata.FunctionManager.createTestingFunctionManager)2 PageRecordSet (io.trino.operator.index.PageRecordSet)2 PageProcessor (io.trino.operator.project.PageProcessor)2 Page (io.trino.spi.Page)2 Type (io.trino.spi.type.Type)2 PageFunctionCompiler (io.trino.sql.gen.PageFunctionCompiler)2 PlanNodeId (io.trino.sql.planner.plan.PlanNodeId)2 RowExpression (io.trino.sql.relational.RowExpression)2 Test (org.testng.annotations.Test)2 CatalogName (io.trino.connector.CatalogName)1 InternalFunctionBundle (io.trino.metadata.InternalFunctionBundle)1 Split (io.trino.metadata.Split)1 DriverYieldSignal (io.trino.operator.DriverYieldSignal)1 CursorProcessor (io.trino.operator.project.CursorProcessor)1 RecordPageSource (io.trino.spi.connector.RecordPageSource)1 TypeOperators (io.trino.spi.type.TypeOperators)1 ExpressionCompiler (io.trino.sql.gen.ExpressionCompiler)1 Symbol (io.trino.sql.planner.Symbol)1 TestingSplit (io.trino.testing.TestingSplit)1