private static <K, V> GroupingOptions buildGroupingOptions(PTable<K, V> ptable, Configuration conf,
int numReducers, ColumnOrder[] columnOrders) {
PTypeFamily tf = ptable.getTypeFamily();
PType<K> keyType = ptable.getKeyType();
Builder builder = GroupingOptions.builder();
if (tf == WritableTypeFamily.getInstance()) {
if (columnOrders.length == 1 && columnOrders[0].order == Order.DESCENDING) {
builder.sortComparatorClass(ReverseWritableComparator.class);
} else {
TupleWritableComparator.configureOrdering(conf, columnOrders);
builder.sortComparatorClass(TupleWritableComparator.class);
}
} else if (tf == AvroTypeFamily.getInstance()) {
AvroType<K> avroType = (AvroType<K>) keyType;
Schema schema = avroType.getSchema();
builder.conf("crunch.schema", schema.toString());
if (columnOrders.length == 1 && columnOrders[0].order == Order.DESCENDING) {
builder.sortComparatorClass(ReverseAvroComparator.class);
}
} else {
throw new RuntimeException("Unrecognized type family: " + tf);
}
configureReducers(builder, ptable, conf, numReducers);
return builder.build();
}