Search in sources :

Example 1 with PLANNER_CONTEXT

use of io.trino.sql.planner.TestingPlannerContext.PLANNER_CONTEXT in project trino by trinodb.

the class TestLiteralEncoder method assertRoundTrip.

private <T> void assertRoundTrip(T value, Type type, BiPredicate<T, T> predicate) {
    Expression expression = encoder.toExpression(TEST_SESSION, value, type);
    assertTrue(isEffectivelyLiteral(PLANNER_CONTEXT, TEST_SESSION, expression), "isEffectivelyLiteral returned false for: " + expression);
    assertEquals(getExpressionType(expression), type);
    @SuppressWarnings("unchecked") T decodedValue = (T) getExpressionValue(expression);
    assertTrue(predicate.test(value, decodedValue));
}
Also used : BIGINT(io.trino.spi.type.BigintType.BIGINT) PLANNER_CONTEXT(io.trino.sql.planner.TestingPlannerContext.PLANNER_CONTEXT) Expression(io.trino.sql.tree.Expression)

Example 2 with PLANNER_CONTEXT

use of io.trino.sql.planner.TestingPlannerContext.PLANNER_CONTEXT in project trino by trinodb.

the class TaskTestUtils method createTestingPlanner.

public static LocalExecutionPlanner createTestingPlanner() {
    PageSourceManager pageSourceManager = new PageSourceManager();
    pageSourceManager.addConnectorPageSourceProvider(CONNECTOR_ID, new TestingPageSourceProvider());
    // we don't start the finalizer so nothing will be collected, which is ok for a test
    FinalizerService finalizerService = new FinalizerService();
    BlockTypeOperators blockTypeOperators = new BlockTypeOperators(PLANNER_CONTEXT.getTypeOperators());
    NodeScheduler nodeScheduler = new NodeScheduler(new UniformNodeSelectorFactory(new InMemoryNodeManager(), new NodeSchedulerConfig().setIncludeCoordinator(true), new NodeTaskMap(finalizerService)));
    NodePartitioningManager nodePartitioningManager = new NodePartitioningManager(nodeScheduler, blockTypeOperators);
    PageFunctionCompiler pageFunctionCompiler = new PageFunctionCompiler(PLANNER_CONTEXT.getFunctionManager(), 0);
    return new LocalExecutionPlanner(PLANNER_CONTEXT, createTestingTypeAnalyzer(PLANNER_CONTEXT), Optional.empty(), pageSourceManager, new IndexManager(), nodePartitioningManager, new PageSinkManager(), new MockDirectExchangeClientSupplier(), new ExpressionCompiler(PLANNER_CONTEXT.getFunctionManager(), pageFunctionCompiler), pageFunctionCompiler, new JoinFilterFunctionCompiler(PLANNER_CONTEXT.getFunctionManager()), new IndexJoinLookupStats(), new TaskManagerConfig(), new GenericSpillerFactory((types, spillContext, memoryContext) -> {
        throw new UnsupportedOperationException();
    }), (types, spillContext, memoryContext) -> {
        throw new UnsupportedOperationException();
    }, (types, partitionFunction, spillContext, memoryContext) -> {
        throw new UnsupportedOperationException();
    }, new PagesIndex.TestingFactory(false), new JoinCompiler(PLANNER_CONTEXT.getTypeOperators()), new TrinoOperatorFactories(), new OrderingCompiler(PLANNER_CONTEXT.getTypeOperators()), new DynamicFilterConfig(), blockTypeOperators, new TableExecuteContextManager(), new ExchangeManagerRegistry(new ExchangeHandleResolver()));
}
Also used : PlanFragment(io.trino.sql.planner.PlanFragment) JoinFilterFunctionCompiler(io.trino.sql.gen.JoinFilterFunctionCompiler) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) CatalogName(io.trino.connector.CatalogName) NodeScheduler(io.trino.execution.scheduler.NodeScheduler) FinalizerService(io.trino.util.FinalizerService) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) TEST_SESSION(io.trino.SessionTestUtils.TEST_SESSION) SINGLE_DISTRIBUTION(io.trino.sql.planner.SystemPartitioningHandle.SINGLE_DISTRIBUTION) TableScanNode(io.trino.sql.planner.plan.TableScanNode) ImmutableMap(com.google.common.collect.ImmutableMap) NodeSchedulerConfig(io.trino.execution.scheduler.NodeSchedulerConfig) PageSinkManager(io.trino.split.PageSinkManager) PageFunctionCompiler(io.trino.sql.gen.PageFunctionCompiler) TrinoOperatorFactories(io.trino.operator.TrinoOperatorFactories) UniformNodeSelectorFactory(io.trino.execution.scheduler.UniformNodeSelectorFactory) IndexJoinLookupStats(io.trino.operator.index.IndexJoinLookupStats) SplitMonitor(io.trino.event.SplitMonitor) MockDirectExchangeClientSupplier(io.trino.execution.TestSqlTaskManager.MockDirectExchangeClientSupplier) List(java.util.List) BIGINT(io.trino.spi.type.BigintType.BIGINT) Split(io.trino.metadata.Split) InMemoryNodeManager(io.trino.metadata.InMemoryNodeManager) Optional(java.util.Optional) PlanFragmentId(io.trino.sql.planner.plan.PlanFragmentId) TestingColumnHandle(io.trino.testing.TestingMetadata.TestingColumnHandle) TypeAnalyzer.createTestingTypeAnalyzer(io.trino.sql.planner.TypeAnalyzer.createTestingTypeAnalyzer) OrderingCompiler(io.trino.sql.gen.OrderingCompiler) NodePartitioningManager(io.trino.sql.planner.NodePartitioningManager) JoinCompiler(io.trino.sql.gen.JoinCompiler) ExchangeHandleResolver(io.trino.metadata.ExchangeHandleResolver) Partitioning(io.trino.sql.planner.Partitioning) PartitioningScheme(io.trino.sql.planner.PartitioningScheme) StatsAndCosts(io.trino.cost.StatsAndCosts) ExpressionCompiler(io.trino.sql.gen.ExpressionCompiler) VARCHAR(io.trino.spi.type.VarcharType.VARCHAR) ImmutableList(com.google.common.collect.ImmutableList) TestingSplit(io.trino.testing.TestingSplit) StageExecutionDescriptor.ungroupedExecution(io.trino.operator.StageExecutionDescriptor.ungroupedExecution) EventListenerConfig(io.trino.eventlistener.EventListenerConfig) IndexManager(io.trino.index.IndexManager) PagesIndex(io.trino.operator.PagesIndex) Symbol(io.trino.sql.planner.Symbol) BlockTypeOperators(io.trino.type.BlockTypeOperators) GenericSpillerFactory(io.trino.spiller.GenericSpillerFactory) PageSourceManager(io.trino.split.PageSourceManager) LocalExecutionPlanner(io.trino.sql.planner.LocalExecutionPlanner) PLANNER_CONTEXT(io.trino.sql.planner.TestingPlannerContext.PLANNER_CONTEXT) EventListenerManager(io.trino.eventlistener.EventListenerManager) TEST_TABLE_HANDLE(io.trino.testing.TestingHandles.TEST_TABLE_HANDLE) OutputBuffers(io.trino.execution.buffer.OutputBuffers) SOURCE_DISTRIBUTION(io.trino.sql.planner.SystemPartitioningHandle.SOURCE_DISTRIBUTION) ExchangeManagerRegistry(io.trino.exchange.ExchangeManagerRegistry) PageFunctionCompiler(io.trino.sql.gen.PageFunctionCompiler) MockDirectExchangeClientSupplier(io.trino.execution.TestSqlTaskManager.MockDirectExchangeClientSupplier) TrinoOperatorFactories(io.trino.operator.TrinoOperatorFactories) NodeSchedulerConfig(io.trino.execution.scheduler.NodeSchedulerConfig) PagesIndex(io.trino.operator.PagesIndex) PageSourceManager(io.trino.split.PageSourceManager) NodePartitioningManager(io.trino.sql.planner.NodePartitioningManager) ExchangeHandleResolver(io.trino.metadata.ExchangeHandleResolver) BlockTypeOperators(io.trino.type.BlockTypeOperators) OrderingCompiler(io.trino.sql.gen.OrderingCompiler) NodeScheduler(io.trino.execution.scheduler.NodeScheduler) GenericSpillerFactory(io.trino.spiller.GenericSpillerFactory) PageSinkManager(io.trino.split.PageSinkManager) JoinCompiler(io.trino.sql.gen.JoinCompiler) LocalExecutionPlanner(io.trino.sql.planner.LocalExecutionPlanner) IndexJoinLookupStats(io.trino.operator.index.IndexJoinLookupStats) UniformNodeSelectorFactory(io.trino.execution.scheduler.UniformNodeSelectorFactory) JoinFilterFunctionCompiler(io.trino.sql.gen.JoinFilterFunctionCompiler) ExchangeManagerRegistry(io.trino.exchange.ExchangeManagerRegistry) InMemoryNodeManager(io.trino.metadata.InMemoryNodeManager) IndexManager(io.trino.index.IndexManager) FinalizerService(io.trino.util.FinalizerService) ExpressionCompiler(io.trino.sql.gen.ExpressionCompiler)

