Exemple #1
0
  @SuppressWarnings("unchecked")
  public OutputEmitter(
      ShipStrategyType strategy,
      int indexInSubtaskGroup,
      TypeComparator<T> comparator,
      Partitioner<?> partitioner,
      DataDistribution distribution) {
    if (strategy == null) {
      throw new NullPointerException();
    }

    this.strategy = strategy;
    this.nextChannelToSendTo = indexInSubtaskGroup;
    this.comparator = comparator;
    this.partitioner = (Partitioner<Object>) partitioner;
    this.distribution = distribution;

    switch (strategy) {
      case PARTITION_CUSTOM:
        extractedKeys = new Object[1];
      case FORWARD:
      case PARTITION_HASH:
      case PARTITION_RANDOM:
      case PARTITION_FORCED_REBALANCE:
        channels = new int[1];
        break;
      case PARTITION_RANGE:
        channels = new int[1];
        if (comparator != null) {
          this.flatComparators = comparator.getFlatComparators();
          this.keys = new Object[flatComparators.length];
        }
        break;
      case BROADCAST:
        break;
      default:
        throw new IllegalArgumentException(
            "Invalid shipping strategy for OutputEmitter: " + strategy.name());
    }

    if (strategy == ShipStrategyType.PARTITION_CUSTOM && partitioner == null) {
      throw new NullPointerException(
          "Partitioner must not be null when the ship strategy is set to custom partitioning.");
    }
  }
 @Override
 public final int[] selectChannels(Record record, int numberOfChannels) {
   switch (strategy) {
     case FORWARD:
     case PARTITION_RANDOM:
     case PARTITION_FORCED_REBALANCE:
       return robin(numberOfChannels);
     case PARTITION_HASH:
       return hashPartitionDefault(record, numberOfChannels);
     case PARTITION_CUSTOM:
       return customPartition(record, numberOfChannels);
     case BROADCAST:
       return broadcast(numberOfChannels);
     case PARTITION_RANGE:
       return rangePartition(record, numberOfChannels);
     default:
       throw new UnsupportedOperationException(
           "Unsupported distribution strategy: " + strategy.name());
   }
 }
  @SuppressWarnings("unchecked")
  public RecordOutputEmitter(
      ShipStrategyType strategy,
      TypeComparator<Record> comparator,
      Partitioner<?> partitioner,
      DataDistribution distr) {
    if (strategy == null) {
      throw new NullPointerException();
    }

    this.strategy = strategy;
    this.comparator = comparator;
    this.distribution = distr;
    this.partitioner = (Partitioner<Object>) partitioner;

    switch (strategy) {
      case FORWARD:
      case PARTITION_FORCED_REBALANCE:
      case PARTITION_HASH:
      case PARTITION_RANGE:
      case PARTITION_RANDOM:
        this.channels = new int[1];
        break;
      case BROADCAST:
      case PARTITION_CUSTOM:
        break;
      default:
        throw new IllegalArgumentException(
            "Invalid shipping strategy for OutputEmitter: " + strategy.name());
    }

    if (strategy == ShipStrategyType.PARTITION_RANGE && distr == null) {
      throw new NullPointerException(
          "Data distribution must not be null when the ship strategy is range partitioning.");
    }
    if (strategy == ShipStrategyType.PARTITION_CUSTOM && partitioner == null) {
      throw new NullPointerException(
          "Partitioner must not be null when the ship strategy is set to custom partitioning.");
    }
  }