Search in sources :

Example 1 with PARTITIONED

use of com.facebook.presto.sql.planner.plan.JoinNode.DistributionType.PARTITIONED in project presto by prestodb.

the class TestLogicalPlanner method testBroadcastCorrelatedSubqueryAvoidsRemoteExchangeBeforeAggregation.

@Test
public void testBroadcastCorrelatedSubqueryAvoidsRemoteExchangeBeforeAggregation() {
    Session broadcastJoin = Session.builder(this.getQueryRunner().getDefaultSession()).setSystemProperty(JOIN_DISTRIBUTION_TYPE, JoinDistributionType.BROADCAST.name()).setSystemProperty(FORCE_SINGLE_NODE_OUTPUT, Boolean.toString(false)).build();
    // make sure there is a remote exchange on the build side
    PlanMatchPattern joinBuildSideWithRemoteExchange = anyTree(node(JoinNode.class, anyTree(node(TableScanNode.class)), anyTree(exchange(REMOTE_STREAMING, ExchangeNode.Type.REPLICATE, anyTree(node(TableScanNode.class))))));
    // validates that there exists only one remote exchange
    Consumer<Plan> validateSingleRemoteExchange = plan -> assertEquals(countOfMatchingNodes(plan, node -> node instanceof ExchangeNode && ((ExchangeNode) node).getScope().isRemote()), 1);
    Consumer<Plan> validateSingleStreamingAggregation = plan -> assertEquals(countOfMatchingNodes(plan, node -> node instanceof AggregationNode && ((AggregationNode) node).getGroupingKeys().contains(new VariableReferenceExpression(Optional.empty(), "unique", BIGINT)) && ((AggregationNode) node).isStreamable()), 1);
    // region is unpartitioned, AssignUniqueId should provide satisfying partitioning for count(*) after LEFT JOIN
    assertPlanWithSession("SELECT (SELECT COUNT(*) FROM region r2 WHERE r2.regionkey > r1.regionkey) FROM region r1", broadcastJoin, false, joinBuildSideWithRemoteExchange, validateSingleRemoteExchange.andThen(validateSingleStreamingAggregation));
    // orders is naturally partitioned, AssignUniqueId should not overwrite its natural partitioning
    assertPlanWithSession("SELECT COUNT(COUNT) " + "FROM (SELECT o1.orderkey orderkey, (SELECT COUNT(*) FROM orders o2 WHERE o2.orderkey > o1.orderkey) COUNT FROM orders o1) " + "GROUP BY orderkey", broadcastJoin, false, joinBuildSideWithRemoteExchange, validateSingleRemoteExchange.andThen(validateSingleStreamingAggregation));
}
Also used : FORCE_SINGLE_NODE_OUTPUT(com.facebook.presto.SystemSessionProperties.FORCE_SINGLE_NODE_OUTPUT) PlanMatchPattern.filter(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.filter) PlanMatchPattern.anyTree(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.anyTree) REPLICATE(com.facebook.presto.sql.planner.plan.ExchangeNode.Type.REPLICATE) PlanMatchPattern.anyNot(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.anyNot) Test(org.testng.annotations.Test) DESCENDING(com.facebook.presto.sql.tree.SortItem.Ordering.DESCENDING) ValuesNode(com.facebook.presto.spi.plan.ValuesNode) PlanMatchPattern(com.facebook.presto.sql.planner.assertions.PlanMatchPattern) PlanMatchPattern.join(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.join) ASC_NULLS_LAST(com.facebook.presto.common.block.SortOrder.ASC_NULLS_LAST) IndexJoinNode(com.facebook.presto.sql.planner.plan.IndexJoinNode) PlanMatchPattern.expression(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.expression) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) Assert.assertFalse(org.testng.Assert.assertFalse) PARTIAL(com.facebook.presto.spi.plan.AggregationNode.Step.PARTIAL) LateralJoinNode(com.facebook.presto.sql.planner.plan.LateralJoinNode) SUBQUERY_MULTIPLE_ROWS(com.facebook.presto.spi.StandardErrorCode.SUBQUERY_MULTIPLE_ROWS) PlanMatchPattern.semiJoin(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.semiJoin) LAST(com.facebook.presto.sql.tree.SortItem.NullOrdering.LAST) PlanMatchPattern.apply(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.apply) PlanMatchPattern.rowNumber(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.rowNumber) JOIN_DISTRIBUTION_TYPE(com.facebook.presto.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE) TASK_CONCURRENCY(com.facebook.presto.SystemSessionProperties.TASK_CONCURRENCY) REPLICATED(com.facebook.presto.sql.planner.plan.JoinNode.DistributionType.REPLICATED) OPTIMIZE_NULLS_IN_JOINS(com.facebook.presto.SystemSessionProperties.OPTIMIZE_NULLS_IN_JOINS) LongLiteral(com.facebook.presto.sql.tree.LongLiteral) ApplyNode(com.facebook.presto.sql.planner.plan.ApplyNode) PlanMatchPattern.strictProject(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.strictProject) PlanMatchPattern.node(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.node) PlanMatchPattern.specification(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.specification) PlanOptimizer(com.facebook.presto.sql.planner.optimizations.PlanOptimizer) GATHER(com.facebook.presto.sql.planner.plan.ExchangeNode.Type.GATHER) OFFSET_CLAUSE_ENABLED(com.facebook.presto.SystemSessionProperties.OFFSET_CLAUSE_ENABLED) DistinctLimitNode(com.facebook.presto.spi.plan.DistinctLimitNode) AddLocalExchanges(com.facebook.presto.sql.planner.optimizations.AddLocalExchanges) ASCENDING(com.facebook.presto.sql.tree.SortItem.Ordering.ASCENDING) PlanMatchPattern.functionCall(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.functionCall) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) Session(com.facebook.presto.Session) ELIMINATE_CROSS_JOINS(com.facebook.presto.sql.analyzer.FeaturesConfig.JoinReorderingStrategy.ELIMINATE_CROSS_JOINS) PlanMatchPattern.exchange(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.exchange) RIGHT(com.facebook.presto.sql.planner.plan.JoinNode.Type.RIGHT) OPTIMIZE_JOINS_WITH_EMPTY_SOURCES(com.facebook.presto.SystemSessionProperties.OPTIMIZE_JOINS_WITH_EMPTY_SOURCES) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) SemiJoinNode(com.facebook.presto.sql.planner.plan.SemiJoinNode) AggregationNode(com.facebook.presto.spi.plan.AggregationNode) QueryTemplate.queryTemplate(com.facebook.presto.tests.QueryTemplate.queryTemplate) BasePlanTest(com.facebook.presto.sql.planner.assertions.BasePlanTest) PlanMatchPattern.output(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.output) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) MorePredicates.isInstanceOfAny(com.facebook.presto.util.MorePredicates.isInstanceOfAny) PlanMatchPattern.window(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.window) JoinDistributionType(com.facebook.presto.sql.analyzer.FeaturesConfig.JoinDistributionType) PlanMatchPattern.aggregation(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.aggregation) PlanMatchPattern.sort(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.sort) OPTIMIZE_HASH_GENERATION(com.facebook.presto.SystemSessionProperties.OPTIMIZE_HASH_GENERATION) PlanMatchPattern.project(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.project) ImmutableMap(com.google.common.collect.ImmutableMap) PlanMatchPattern.topN(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.topN) Predicate(java.util.function.Predicate) Domain.singleValue(com.facebook.presto.common.predicate.Domain.singleValue) PlanMatchPattern.constrainedTableScan(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.constrainedTableScan) String.format(java.lang.String.format) REMOTE_STREAMING(com.facebook.presto.sql.planner.plan.ExchangeNode.Scope.REMOTE_STREAMING) List(java.util.List) RowNumberSymbolMatcher(com.facebook.presto.sql.planner.assertions.RowNumberSymbolMatcher) ExpressionMatcher(com.facebook.presto.sql.planner.assertions.ExpressionMatcher) MorePredicates(com.facebook.presto.util.MorePredicates) JOIN_REORDERING_STRATEGY(com.facebook.presto.SystemSessionProperties.JOIN_REORDERING_STRATEGY) PlanMatchPattern.markDistinct(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.markDistinct) Optional(java.util.Optional) INNER(com.facebook.presto.sql.planner.plan.JoinNode.Type.INNER) PlanMatchPattern.assignUniqueId(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.assignUniqueId) Assert.assertEquals(org.testng.Assert.assertEquals) SINGLE(com.facebook.presto.spi.plan.AggregationNode.Step.SINGLE) VarcharType.createVarcharType(com.facebook.presto.common.type.VarcharType.createVarcharType) DISTRIBUTED_SORT(com.facebook.presto.SystemSessionProperties.DISTRIBUTED_SORT) ENFORCE_FIXED_DISTRIBUTION_FOR_OUTPUT_OPERATOR(com.facebook.presto.SystemSessionProperties.ENFORCE_FIXED_DISTRIBUTION_FOR_OUTPUT_OPERATOR) PlanMatchPattern.singleGroupingSet(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.singleGroupingSet) FilterNode(com.facebook.presto.spi.plan.FilterNode) QueryTemplate(com.facebook.presto.tests.QueryTemplate) ImmutableList(com.google.common.collect.ImmutableList) LOCAL(com.facebook.presto.sql.planner.plan.ExchangeNode.Scope.LOCAL) REPARTITION(com.facebook.presto.sql.planner.plan.ExchangeNode.Type.REPARTITION) PlanMatchPattern.equiJoinClause(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.equiJoinClause) FINAL(com.facebook.presto.spi.plan.AggregationNode.Step.FINAL) PlanMatchPattern.topNRowNumber(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.topNRowNumber) PlanMatchPattern.any(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.any) PlanMatchPattern.strictTableScan(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.strictTableScan) PlanNodeSearcher.searchFrom(com.facebook.presto.sql.planner.optimizations.PlanNodeSearcher.searchFrom) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) PlanMatchPattern.constrainedTableScanWithTableLayout(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.constrainedTableScanWithTableLayout) PlanMatchPattern.limit(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.limit) PlanMatchPattern.tableScan(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.tableScan) Consumer(java.util.function.Consumer) PlanNode(com.facebook.presto.spi.plan.PlanNode) LEFT(com.facebook.presto.sql.planner.plan.JoinNode.Type.LEFT) PlanMatchPattern.values(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.values) PARTITIONED(com.facebook.presto.sql.planner.plan.JoinNode.DistributionType.PARTITIONED) EnforceSingleRowNode(com.facebook.presto.sql.planner.plan.EnforceSingleRowNode) ExchangeNode(com.facebook.presto.sql.planner.plan.ExchangeNode) StatisticsWriterNode(com.facebook.presto.sql.planner.plan.StatisticsWriterNode) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) ExchangeNode(com.facebook.presto.sql.planner.plan.ExchangeNode) IndexJoinNode(com.facebook.presto.sql.planner.plan.IndexJoinNode) LateralJoinNode(com.facebook.presto.sql.planner.plan.LateralJoinNode) SemiJoinNode(com.facebook.presto.sql.planner.plan.SemiJoinNode) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) PlanMatchPattern(com.facebook.presto.sql.planner.assertions.PlanMatchPattern) AggregationNode(com.facebook.presto.spi.plan.AggregationNode) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test) BasePlanTest(com.facebook.presto.sql.planner.assertions.BasePlanTest)

