Search in sources :

Example 1 with ASC_NULLS_LAST

use of io.prestosql.spi.block.SortOrder.ASC_NULLS_LAST in project hetu-core by openlookeng.

the class TestLogicalPlanner method testWithTies.

@Test
public void testWithTies() {
    assertPlan("SELECT name, regionkey FROM nation ORDER BY regionkey FETCH FIRST 6 ROWS WITH TIES", any(strictProject(ImmutableMap.of("name", new ExpressionMatcher("name"), "regionkey", new ExpressionMatcher("regionkey")), topNRankingNumber(pattern -> pattern.specification(ImmutableList.of(), ImmutableList.of("regionkey"), ImmutableMap.of("regionkey", ASC_NULLS_LAST)), anyTree(sort(ImmutableList.of(sort("regionkey", ASCENDING, LAST)), any(tableScan("nation", ImmutableMap.of("NAME", "name", "REGIONKEY", "regionkey")))))))));
    assertPlan("SELECT name, regionkey FROM nation ORDER BY regionkey OFFSET 10 ROWS FETCH FIRST 6 ROWS WITH TIES", any(strictProject(ImmutableMap.of("name", new ExpressionMatcher("name"), "regionkey", new ExpressionMatcher("regionkey")), filter("row_num > BIGINT '10'", rowNumber(pattern -> pattern.partitionBy(ImmutableList.of()), strictProject(ImmutableMap.of("name", new ExpressionMatcher("name"), "regionkey", new ExpressionMatcher("regionkey")), topNRankingNumber(pattern -> pattern.specification(ImmutableList.of(), ImmutableList.of("regionkey"), ImmutableMap.of("regionkey", ASC_NULLS_LAST)), anyTree(sort(ImmutableList.of(sort("regionkey", ASCENDING, LAST)), any(tableScan("nation", ImmutableMap.of("NAME", "name", "REGIONKEY", "regionkey")))))))).withAlias("row_num", new RowNumberSymbolMatcher())))));
}
Also used : ExpressionMatcher(io.prestosql.sql.planner.assertions.ExpressionMatcher) 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) RowNumberSymbolMatcher(io.prestosql.sql.planner.assertions.RowNumberSymbolMatcher) Test(org.testng.annotations.Test) BasePlanTest(io.prestosql.sql.planner.assertions.BasePlanTest)

Example 2 with ASC_NULLS_LAST

use of io.prestosql.spi.block.SortOrder.ASC_NULLS_LAST in project hetu-core by openlookeng.

the class TestWindow method testWindow.

