@Override
    public void coGroup(
        Iterator<Record> candidates, Iterator<Record> current, Collector<Record> out)
        throws Exception {
      if (!current.hasNext()) {
        throw new Exception("Error: Id not encountered before.");
      }
      Record old = current.next();
      long oldId = old.getField(1, LongValue.class).getValue();

      long minimumComponentID = Long.MAX_VALUE;

      while (candidates.hasNext()) {
        long candidateComponentID = candidates.next().getField(1, LongValue.class).getValue();
        if (candidateComponentID < minimumComponentID) {
          minimumComponentID = candidateComponentID;
        }
      }

      if (minimumComponentID < oldId) {
        newComponentId.setValue(minimumComponentID);
        old.setField(1, newComponentId);
        out.collect(old);
      }
    }
    @Override
    public Record combineFirst(Iterator<Record> records) {
      Record next = null;
      long min = Long.MAX_VALUE;
      while (records.hasNext()) {
        next = records.next();
        min = Math.min(min, next.getField(1, LongValue.class).getValue());
      }

      newComponentId.setValue(min);
      next.setField(1, newComponentId);
      return next;
    }