Search in sources :

Example 1 with LOCAL

use of io.prestosql.sql.planner.plan.ExchangeNode.Scope.LOCAL 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)

Example 2 with LOCAL

use of io.prestosql.sql.planner.plan.ExchangeNode.Scope.LOCAL in project hetu-core by openlookeng.

the class PropertyDerivations method deriveProperties.

public static ActualProperties deriveProperties(PlanNode node, List<ActualProperties> inputProperties, Metadata metadata, Session session, TypeProvider types, TypeAnalyzer typeAnalyzer) {
    ActualProperties output = node.accept(new Visitor(metadata, session, types, typeAnalyzer), inputProperties);
    output.getNodePartitioning().ifPresent(partitioning -> verify(node.getOutputSymbols().containsAll(partitioning.getColumns()), "Node-level partitioning properties contain columns not present in node's output"));
    verify(node.getOutputSymbols().containsAll(output.getConstants().keySet()), "Node-level constant properties contain columns not present in node's output");
    Set<Symbol> localPropertyColumns = output.getLocalProperties().stream().flatMap(property -> property.getColumns().stream()).collect(Collectors.toSet());
    verify(node.getOutputSymbols().containsAll(localPropertyColumns), "Node-level local properties contain columns not present in node's output");
    return output;
}
Also used : TableDeleteNode(io.prestosql.sql.planner.plan.TableDeleteNode) SortNode(io.prestosql.sql.planner.plan.SortNode) TypeProvider(io.prestosql.sql.planner.TypeProvider) NullableValue(io.prestosql.spi.predicate.NullableValue) CTEScanNode(io.prestosql.spi.plan.CTEScanNode) AggregationNode(io.prestosql.spi.plan.AggregationNode) TypeAnalyzer(io.prestosql.sql.planner.TypeAnalyzer) TableUpdateNode(io.prestosql.sql.planner.plan.TableUpdateNode) Map(java.util.Map) OutputNode(io.prestosql.sql.planner.plan.OutputNode) TopNRankingNumberNode(io.prestosql.sql.planner.plan.TopNRankingNumberNode) ConstantProperty(io.prestosql.spi.connector.ConstantProperty) SymbolUtils(io.prestosql.sql.planner.SymbolUtils) Global.singleStreamPartition(io.prestosql.sql.planner.optimizations.ActualProperties.Global.singleStreamPartition) DomainTranslator(io.prestosql.spi.relation.DomainTranslator) CreateIndexNode(io.prestosql.sql.planner.plan.CreateIndexNode) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) TableScanNode(io.prestosql.spi.plan.TableScanNode) Set(java.util.Set) IndexSourceNode(io.prestosql.sql.planner.plan.IndexSourceNode) PlanNode(io.prestosql.spi.plan.PlanNode) RowExpressionDomainTranslator(io.prestosql.sql.relational.RowExpressionDomainTranslator) ProjectNode(io.prestosql.spi.plan.ProjectNode) Metadata(io.prestosql.metadata.Metadata) NodeRef(io.prestosql.sql.tree.NodeRef) RowExpressionInterpreter(io.prestosql.sql.planner.RowExpressionInterpreter) SpatialJoinNode(io.prestosql.sql.planner.plan.SpatialJoinNode) SymbolReference(io.prestosql.sql.tree.SymbolReference) LOCAL(io.prestosql.sql.planner.plan.ExchangeNode.Scope.LOCAL) Domain(io.prestosql.spi.predicate.Domain) StatisticsWriterNode(io.prestosql.sql.planner.plan.StatisticsWriterNode) VacuumTableNode(io.prestosql.sql.planner.plan.VacuumTableNode) DistinctLimitNode(io.prestosql.sql.planner.plan.DistinctLimitNode) TableProperties(io.prestosql.metadata.TableProperties) GroupIdNode(io.prestosql.spi.plan.GroupIdNode) Iterables(com.google.common.collect.Iterables) ExpressionInterpreter(io.prestosql.sql.planner.ExpressionInterpreter) AssignUniqueId(io.prestosql.sql.planner.plan.AssignUniqueId) UnnestNode(io.prestosql.sql.planner.plan.UnnestNode) REMOTE(io.prestosql.sql.planner.plan.ExchangeNode.Scope.REMOTE) ExpressionDomainTranslator(io.prestosql.sql.planner.ExpressionDomainTranslator) Session(io.prestosql.Session) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) DeleteNode(io.prestosql.sql.planner.plan.DeleteNode) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) ValuesNode(io.prestosql.spi.plan.ValuesNode) SystemSessionProperties.planWithTableNodePartitioning(io.prestosql.SystemSessionProperties.planWithTableNodePartitioning) ARBITRARY_DISTRIBUTION(io.prestosql.sql.planner.SystemPartitioningHandle.ARBITRARY_DISTRIBUTION) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) SampleNode(io.prestosql.sql.planner.plan.SampleNode) WindowNode(io.prestosql.spi.plan.WindowNode) LimitNode(io.prestosql.spi.plan.LimitNode) Expression(io.prestosql.sql.tree.Expression) UpdateIndexNode(io.prestosql.sql.planner.plan.UpdateIndexNode) SystemSessionProperties(io.prestosql.SystemSessionProperties) TupleDomain.extractFixedValues(io.prestosql.spi.predicate.TupleDomain.extractFixedValues) SortingProperty(io.prestosql.spi.connector.SortingProperty) TableFinishNode(io.prestosql.sql.planner.plan.TableFinishNode) ExchangeNode(io.prestosql.sql.planner.plan.ExchangeNode) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) NoOpSymbolResolver(io.prestosql.sql.planner.NoOpSymbolResolver) FilterNode(io.prestosql.spi.plan.FilterNode) Collectors.toMap(java.util.stream.Collectors.toMap) Type(io.prestosql.spi.type.Type) OriginalExpressionUtils.castToExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToExpression) Global.streamPartitionedOn(io.prestosql.sql.planner.optimizations.ActualProperties.Global.streamPartitionedOn) Global.coordinatorSingleStreamPartition(io.prestosql.sql.planner.optimizations.ActualProperties.Global.coordinatorSingleStreamPartition) Global.arbitraryPartition(io.prestosql.sql.planner.optimizations.ActualProperties.Global.arbitraryPartition) ApplyNode(io.prestosql.sql.planner.plan.ApplyNode) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) IndexJoinNode(io.prestosql.sql.planner.plan.IndexJoinNode) CubeFinishNode(io.prestosql.sql.planner.plan.CubeFinishNode) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) RowNumberNode(io.prestosql.sql.planner.plan.RowNumberNode) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) EnforceSingleRowNode(io.prestosql.sql.planner.plan.EnforceSingleRowNode) TopNNode(io.prestosql.spi.plan.TopNNode) Optional(java.util.Optional) InternalPlanVisitor(io.prestosql.sql.planner.plan.InternalPlanVisitor) CoalesceExpression(io.prestosql.sql.tree.CoalesceExpression) SINGLE_DISTRIBUTION(io.prestosql.sql.planner.SystemPartitioningHandle.SINGLE_DISTRIBUTION) LateralJoinNode(io.prestosql.sql.planner.plan.LateralJoinNode) HashMap(java.util.HashMap) SemiJoinNode(io.prestosql.sql.planner.plan.SemiJoinNode) OPTIMIZED(io.prestosql.sql.planner.RowExpressionInterpreter.Level.OPTIMIZED) ImmutableBiMap(com.google.common.collect.ImmutableBiMap) OriginalExpressionUtils.isExpression(io.prestosql.sql.relational.OriginalExpressionUtils.isExpression) ImmutableList(com.google.common.collect.ImmutableList) OrderingScheme(io.prestosql.spi.plan.OrderingScheme) Verify.verify(com.google.common.base.Verify.verify) Objects.requireNonNull(java.util.Objects.requireNonNull) GroupingProperty(io.prestosql.spi.connector.GroupingProperty) MarkDistinctNode(io.prestosql.spi.plan.MarkDistinctNode) JoinNode(io.prestosql.spi.plan.JoinNode) Symbol(io.prestosql.spi.plan.Symbol) TableWriterNode(io.prestosql.sql.planner.plan.TableWriterNode) LocalProperty(io.prestosql.spi.connector.LocalProperty) TablePartitioning(io.prestosql.metadata.TableProperties.TablePartitioning) TupleDomain(io.prestosql.spi.predicate.TupleDomain) UpdateNode(io.prestosql.sql.planner.plan.UpdateNode) Global.partitionedOn(io.prestosql.sql.planner.optimizations.ActualProperties.Global.partitionedOn) Global(io.prestosql.sql.planner.optimizations.ActualProperties.Global) RowExpression(io.prestosql.spi.relation.RowExpression) ExplainAnalyzeNode(io.prestosql.sql.planner.plan.ExplainAnalyzeNode) InternalPlanVisitor(io.prestosql.sql.planner.plan.InternalPlanVisitor) Symbol(io.prestosql.spi.plan.Symbol)

