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));
}
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()));
}
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"));
}
Aggregations