@Override public void processNext(RecordReader reader, Output output) throws Exception { reducer.reduce(reader.peek()[0], new KeyRecordIterator( reader.peek()[0], reader), output); } });
public void reduce(final Reader in, final Writer out, final Reducer reducer) throws Exception { handle(in, out, new RecordProcessor() { @Override public void processNext(RecordReader reader, Output output) throws Exception { reducer.reduce(reader.peek()[0], new KeyRecordIterator( reader.peek()[0], reader), output); } }); }
private String[] next() { final String[] ret = next; next = readNext(); return ret; }
private void handle(final Reader in, final Writer out, final RecordProcessor processor) throws Exception { final RecordReader reader = new RecordReader(in); final OutputStreamOutput output = new OutputStreamOutput(out); try { while (reader.hasNext()) { processor.processNext(reader, output); } } finally { try { output.close(); } finally { reader.close(); } } }
public static void main(final String[] args) throws Exception { new GenericMR().reduce(System.in, System.out, new Reducer() { public void reduce(String key, Iterator<String[]> records, Output output) throws Exception { int count = 0; while (records.hasNext()) { // note we use col[1] -- the key is provided again as col[0] count += Integer.parseInt(records.next()[1]); } output.collect(new String[] {key, String.valueOf(count)}); } }); } }
@Override public void map(final String[] record, final Output output) throws Exception { output.collect(record); } });
@Override public void processNext(RecordReader reader, Output output) throws Exception { mapper.map(reader.next(), output); } });
@Override public void collect(String[] record) throws Exception { out.println(_join(record, "\t")); }
@Override public boolean hasNext() { return (reader.hasNext() && key.equals(reader.peek()[0])); }
public void reduce(final InputStream in, final OutputStream out, final Reducer reducer) throws Exception { reduce(new InputStreamReader(in), new OutputStreamWriter(out), reducer); }
public void map(final InputStream in, final OutputStream out, final Mapper mapper) throws Exception { map(new InputStreamReader(in), new OutputStreamWriter(out), mapper); }
@Override public void processNext(RecordReader reader, Output output) throws Exception { reducer.reduce(reader.peek()[0], new KeyRecordIterator( reader.peek()[0], reader), output); } });
public void map(final Reader in, final Writer out, final Mapper mapper) throws Exception { handle(in, out, new RecordProcessor() { @Override public void processNext(RecordReader reader, Output output) throws Exception { mapper.map(reader.next(), output); } }); }
private RecordReader(final Reader in) { reader = new BufferedReader(in); next = readNext(); }
public void reduce(String key, Iterator<String[]> records, Output output) throws Exception { int count = 0; while (records.hasNext()) { // note we use col[1] -- the key is provided again as col[0] count += Integer.parseInt(records.next()[1]); } output.collect(new String[] {key, String.valueOf(count)}); } });
@Override public void processNext(RecordReader reader, Output output) throws Exception { reducer.reduce(reader.peek()[0], new KeyRecordIterator( reader.peek()[0], reader), output); } });
@Override public void processNext(RecordReader reader, Output output) throws Exception { reducer.reduce(reader.peek()[0], new KeyRecordIterator( reader.peek()[0], reader), output); } });
@Override public void processNext(RecordReader reader, Output output) throws Exception { reducer.reduce(reader.peek()[0], new KeyRecordIterator( reader.peek()[0], reader), output); } });