Search in sources :

Example 1 with PlanMatchPattern

use of io.prestosql.sql.planner.assertions.PlanMatchPattern in project hetu-core by openlookeng.

the class TestEliminateSorts method testNotEliminateSorts.

@Test
public void testNotEliminateSorts() {
    @Language("SQL") String sql = "SELECT quantity, row_number() OVER (ORDER BY quantity) FROM lineitem ORDER BY tax";
    PlanMatchPattern pattern = anyTree(sort(anyTree(window(windowMatcherBuilder -> windowMatcherBuilder.specification(windowSpec).addFunction(functionCall("row_number", Optional.empty(), ImmutableList.of())), anyTree(LINEITEM_TABLESCAN_Q)))));
    assertUnitPlan(sql, pattern);
}
Also used : BasePlanTest(io.prestosql.sql.planner.assertions.BasePlanTest) PlanMatchPattern.tableScan(io.prestosql.sql.planner.assertions.PlanMatchPattern.tableScan) ImmutableSet(com.google.common.collect.ImmutableSet) RuleStatsRecorder(io.prestosql.sql.planner.RuleStatsRecorder) ImmutableMap(com.google.common.collect.ImmutableMap) Language(org.intellij.lang.annotations.Language) PlanMatchPattern.specification(io.prestosql.sql.planner.assertions.PlanMatchPattern.specification) PlanMatchPattern(io.prestosql.sql.planner.assertions.PlanMatchPattern) IterativeOptimizer(io.prestosql.sql.planner.iterative.IterativeOptimizer) Test(org.testng.annotations.Test) PlanMatchPattern.output(io.prestosql.sql.planner.assertions.PlanMatchPattern.output) SqlParser(io.prestosql.sql.parser.SqlParser) SortOrder(io.prestosql.spi.block.SortOrder) TypeAnalyzer(io.prestosql.sql.planner.TypeAnalyzer) RemoveRedundantIdentityProjections(io.prestosql.sql.planner.iterative.rule.RemoveRedundantIdentityProjections) PlanMatchPattern.sort(io.prestosql.sql.planner.assertions.PlanMatchPattern.sort) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) WindowNode(io.prestosql.spi.plan.WindowNode) PlanMatchPattern.functionCall(io.prestosql.sql.planner.assertions.PlanMatchPattern.functionCall) ExpectedValueProvider(io.prestosql.sql.planner.assertions.ExpectedValueProvider) Optional(java.util.Optional) PlanMatchPattern.window(io.prestosql.sql.planner.assertions.PlanMatchPattern.window) PlanMatchPattern.anyTree(io.prestosql.sql.planner.assertions.PlanMatchPattern.anyTree) Language(org.intellij.lang.annotations.Language) PlanMatchPattern(io.prestosql.sql.planner.assertions.PlanMatchPattern) BasePlanTest(io.prestosql.sql.planner.assertions.BasePlanTest) Test(org.testng.annotations.Test)

Example 2 with PlanMatchPattern

use of io.prestosql.sql.planner.assertions.PlanMatchPattern in project hetu-core by openlookeng.

the class TestMergeWindows method testMergeableWindowsAllOptimizers.

/**
 * There are two types of tests in here, and they answer two different
 * questions about MergeWindows (MW):
 * <p>
 * 1) Is MW working as it's supposed to be? The tests running the minimal
 * set of optimizers can tell us this.
 * 2) Has some other optimizer changed the plan in such a way that MW no
 * longer merges windows with identical specifications because the plan
 * that MW sees cannot be optimized by MW? The test running the full set
 * of optimizers answers this, though it isn't actually meaningful unless
 * we know the answer to question 1 is "yes".
 * <p>
 * The tests that use only the minimal set of optimizers are closer to true
 * "unit" tests in that they verify the behavior of MW with as few
 * external dependencies as possible. Those dependencies to include the
 * parser and analyzer, so the phrase "unit" tests should be taken with a
 * grain of salt. Using the parser and anayzler instead of creating plan
 * nodes by hand does have a couple of advantages over a true unit test:
 * 1) The tests are more self-maintaining.
 * 2) They're a lot easier to read.
 * 3) It's a lot less typing.
 * <p>
 * The test that runs with all of the optimzers acts as an integration test
 * and ensures that MW is effective when run with the complete set of
 * optimizers.
 */
