@Test public void testCrossValidationOneSchema() throws TupleMRException, IOException { Configuration conf = getConf(); int maxIndex = SCHEMA.getFields().size() - 1; for (int randomSchema = 0; randomSchema < MAX_RANDOM_SCHEMAS; randomSchema++) { Schema schema = permuteSchema(SCHEMA); OrderBy sortCriteria = createRandomSortCriteria(schema, maxIndex + 1); // TODO could we get empty group fields ?? String[] groupFields = getFirstFields(sortCriteria, 1 + random.nextInt(sortCriteria.getElements().size() - 1)); ITuple[] tuples = new ITuple[] {new Tuple(schema), new Tuple(schema)}; for (ITuple tuple : tuples) { fillTuple(false, tuple, 0, maxIndex); } for (int minIndex = maxIndex; minIndex >= 0; minIndex--) { /* trick for speeding up the tests */ DCUtils.cleanupTemporaryInstanceCache(conf, "comparator.dat"); TupleMRConfigBuilder builder = new TupleMRConfigBuilder(); builder.addIntermediateSchema(schema); builder.setGroupByFields(groupFields); builder.setOrderBy(sortCriteria); TupleMRConfig tupleMRConf = builder.buildConf(); TupleMRConfig.set(tupleMRConf, conf); // tupleMRConf has changed -> we need a new Serialization object ser = new HadoopSerialization(conf); SortComparator sortComparator = new SortComparator(); GroupComparator groupComparator = new GroupComparator(); sortComparator.setConf(conf); groupComparator.setConf(conf); for (ITuple tuple : tuples) { fillTuple(true, tuple, minIndex, maxIndex); } for (int indexTuple1 = 0; indexTuple1 < tuples.length; indexTuple1++) { for (int indexTuple2 = indexTuple1 + 1; indexTuple2 < tuples.length; indexTuple2++) { ITuple tuple1 = tuples[indexTuple1]; ITuple tuple2 = tuples[indexTuple2]; assertSameComparison("Sort comparator", sortComparator, tuple1, tuple2); assertOppositeOrEqualsComparison(sortComparator, tuple1, tuple2); assertSameComparison("Group comparator", groupComparator, tuple1, tuple2); assertOppositeOrEqualsComparison(groupComparator, tuple1, tuple2); } } } } }
@SuppressWarnings("unchecked") public int compare(Object o1, Object o2) { return _gcmpr.compareGroup(o1, o2); }