@Test
public void testGenericReflectConflict() throws IOException {
final Random rand = new Random();
rand.setSeed(12345);
Configuration conf = new Configuration();
Pipeline pipeline = new MRPipeline(AvroModeIT.class, conf);
Source<GenericData.Record> source = From.avroFile(
tmpDir.copyResourceFileName("strings-100.avro"),
Avros.generics(GENERIC_SCHEMA));
PTable<Long, float[]> mapPhase = pipeline
.read(source)
.parallelDo(new DoFn<GenericData.Record, Pair<Long, float[]>>() {
@Override
public void process(GenericData.Record input, Emitter<Pair<Long, float[]>> emitter) {
emitter.emit(Pair.of(
Long.valueOf(input.get("text").toString().length()),
new float[] {rand.nextFloat(), rand.nextFloat()}));
}
}, Avros.tableOf(Avros.longs(), FLOAT_ARRAY));
PTable<Long, float[]> result = mapPhase
.groupByKey()
.combineValues(new Aggregator<float[]>() {
float[] accumulator = null;
@Override
public Iterable<float[]> results() {
return ImmutableList.of(accumulator);
}
@Override
public void initialize(Configuration conf) {
}
@Override
public void reset() {
this.accumulator = null;
}
@Override
public void update(float[] value) {
if (accumulator == null) {
accumulator = Arrays.copyOf(value, 2);
} else {
for (int i = 0; i < value.length; i += 1) {
accumulator[i] += value[i];
}
}
}
});
pipeline.writeTextFile(result, tmpDir.getFileName("unused"));
Assert.assertTrue("Should succeed", pipeline.done().succeeded());
}