@Test
public void testMergeableWindowsAllOptimizers() {
    @Language("SQL") String sql = "SELECT " + "SUM(quantity) OVER (PARTITION BY suppkey ORDER BY orderkey ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) sum_quantity_A, " + "SUM(quantity) OVER (PARTITION BY orderkey ORDER BY shipdate ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) sum_quantity_B, " + "SUM(discount) OVER (PARTITION BY suppkey ORDER BY orderkey ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) sum_discount_A " + "FROM lineitem";
    PlanMatchPattern pattern = anyTree(window(windowMatcherBuilder -> windowMatcherBuilder.specification(specificationA).addFunction(functionCall("sum", COMMON_FRAME, ImmutableList.of(QUANTITY_ALIAS))).addFunction(functionCall("sum", COMMON_FRAME, ImmutableList.of(DISCOUNT_ALIAS))), anyTree(window(windowMatcherBuilder -> windowMatcherBuilder.specification(specificationB).addFunction(functionCall("sum", COMMON_FRAME, ImmutableList.of(QUANTITY_ALIAS))), anyNot(WindowNode.class, // should be anyTree(LINEITEM_TABLESCAN_DOQSS) but anyTree does not handle zero nodes case correctly
    LINEITEM_TABLESCAN_DOQSS)))));
    assertPlan(sql, pattern);
}
Also used : PlanMatchPattern.project(io.prestosql.sql.planner.assertions.PlanMatchPattern.project) PlanMatchPattern.tableScan(io.prestosql.sql.planner.assertions.PlanMatchPattern.tableScan) PlanMatchPattern.specification(io.prestosql.sql.planner.assertions.PlanMatchPattern.specification) Test(org.testng.annotations.Test) SortOrder(io.prestosql.spi.block.SortOrder) RemoveRedundantIdentityProjections(io.prestosql.sql.planner.iterative.rule.RemoveRedundantIdentityProjections) ImmutableList(com.google.common.collect.ImmutableList) WindowFrame(io.prestosql.sql.tree.WindowFrame) PlanMatchPattern.functionCall(io.prestosql.sql.planner.assertions.PlanMatchPattern.functionCall) Map(java.util.Map) ExpectedValueProvider(io.prestosql.sql.planner.assertions.ExpectedValueProvider) FrameBoundType(io.prestosql.spi.sql.expression.Types.FrameBoundType) PlanMatchPattern.filter(io.prestosql.sql.planner.assertions.PlanMatchPattern.filter) PlanMatchPattern.expression(io.prestosql.sql.planner.assertions.PlanMatchPattern.expression) PlanMatchPattern.window(io.prestosql.sql.planner.assertions.PlanMatchPattern.window) JoinNode(io.prestosql.spi.plan.JoinNode) PlanMatchPattern.anyTree(io.prestosql.sql.planner.assertions.PlanMatchPattern.anyTree) BasePlanTest(io.prestosql.sql.planner.assertions.BasePlanTest) TranslateExpressions(io.prestosql.sql.planner.iterative.rule.TranslateExpressions) ImmutableSet(com.google.common.collect.ImmutableSet) PlanMatchPattern.join(io.prestosql.sql.planner.assertions.PlanMatchPattern.join) WindowFrameType(io.prestosql.spi.sql.expression.Types.WindowFrameType) RuleStatsRecorder(io.prestosql.sql.planner.RuleStatsRecorder) ImmutableMap(com.google.common.collect.ImmutableMap) Rule(io.prestosql.sql.planner.iterative.Rule) Language(org.intellij.lang.annotations.Language) PlanMatchPattern(io.prestosql.sql.planner.assertions.PlanMatchPattern) IterativeOptimizer(io.prestosql.sql.planner.iterative.IterativeOptimizer) GatherAndMergeWindows(io.prestosql.sql.planner.iterative.rule.GatherAndMergeWindows) PlanMatchPattern.anyNot(io.prestosql.sql.planner.assertions.PlanMatchPattern.anyNot) List(java.util.List) WindowNode(io.prestosql.spi.plan.WindowNode) Optional(java.util.Optional) PlanMatchPattern.any(io.prestosql.sql.planner.assertions.PlanMatchPattern.any) FrameBound(io.prestosql.sql.tree.FrameBound) Language(org.intellij.lang.annotations.Language) PlanMatchPattern(io.prestosql.sql.planner.assertions.PlanMatchPattern) Test(org.testng.annotations.Test) BasePlanTest(io.prestosql.sql.planner.assertions.BasePlanTest)