Example 3 with LOCAL

use of io.prestosql.sql.planner.plan.ExchangeNode.Scope.LOCAL in project hetu-core by openlookeng.

the class TestValidateAggregationsWithDefaultValues method testWithPartialAggregationBelowJoinWithoutSeparatingExchange.

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Final aggregation with default value not separated from partial aggregation by local hash exchange")
public void testWithPartialAggregationBelowJoinWithoutSeparatingExchange() {
    Symbol symbolObj = new Symbol("symbol");
    PlanNode root = builder.aggregation(af -> af.step(FINAL).groupingSets(groupingSets(ImmutableList.of(symbolObj), 2, ImmutableSet.of(0))).source(builder.join(INNER, builder.aggregation(ap -> ap.step(PARTIAL).groupingSets(groupingSets(ImmutableList.of(symbolObj), 2, ImmutableSet.of(0))).source(tableScanNode)), builder.values())));
    validatePlan(root, true);
}
Also used : TpchTableHandle(io.prestosql.plugin.tpch.TpchTableHandle) TpchColumnHandle(io.prestosql.plugin.tpch.TpchColumnHandle) TypeProvider(io.prestosql.sql.planner.TypeProvider) Test(org.testng.annotations.Test) SqlParser(io.prestosql.sql.parser.SqlParser) TableHandle(io.prestosql.spi.metadata.TableHandle) PARTIAL(io.prestosql.spi.plan.AggregationNode.Step.PARTIAL) TypeAnalyzer(io.prestosql.sql.planner.TypeAnalyzer) REMOTE(io.prestosql.sql.planner.plan.ExchangeNode.Scope.REMOTE) WarningCollector(io.prestosql.execution.warnings.WarningCollector) ImmutableList(com.google.common.collect.ImmutableList) REPARTITION(io.prestosql.sql.planner.plan.ExchangeNode.Type.REPARTITION) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) Symbol(io.prestosql.spi.plan.Symbol) BasePlanTest(io.prestosql.sql.planner.assertions.BasePlanTest) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) BeforeClass(org.testng.annotations.BeforeClass) CatalogName(io.prestosql.spi.connector.CatalogName) TableScanNode(io.prestosql.spi.plan.TableScanNode) PlanNode(io.prestosql.spi.plan.PlanNode) FINAL(io.prestosql.spi.plan.AggregationNode.Step.FINAL) Metadata(io.prestosql.metadata.Metadata) AggregationNode.groupingSets(io.prestosql.spi.plan.AggregationNode.groupingSets) TestingTransactionHandle(io.prestosql.testing.TestingTransactionHandle) LOCAL(io.prestosql.sql.planner.plan.ExchangeNode.Scope.LOCAL) PlanNodeIdAllocator(io.prestosql.spi.plan.PlanNodeIdAllocator) INNER(io.prestosql.spi.plan.JoinNode.Type.INNER) Optional(java.util.Optional) PlanBuilder(io.prestosql.sql.planner.iterative.rule.test.PlanBuilder) PlanNode(io.prestosql.spi.plan.PlanNode) Symbol(io.prestosql.spi.plan.Symbol) Test(org.testng.annotations.Test) BasePlanTest(io.prestosql.sql.planner.assertions.BasePlanTest)

