/** {@inheritDoc} */
@Override
protected void reduce(final EmitKey key, final Iterable<EmitValue> values, final Context context) throws IOException, InterruptedException {
// get the table named by the emit key
final Table t = this.tables.get(key.getName());
// if we are non-associative, just pass the output through
// TODO: find away to avoid combiner entirely when non-associative
if (!t.isAssociative()) {
for (final EmitValue value : values)
context.write(key, value);
return;
}
// tell it we will be combining
t.setCombining(true);
// Counter counter = context.getCounter("Values Emitted",
// key.toString());
// LOG.fatal("counter for \"Values Output\"" + key.toString() + " " +
// Long.toString(counter.getValue()));
// initialize the table
t.start(key);
// set the reducer context
t.setContext(context);
for (final EmitValue value : values)
try {
t.aggregate(value.getData(), value.getMetadata());
} catch (final FinishedException e) {
// we are done
return;
} catch (final IOException e) {
// won't be robust to IOExceptions
throw e;
} catch (final InterruptedException e) {
// won't be robust to InterruptedExceptions
throw e;
} catch (final RuntimeException e) {
if (this.robust)
SizzleCombiner.LOG.error(e.getClass().getName() + " caught", e);
else
throw e;
} catch (final Exception e) {
if (this.robust)
SizzleCombiner.LOG.error(e.getClass().getName() + " caught", e);
else
throw new RuntimeException(e.getClass().getName() + " caught", e);
}
// finish it!
t.finish();
}