Example 3 with PlanMatchPattern

use of io.prestosql.sql.planner.assertions.PlanMatchPattern in project hetu-core by openlookeng.

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, 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() == REMOTE), 1);
    Consumer<Plan> validateSingleStreamingAggregation = plan -> assertEquals(countOfMatchingNodes(plan, node -> node instanceof AggregationNode && ((AggregationNode) node).getGroupingKeys().contains(new Symbol("unique")) && ((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 : REPLICATED(io.prestosql.spi.plan.JoinNode.DistributionType.REPLICATED) SortNode(io.prestosql.sql.planner.plan.SortNode) JoinDistributionType(io.prestosql.sql.analyzer.FeaturesConfig.JoinDistributionType) OPTIMIZE_HASH_GENERATION(io.prestosql.SystemSessionProperties.OPTIMIZE_HASH_GENERATION) PlanMatchPattern.markDistinct(io.prestosql.sql.planner.assertions.PlanMatchPattern.markDistinct) ValueSet(io.prestosql.spi.predicate.ValueSet) Test(org.testng.annotations.Test) PlanMatchPattern.singleGroupingSet(io.prestosql.sql.planner.assertions.PlanMatchPattern.singleGroupingSet) AggregationNode(io.prestosql.spi.plan.AggregationNode) JOIN_REORDERING_STRATEGY(io.prestosql.SystemSessionProperties.JOIN_REORDERING_STRATEGY) PlanMatchPattern.values(io.prestosql.sql.planner.assertions.PlanMatchPattern.values) Slices(io.airlift.slice.Slices) Map(java.util.Map) Domain.singleValue(io.prestosql.spi.predicate.Domain.singleValue) PlanMatchPattern.node(io.prestosql.sql.planner.assertions.PlanMatchPattern.node) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) PlanMatchPattern.strictTableScan(io.prestosql.sql.planner.assertions.PlanMatchPattern.strictTableScan) PlanMatchPattern.expression(io.prestosql.sql.planner.assertions.PlanMatchPattern.expression) Assert.assertFalse(org.testng.Assert.assertFalse) PlanMatchPattern.join(io.prestosql.sql.planner.assertions.PlanMatchPattern.join) PlanMatchPattern.strictProject(io.prestosql.sql.planner.assertions.PlanMatchPattern.strictProject) PlanMatchPattern(io.prestosql.sql.planner.assertions.PlanMatchPattern) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) TableScanNode(io.prestosql.spi.plan.TableScanNode) PlanNode(io.prestosql.spi.plan.PlanNode) ProjectNode(io.prestosql.spi.plan.ProjectNode) VarcharType.createVarcharType(io.prestosql.spi.type.VarcharType.createVarcharType) MorePredicates(io.prestosql.util.MorePredicates) CheckSubqueryNodesAreRewritten(io.prestosql.sql.planner.optimizations.CheckSubqueryNodesAreRewritten) LongLiteral(io.prestosql.sql.tree.LongLiteral) QueryTemplate(io.prestosql.tests.QueryTemplate) LOCAL(io.prestosql.sql.planner.plan.ExchangeNode.Scope.LOCAL) Domain(io.prestosql.spi.predicate.Domain) INNER(io.prestosql.spi.plan.JoinNode.Type.INNER) StatisticsWriterNode(io.prestosql.sql.planner.plan.StatisticsWriterNode) DistinctLimitNode(io.prestosql.sql.planner.plan.DistinctLimitNode) OPTIMIZED(io.prestosql.sql.planner.LogicalPlanner.Stage.OPTIMIZED) JOIN_DISTRIBUTION_TYPE(io.prestosql.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE) QueryTemplate.queryTemplate(io.prestosql.tests.QueryTemplate.queryTemplate) PlanMatchPattern.equiJoinClause(io.prestosql.sql.planner.assertions.PlanMatchPattern.equiJoinClause) PlanMatchPattern.assignUniqueId(io.prestosql.sql.planner.assertions.PlanMatchPattern.assignUniqueId) REMOTE(io.prestosql.sql.planner.plan.ExchangeNode.Scope.REMOTE) GATHER(io.prestosql.sql.planner.plan.ExchangeNode.Type.GATHER) SINGLE(io.prestosql.spi.plan.AggregationNode.Step.SINGLE) REPARTITION(io.prestosql.sql.planner.plan.ExchangeNode.Type.REPARTITION) Session(io.prestosql.Session) PlanMatchPattern.anyTree(io.prestosql.sql.planner.assertions.PlanMatchPattern.anyTree) MoreCollectors.toOptional(com.google.common.collect.MoreCollectors.toOptional) PlanMatchPattern.output(io.prestosql.sql.planner.assertions.PlanMatchPattern.output) ExpressionMatcher(io.prestosql.sql.planner.assertions.ExpressionMatcher) PlanMatchPattern.anyNot(io.prestosql.sql.planner.assertions.PlanMatchPattern.anyNot) ValuesNode(io.prestosql.spi.plan.ValuesNode) DESCENDING(io.prestosql.sql.tree.SortItem.Ordering.DESCENDING) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) LimitNode(io.prestosql.spi.plan.LimitNode) PlanOptimizer(io.prestosql.sql.planner.optimizations.PlanOptimizer) PlanMatchPattern.any(io.prestosql.sql.planner.assertions.PlanMatchPattern.any) PlanMatchPattern.aggregation(io.prestosql.sql.planner.assertions.PlanMatchPattern.aggregation) PlanMatchPattern.project(io.prestosql.sql.planner.assertions.PlanMatchPattern.project) PlanMatchPattern.tableScan(io.prestosql.sql.planner.assertions.PlanMatchPattern.tableScan) TpchColumnHandle(io.prestosql.plugin.tpch.TpchColumnHandle) PlanMatchPattern.semiJoin(io.prestosql.sql.planner.assertions.PlanMatchPattern.semiJoin) RowNumberSymbolMatcher(io.prestosql.sql.planner.assertions.RowNumberSymbolMatcher) ExchangeNode(io.prestosql.sql.planner.plan.ExchangeNode) FilterNode(io.prestosql.spi.plan.FilterNode) JoinReorderingStrategy(io.prestosql.sql.analyzer.FeaturesConfig.JoinReorderingStrategy) FORCE_SINGLE_NODE_OUTPUT(io.prestosql.SystemSessionProperties.FORCE_SINGLE_NODE_OUTPUT) ASC_NULLS_LAST(io.prestosql.spi.block.SortOrder.ASC_NULLS_LAST) ApplyNode(io.prestosql.sql.planner.plan.ApplyNode) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) FINAL(io.prestosql.spi.plan.AggregationNode.Step.FINAL) IndexJoinNode(io.prestosql.sql.planner.plan.IndexJoinNode) FILTERING_SEMI_JOIN_TO_INNER(io.prestosql.SystemSessionProperties.FILTERING_SEMI_JOIN_TO_INNER) String.format(java.lang.String.format) PlanMatchPattern.sort(io.prestosql.sql.planner.assertions.PlanMatchPattern.sort) List(java.util.List) EnforceSingleRowNode(io.prestosql.sql.planner.plan.EnforceSingleRowNode) MorePredicates.isInstanceOfAny(io.prestosql.util.MorePredicates.isInstanceOfAny) TopNNode(io.prestosql.spi.plan.TopNNode) Entry(java.util.Map.Entry) Optional(java.util.Optional) PlanMatchPattern.topNRankingNumber(io.prestosql.sql.planner.assertions.PlanMatchPattern.topNRankingNumber) PlanMatchPattern.topN(io.prestosql.sql.planner.assertions.PlanMatchPattern.topN) PlanMatchPattern.constrainedTableScan(io.prestosql.sql.planner.assertions.PlanMatchPattern.constrainedTableScan) LAST(io.prestosql.sql.tree.SortItem.NullOrdering.LAST) TpchTableHandle(io.prestosql.plugin.tpch.TpchTableHandle) LateralJoinNode(io.prestosql.sql.planner.plan.LateralJoinNode) PlanMatchPattern.apply(io.prestosql.sql.planner.assertions.PlanMatchPattern.apply) Assert.assertEquals(org.testng.Assert.assertEquals) PARTITIONED(io.prestosql.spi.plan.JoinNode.DistributionType.PARTITIONED) PARTIAL(io.prestosql.spi.plan.AggregationNode.Step.PARTIAL) SemiJoinNode(io.prestosql.sql.planner.plan.SemiJoinNode) SUBQUERY_MULTIPLE_ROWS(io.prestosql.spi.StandardErrorCode.SUBQUERY_MULTIPLE_ROWS) ImmutableList(com.google.common.collect.ImmutableList) Range(io.prestosql.spi.predicate.Range) PlanMatchPattern.functionCall(io.prestosql.sql.planner.assertions.PlanMatchPattern.functionCall) PlanMatchPattern.filter(io.prestosql.sql.planner.assertions.PlanMatchPattern.filter) PlanMatchPattern.exchange(io.prestosql.sql.planner.assertions.PlanMatchPattern.exchange) REPLICATE(io.prestosql.sql.planner.plan.ExchangeNode.Type.REPLICATE) JoinNode(io.prestosql.spi.plan.JoinNode) Symbol(io.prestosql.spi.plan.Symbol) BasePlanTest(io.prestosql.sql.planner.assertions.BasePlanTest) ASCENDING(io.prestosql.sql.tree.SortItem.Ordering.ASCENDING) DISTRIBUTED_SORT(io.prestosql.SystemSessionProperties.DISTRIBUTED_SORT) TupleDomain(io.prestosql.spi.predicate.TupleDomain) PlanMatchPattern.limit(io.prestosql.sql.planner.assertions.PlanMatchPattern.limit) Consumer(java.util.function.Consumer) PlanNodeSearcher.searchFrom(io.prestosql.sql.planner.optimizations.PlanNodeSearcher.searchFrom) PlanMatchPattern.rowNumber(io.prestosql.sql.planner.assertions.PlanMatchPattern.rowNumber) AddLocalExchanges(io.prestosql.sql.planner.optimizations.AddLocalExchanges) LEFT(io.prestosql.spi.plan.JoinNode.Type.LEFT) PlanMatchPattern.constrainedTableScanWithTableLayout(io.prestosql.sql.planner.assertions.PlanMatchPattern.constrainedTableScanWithTableLayout) TableScanNode(io.prestosql.spi.plan.TableScanNode) ExchangeNode(io.prestosql.sql.planner.plan.ExchangeNode) IndexJoinNode(io.prestosql.sql.planner.plan.IndexJoinNode) LateralJoinNode(io.prestosql.sql.planner.plan.LateralJoinNode) SemiJoinNode(io.prestosql.sql.planner.plan.SemiJoinNode) JoinNode(io.prestosql.spi.plan.JoinNode) Symbol(io.prestosql.spi.plan.Symbol) PlanMatchPattern(io.prestosql.sql.planner.assertions.PlanMatchPattern) AggregationNode(io.prestosql.spi.plan.AggregationNode) Session(io.prestosql.Session) Test(org.testng.annotations.Test) BasePlanTest(io.prestosql.sql.planner.assertions.BasePlanTest)

