public PartitioningProperties mergeWithParent(PartitioningProperties parent) { // Non-negotiable if we require a specific partitioning if (partitioning.isPresent()) { return this; } // Partitioning with different replication cannot be compared if (nullsAndAnyReplicated != parent.nullsAndAnyReplicated) { return this; } if (parent.partitioning.isPresent()) { // If the parent has a partitioning preference, propagate parent only if the parent's partitioning columns satisfies our preference. // Otherwise, ignore the parent since the parent will have to repartition anyways. return partitioningColumns.containsAll(parent.partitioningColumns) ? parent : this; } // Otherwise partition on any common columns if available Set<Symbol> common = Sets.intersection(partitioningColumns, parent.partitioningColumns); return common.isEmpty() ? this : partitioned(common).withNullsAndAnyReplicated(nullsAndAnyReplicated); }
.withNullsAndAnyReplicated(nullsAndAnyReplicated))) .build();
private Partitioning selectUnionPartitioning(UnionNode node, PreferredProperties preferredProperties, PreferredProperties.PartitioningProperties parentPreference) { // Use the parent's requested partitioning if available if (parentPreference.getPartitioning().isPresent()) { return parentPreference.getPartitioning().get(); } // Try planning the children to see if any of them naturally produce a partitioning (for now, just select the first) boolean nullsAndAnyReplicated = parentPreference.isNullsAndAnyReplicated(); for (int sourceIndex = 0; sourceIndex < node.getSources().size(); sourceIndex++) { PreferredProperties.PartitioningProperties childPartitioning = parentPreference.translate(outputToInputTranslator(node, sourceIndex)).get(); PreferredProperties childPreferred = PreferredProperties.builder() .global(PreferredProperties.Global.distributed(childPartitioning.withNullsAndAnyReplicated(nullsAndAnyReplicated))) .build(); PlanWithProperties child = node.getSources().get(sourceIndex).accept(this, childPreferred); if (child.getProperties().isNodePartitionedOn(childPartitioning.getPartitioningColumns(), nullsAndAnyReplicated)) { Function<Symbol, Optional<Symbol>> childToParent = createTranslator(createMapping(node.sourceOutputLayout(sourceIndex), node.getOutputSymbols())); return child.getProperties().translate(childToParent).getNodePartitioning().get(); } } // Otherwise, choose an arbitrary partitioning over the columns return Partitioning.create(FIXED_HASH_DISTRIBUTION, ImmutableList.copyOf(parentPreference.getPartitioningColumns())); }
public static PreferredProperties partitionedWithNullsAndAnyReplicated(Partitioning partitioning) { return builder() .global(Global.distributed(PartitioningProperties.partitioned(partitioning).withNullsAndAnyReplicated(true))) .build(); }
public static PreferredProperties partitionedWithNullsAndAnyReplicated(Set<Symbol> columns) { return builder() .global(Global.distributed(PartitioningProperties.partitioned(columns).withNullsAndAnyReplicated(true))) .build(); }