Example 3 with PLANNER_CONTEXT

use of io.trino.sql.planner.TestingPlannerContext.PLANNER_CONTEXT in project trino by trinodb.

the class TestPushProjectionThroughJoin method testPushesProjectionThroughJoin.

@Test
public void testPushesProjectionThroughJoin() {
    PlanNodeIdAllocator idAllocator = new PlanNodeIdAllocator();
    PlanBuilder p = new PlanBuilder(idAllocator, dummyMetadata(), TEST_SESSION);
    Symbol a0 = p.symbol("a0");
    Symbol a1 = p.symbol("a1");
    Symbol a2 = p.symbol("a2");
    Symbol a3 = p.symbol("a3");
    Symbol b0 = p.symbol("b0");
    Symbol b1 = p.symbol("b1");
    Symbol b2 = p.symbol("b2");
    ProjectNode planNode = p.project(Assignments.of(a3, new ArithmeticUnaryExpression(MINUS, a2.toSymbolReference()), b2, new ArithmeticUnaryExpression(PLUS, b1.toSymbolReference())), p.join(INNER, // intermediate non-identity projections should be fully inlined
    p.project(Assignments.of(a2, new ArithmeticUnaryExpression(PLUS, a0.toSymbolReference()), a1, a1.toSymbolReference()), p.project(Assignments.builder().putIdentity(a0).putIdentity(a1).build(), p.values(a0, a1))), p.values(b0, b1), new JoinNode.EquiJoinClause(a1, b1)));
    Session session = testSessionBuilder().build();
    Optional<PlanNode> rewritten = pushProjectionThroughJoin(PLANNER_CONTEXT, planNode, noLookup(), idAllocator, session, createTestingTypeAnalyzer(PLANNER_CONTEXT), p.getTypes());
    assertTrue(rewritten.isPresent());
    assertPlan(session, dummyMetadata(), createTestingFunctionManager(), node -> unknown(), new Plan(rewritten.get(), p.getTypes(), empty()), noLookup(), join(INNER, ImmutableList.of(aliases -> new JoinNode.EquiJoinClause(new Symbol("a1"), new Symbol("b1"))), strictProject(ImmutableMap.of("a3", expression("-(+a0)"), "a1", expression("a1")), strictProject(ImmutableMap.of("a0", expression("a0"), "a1", expression("a1")), PlanMatchPattern.values("a0", "a1"))), strictProject(ImmutableMap.of("b2", expression("+b1"), "b1", expression("b1")), PlanMatchPattern.values("b0", "b1"))).withExactOutputs("a3", "b2"));
}
Also used : TypeAnalyzer.createTestingTypeAnalyzer(io.trino.sql.planner.TypeAnalyzer.createTestingTypeAnalyzer) PlanAssert.assertPlan(io.trino.sql.planner.assertions.PlanAssert.assertPlan) INNER(io.trino.sql.planner.plan.JoinNode.Type.INNER) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PlanMatchPattern(io.trino.sql.planner.assertions.PlanMatchPattern) Test(org.testng.annotations.Test) PlanNode(io.trino.sql.planner.plan.PlanNode) Lookup.noLookup(io.trino.sql.planner.iterative.Lookup.noLookup) FunctionManager.createTestingFunctionManager(io.trino.metadata.FunctionManager.createTestingFunctionManager) LEFT(io.trino.sql.planner.plan.JoinNode.Type.LEFT) ImmutableList(com.google.common.collect.ImmutableList) ArithmeticUnaryExpression(io.trino.sql.tree.ArithmeticUnaryExpression) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) TEST_SESSION(io.trino.SessionTestUtils.TEST_SESSION) JoinNode(io.trino.sql.planner.plan.JoinNode) ProjectNode(io.trino.sql.planner.plan.ProjectNode) ArithmeticBinaryExpression(io.trino.sql.tree.ArithmeticBinaryExpression) PlanMatchPattern.join(io.trino.sql.planner.assertions.PlanMatchPattern.join) PLUS(io.trino.sql.tree.ArithmeticUnaryExpression.Sign.PLUS) Symbol(io.trino.sql.planner.Symbol) PlanMatchPattern.expression(io.trino.sql.planner.assertions.PlanMatchPattern.expression) ImmutableMap(com.google.common.collect.ImmutableMap) Assignments(io.trino.sql.planner.plan.Assignments) AbstractMockMetadata.dummyMetadata(io.trino.metadata.AbstractMockMetadata.dummyMetadata) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) PlanMatchPattern.strictProject(io.trino.sql.planner.assertions.PlanMatchPattern.strictProject) PushProjectionThroughJoin.pushProjectionThroughJoin(io.trino.sql.planner.iterative.rule.PushProjectionThroughJoin.pushProjectionThroughJoin) ADD(io.trino.sql.tree.ArithmeticBinaryExpression.Operator.ADD) PLANNER_CONTEXT(io.trino.sql.planner.TestingPlannerContext.PLANNER_CONTEXT) PlanNodeStatsEstimate.unknown(io.trino.cost.PlanNodeStatsEstimate.unknown) StatsAndCosts.empty(io.trino.cost.StatsAndCosts.empty) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) Plan(io.trino.sql.planner.Plan) MINUS(io.trino.sql.tree.ArithmeticUnaryExpression.Sign.MINUS) PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) Session(io.trino.Session) PlanNode(io.trino.sql.planner.plan.PlanNode) PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) Symbol(io.trino.sql.planner.Symbol) ProjectNode(io.trino.sql.planner.plan.ProjectNode) ArithmeticUnaryExpression(io.trino.sql.tree.ArithmeticUnaryExpression) PlanAssert.assertPlan(io.trino.sql.planner.assertions.PlanAssert.assertPlan) Plan(io.trino.sql.planner.Plan) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) Session(io.trino.Session) Test(org.testng.annotations.Test)

