public RuleAssert on(Function<PlanBuilder, PlanNode> planProvider) { checkArgument(plan == null, "plan has already been set"); PlanBuilder builder = new PlanBuilder(idAllocator, metadata); plan = planProvider.apply(builder); types = builder.getTypes(); return this; }
@Test public void testLimitOnTopOfValues() { PlanBuilder planBuilder = new PlanBuilder(new PlanNodeIdAllocator(), dummyMetadata()); assertEquals( extractCardinality(planBuilder.limit(3, planBuilder.values(emptyList(), ImmutableList.of(emptyList())))), Range.singleton(1L)); assertEquals( extractCardinality(planBuilder.limit(3, planBuilder.values(emptyList(), ImmutableList.of(emptyList(), emptyList(), emptyList(), emptyList())))), Range.singleton(3L)); } }
@Test public void testJoinOrder() { PlanBuilder planBuilder = new PlanBuilder(new PlanNodeIdAllocator(), dummyMetadata()); TableScanNode a = planBuilder.tableScan(emptyList(), emptyMap()); TableScanNode b = planBuilder.tableScan(emptyList(), emptyMap()); List<PlanNodeId> order = scheduleOrder(planBuilder.join(JoinNode.Type.INNER, a, b)); assertEquals(order, ImmutableList.of(b.getId(), a.getId())); }
@Test public void testIndexJoinOrder() { PlanBuilder planBuilder = new PlanBuilder(new PlanNodeIdAllocator(), dummyMetadata()); TableScanNode a = planBuilder.tableScan(emptyList(), emptyMap()); TableScanNode b = planBuilder.tableScan(emptyList(), emptyMap()); List<PlanNodeId> order = scheduleOrder(planBuilder.indexJoin(IndexJoinNode.Type.INNER, a, b)); assertEquals(order, ImmutableList.of(b.getId(), a.getId())); }
private PlanBuilder planBuilder() { return new PlanBuilder(new PlanNodeIdAllocator(), queryRunner.getMetadata()); } }
public StatsCalculatorAssertion assertStatsFor(Function<PlanBuilder, PlanNode> planProvider) { PlanBuilder planBuilder = new PlanBuilder(new PlanNodeIdAllocator(), metadata); PlanNode planNode = planProvider.apply(planBuilder); return new StatsCalculatorAssertion(statsCalculator, session, planNode, planBuilder.getTypes()); }
private void validatePlan(Function<PlanBuilder, PlanNode> planProvider) { PlanBuilder builder = new PlanBuilder(idAllocator, metadata); PlanNode planNode = planProvider.apply(builder); TypeProvider types = builder.getTypes(); getQueryRunner().inTransaction(session -> { // metadata.getCatalogHandle() registers the catalog for the transaction session.getCatalog().ifPresent(catalog -> metadata.getCatalogHandle(session, catalog)); new ValidateStreamingAggregations().validate(planNode, session, metadata, sqlParser, types, WarningCollector.NOOP); return null; }); } }
@Test public void testSemiJoinOrder() { PlanBuilder planBuilder = new PlanBuilder(new PlanNodeIdAllocator(), dummyMetadata()); Symbol sourceJoin = planBuilder.symbol("sourceJoin"); TableScanNode a = planBuilder.tableScan(ImmutableList.of(sourceJoin), ImmutableMap.of(sourceJoin, new TestingColumnHandle("sourceJoin"))); Symbol filteringSource = planBuilder.symbol("filteringSource"); TableScanNode b = planBuilder.tableScan(ImmutableList.of(filteringSource), ImmutableMap.of(filteringSource, new TestingColumnHandle("filteringSource"))); List<PlanNodeId> order = scheduleOrder(planBuilder.semiJoin( sourceJoin, filteringSource, planBuilder.symbol("semiJoinOutput"), Optional.empty(), Optional.empty(), a, b)); assertEquals(order, ImmutableList.of(b.getId(), a.getId())); } }
@Test public void testDoesNotCreateJoinWhenPartitionedOnCrossJoin() { PlanNodeIdAllocator idAllocator = new PlanNodeIdAllocator(); PlanBuilder p = new PlanBuilder(idAllocator, queryRunner.getMetadata()); Symbol a1 = p.symbol("A1"); Symbol b1 = p.symbol("B1"); MultiJoinNode multiJoinNode = new MultiJoinNode( new LinkedHashSet<>(ImmutableList.of(p.values(a1), p.values(b1))), TRUE_LITERAL, ImmutableList.of(a1, b1)); JoinEnumerator joinEnumerator = new JoinEnumerator( new CostComparator(1, 1, 1), multiJoinNode.getFilter(), createContext()); JoinEnumerationResult actual = joinEnumerator.createJoinAccordingToPartitioning(multiJoinNode.getSources(), multiJoinNode.getOutputSymbols(), ImmutableSet.of(0)); assertFalse(actual.getPlanNode().isPresent()); assertEquals(actual.getCost(), PlanNodeCostEstimate.infinite()); }
@BeforeClass public void setup() { metadata = getQueryRunner().getMetadata(); builder = new PlanBuilder(new PlanNodeIdAllocator(), metadata); ConnectorId connectorId = getCurrentConnectorId(); TableHandle nationTableHandle = new TableHandle( connectorId, new TpchTableHandle("nation", 1.0)); TableLayoutHandle nationTableLayoutHandle = new TableLayoutHandle(connectorId, TestingTransactionHandle.create(), new TpchTableLayoutHandle((TpchTableHandle) nationTableHandle.getConnectorHandle(), TupleDomain.all())); TpchColumnHandle nationkeyColumnHandle = new TpchColumnHandle("nationkey", BIGINT); symbol = new Symbol("nationkey"); tableScanNode = builder.tableScan(nationTableHandle, ImmutableList.of(symbol), ImmutableMap.of(symbol, nationkeyColumnHandle), Optional.of(nationTableLayoutHandle)); }