Пример #1
0
 static void setComparator(Criteria criteria, String field, RawComparator<?> comparator) {
   for (SortElement element : criteria.getElements()) {
     if (element.getName().equals(field)) {
       element.setCustomComparator(comparator);
     }
   }
 }
Пример #2
0
 protected static String[] getFirstFields(OrderBy sortCriteria, int numFields) {
   String[] result = new String[numFields];
   for (int i = 0; i < numFields; i++) {
     SortElement element = sortCriteria.getElements().get(i);
     result[i] = element.getName();
   }
   return result;
 }
Пример #3
0
 /** Initialize the custom comparators. Creates a quick access array for the custom comparators. */
 private void initComparators() {
   TupleMRConfigBuilder.initializeComparators(
       context.getHadoopContext().getConfiguration(), tupleMRConfig);
   customComparators = new RawComparator<?>[maxDepth + 1];
   for (int i = minDepth; i <= maxDepth; i++) {
     SortElement element = tupleMRConfig.getCommonCriteria().getElements().get(i);
     if (element.getCustomComparator() != null) {
       customComparators[i] = element.getCustomComparator();
     }
   }
 }
Пример #4
0
  /**
   * Returns the fields that are a subset from the groupBy fields and will be used when rollup is
   * needed.
   *
   * @see RollupReducer
   */
  public List<String> calculateRollupBaseFields() {
    if (rollupFrom == null) {
      return getGroupByFields();
    }

    List<String> result = new ArrayList<String>();
    for (SortElement element : commonCriteria.getElements()) {
      result.add(element.getName());
      if (element.getName().equals(rollupFrom)) {
        break;
      }
    }
    return result;
  }
Пример #5
0
  /** Returns the instance files created */
  static Set<String> serializeComparators(
      Criteria criteria,
      Configuration conf,
      List<String> comparatorRefs,
      List<String> comparatorInstanceFiles,
      String prefix)
      throws TupleMRException {

    Set<String> instanceFiles = new HashSet<String>();

    if (criteria == null) {
      return instanceFiles;
    }

    for (SortElement element : criteria.getElements()) {
      if (element.getCustomComparator() != null) {
        RawComparator<?> comparator = element.getCustomComparator();

        if (!(comparator instanceof Serializable)) {
          throw new TupleMRException(
              "The class '"
                  + comparator.getClass().getName()
                  + "' is not Serializable."
                  + " The customs comparators must implement Serializable.");
        }

        String ref = prefix + "|" + element.getName();
        String uniqueName = UUID.randomUUID().toString() + '.' + "comparator.dat";
        try {
          InstancesDistributor.distribute(comparator, uniqueName, conf);
          instanceFiles.add(uniqueName);
        } catch (Exception e) {
          throw new TupleMRException(
              "The class " + comparator.getClass().getName() + " can't be serialized", e);
        }

        comparatorRefs.add(ref);
        comparatorInstanceFiles.add(uniqueName);
      }
    }

    return instanceFiles;
  }