Search in sources :

Example 21 with Metadata

use of io.trino.metadata.Metadata in project trino by trinodb.

the class PlanFragmenter method analyzeGroupedExecution.

private SubPlan analyzeGroupedExecution(Session session, SubPlan subPlan) {
    PlanFragment fragment = subPlan.getFragment();
    GroupedExecutionProperties properties = fragment.getRoot().accept(new GroupedExecutionTagger(session, metadata, nodePartitioningManager), null);
    if (properties.isSubTreeUseful()) {
        boolean preferDynamic = fragment.getRemoteSourceNodes().stream().allMatch(node -> node.getExchangeType() == REPLICATE) && isDynamicScheduleForGroupedExecution(session);
        BucketNodeMap bucketNodeMap = nodePartitioningManager.getBucketNodeMap(session, fragment.getPartitioning(), preferDynamic);
        if (bucketNodeMap.isDynamic()) {
            fragment = fragment.withDynamicLifespanScheduleGroupedExecution(properties.getCapableTableScanNodes());
        } else {
            fragment = fragment.withFixedLifespanScheduleGroupedExecution(properties.getCapableTableScanNodes());
        }
    }
    ImmutableList.Builder<SubPlan> result = ImmutableList.builder();
    for (SubPlan child : subPlan.getChildren()) {
        result.add(analyzeGroupedExecution(session, child));
    }
    return new SubPlan(fragment, result.build());
}
Also used : BucketNodeMap(io.trino.execution.scheduler.BucketNodeMap) TableWriterNode(io.trino.sql.planner.plan.TableWriterNode) PlanNode(io.trino.sql.planner.plan.PlanNode) RemoteSourceNode(io.trino.sql.planner.plan.RemoteSourceNode) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Predicates.in(com.google.common.base.Predicates.in) SystemSessionProperties.getRetryPolicy(io.trino.SystemSessionProperties.getRetryPolicy) SystemSessionProperties.isDynamicScheduleForGroupedExecution(io.trino.SystemSessionProperties.isDynamicScheduleForGroupedExecution) ConnectorPartitionHandle(io.trino.spi.connector.ConnectorPartitionHandle) TableDeleteNode(io.trino.sql.planner.plan.TableDeleteNode) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) PlanPrinter.jsonFragmentPlan(io.trino.sql.planner.planprinter.PlanPrinter.jsonFragmentPlan) Map(java.util.Map) OutputNode(io.trino.sql.planner.plan.OutputNode) SINGLE_DISTRIBUTION(io.trino.sql.planner.SystemPartitioningHandle.SINGLE_DISTRIBUTION) JoinNode(io.trino.sql.planner.plan.JoinNode) TableScanNode(io.trino.sql.planner.plan.TableScanNode) ExplainAnalyzeNode(io.trino.sql.planner.plan.ExplainAnalyzeNode) ImmutableSet(com.google.common.collect.ImmutableSet) StatisticsWriterNode(io.trino.sql.planner.plan.StatisticsWriterNode) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) QUERY_HAS_TOO_MANY_STAGES(io.trino.spi.StandardErrorCode.QUERY_HAS_TOO_MANY_STAGES) SchedulingOrderVisitor.scheduleOrder(io.trino.sql.planner.SchedulingOrderVisitor.scheduleOrder) Set(java.util.Set) TrinoException(io.trino.spi.TrinoException) SystemSessionProperties.getQueryMaxStageCount(io.trino.SystemSessionProperties.getQueryMaxStageCount) PatternRecognitionNode(io.trino.sql.planner.plan.PatternRecognitionNode) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) QueryManagerConfig(io.trino.execution.QueryManagerConfig) SimplePlanRewriter(io.trino.sql.planner.plan.SimplePlanRewriter) List(java.util.List) NOT_PARTITIONED(io.trino.spi.connector.NotPartitionedPartitionHandle.NOT_PARTITIONED) ConnectorPartitioningHandle(io.trino.spi.connector.ConnectorPartitioningHandle) TrinoWarning(io.trino.spi.TrinoWarning) COORDINATOR_DISTRIBUTION(io.trino.sql.planner.SystemPartitioningHandle.COORDINATOR_DISTRIBUTION) TopNRankingNode(io.trino.sql.planner.plan.TopNRankingNode) Optional(java.util.Optional) ExchangeNode(io.trino.sql.planner.plan.ExchangeNode) PlanFragmentId(io.trino.sql.planner.plan.PlanFragmentId) ValuesNode(io.trino.sql.planner.plan.ValuesNode) WindowNode(io.trino.sql.planner.plan.WindowNode) Session(io.trino.Session) Type(io.trino.spi.type.Type) RetryPolicy(io.trino.operator.RetryPolicy) REPLICATE(io.trino.sql.planner.plan.ExchangeNode.Type.REPLICATE) StatsAndCosts(io.trino.cost.StatsAndCosts) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) RowNumberNode(io.trino.sql.planner.plan.RowNumberNode) Objects.requireNonNull(java.util.Objects.requireNonNull) SystemSessionProperties(io.trino.SystemSessionProperties) RefreshMaterializedViewNode(io.trino.sql.planner.plan.RefreshMaterializedViewNode) AggregationNode(io.trino.sql.planner.plan.AggregationNode) StageExecutionDescriptor.ungroupedExecution(io.trino.operator.StageExecutionDescriptor.ungroupedExecution) TablePartitioning(io.trino.metadata.TableProperties.TablePartitioning) SystemSessionProperties.isForceSingleNodeOutput(io.trino.SystemSessionProperties.isForceSingleNodeOutput) PlanVisitor(io.trino.sql.planner.plan.PlanVisitor) TOO_MANY_STAGES(io.trino.spi.connector.StandardWarningCode.TOO_MANY_STAGES) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) Maps(com.google.common.collect.Maps) FunctionManager(io.trino.metadata.FunctionManager) TableHandle(io.trino.metadata.TableHandle) REMOTE(io.trino.sql.planner.plan.ExchangeNode.Scope.REMOTE) SOURCE_DISTRIBUTION(io.trino.sql.planner.SystemPartitioningHandle.SOURCE_DISTRIBUTION) WarningCollector(io.trino.execution.warnings.WarningCollector) Metadata(io.trino.metadata.Metadata) TableFinishNode(io.trino.sql.planner.plan.TableFinishNode) BucketNodeMap(io.trino.execution.scheduler.BucketNodeMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList)