Example 4 with PlanMatchPattern

use of io.prestosql.sql.planner.assertions.PlanMatchPattern in project hetu-core by openlookeng.

the class TestPredicatePushdown method testPredicateOnPartitionSymbolsPushedThroughWindow.

@Test
public void testPredicateOnPartitionSymbolsPushedThroughWindow() {
    PlanMatchPattern tableScan = tableScan("orders", ImmutableMap.of("CUST_KEY", "custkey", "ORDER_KEY", "orderkey"));
    assertPlan("SELECT * FROM (" + "SELECT custkey, orderkey, rank() OVER (PARTITION BY custkey  ORDER BY orderdate ASC)" + "FROM orders" + ") WHERE custkey = 0 AND orderkey > 0", anyTree(filter("ORDER_KEY > BIGINT '0'", anyTree(node(WindowNode.class, anyTree(filter("CUST_KEY = BIGINT '0'", tableScan)))))));
}
Also used : PlanMatchPattern(io.prestosql.sql.planner.assertions.PlanMatchPattern) Test(org.testng.annotations.Test) BasePlanTest(io.prestosql.sql.planner.assertions.BasePlanTest)

Example 5 with PlanMatchPattern

use of io.prestosql.sql.planner.assertions.PlanMatchPattern in project hetu-core by openlookeng.

