@Retention(value=RUNTIME) @Target(value=TYPE) public static @interface ReduceOperator.Combinable
\@Combinable
public static class CountWords extends ReduceFunction<StringValue>
{
private final IntValue theInteger = new IntValue();
\@Override
public void reduce(StringValue key, Iterator<Record> records, Collector out) throws Exception
{
Record element = null;
int sum = 0;
while (records.hasNext()) {
element = records.next();
element.getField(1, this.theInteger);
// we could have equivalently used IntValue i = record.getField(1, IntValue.class);
sum += this.theInteger.getValue();
}
element.setField(1, this.theInteger);
out.collect(element);
}
public void combine(StringValue key, Iterator<Record> records, Collector out) throws Exception
{
this.reduce(key, records, out);
}
}
Copyright © 2014–2015 The Apache Software Foundation. All rights reserved.