Search in sources :

Example 6 with PartitioningScheme

use of io.trino.sql.planner.PartitioningScheme in project trino by trinodb.

the class TestApplyPreferredTableWriterPartitioning method testThresholdWithMultiplePartitions.

@Test
public void testThresholdWithMultiplePartitions() {
    PlanNodeStatsEstimate stats = PlanNodeStatsEstimate.builder().addSymbolStatistics(ImmutableMap.of(new Symbol("col_one"), new SymbolStatsEstimate(0, 0, 0, 0, 5))).addSymbolStatistics(ImmutableMap.of(new Symbol("col_two"), new SymbolStatsEstimate(0, 0, 0, 0, 10))).build();
    assertPreferredPartitioning(new PartitioningScheme(Partitioning.create(FIXED_HASH_DISTRIBUTION, ImmutableList.of(new Symbol("col_one"), new Symbol("col_two"))), ImmutableList.of(new Symbol("col_one"), new Symbol("col_two")))).withSession(SESSION_WITH_PREFERRED_PARTITIONING_DEFAULT_THRESHOLD).overrideStats(NODE_ID, stats).matches(SUCCESSFUL_MATCH);
}
Also used : PlanNodeStatsEstimate(io.trino.cost.PlanNodeStatsEstimate) Symbol(io.trino.sql.planner.Symbol) PartitioningScheme(io.trino.sql.planner.PartitioningScheme) SymbolStatsEstimate(io.trino.cost.SymbolStatsEstimate) Test(org.testng.annotations.Test)

Example 7 with PartitioningScheme

use of io.trino.sql.planner.PartitioningScheme in project trino by trinodb.

the class TestSourcePartitionedScheduler method createFragment.

private static PlanFragment createFragment() {
    Symbol symbol = new Symbol("column");
    Symbol buildSymbol = new Symbol("buildColumn");
    // table scan with splitCount splits
    TableScanNode tableScan = TableScanNode.newInstance(TABLE_SCAN_NODE_ID, TEST_TABLE_HANDLE, ImmutableList.of(symbol), ImmutableMap.of(symbol, new TestingColumnHandle("column")), false, Optional.empty());
    FilterNode filterNode = new FilterNode(new PlanNodeId("filter_node_id"), tableScan, createDynamicFilterExpression(TEST_SESSION, createTestMetadataManager(), DYNAMIC_FILTER_ID, VARCHAR, symbol.toSymbolReference()));
    RemoteSourceNode remote = new RemoteSourceNode(new PlanNodeId("remote_id"), new PlanFragmentId("plan_fragment_id"), ImmutableList.of(buildSymbol), Optional.empty(), REPLICATE, RetryPolicy.NONE);
    return new PlanFragment(new PlanFragmentId("plan_id"), new JoinNode(new PlanNodeId("join_id"), INNER, filterNode, remote, ImmutableList.of(), tableScan.getOutputSymbols(), remote.getOutputSymbols(), false, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of(DYNAMIC_FILTER_ID, buildSymbol), Optional.empty()), ImmutableMap.of(symbol, VARCHAR), SOURCE_DISTRIBUTION, ImmutableList.of(TABLE_SCAN_NODE_ID), new PartitioningScheme(Partitioning.create(SINGLE_DISTRIBUTION, ImmutableList.of()), ImmutableList.of(symbol)), ungroupedExecution(), StatsAndCosts.empty(), Optional.empty());
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) TestingColumnHandle(io.trino.testing.TestingMetadata.TestingColumnHandle) RemoteSourceNode(io.trino.sql.planner.plan.RemoteSourceNode) TableScanNode(io.trino.sql.planner.plan.TableScanNode) Symbol(io.trino.sql.planner.Symbol) JoinNode(io.trino.sql.planner.plan.JoinNode) PartitioningScheme(io.trino.sql.planner.PartitioningScheme) FilterNode(io.trino.sql.planner.plan.FilterNode) PlanFragmentId(io.trino.sql.planner.plan.PlanFragmentId) PlanFragment(io.trino.sql.planner.PlanFragment)

Example 8 with PartitioningScheme

use of io.trino.sql.planner.PartitioningScheme in project trino by trinodb.

the class TestStageStateMachine method createValuesPlan.

private static PlanFragment createValuesPlan() {
    Symbol symbol = new Symbol("column");
    PlanNodeId valuesNodeId = new PlanNodeId("plan");
    PlanFragment planFragment = new PlanFragment(new PlanFragmentId("plan"), new ValuesNode(valuesNodeId, ImmutableList.of(symbol), ImmutableList.of(new Row(ImmutableList.of(new StringLiteral("foo"))))), ImmutableMap.of(symbol, VARCHAR), SOURCE_DISTRIBUTION, ImmutableList.of(valuesNodeId), new PartitioningScheme(Partitioning.create(SINGLE_DISTRIBUTION, ImmutableList.of()), ImmutableList.of(symbol)), ungroupedExecution(), StatsAndCosts.empty(), Optional.empty());
    return planFragment;
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) ValuesNode(io.trino.sql.planner.plan.ValuesNode) StringLiteral(io.trino.sql.tree.StringLiteral) Symbol(io.trino.sql.planner.Symbol) PartitioningScheme(io.trino.sql.planner.PartitioningScheme) PlanFragmentId(io.trino.sql.planner.plan.PlanFragmentId) Row(io.trino.sql.tree.Row) PlanFragment(io.trino.sql.planner.PlanFragment)