the class TestMergeWindows method testNotMergeAcrossJoinBranches.

@Test
public void testNotMergeAcrossJoinBranches() {
    String rOrderkeyAlias = "R_ORDERKEY";
    String rShipdateAlias = "R_SHIPDATE";
    String rQuantityAlias = "R_QUANTITY";
    @Language("SQL") String sql = "WITH foo AS (" + "SELECT " + "suppkey, orderkey, partkey, " + "SUM(discount) OVER (PARTITION BY orderkey ORDER BY shipdate, quantity DESC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) a " + "FROM lineitem WHERE (partkey = 272 OR partkey = 273) AND suppkey > 50 " + "), " + "bar AS ( " + "SELECT " + "suppkey, orderkey, partkey, " + "AVG(quantity) OVER (PARTITION BY orderkey ORDER BY shipdate, quantity DESC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) b " + "FROM lineitem WHERE (partkey = 272 OR partkey = 273) AND suppkey > 50 " + ")" + "SELECT * FROM foo, bar WHERE foo.a = bar.b";
    ExpectedValueProvider<WindowNode.Specification> leftSpecification = specification(ImmutableList.of(ORDERKEY_ALIAS), ImmutableList.of(SHIPDATE_ALIAS, QUANTITY_ALIAS), ImmutableMap.of(SHIPDATE_ALIAS, SortOrder.ASC_NULLS_LAST, QUANTITY_ALIAS, SortOrder.DESC_NULLS_LAST));
    ExpectedValueProvider<WindowNode.Specification> rightSpecification = specification(ImmutableList.of(rOrderkeyAlias), ImmutableList.of(rShipdateAlias, rQuantityAlias), ImmutableMap.of(rShipdateAlias, SortOrder.ASC_NULLS_LAST, rQuantityAlias, SortOrder.DESC_NULLS_LAST));
    // Too many items in the map to call ImmutableMap.of() :-(
    ImmutableMap.Builder<String, String> leftTableScanBuilder = ImmutableMap.builder();
    leftTableScanBuilder.put(DISCOUNT_ALIAS, "discount");
    leftTableScanBuilder.put(ORDERKEY_ALIAS, "orderkey");
    leftTableScanBuilder.put("PARTKEY", "partkey");
    leftTableScanBuilder.put(SUPPKEY_ALIAS, "suppkey");
    leftTableScanBuilder.put(QUANTITY_ALIAS, "quantity");
    leftTableScanBuilder.put(SHIPDATE_ALIAS, "shipdate");
    PlanMatchPattern leftTableScan = tableScan("lineitem", leftTableScanBuilder.build());
    PlanMatchPattern rightTableScan = tableScan("lineitem", ImmutableMap.of(rOrderkeyAlias, "orderkey", "R_PARTKEY", "partkey", "R_SUPPKEY", "suppkey", rQuantityAlias, "quantity", rShipdateAlias, "shipdate"));
    assertUnitPlan(sql, anyTree(filter("SUM = AVG", join(JoinNode.Type.INNER, ImmutableList.of(), any(window(windowMatcherBuilder -> windowMatcherBuilder.specification(leftSpecification).addFunction("SUM", functionCall("sum", COMMON_FRAME, ImmutableList.of(DISCOUNT_ALIAS))), any(leftTableScan))), any(window(windowMatcherBuilder -> windowMatcherBuilder.specification(rightSpecification).addFunction("AVG", functionCall("avg", COMMON_FRAME, ImmutableList.of(rQuantityAlias))), any(rightTableScan)))))));
}
Also used : PlanMatchPattern.project(io.prestosql.sql.planner.assertions.PlanMatchPattern.project) PlanMatchPattern.tableScan(io.prestosql.sql.planner.assertions.PlanMatchPattern.tableScan) PlanMatchPattern.specification(io.prestosql.sql.planner.assertions.PlanMatchPattern.specification) Test(org.testng.annotations.Test) SortOrder(io.prestosql.spi.block.SortOrder) RemoveRedundantIdentityProjections(io.prestosql.sql.planner.iterative.rule.RemoveRedundantIdentityProjections) ImmutableList(com.google.common.collect.ImmutableList) WindowFrame(io.prestosql.sql.tree.WindowFrame) PlanMatchPattern.functionCall(io.prestosql.sql.planner.assertions.PlanMatchPattern.functionCall) Map(java.util.Map) ExpectedValueProvider(io.prestosql.sql.planner.assertions.ExpectedValueProvider) FrameBoundType(io.prestosql.spi.sql.expression.Types.FrameBoundType) PlanMatchPattern.filter(io.prestosql.sql.planner.assertions.PlanMatchPattern.filter) PlanMatchPattern.expression(io.prestosql.sql.planner.assertions.PlanMatchPattern.expression) PlanMatchPattern.window(io.prestosql.sql.planner.assertions.PlanMatchPattern.window) JoinNode(io.prestosql.spi.plan.JoinNode) PlanMatchPattern.anyTree(io.prestosql.sql.planner.assertions.PlanMatchPattern.anyTree) BasePlanTest(io.prestosql.sql.planner.assertions.BasePlanTest) TranslateExpressions(io.prestosql.sql.planner.iterative.rule.TranslateExpressions) ImmutableSet(com.google.common.collect.ImmutableSet) PlanMatchPattern.join(io.prestosql.sql.planner.assertions.PlanMatchPattern.join) WindowFrameType(io.prestosql.spi.sql.expression.Types.WindowFrameType) RuleStatsRecorder(io.prestosql.sql.planner.RuleStatsRecorder) ImmutableMap(com.google.common.collect.ImmutableMap) Rule(io.prestosql.sql.planner.iterative.Rule) Language(org.intellij.lang.annotations.Language) PlanMatchPattern(io.prestosql.sql.planner.assertions.PlanMatchPattern) IterativeOptimizer(io.prestosql.sql.planner.iterative.IterativeOptimizer) GatherAndMergeWindows(io.prestosql.sql.planner.iterative.rule.GatherAndMergeWindows) PlanMatchPattern.anyNot(io.prestosql.sql.planner.assertions.PlanMatchPattern.anyNot) List(java.util.List) WindowNode(io.prestosql.spi.plan.WindowNode) Optional(java.util.Optional) PlanMatchPattern.any(io.prestosql.sql.planner.assertions.PlanMatchPattern.any) FrameBound(io.prestosql.sql.tree.FrameBound) Language(org.intellij.lang.annotations.Language) PlanMatchPattern(io.prestosql.sql.planner.assertions.PlanMatchPattern) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.testng.annotations.Test) BasePlanTest(io.prestosql.sql.planner.assertions.BasePlanTest)

