// TODO: Make secondary sorting optional, and come up with a function to generate
// a sortable key (vs just using the same serialization as for sharding).
out = new Each(out, new Fields(0), new MakeSortableKey(keySortField, spec), Fields.ALL);
//put in order of shard, key, value, sortablekey
out = new Each(out, new Fields(2, 0, 1, 3), new Identity(), Fields.RESULTS);
out = new GroupBy(out, new Fields(0), new Fields(3)); // group by shard
// emit shard, key, value
out = new Each(out, new Fields(0, 1, 2), new Identity());
setTails(out);
}