Search in sources :

Example 1 with TestingFunctionResolution

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

the class TestSetSessionTask method testSetSession.

@Test
public void testSetSession() {
    testSetSession("bar", new StringLiteral("baz"), "baz");
    testSetSession("bar", new TestingFunctionResolution(transactionManager, plannerContext).functionCallBuilder(QualifiedName.of("concat")).addArgument(VARCHAR, new StringLiteral("ban")).addArgument(VARCHAR, new StringLiteral("ana")).build(), "banana");
}
Also used : TestingFunctionResolution(io.trino.metadata.TestingFunctionResolution) StringLiteral(io.trino.sql.tree.StringLiteral) Test(org.testng.annotations.Test)

Example 2 with TestingFunctionResolution

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

the class TestSetSessionTask method testSetSessionWithParameters.

@Test
public void testSetSessionWithParameters() {
    FunctionCall functionCall = new TestingFunctionResolution(transactionManager, plannerContext).functionCallBuilder(QualifiedName.of("concat")).addArgument(VARCHAR, new StringLiteral("ban")).addArgument(VARCHAR, new Parameter(0)).build();
    testSetSessionWithParameters("bar", functionCall, "banana", ImmutableList.of(new StringLiteral("ana")));
}
Also used : TestingFunctionResolution(io.trino.metadata.TestingFunctionResolution) StringLiteral(io.trino.sql.tree.StringLiteral) Parameter(io.trino.sql.tree.Parameter) FunctionCall(io.trino.sql.tree.FunctionCall) Test(org.testng.annotations.Test)

Example 3 with TestingFunctionResolution

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

the class TestFilterAndProjectOperator method testMergeOutput.

@Test
public void testMergeOutput() {
    List<Page> input = rowPagesBuilder(VARCHAR, BIGINT).addSequencePage(100, 0, 0).addSequencePage(100, 0, 0).addSequencePage(100, 0, 0).addSequencePage(100, 0, 0).build();
    TestingFunctionResolution functionResolution = new TestingFunctionResolution();
    RowExpression filter = call(functionResolution.resolveOperator(EQUAL, ImmutableList.of(BIGINT, BIGINT)), field(1, BIGINT), constant(10L, BIGINT));
    ExpressionCompiler compiler = functionResolution.getExpressionCompiler();
    Supplier<PageProcessor> processor = compiler.compilePageProcessor(Optional.of(filter), ImmutableList.of(field(1, BIGINT)));
    OperatorFactory operatorFactory = FilterAndProjectOperator.createOperatorFactory(0, new PlanNodeId("test"), processor, ImmutableList.of(BIGINT), DataSize.of(64, KILOBYTE), 2);
    List<Page> expected = rowPagesBuilder(BIGINT).row(10L).row(10L).row(10L).row(10L).build();
    assertOperatorEquals(operatorFactory, ImmutableList.of(BIGINT), driverContext, input, expected);
}
Also used : TestingFunctionResolution(io.trino.metadata.TestingFunctionResolution) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) PageProcessor(io.trino.operator.project.PageProcessor) RowExpression(io.trino.sql.relational.RowExpression) Page(io.trino.spi.Page) ExpressionCompiler(io.trino.sql.gen.ExpressionCompiler) Test(org.testng.annotations.Test)

Example 4 with TestingFunctionResolution

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

the class TestPageProcessor method testExpressionProfiler.