Aggregations

PlanMatchPattern (io.prestosql.sql.planner.assertions.PlanMatchPattern)10 Test (org.testng.annotations.Test)9 ImmutableList (com.google.common.collect.ImmutableList)8 BasePlanTest (io.prestosql.sql.planner.assertions.BasePlanTest)8 List (java.util.List)8 Optional (java.util.Optional)8 ImmutableMap (com.google.common.collect.ImmutableMap)7 ExpectedValueProvider (io.prestosql.sql.planner.assertions.ExpectedValueProvider)6 PlanMatchPattern.anyTree (io.prestosql.sql.planner.assertions.PlanMatchPattern.anyTree)6 PlanMatchPattern.functionCall (io.prestosql.sql.planner.assertions.PlanMatchPattern.functionCall)6 PlanMatchPattern.tableScan (io.prestosql.sql.planner.assertions.PlanMatchPattern.tableScan)6 Language (org.intellij.lang.annotations.Language)6 ImmutableSet (com.google.common.collect.ImmutableSet)5 SortOrder (io.prestosql.spi.block.SortOrder)5 WindowNode (io.prestosql.spi.plan.WindowNode)5 RuleStatsRecorder (io.prestosql.sql.planner.RuleStatsRecorder)5 PlanMatchPattern.specification (io.prestosql.sql.planner.assertions.PlanMatchPattern.specification)5 PlanMatchPattern.window (io.prestosql.sql.planner.assertions.PlanMatchPattern.window)5 IterativeOptimizer (io.prestosql.sql.planner.iterative.IterativeOptimizer)5 RemoveRedundantIdentityProjections (io.prestosql.sql.planner.iterative.rule.RemoveRedundantIdentityProjections)5