use of com.datatorrent.api.Partitioner.Partition in project apex-core by apache.
the class PhysicalPlan method initPartitioning.
private void initPartitioning(PMapping m, int partitionCnt) {
Operator operator = m.logicalOperator.getOperator();
Collection<Partition<Operator>> partitions;
@SuppressWarnings("unchecked") Partitioner<Operator> partitioner = m.logicalOperator.getAttributes().contains(OperatorContext.PARTITIONER) ? (Partitioner<Operator>) m.logicalOperator.getValue(OperatorContext.PARTITIONER) : operator instanceof Partitioner ? (Partitioner<Operator>) operator : null;
Collection<Partition<Operator>> collection = new ArrayList<>(1);
DefaultPartition<Operator> firstPartition = new DefaultPartition<>(operator);
collection.add(firstPartition);
if (partitioner != null) {
partitions = partitioner.definePartitions(collection, new PartitioningContextImpl(m, partitionCnt));
if (partitions == null || partitions.isEmpty()) {
throw new IllegalStateException("Partitioner returns null or empty.");
}
} else {
// Non zero in the case of parallel partitioning.
for (int partitionCounter = 0; partitionCounter < partitionCnt - 1; partitionCounter++) {
collection.add(firstPartition);
}
partitions = collection;
}
Collection<StatsListener> statsListeners = m.logicalOperator.getValue(OperatorContext.STATS_LISTENERS);
if (statsListeners != null && !statsListeners.isEmpty()) {
if (m.statsHandlers == null) {
m.statsHandlers = new ArrayList<>(statsListeners.size());
}
for (StatsListener sl : statsListeners) {
m.statsHandlers.add(getStatsListenerAdapter(sl));
}
}
if (m.logicalOperator.getOperator() instanceof StatsListener) {
if (m.statsHandlers == null) {
m.statsHandlers = new ArrayList<>(1);
}
m.statsHandlers.add(new StatsListenerProxy(m.logicalOperator));
}
// create operator instance per partition
Map<Integer, Partition<Operator>> operatorIdToPartition = Maps.newHashMapWithExpectedSize(partitions.size());
for (Partition<Operator> partition : partitions) {
PTOperator p = addPTOperator(m, partition, null);
operatorIdToPartition.put(p.getId(), partition);
}
if (partitioner != null) {
partitioner.partitioned(operatorIdToPartition);
}
}
Aggregations