// Verify that running with a combination of reflect and specific schema
// doesn't crash
@Test
public void testCombinationOfReflectionAndSpecific() throws IOException {
Assume.assumeTrue(Avros.CAN_COMBINE_SPECIFIC_AND_REFLECT_SCHEMAS);
Pipeline pipeline = new MRPipeline(AvroReflectIT.class, tmpDir.getDefaultConfiguration());
PCollection<Pair<StringWrapper, Person>> hybridPairCollection = pipeline.readTextFile(
tmpDir.copyResourceFileName("set1.txt")).parallelDo(new MapFn<String, Pair<StringWrapper, Person>>() {
@Override
public Pair<StringWrapper, Person> map(String input) {
Person person = new Person();
person.name = input;
person.age = 42;
person.siblingnames = Lists.<CharSequence> newArrayList(input);
return Pair.of(new StringWrapper(input), person);
}
}, Avros.pairs(Avros.reflects(StringWrapper.class), Avros.records(Person.class)));
PCollection<Pair<String, Long>> countCollection = Aggregate.count(hybridPairCollection).parallelDo(
new MapFn<Pair<Pair<StringWrapper, Person>, Long>, Pair<String, Long>>() {
@Override
public Pair<String, Long> map(Pair<Pair<StringWrapper, Person>, Long> input) {
return Pair.of(input.first().first().getValue(), input.second());
}
}, Avros.pairs(Avros.strings(), Avros.longs()));
List<Pair<String, Long>> materialized = Lists.newArrayList(countCollection.materialize());
List<Pair<String, Long>> expected = Lists.newArrayList(Pair.of("a", 1L), Pair.of("b", 1L), Pair.of("c", 1L),
Pair.of("e", 1L));
Collections.sort(materialized);
assertEquals(expected, materialized);
pipeline.done();
}