Example #1
0
  static void deserializeComparators(Configuration conf, TupleMRConfig mrConfig)
      throws TupleMRException {
    String[] comparatorRefs = conf.getStrings(CONF_COMPARATOR_REFERENCES);
    String[] comparatorInstanceFiles = conf.getStrings(CONF_COMPARATOR_INSTANCES);

    if (comparatorRefs == null) {
      return;
    }
    try {
      for (int i = 0; i < comparatorRefs.length; i++) {
        String[] ref = comparatorRefs[i].split("\\|");
        String instanceFile = comparatorInstanceFiles[i];

        // Here we use "false" as last parameter because otherwise it could be
        // an infinite loop. We will call setConf() later.
        RawComparator<?> comparator =
            InstancesDistributor.loadInstance(conf, RawComparator.class, instanceFile, false);

        if (ref[0].equals(COMMON)) {
          setComparator(mrConfig.getCommonCriteria(), ref[1], comparator);
        } else {
          setComparator(
              mrConfig.getSpecificOrderBys().get(new Integer(ref[0])), ref[1], comparator);
        }
      }
    } catch (IOException e) {
      throw new TupleMRException(e);
    }
  }
Example #2
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;
  }