Example 22 with Metadata

use of io.trino.metadata.Metadata in project trino by trinodb.

the class IndexJoinMatcher method detailMatches.

@Override
public MatchResult detailMatches(PlanNode node, StatsProvider stats, Session session, Metadata metadata, SymbolAliases symbolAliases) {
    checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName());
    IndexJoinNode indexJoinNode = (IndexJoinNode) node;
    if (indexJoinNode.getCriteria().size() != criteria.size()) {
        return NO_MATCH;
    }
    Set<IndexJoinNode.EquiJoinClause> actualCriteria = ImmutableSet.copyOf(indexJoinNode.getCriteria());
    Set<IndexJoinNode.EquiJoinClause> expectedCriteria = criteria.stream().map(equiClause -> equiClause.getExpectedValue(symbolAliases)).collect(toImmutableSet());
    if (!expectedCriteria.equals(actualCriteria)) {
        return NO_MATCH;
    }
    if (!indexJoinNode.getProbeHashSymbol().equals(probeHashSymbol.map(alias -> alias.toSymbol(symbolAliases)))) {
        return NO_MATCH;
    }
    if (!indexJoinNode.getIndexHashSymbol().equals(indexHashSymbol.map(alias -> alias.toSymbol(symbolAliases)))) {
        return NO_MATCH;
    }
    return MatchResult.match();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) IndexJoinNode(io.trino.sql.planner.plan.IndexJoinNode) Set(java.util.Set) StatsProvider(io.trino.cost.StatsProvider) PlanNode(io.trino.sql.planner.plan.PlanNode) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) Objects.requireNonNull(java.util.Objects.requireNonNull) Metadata(io.trino.metadata.Metadata) Optional(java.util.Optional) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) NO_MATCH(io.trino.sql.planner.assertions.MatchResult.NO_MATCH) Session(io.trino.Session) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) IndexJoinNode(io.trino.sql.planner.plan.IndexJoinNode)

Example 23 with Metadata

use of io.trino.metadata.Metadata in project trino by trinodb.

the class UnnestMatcher method detailMatches.

@Override
public MatchResult detailMatches(PlanNode node, StatsProvider stats, Session session, Metadata metadata, SymbolAliases symbolAliases) {
    checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName());
    UnnestNode unnestNode = (UnnestNode) node;
    if (unnestNode.getReplicateSymbols().size() != replicateSymbols.size()) {
        return NO_MATCH;
    }
    if (!replicateSymbols.stream().map(symbolAliases::get).map(Symbol::from).collect(toImmutableList()).equals(unnestNode.getReplicateSymbols())) {
        return NO_MATCH;
    }
    if (unnestNode.getMappings().size() != unnestMappings.size()) {
        return NO_MATCH;
    }
    if (!IntStream.range(0, unnestMappings.size()).boxed().allMatch(index -> {
        Mapping nodeMapping = unnestNode.getMappings().get(index);
        PlanMatchPattern.UnnestMapping patternMapping = unnestMappings.get(index);
        return nodeMapping.getInput().toSymbolReference().equals(symbolAliases.get(patternMapping.getInput())) && patternMapping.getOutputs().size() == nodeMapping.getOutputs().size();
    })) {
        return NO_MATCH;
    }
    if (ordinalitySymbol.isPresent() != unnestNode.getOrdinalitySymbol().isPresent()) {
        return NO_MATCH;
    }
    if (!type.equals(unnestNode.getJoinType())) {
        return NO_MATCH;
    }
    if (filter.isPresent() != unnestNode.getFilter().isPresent()) {
        return NO_MATCH;
    }
    if (filter.isEmpty()) {
        return MatchResult.match();
    }
    if (!new ExpressionVerifier(symbolAliases).process(unnestNode.getFilter().get(), filter.get())) {
        return NO_MATCH;
    }
    return MatchResult.match();
}
Also used : IntStream(java.util.stream.IntStream) Symbol(io.trino.sql.planner.Symbol) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) StatsProvider(io.trino.cost.StatsProvider) UnnestNode(io.trino.sql.planner.plan.UnnestNode) PlanNode(io.trino.sql.planner.plan.PlanNode) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) Mapping(io.trino.sql.planner.plan.UnnestNode.Mapping) Objects.requireNonNull(java.util.Objects.requireNonNull) Metadata(io.trino.metadata.Metadata) Optional(java.util.Optional) NO_MATCH(io.trino.sql.planner.assertions.MatchResult.NO_MATCH) Expression(io.trino.sql.tree.Expression) JoinNode(io.trino.sql.planner.plan.JoinNode) Session(io.trino.Session) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) UnnestNode(io.trino.sql.planner.plan.UnnestNode) Mapping(io.trino.sql.planner.plan.UnnestNode.Mapping)