@Test
public void testWindow() {
    // Window partition key is pre-bucketed.
    assertDistributedPlan("SELECT rank() OVER (PARTITION BY orderkey) FROM orders", anyTree(window(pattern -> pattern.specification(specification(ImmutableList.of("orderkey"), ImmutableList.of(), ImmutableMap.of())).addFunction(functionCall("rank", Optional.empty(), ImmutableList.of())), project(tableScan("orders", ImmutableMap.of("orderkey", "orderkey"))))));
    assertDistributedPlan("SELECT row_number() OVER (PARTITION BY orderkey) FROM orders", anyTree(rowNumber(pattern -> pattern.partitionBy(ImmutableList.of("orderkey")), project(tableScan("orders", ImmutableMap.of("orderkey", "orderkey"))))));
    // Window partition key is not pre-bucketed.
    assertDistributedPlan("SELECT rank() OVER (PARTITION BY orderstatus) FROM orders", anyTree(window(pattern -> pattern.specification(specification(ImmutableList.of("orderstatus"), ImmutableList.of(), ImmutableMap.of())).addFunction(functionCall("rank", Optional.empty(), ImmutableList.of())), exchange(LOCAL, GATHER, exchange(REMOTE, REPARTITION, project(tableScan("orders", ImmutableMap.of("orderstatus", "orderstatus"))))))));
    assertDistributedPlan("SELECT row_number() OVER (PARTITION BY orderstatus) FROM orders", anyTree(rowNumber(pattern -> pattern.partitionBy(ImmutableList.of("orderstatus")), exchange(LOCAL, GATHER, exchange(REMOTE, REPARTITION, project(tableScan("orders", ImmutableMap.of("orderstatus", "orderstatus"))))))));
    // Window to TopN RankingFunction
    for (RankingFunction rankingFunction : RankingFunction.values()) {
        assertDistributedPlan(format("SELECT orderkey FROM (SELECT orderkey, %s() OVER (PARTITION BY orderkey ORDER BY custkey) n FROM orders) WHERE n = 1", rankingFunction.getName().getObjectName()), anyTree(topNRankingNumber(pattern -> pattern.specification(ImmutableList.of("orderkey"), ImmutableList.of("custkey"), ImmutableMap.of("custkey", ASC_NULLS_LAST)), project(tableScan("orders", ImmutableMap.of("orderkey", "orderkey", "custkey", "custkey"))))));
        assertDistributedPlan(format("SELECT orderstatus FROM (SELECT orderstatus, %s() OVER (PARTITION BY orderstatus ORDER BY custkey) n FROM orders) WHERE n = 1", rankingFunction.getName().getObjectName()), anyTree(topNRankingNumber(pattern -> pattern.specification(ImmutableList.of("orderstatus"), ImmutableList.of("custkey"), ImmutableMap.of("custkey", ASC_NULLS_LAST)).partial(false), exchange(LOCAL, GATHER, exchange(REMOTE, REPARTITION, topNRankingNumber(topNRowNumber -> topNRowNumber.specification(ImmutableList.of("orderstatus"), ImmutableList.of("custkey"), ImmutableMap.of("custkey", ASC_NULLS_LAST)).partial(true), project(tableScan("orders", ImmutableMap.of("orderstatus", "orderstatus", "custkey", "custkey")))))))));
    }
}
Also used : PlanMatchPattern.project(io.prestosql.sql.planner.assertions.PlanMatchPattern.project) PlanMatchPattern.tableScan(io.prestosql.sql.planner.assertions.PlanMatchPattern.tableScan) REPLICATED(io.prestosql.spi.plan.JoinNode.DistributionType.REPLICATED) PlanMatchPattern.equiJoinClause(io.prestosql.sql.planner.assertions.PlanMatchPattern.equiJoinClause) PlanMatchPattern.specification(io.prestosql.sql.planner.assertions.PlanMatchPattern.specification) JoinDistributionType(io.prestosql.sql.analyzer.FeaturesConfig.JoinDistributionType) Test(org.testng.annotations.Test) PARTITIONED(io.prestosql.spi.plan.JoinNode.DistributionType.PARTITIONED) PlanMatchPattern.singleGroupingSet(io.prestosql.sql.planner.assertions.PlanMatchPattern.singleGroupingSet) JOIN_REORDERING_STRATEGY(io.prestosql.SystemSessionProperties.JOIN_REORDERING_STRATEGY) REMOTE(io.prestosql.sql.planner.plan.ExchangeNode.Scope.REMOTE) GATHER(io.prestosql.sql.planner.plan.ExchangeNode.Type.GATHER) ImmutableList(com.google.common.collect.ImmutableList) PlanMatchPattern.functionCall(io.prestosql.sql.planner.assertions.PlanMatchPattern.functionCall) JoinReorderingStrategy(io.prestosql.sql.analyzer.FeaturesConfig.JoinReorderingStrategy) REPARTITION(io.prestosql.sql.planner.plan.ExchangeNode.Type.REPARTITION) Session(io.prestosql.Session) FORCE_SINGLE_NODE_OUTPUT(io.prestosql.SystemSessionProperties.FORCE_SINGLE_NODE_OUTPUT) PlanMatchPattern.exchange(io.prestosql.sql.planner.assertions.PlanMatchPattern.exchange) REPLICATE(io.prestosql.sql.planner.plan.ExchangeNode.Type.REPLICATE) PlanMatchPattern.window(io.prestosql.sql.planner.assertions.PlanMatchPattern.window) PlanMatchPattern.anyTree(io.prestosql.sql.planner.assertions.PlanMatchPattern.anyTree) ASC_NULLS_LAST(io.prestosql.spi.block.SortOrder.ASC_NULLS_LAST) BasePlanTest(io.prestosql.sql.planner.assertions.BasePlanTest) PlanMatchPattern.join(io.prestosql.sql.planner.assertions.PlanMatchPattern.join) ImmutableMap(com.google.common.collect.ImmutableMap) FINAL(io.prestosql.spi.plan.AggregationNode.Step.FINAL) String.format(java.lang.String.format) PlanMatchPattern.rowNumber(io.prestosql.sql.planner.assertions.PlanMatchPattern.rowNumber) LOCAL(io.prestosql.sql.planner.plan.ExchangeNode.Scope.LOCAL) INNER(io.prestosql.spi.plan.JoinNode.Type.INNER) RankingFunction(io.prestosql.operator.window.RankingFunction) Optional(java.util.Optional) PlanMatchPattern.topNRankingNumber(io.prestosql.sql.planner.assertions.PlanMatchPattern.topNRankingNumber) PlanMatchPattern.aggregation(io.prestosql.sql.planner.assertions.PlanMatchPattern.aggregation) JOIN_DISTRIBUTION_TYPE(io.prestosql.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE) RankingFunction(io.prestosql.operator.window.RankingFunction) Test(org.testng.annotations.Test) BasePlanTest(io.prestosql.sql.planner.assertions.BasePlanTest)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Session (io.prestosql.Session)2 FORCE_SINGLE_NODE_OUTPUT (io.prestosql.SystemSessionProperties.FORCE_SINGLE_NODE_OUTPUT)2 JOIN_DISTRIBUTION_TYPE (io.prestosql.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE)2 JOIN_REORDERING_STRATEGY (io.prestosql.SystemSessionProperties.JOIN_REORDERING_STRATEGY)2 ASC_NULLS_LAST (io.prestosql.spi.block.SortOrder.ASC_NULLS_LAST)2 FINAL (io.prestosql.spi.plan.AggregationNode.Step.FINAL)2 PARTITIONED (io.prestosql.spi.plan.JoinNode.DistributionType.PARTITIONED)2 REPLICATED (io.prestosql.spi.plan.JoinNode.DistributionType.REPLICATED)2 INNER (io.prestosql.spi.plan.JoinNode.Type.INNER)2 JoinDistributionType (io.prestosql.sql.analyzer.FeaturesConfig.JoinDistributionType)2 JoinReorderingStrategy (io.prestosql.sql.analyzer.FeaturesConfig.JoinReorderingStrategy)2 BasePlanTest (io.prestosql.sql.planner.assertions.BasePlanTest)2 PlanMatchPattern.aggregation (io.prestosql.sql.planner.assertions.PlanMatchPattern.aggregation)2 PlanMatchPattern.anyTree (io.prestosql.sql.planner.assertions.PlanMatchPattern.anyTree)2 PlanMatchPattern.equiJoinClause (io.prestosql.sql.planner.assertions.PlanMatchPattern.equiJoinClause)2 PlanMatchPattern.exchange (io.prestosql.sql.planner.assertions.PlanMatchPattern.exchange)2 PlanMatchPattern.functionCall (io.prestosql.sql.planner.assertions.PlanMatchPattern.functionCall)2 PlanMatchPattern.join (io.prestosql.sql.planner.assertions.PlanMatchPattern.join)2