Aggregations

PLANNER_CONTEXT (io.trino.sql.planner.TestingPlannerContext.PLANNER_CONTEXT)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 TEST_SESSION (io.trino.SessionTestUtils.TEST_SESSION)2 BIGINT (io.trino.spi.type.BigintType.BIGINT)2 Symbol (io.trino.sql.planner.Symbol)2 ObjectMapperProvider (io.airlift.json.ObjectMapperProvider)1 Session (io.trino.Session)1 CatalogName (io.trino.connector.CatalogName)1 PlanNodeStatsEstimate.unknown (io.trino.cost.PlanNodeStatsEstimate.unknown)1 StatsAndCosts (io.trino.cost.StatsAndCosts)1 StatsAndCosts.empty (io.trino.cost.StatsAndCosts.empty)1 SplitMonitor (io.trino.event.SplitMonitor)1 EventListenerConfig (io.trino.eventlistener.EventListenerConfig)1 EventListenerManager (io.trino.eventlistener.EventListenerManager)1 ExchangeManagerRegistry (io.trino.exchange.ExchangeManagerRegistry)1 MockDirectExchangeClientSupplier (io.trino.execution.TestSqlTaskManager.MockDirectExchangeClientSupplier)1 OutputBuffers (io.trino.execution.buffer.OutputBuffers)1 NodeScheduler (io.trino.execution.scheduler.NodeScheduler)1 NodeSchedulerConfig (io.trino.execution.scheduler.NodeSchedulerConfig)1