Example 24 with Metadata

use of io.trino.metadata.Metadata in project trino by trinodb.

the class ValuesMatcher method detailMatches.

@Override
public MatchResult detailMatches(PlanNode node, StatsProvider stats, Session session, Metadata metadata, SymbolAliases symbolAliases) {
    checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName());
    ValuesNode valuesNode = (ValuesNode) node;
    if (expectedRows.isPresent()) {
        if (expectedRows.get().size() != valuesNode.getRowCount()) {
            return NO_MATCH;
        }
        if (outputSymbolAliases.size() > 0) {
            if (!expectedRows.equals(valuesNode.getRows())) {
                return NO_MATCH;
            }
        }
    }
    return match(SymbolAliases.builder().putAll(Maps.transformValues(outputSymbolAliases, index -> valuesNode.getOutputSymbols().get(index).toSymbolReference())).build());
}
Also used : MatchResult.match(io.trino.sql.planner.assertions.MatchResult.match) ImmutableMap(com.google.common.collect.ImmutableMap) Maps(com.google.common.collect.Maps) StatsProvider(io.trino.cost.StatsProvider) PlanNode(io.trino.sql.planner.plan.PlanNode) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Metadata(io.trino.metadata.Metadata) Optional(java.util.Optional) NO_MATCH(io.trino.sql.planner.assertions.MatchResult.NO_MATCH) Expression(io.trino.sql.tree.Expression) ValuesNode(io.trino.sql.planner.plan.ValuesNode) Session(io.trino.Session) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) ValuesNode(io.trino.sql.planner.plan.ValuesNode)

Example 25 with Metadata

use of io.trino.metadata.Metadata in project trino by trinodb.

the class MarkDistinctMatcher method detailMatches.

@Override
public MatchResult detailMatches(PlanNode node, StatsProvider stats, Session session, Metadata metadata, SymbolAliases symbolAliases) {
    checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName());
    MarkDistinctNode markDistinctNode = (MarkDistinctNode) node;
    if (!markDistinctNode.getHashSymbol().equals(hashSymbol.map(alias -> alias.toSymbol(symbolAliases)))) {
        return NO_MATCH;
    }
    if (!ImmutableSet.copyOf(markDistinctNode.getDistinctSymbols()).equals(distinctSymbols.stream().map(alias -> alias.toSymbol(symbolAliases)).collect(toImmutableSet()))) {
        return NO_MATCH;
    }
    return match(markerSymbol.toString(), markDistinctNode.getMarkerSymbol().toSymbolReference());
}
Also used : MarkDistinctNode(io.trino.sql.planner.plan.MarkDistinctNode) ImmutableSet(com.google.common.collect.ImmutableSet) MatchResult.match(io.trino.sql.planner.assertions.MatchResult.match) StatsProvider(io.trino.cost.StatsProvider) PlanNode(io.trino.sql.planner.plan.PlanNode) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) Metadata(io.trino.metadata.Metadata) Optional(java.util.Optional) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) NO_MATCH(io.trino.sql.planner.assertions.MatchResult.NO_MATCH) Session(io.trino.Session) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) MarkDistinctNode(io.trino.sql.planner.plan.MarkDistinctNode)

Aggregations

Metadata (io.trino.metadata.Metadata)50 Session (io.trino.Session)35 List (java.util.List)34 Optional (java.util.Optional)31 Objects.requireNonNull (java.util.Objects.requireNonNull)30 PlanNode (io.trino.sql.planner.plan.PlanNode)22 Expression (io.trino.sql.tree.Expression)21 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)20 Set (java.util.Set)19 Preconditions.checkState (com.google.common.base.Preconditions.checkState)18 Map (java.util.Map)16 ImmutableList (com.google.common.collect.ImmutableList)15 MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)14 StatsProvider (io.trino.cost.StatsProvider)14 QualifiedObjectName (io.trino.metadata.QualifiedObjectName)14 Symbol (io.trino.sql.planner.Symbol)14 ImmutableMap (com.google.common.collect.ImmutableMap)13 ImmutableSet (com.google.common.collect.ImmutableSet)13 TableHandle (io.trino.metadata.TableHandle)13 NO_MATCH (io.trino.sql.planner.assertions.MatchResult.NO_MATCH)13