Example 4 with LOCAL

use of io.prestosql.sql.planner.plan.ExchangeNode.Scope.LOCAL in project hetu-core by openlookeng.

the class TestValidateAggregationsWithDefaultValues method testWithPartialAggregationBelowJoin.

@Test
public void testWithPartialAggregationBelowJoin() {
    Symbol symbolObj = new Symbol("symbol");
    PlanNode root = builder.aggregation(af -> af.step(FINAL).groupingSets(groupingSets(ImmutableList.of(symbolObj), 2, ImmutableSet.of(0))).source(builder.join(INNER, builder.exchange(e -> e.type(REPARTITION).scope(LOCAL).fixedHashDistributionParitioningScheme(ImmutableList.of(symbolObj), ImmutableList.of(symbolObj)).addInputsSet(symbolObj).addSource(builder.aggregation(ap -> ap.step(PARTIAL).groupingSets(groupingSets(ImmutableList.of(symbolObj), 2, ImmutableSet.of(0))).source(tableScanNode)))), builder.values())));
    validatePlan(root, true);
}
Also used : TpchTableHandle(io.prestosql.plugin.tpch.TpchTableHandle) TpchColumnHandle(io.prestosql.plugin.tpch.TpchColumnHandle) TypeProvider(io.prestosql.sql.planner.TypeProvider) Test(org.testng.annotations.Test) SqlParser(io.prestosql.sql.parser.SqlParser) TableHandle(io.prestosql.spi.metadata.TableHandle) PARTIAL(io.prestosql.spi.plan.AggregationNode.Step.PARTIAL) TypeAnalyzer(io.prestosql.sql.planner.TypeAnalyzer) REMOTE(io.prestosql.sql.planner.plan.ExchangeNode.Scope.REMOTE) WarningCollector(io.prestosql.execution.warnings.WarningCollector) ImmutableList(com.google.common.collect.ImmutableList) REPARTITION(io.prestosql.sql.planner.plan.ExchangeNode.Type.REPARTITION) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) Symbol(io.prestosql.spi.plan.Symbol) BasePlanTest(io.prestosql.sql.planner.assertions.BasePlanTest) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) BeforeClass(org.testng.annotations.BeforeClass) CatalogName(io.prestosql.spi.connector.CatalogName) TableScanNode(io.prestosql.spi.plan.TableScanNode) PlanNode(io.prestosql.spi.plan.PlanNode) FINAL(io.prestosql.spi.plan.AggregationNode.Step.FINAL) Metadata(io.prestosql.metadata.Metadata) AggregationNode.groupingSets(io.prestosql.spi.plan.AggregationNode.groupingSets) TestingTransactionHandle(io.prestosql.testing.TestingTransactionHandle) LOCAL(io.prestosql.sql.planner.plan.ExchangeNode.Scope.LOCAL) PlanNodeIdAllocator(io.prestosql.spi.plan.PlanNodeIdAllocator) INNER(io.prestosql.spi.plan.JoinNode.Type.INNER) Optional(java.util.Optional) PlanBuilder(io.prestosql.sql.planner.iterative.rule.test.PlanBuilder) PlanNode(io.prestosql.spi.plan.PlanNode) Symbol(io.prestosql.spi.plan.Symbol) Test(org.testng.annotations.Test) BasePlanTest(io.prestosql.sql.planner.assertions.BasePlanTest)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 LOCAL (io.prestosql.sql.planner.plan.ExchangeNode.Scope.LOCAL)4 REMOTE (io.prestosql.sql.planner.plan.ExchangeNode.Scope.REMOTE)4 Optional (java.util.Optional)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 Metadata (io.prestosql.metadata.Metadata)3 FINAL (io.prestosql.spi.plan.AggregationNode.Step.FINAL)3 INNER (io.prestosql.spi.plan.JoinNode.Type.INNER)3 Session (io.prestosql.Session)2 WarningCollector (io.prestosql.execution.warnings.WarningCollector)2 TpchColumnHandle (io.prestosql.plugin.tpch.TpchColumnHandle)2 TpchTableHandle (io.prestosql.plugin.tpch.TpchTableHandle)2 CatalogName (io.prestosql.spi.connector.CatalogName)2 TableHandle (io.prestosql.spi.metadata.TableHandle)2 PARTIAL (io.prestosql.spi.plan.AggregationNode.Step.PARTIAL)2 AggregationNode.groupingSets (io.prestosql.spi.plan.AggregationNode.groupingSets)2 PlanNode (io.prestosql.spi.plan.PlanNode)2 PlanNodeIdAllocator (io.prestosql.spi.plan.PlanNodeIdAllocator)2 Symbol (io.prestosql.spi.plan.Symbol)2