Example 2 with PARTITIONED

use of com.facebook.presto.sql.planner.plan.JoinNode.DistributionType.PARTITIONED in project presto by prestodb.

the class TestPredicatePushdown method testPredicatePushDownCreatesValidJoin.

@Test
public void testPredicatePushDownCreatesValidJoin() {
    RuleTester tester = new RuleTester();
    tester.assertThat(new PredicatePushDown(tester.getMetadata(), tester.getSqlParser())).on(p -> p.join(INNER, p.filter(p.comparison(OperatorType.EQUAL, p.variable("a1"), constant(1L, INTEGER)), p.values(p.variable("a1"))), p.values(p.variable("b1")), ImmutableList.of(new EquiJoinClause(p.variable("a1"), p.variable("b1"))), ImmutableList.of(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(PARTITIONED), ImmutableMap.of())).matches(project(join(INNER, ImmutableList.of(), Optional.empty(), Optional.of(REPLICATED), project(filter("a1=1", values("a1"))), project(filter("1=b1", values("b1"))))));
}
Also used : EquiJoinClause(com.facebook.presto.sql.planner.plan.JoinNode.EquiJoinClause) PlanOptimizer(com.facebook.presto.sql.planner.optimizations.PlanOptimizer) PlanMatchPattern.filter(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.filter) BasePlanTest(com.facebook.presto.sql.planner.assertions.BasePlanTest) PredicatePushDown(com.facebook.presto.sql.planner.optimizations.PredicatePushDown) PlanMatchPattern.anyTree(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.anyTree) PlanMatchPattern.output(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.output) PlanMatchPattern.assignUniqueId(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.assignUniqueId) Test(org.testng.annotations.Test) Expressions.constant(com.facebook.presto.sql.relational.Expressions.constant) PlanMatchPattern(com.facebook.presto.sql.planner.assertions.PlanMatchPattern) PlanMatchPattern.join(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.join) ImmutableList(com.google.common.collect.ImmutableList) PlanMatchPattern.equiJoinClause(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.equiJoinClause) Map(java.util.Map) PlanMatchPattern.expression(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.expression) PlanMatchPattern.project(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.project) WindowNode(com.facebook.presto.sql.planner.plan.WindowNode) ImmutableMap(com.google.common.collect.ImmutableMap) PlanMatchPattern.semiJoin(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.semiJoin) PlanMatchPattern.tableScan(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.tableScan) PlanMatchPattern.exchange(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.exchange) OperatorType(com.facebook.presto.common.function.OperatorType) List(java.util.List) REPLICATED(com.facebook.presto.sql.planner.plan.JoinNode.DistributionType.REPLICATED) LEFT(com.facebook.presto.sql.planner.plan.JoinNode.Type.LEFT) INTEGER(com.facebook.presto.common.type.IntegerType.INTEGER) Optional(java.util.Optional) PlanMatchPattern.values(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.values) PARTITIONED(com.facebook.presto.sql.planner.plan.JoinNode.DistributionType.PARTITIONED) RuleTester(com.facebook.presto.sql.planner.iterative.rule.test.RuleTester) ExchangeNode(com.facebook.presto.sql.planner.plan.ExchangeNode) PlanMatchPattern.node(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.node) INNER(com.facebook.presto.sql.planner.plan.JoinNode.Type.INNER) RuleTester(com.facebook.presto.sql.planner.iterative.rule.test.RuleTester) EquiJoinClause(com.facebook.presto.sql.planner.plan.JoinNode.EquiJoinClause) PredicatePushDown(com.facebook.presto.sql.planner.optimizations.PredicatePushDown) BasePlanTest(com.facebook.presto.sql.planner.assertions.BasePlanTest) Test(org.testng.annotations.Test)

Example 3 with PARTITIONED

use of com.facebook.presto.sql.planner.plan.JoinNode.DistributionType.PARTITIONED in project presto by prestodb.

the class TestDetermineJoinDistributionType method testPartitionFullOuterJoin.

@Test
public void testPartitionFullOuterJoin() {
    int aRows = 10_000;
    int bRows = 10;
    assertDetermineJoinDistributionType().setSystemProperty(JOIN_DISTRIBUTION_TYPE, JoinDistributionType.AUTOMATIC.name()).overrideStats("valuesA", PlanNodeStatsEstimate.builder().setOutputRowCount(aRows).addVariableStatistics(ImmutableMap.of(new VariableReferenceExpression(Optional.empty(), "A1", BIGINT), new VariableStatsEstimate(0, 100, 0, 640000, 100))).build()).overrideStats("valuesB", PlanNodeStatsEstimate.builder().setOutputRowCount(bRows).addVariableStatistics(ImmutableMap.of(new VariableReferenceExpression(Optional.empty(), "B1", BIGINT), new VariableStatsEstimate(0, 100, 0, 640000, 100))).build()).on(p -> p.join(FULL, p.values(new PlanNodeId("valuesA"), aRows, p.variable("A1", BIGINT)), p.values(new PlanNodeId("valuesB"), bRows, p.variable("B1", BIGINT)), ImmutableList.of(new JoinNode.EquiJoinClause(p.variable("A1", BIGINT), p.variable("B1", BIGINT))), ImmutableList.of(p.variable("A1", BIGINT), p.variable("B1", BIGINT)), Optional.empty())).matches(join(FULL, ImmutableList.of(equiJoinClause("A1", "B1")), Optional.empty(), Optional.of(PARTITIONED), values(ImmutableMap.of("A1", 0)), values(ImmutableMap.of("B1", 0))));
}
Also used : Type(com.facebook.presto.sql.planner.plan.JoinNode.Type) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) PlanBuilder.castToRowExpression(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder.castToRowExpression) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) Test(org.testng.annotations.Test) FULL(com.facebook.presto.sql.planner.plan.JoinNode.Type.FULL) PlanMatchPattern.join(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.join) JoinDistributionType(com.facebook.presto.sql.analyzer.FeaturesConfig.JoinDistributionType) ImmutableList(com.google.common.collect.ImmutableList) JOIN_MAX_BROADCAST_TABLE_SIZE(com.facebook.presto.SystemSessionProperties.JOIN_MAX_BROADCAST_TABLE_SIZE) PlanMatchPattern.equiJoinClause(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.equiJoinClause) PlanMatchPattern.enforceSingleRow(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.enforceSingleRow) RuleAssert(com.facebook.presto.sql.planner.iterative.rule.test.RuleAssert) TaskCountEstimator(com.facebook.presto.cost.TaskCountEstimator) DistributionType(com.facebook.presto.sql.planner.plan.JoinNode.DistributionType) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) AfterClass(org.testng.annotations.AfterClass) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) PlanNodeStatsEstimate(com.facebook.presto.cost.PlanNodeStatsEstimate) ImmutableMap(com.google.common.collect.ImmutableMap) BeforeClass(org.testng.annotations.BeforeClass) JOIN_DISTRIBUTION_TYPE(com.facebook.presto.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE) RIGHT(com.facebook.presto.sql.planner.plan.JoinNode.Type.RIGHT) PlanBuilder.constantExpressions(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder.constantExpressions) REPLICATED(com.facebook.presto.sql.planner.plan.JoinNode.DistributionType.REPLICATED) LEFT(com.facebook.presto.sql.planner.plan.JoinNode.Type.LEFT) CostComparator(com.facebook.presto.cost.CostComparator) Optional(java.util.Optional) PlanMatchPattern.values(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.values) PARTITIONED(com.facebook.presto.sql.planner.plan.JoinNode.DistributionType.PARTITIONED) VariableStatsEstimate(com.facebook.presto.cost.VariableStatsEstimate) RuleTester(com.facebook.presto.sql.planner.iterative.rule.test.RuleTester) INNER(com.facebook.presto.sql.planner.plan.JoinNode.Type.INNER) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) VariableStatsEstimate(com.facebook.presto.cost.VariableStatsEstimate) Test(org.testng.annotations.Test)