@Test
public void testExpressionProfiler() {
    TestingFunctionResolution functionResolution = new TestingFunctionResolution();
    CallExpression add10Expression = call(functionResolution.resolveOperator(ADD, ImmutableList.of(BIGINT, BIGINT)), field(0, BIGINT), constant(10L, BIGINT));
    TestingTicker testingTicker = new TestingTicker();
    PageFunctionCompiler functionCompiler = functionResolution.getPageFunctionCompiler();
    Supplier<PageProjection> projectionSupplier = functionCompiler.compileProjection(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<Block> work = projection.project(SESSION, 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 : TestingFunctionResolution(io.trino.metadata.TestingFunctionResolution) TestingTicker(io.airlift.testing.TestingTicker) PageFunctionCompiler(io.trino.sql.gen.PageFunctionCompiler) LazyBlock(io.trino.spi.block.LazyBlock) Block(io.trino.spi.block.Block) BlockAssertions.createLongSequenceBlock(io.trino.block.BlockAssertions.createLongSequenceBlock) BlockAssertions.createStringsBlock(io.trino.block.BlockAssertions.createStringsBlock) BlockAssertions.createSlicesBlock(io.trino.block.BlockAssertions.createSlicesBlock) VariableWidthBlock(io.trino.spi.block.VariableWidthBlock) DriverYieldSignal(io.trino.operator.DriverYieldSignal) Page(io.trino.spi.Page) CallExpression(io.trino.sql.relational.CallExpression) ExpressionProfiler(io.trino.sql.gen.ExpressionProfiler) Test(org.testng.annotations.Test)

Example 5 with TestingFunctionResolution

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

the class TestFilterStatsRule method testUnestimatableFunction.

@Test
public void testUnestimatableFunction() {
    // can't estimate function and default filter factor is turned off
    ComparisonExpression unestimatableExpression = new ComparisonExpression(Operator.EQUAL, new TestingFunctionResolution().functionCallBuilder(QualifiedName.of("sin")).addArgument(DOUBLE, new SymbolReference("i1")).build(), new DoubleLiteral("1"));
    tester().assertStatsFor(pb -> pb.filter(unestimatableExpression, pb.values(pb.symbol("i1"), pb.symbol("i2"), pb.symbol("i3")))).withSourceStats(0, PlanNodeStatsEstimate.builder().setOutputRowCount(10).addSymbolStatistics(new Symbol("i1"), SymbolStatsEstimate.builder().setLowValue(1).setHighValue(10).setDistinctValuesCount(5).setNullsFraction(0).build()).addSymbolStatistics(new Symbol("i2"), SymbolStatsEstimate.builder().setLowValue(0).setHighValue(3).setDistinctValuesCount(4).setNullsFraction(0).build()).addSymbolStatistics(new Symbol("i3"), SymbolStatsEstimate.builder().setLowValue(10).setHighValue(15).setDistinctValuesCount(4).setNullsFraction(0.1).build()).build()).check(PlanNodeStatsAssertion::outputRowsCountUnknown);
    // can't estimate function, but default filter factor is turned on
    defaultFilterTester.assertStatsFor(pb -> pb.filter(unestimatableExpression, pb.values(pb.symbol("i1"), pb.symbol("i2"), pb.symbol("i3")))).withSourceStats(0, PlanNodeStatsEstimate.builder().setOutputRowCount(10).addSymbolStatistics(new Symbol("i1"), SymbolStatsEstimate.builder().setLowValue(1).setHighValue(10).setDistinctValuesCount(5).setNullsFraction(0).build()).addSymbolStatistics(new Symbol("i2"), SymbolStatsEstimate.builder().setLowValue(0).setHighValue(3).setDistinctValuesCount(4).setNullsFraction(0).build()).addSymbolStatistics(new Symbol("i3"), SymbolStatsEstimate.builder().setLowValue(10).setHighValue(15).setDistinctValuesCount(4).setNullsFraction(0.1).build()).build()).check(check -> check.outputRowsCount(9).symbolStats("i1", assertion -> assertion.lowValue(1).highValue(10).dataSizeUnknown().distinctValuesCount(5).nullsFraction(0)).symbolStats("i2", assertion -> assertion.lowValue(0).highValue(3).dataSizeUnknown().distinctValuesCount(4).nullsFraction(0)).symbolStats("i3", assertion -> assertion.lowValue(10).highValue(15).dataSizeUnknown().distinctValuesCount(4).nullsFraction(0.1)));
}
Also used : TestingFunctionResolution(io.trino.metadata.TestingFunctionResolution) Symbol(io.trino.sql.planner.Symbol) AfterClass(org.testng.annotations.AfterClass) BeforeClass(org.testng.annotations.BeforeClass) TestingFunctionResolution(io.trino.metadata.TestingFunctionResolution) Test(org.testng.annotations.Test) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) DoubleLiteral(io.trino.sql.tree.DoubleLiteral) QualifiedName(io.trino.sql.tree.QualifiedName) DOUBLE(io.trino.spi.type.DoubleType.DOUBLE) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) SymbolReference(io.trino.sql.tree.SymbolReference) Operator(io.trino.sql.tree.ComparisonExpression.Operator) PlanBuilder.expression(io.trino.sql.planner.iterative.rule.test.PlanBuilder.expression) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) SymbolReference(io.trino.sql.tree.SymbolReference) Symbol(io.trino.sql.planner.Symbol) DoubleLiteral(io.trino.sql.tree.DoubleLiteral) Test(org.testng.annotations.Test)

Aggregations

TestingFunctionResolution (io.trino.metadata.TestingFunctionResolution)12 Test (org.testng.annotations.Test)9 Page (io.trino.spi.Page)3 RowExpression (io.trino.sql.relational.RowExpression)3 BeforeClass (org.testng.annotations.BeforeClass)3 PageProcessor (io.trino.operator.project.PageProcessor)2 Block (io.trino.spi.block.Block)2 ExpressionCompiler (io.trino.sql.gen.ExpressionCompiler)2 PlanNodeId (io.trino.sql.planner.plan.PlanNodeId)2 StringLiteral (io.trino.sql.tree.StringLiteral)2 TestingTicker (io.airlift.testing.TestingTicker)1 BlockAssertions.createLongSequenceBlock (io.trino.block.BlockAssertions.createLongSequenceBlock)1 BlockAssertions.createSlicesBlock (io.trino.block.BlockAssertions.createSlicesBlock)1 BlockAssertions.createStringsBlock (io.trino.block.BlockAssertions.createStringsBlock)1 ResolvedFunction (io.trino.metadata.ResolvedFunction)1 DriverYieldSignal (io.trino.operator.DriverYieldSignal)1 Aggregator (io.trino.operator.aggregation.Aggregator)1 TestingAggregationFunction (io.trino.operator.aggregation.TestingAggregationFunction)1 BlockBuilder (io.trino.spi.block.BlockBuilder)1 LazyBlock (io.trino.spi.block.LazyBlock)1