From 7b9a82d8df247003d19042470c7c3d7a94f7884e Mon Sep 17 00:00:00 2001 From: Doug Meil Date: Wed, 31 Aug 2011 23:31:05 +0000 Subject: [PATCH] HBASE-4317 book.xml - minor cleanup of MR examples git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1163866 13f79535-47bb-0310-9956-ffa450edef68 --- src/docbkx/book.xml | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/docbkx/book.xml b/src/docbkx/book.xml index 86ffcff35e4..9ac92155030 100644 --- a/src/docbkx/book.xml +++ b/src/docbkx/book.xml @@ -126,7 +126,7 @@ TableMapReduceUtil.initTableMapperJob( job.setOutputFormatClass(NullOutputFormat.class); // because we aren't emitting anything from mapper boolean b = job.waitForCompletion(true); -if ( b == false) { +if (!b) { throw new IOException("error with job!"); } @@ -169,14 +169,14 @@ TableMapReduceUtil.initTableReducerJob( job.setNumReduceTasks(0); boolean b = job.waitForCompletion(true); -if ( b == false) { - throw new IOException("error with job!"); +if (!b) { + throw new IOException("error with job!"); } An explanation is required of what TableMapReduceUtil is doing, especially with the reducer. TableOutputFormat is being used as the outputFormat class, and several parameters are being set on the config (e.g., TableOutputFormat.OUTPUT_TABLE), as - well as setting the reducer output keys to ImmutableBytesWritable and Writable. + well as setting the reducer output key to ImmutableBytesWritable and reducer value to Writable. These could be set by the programmer on the job and conf, but TableMapReduceUtil tries to make things easier. The following is the example mapper, which will create a Put and matching the input Result and emit it. Note: this is what the CopyTable utility does. @@ -189,13 +189,12 @@ public static class MyMapper extends TableMapper<ImmutableBytesWritable, Put& context.write(row, resultToPut(row,value)); } - private static Put resultToPut(ImmutableBytesWritable key, Result result) - throws IOException { - Put put = new Put(key.get()); - for (KeyValue kv : result.raw()) { - put.add(kv); - } - return put; + private static Put resultToPut(ImmutableBytesWritable key, Result result) throws IOException { + Put put = new Put(key.get()); + for (KeyValue kv : result.raw()) { + put.add(kv); + } + return put; } } @@ -235,7 +234,7 @@ TableMapReduceUtil.initTableReducerJob( job.setNumReduceTasks(1); // at least one, adjust as required boolean b = job.waitForCompletion(true); -if ( b == false) { +if (!b) { throw new IOException("error with job!"); }