static void setComparator(Criteria criteria, String field, RawComparator<?> comparator) { for (SortElement element : criteria.getElements()) { if (element.getName().equals(field)) { element.setCustomComparator(comparator); } } }
/** * 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; }
/** 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; }