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);
}
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());
}
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;
}
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());
}
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()));
}
Aggregations