Example 4 with PARTITIONED

use of com.facebook.presto.sql.planner.plan.JoinNode.DistributionType.PARTITIONED in project presto by prestodb.

the class TestDetermineJoinDistributionType method testChoosesRightWhenFallsBackToSyntactic.

@Test
public void testChoosesRightWhenFallsBackToSyntactic() {
    int aRows = 1_000__00;
    int bRows = 1_0;
    assertDetermineJoinDistributionType(new CostComparator(75, 10, 15)).setSystemProperty(JOIN_DISTRIBUTION_TYPE, JoinDistributionType.AUTOMATIC.name()).setSystemProperty(JOIN_MAX_BROADCAST_TABLE_SIZE, "100MB").overrideStats("valuesA", PlanNodeStatsEstimate.builder().setOutputRowCount(aRows).addVariableStatistics(ImmutableMap.of(new VariableReferenceExpression(Optional.empty(), "A1", BIGINT), new VariableStatsEstimate(0, 100, 0, 640000, 100))).build()).overrideStats("valuesB", PlanNodeStatsEstimate.builder().setOutputRowCount(bRows).addVariableStatistics(ImmutableMap.of(new VariableReferenceExpression(Optional.empty(), "B1", BIGINT), new VariableStatsEstimate(0, 100, 0, 640000, 100))).build()).on(p -> p.join(RIGHT, p.values(new PlanNodeId("valuesA"), aRows, p.variable("A1", BIGINT)), p.values(new PlanNodeId("valuesB"), bRows, p.variable("B1", BIGINT)), ImmutableList.of(), ImmutableList.of(p.variable("A1", BIGINT), p.variable("B1", BIGINT)), Optional.empty())).matches(join(RIGHT, ImmutableList.of(), Optional.empty(), Optional.of(PARTITIONED), values(ImmutableMap.of("B1", 0)), values(ImmutableMap.of("A1", 0))));
}
Also used : CostComparator(com.facebook.presto.cost.CostComparator) Type(com.facebook.presto.sql.planner.plan.JoinNode.Type) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) PlanBuilder.castToRowExpression(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder.castToRowExpression) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) Test(org.testng.annotations.Test) FULL(com.facebook.presto.sql.planner.plan.JoinNode.Type.FULL) PlanMatchPattern.join(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.join) JoinDistributionType(com.facebook.presto.sql.analyzer.FeaturesConfig.JoinDistributionType) ImmutableList(com.google.common.collect.ImmutableList) JOIN_MAX_BROADCAST_TABLE_SIZE(com.facebook.presto.SystemSessionProperties.JOIN_MAX_BROADCAST_TABLE_SIZE) PlanMatchPattern.equiJoinClause(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.equiJoinClause) PlanMatchPattern.enforceSingleRow(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.enforceSingleRow) RuleAssert(com.facebook.presto.sql.planner.iterative.rule.test.RuleAssert) TaskCountEstimator(com.facebook.presto.cost.TaskCountEstimator) DistributionType(com.facebook.presto.sql.planner.plan.JoinNode.DistributionType) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) AfterClass(org.testng.annotations.AfterClass) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) PlanNodeStatsEstimate(com.facebook.presto.cost.PlanNodeStatsEstimate) ImmutableMap(com.google.common.collect.ImmutableMap) BeforeClass(org.testng.annotations.BeforeClass) JOIN_DISTRIBUTION_TYPE(com.facebook.presto.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE) RIGHT(com.facebook.presto.sql.planner.plan.JoinNode.Type.RIGHT) PlanBuilder.constantExpressions(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder.constantExpressions) REPLICATED(com.facebook.presto.sql.planner.plan.JoinNode.DistributionType.REPLICATED) LEFT(com.facebook.presto.sql.planner.plan.JoinNode.Type.LEFT) CostComparator(com.facebook.presto.cost.CostComparator) Optional(java.util.Optional) PlanMatchPattern.values(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.values) PARTITIONED(com.facebook.presto.sql.planner.plan.JoinNode.DistributionType.PARTITIONED) VariableStatsEstimate(com.facebook.presto.cost.VariableStatsEstimate) RuleTester(com.facebook.presto.sql.planner.iterative.rule.test.RuleTester) INNER(com.facebook.presto.sql.planner.plan.JoinNode.Type.INNER) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) VariableStatsEstimate(com.facebook.presto.cost.VariableStatsEstimate) Test(org.testng.annotations.Test)

