new Sort.ColumnOrder[] { by(1, ASCENDING), by(2, DESCENDING) }, new String[] { "A", "this doc has this text" });
}
@Test
public void testAvroReflectSortPair() throws IOException {
Pipeline pipeline = new SparkPipeline("local", "sort");
pipeline.enableDebug();
String rsrc = tmpDir.copyResourceFileName("set2.txt");
PCollection<Pair<String, StringWrapper>> in = pipeline.readTextFile(rsrc)
.parallelDo(new MapFn<String, Pair<String, StringWrapper>>() {
@Override
public Pair<String, StringWrapper> map(String input) {
return Pair.of(input, wrap(input));
}
}, Avros.pairs(Avros.strings(), Avros.reflects(StringWrapper.class)));
PCollection<Pair<String, StringWrapper>> sorted = Sort.sort(in, Sort.Order.ASCENDING);
List<Pair<String, StringWrapper>> expected = Lists.newArrayList();
expected.add(Pair.of("a", wrap("a")));
expected.add(Pair.of("c", wrap("c")));
expected.add(Pair.of("d", wrap("d")));
assertEquals(expected, Lists.newArrayList(sorted.materialize()));
pipeline.done();
}