Example 9 with PartitioningScheme

use of io.trino.sql.planner.PartitioningScheme in project trino by trinodb.

the class PruneTableExecuteSourceColumns method apply.

@Override
public Result apply(TableExecuteNode tableExecuteNode, Captures captures, Context context) {
    ImmutableSet.Builder<Symbol> requiredInputs = ImmutableSet.<Symbol>builder().addAll(tableExecuteNode.getColumns());
    if (tableExecuteNode.getPartitioningScheme().isPresent()) {
        PartitioningScheme partitioningScheme = tableExecuteNode.getPartitioningScheme().get();
        partitioningScheme.getPartitioning().getColumns().forEach(requiredInputs::add);
        partitioningScheme.getHashColumn().ifPresent(requiredInputs::add);
    }
    return restrictChildOutputs(context.getIdAllocator(), tableExecuteNode, requiredInputs.build()).map(Result::ofPlanNode).orElse(Result.empty());
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Symbol(io.trino.sql.planner.Symbol) PartitioningScheme(io.trino.sql.planner.PartitioningScheme)

Example 10 with PartitioningScheme

use of io.trino.sql.planner.PartitioningScheme in project trino by trinodb.

the class PruneExchangeColumns method pushDownProjectOff.

@Override
protected Optional<PlanNode> pushDownProjectOff(Context context, ExchangeNode exchangeNode, Set<Symbol> referencedOutputs) {
    // Extract output symbols referenced by parent node or used for partitioning, ordering or as a hash symbol of the Exchange
    ImmutableSet.Builder<Symbol> builder = ImmutableSet.builder();
    builder.addAll(referencedOutputs);
    builder.addAll(exchangeNode.getPartitioningScheme().getPartitioning().getColumns());
    exchangeNode.getPartitioningScheme().getHashColumn().ifPresent(builder::add);
    exchangeNode.getOrderingScheme().ifPresent(orderingScheme -> builder.addAll(orderingScheme.getOrderBy()));
    Set<Symbol> outputsToRetain = builder.build();
    if (outputsToRetain.size() == exchangeNode.getOutputSymbols().size()) {
        return Optional.empty();
    }
    ImmutableList.Builder<Symbol> newOutputs = ImmutableList.builder();
    List<List<Symbol>> newInputs = new ArrayList<>(exchangeNode.getInputs().size());
    for (int i = 0; i < exchangeNode.getInputs().size(); i++) {
        newInputs.add(new ArrayList<>());
    }
    // Retain used symbols from output list and corresponding symbols from all input lists
    for (int i = 0; i < exchangeNode.getOutputSymbols().size(); i++) {
        Symbol output = exchangeNode.getOutputSymbols().get(i);
        if (outputsToRetain.contains(output)) {
            newOutputs.add(output);
            for (int source = 0; source < exchangeNode.getInputs().size(); source++) {
                newInputs.get(source).add(exchangeNode.getInputs().get(source).get(i));
            }
        }
    }
    // newOutputs contains all partition, sort and hash symbols so simply swap the output layout
    PartitioningScheme newPartitioningScheme = new PartitioningScheme(exchangeNode.getPartitioningScheme().getPartitioning(), newOutputs.build(), exchangeNode.getPartitioningScheme().getHashColumn(), exchangeNode.getPartitioningScheme().isReplicateNullsAndAny(), exchangeNode.getPartitioningScheme().getBucketToPartition());
    return Optional.of(new ExchangeNode(exchangeNode.getId(), exchangeNode.getType(), exchangeNode.getScope(), newPartitioningScheme, exchangeNode.getSources(), newInputs, exchangeNode.getOrderingScheme()));
}
Also used : ExchangeNode(io.trino.sql.planner.plan.ExchangeNode) Symbol(io.trino.sql.planner.Symbol) ImmutableList(com.google.common.collect.ImmutableList) PartitioningScheme(io.trino.sql.planner.PartitioningScheme) ArrayList(java.util.ArrayList) ImmutableSet(com.google.common.collect.ImmutableSet) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList)

Aggregations

PartitioningScheme (io.trino.sql.planner.PartitioningScheme)16 Symbol (io.trino.sql.planner.Symbol)14 PlanFragment (io.trino.sql.planner.PlanFragment)7 PlanNodeId (io.trino.sql.planner.plan.PlanNodeId)7 PlanFragmentId (io.trino.sql.planner.plan.PlanFragmentId)6 ImmutableSet (com.google.common.collect.ImmutableSet)5 ExchangeNode (io.trino.sql.planner.plan.ExchangeNode)5 PlanNode (io.trino.sql.planner.plan.PlanNode)5 RemoteSourceNode (io.trino.sql.planner.plan.RemoteSourceNode)5 JoinNode (io.trino.sql.planner.plan.JoinNode)4 TableScanNode (io.trino.sql.planner.plan.TableScanNode)4 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Type (io.trino.spi.type.Type)3 AggregationNode (io.trino.sql.planner.plan.AggregationNode)3 Assignments (io.trino.sql.planner.plan.Assignments)3 FilterNode (io.trino.sql.planner.plan.FilterNode)3 ProjectNode (io.trino.sql.planner.plan.ProjectNode)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3