Example 5 with PARTITIONED

use of com.facebook.presto.sql.planner.plan.JoinNode.DistributionType.PARTITIONED in project presto by prestodb.

the class TestDetermineJoinDistributionType method testReplicatesWhenNotRestricted.

@Test
public void testReplicatesWhenNotRestricted() {
    int aRows = 10_000;
    int bRows = 10;
    PlanNodeStatsEstimate probeSideStatsEstimate = PlanNodeStatsEstimate.builder().setOutputRowCount(aRows).addVariableStatistics(ImmutableMap.of(new VariableReferenceExpression(Optional.empty(), "A1", BIGINT), new VariableStatsEstimate(0, 100, 0, 640000, 10))).build();
    PlanNodeStatsEstimate buildSideStatsEstimate = PlanNodeStatsEstimate.builder().setOutputRowCount(bRows).addVariableStatistics(ImmutableMap.of(new VariableReferenceExpression(Optional.empty(), "B1", BIGINT), new VariableStatsEstimate(0, 100, 0, 640000, 10))).build();
    // B table is small enough to be replicated in AUTOMATIC_RESTRICTED mode
    assertDetermineJoinDistributionType().setSystemProperty(JOIN_DISTRIBUTION_TYPE, JoinDistributionType.AUTOMATIC.name()).setSystemProperty(JOIN_MAX_BROADCAST_TABLE_SIZE, "100MB").overrideStats("valuesA", probeSideStatsEstimate).overrideStats("valuesB", buildSideStatsEstimate).on(p -> p.join(INNER, p.values(new PlanNodeId("valuesA"), aRows, p.variable("A1", BIGINT)), p.values(new PlanNodeId("valuesB"), bRows, p.variable("B1", BIGINT)), ImmutableList.of(new JoinNode.EquiJoinClause(p.variable("A1", BIGINT), p.variable("B1", BIGINT))), ImmutableList.of(p.variable("A1", BIGINT), p.variable("B1", BIGINT)), Optional.empty())).matches(join(INNER, ImmutableList.of(equiJoinClause("A1", "B1")), Optional.empty(), Optional.of(REPLICATED), values(ImmutableMap.of("A1", 0)), values(ImmutableMap.of("B1", 0))));
    probeSideStatsEstimate = PlanNodeStatsEstimate.builder().setOutputRowCount(aRows).addVariableStatistics(ImmutableMap.of(new VariableReferenceExpression(Optional.empty(), "A1", BIGINT), new VariableStatsEstimate(0, 100, 0, 640000d * 10000, 10))).build();
    buildSideStatsEstimate = PlanNodeStatsEstimate.builder().setOutputRowCount(bRows).addVariableStatistics(ImmutableMap.of(new VariableReferenceExpression(Optional.empty(), "B1", BIGINT), new VariableStatsEstimate(0, 100, 0, 640000d * 10000, 10))).build();
    // B table exceeds AUTOMATIC_RESTRICTED limit therefore it is partitioned
    assertDetermineJoinDistributionType().setSystemProperty(JOIN_DISTRIBUTION_TYPE, JoinDistributionType.AUTOMATIC.name()).setSystemProperty(JOIN_MAX_BROADCAST_TABLE_SIZE, "100MB").overrideStats("valuesA", probeSideStatsEstimate).overrideStats("valuesB", buildSideStatsEstimate).on(p -> p.join(INNER, p.values(new PlanNodeId("valuesA"), aRows, p.variable("A1", BIGINT)), p.values(new PlanNodeId("valuesB"), bRows, p.variable("B1", BIGINT)), ImmutableList.of(new JoinNode.EquiJoinClause(p.variable("A1", BIGINT), p.variable("B1", BIGINT))), ImmutableList.of(p.variable("A1", BIGINT), p.variable("B1", BIGINT)), Optional.empty())).matches(join(INNER, ImmutableList.of(equiJoinClause("A1", "B1")), Optional.empty(), Optional.of(PARTITIONED), values(ImmutableMap.of("A1", 0)), values(ImmutableMap.of("B1", 0))));
}
Also used : Type(com.facebook.presto.sql.planner.plan.JoinNode.Type) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) PlanBuilder.castToRowExpression(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder.castToRowExpression) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) Test(org.testng.annotations.Test) FULL(com.facebook.presto.sql.planner.plan.JoinNode.Type.FULL) PlanMatchPattern.join(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.join) JoinDistributionType(com.facebook.presto.sql.analyzer.FeaturesConfig.JoinDistributionType) ImmutableList(com.google.common.collect.ImmutableList) JOIN_MAX_BROADCAST_TABLE_SIZE(com.facebook.presto.SystemSessionProperties.JOIN_MAX_BROADCAST_TABLE_SIZE) PlanMatchPattern.equiJoinClause(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.equiJoinClause) PlanMatchPattern.enforceSingleRow(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.enforceSingleRow) RuleAssert(com.facebook.presto.sql.planner.iterative.rule.test.RuleAssert) TaskCountEstimator(com.facebook.presto.cost.TaskCountEstimator) DistributionType(com.facebook.presto.sql.planner.plan.JoinNode.DistributionType) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) AfterClass(org.testng.annotations.AfterClass) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) PlanNodeStatsEstimate(com.facebook.presto.cost.PlanNodeStatsEstimate) ImmutableMap(com.google.common.collect.ImmutableMap) BeforeClass(org.testng.annotations.BeforeClass) JOIN_DISTRIBUTION_TYPE(com.facebook.presto.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE) RIGHT(com.facebook.presto.sql.planner.plan.JoinNode.Type.RIGHT) PlanBuilder.constantExpressions(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder.constantExpressions) REPLICATED(com.facebook.presto.sql.planner.plan.JoinNode.DistributionType.REPLICATED) LEFT(com.facebook.presto.sql.planner.plan.JoinNode.Type.LEFT) CostComparator(com.facebook.presto.cost.CostComparator) Optional(java.util.Optional) PlanMatchPattern.values(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.values) PARTITIONED(com.facebook.presto.sql.planner.plan.JoinNode.DistributionType.PARTITIONED) VariableStatsEstimate(com.facebook.presto.cost.VariableStatsEstimate) RuleTester(com.facebook.presto.sql.planner.iterative.rule.test.RuleTester) INNER(com.facebook.presto.sql.planner.plan.JoinNode.Type.INNER) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) PlanNodeStatsEstimate(com.facebook.presto.cost.PlanNodeStatsEstimate) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) VariableStatsEstimate(com.facebook.presto.cost.VariableStatsEstimate) Test(org.testng.annotations.Test)

Aggregations

PlanMatchPattern.equiJoinClause (com.facebook.presto.sql.planner.assertions.PlanMatchPattern.equiJoinClause)8 PlanMatchPattern.join (com.facebook.presto.sql.planner.assertions.PlanMatchPattern.join)8 PlanMatchPattern.values (com.facebook.presto.sql.planner.assertions.PlanMatchPattern.values)8 PARTITIONED (com.facebook.presto.sql.planner.plan.JoinNode.DistributionType.PARTITIONED)8 REPLICATED (com.facebook.presto.sql.planner.plan.JoinNode.DistributionType.REPLICATED)8 INNER (com.facebook.presto.sql.planner.plan.JoinNode.Type.INNER)8 ImmutableList (com.google.common.collect.ImmutableList)8 ImmutableMap (com.google.common.collect.ImmutableMap)8 Optional (java.util.Optional)8 Test (org.testng.annotations.Test)8 JOIN_DISTRIBUTION_TYPE (com.facebook.presto.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE)7 BIGINT (com.facebook.presto.common.type.BigintType.BIGINT)7 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)7 JoinDistributionType (com.facebook.presto.sql.analyzer.FeaturesConfig.JoinDistributionType)7 RuleTester (com.facebook.presto.sql.planner.iterative.rule.test.RuleTester)7 LEFT (com.facebook.presto.sql.planner.plan.JoinNode.Type.LEFT)7 JOIN_MAX_BROADCAST_TABLE_SIZE (com.facebook.presto.SystemSessionProperties.JOIN_MAX_BROADCAST_TABLE_SIZE)6 JoinNode (com.facebook.presto.sql.planner.plan.JoinNode)6 RIGHT (com.facebook.presto.sql.planner.plan.JoinNode.Type.RIGHT)6 CostComparator (com.facebook.presto.cost.CostComparator)5