You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hbase.apache.org by bharath vissapragada <bh...@students.iiit.ac.in> on 2009/07/24 19:59:37 UTC

Doubt in implementing TableReduce Interface

Hi all,

i have implemented TableMap interface succesfully to emit <Text,Text> pairs
.. so now i must implement TableReduce interface to receive those
<Text,Text> pairs correspondingly ...  Is the following code correct

public class MyTableReduce
extends MapReduceBase
implements TableReduce<Text, Text> {

 public void reduce(Text key, Iterator<Text> values,
      OutputCollector<ImmutableBytesWritable, BatchUpdate> output,
      @SuppressWarnings("unused") Reporter reporter)
      throws IOException {
}
}

Re: Doubt in implementing TableReduce Interface

Posted by Ninad Raut <hb...@gmail.com>.
the method looks fine. Put some logging inside the reduce method to trace
the inputs to the reduce.  Here's an example... change IntWritable to Text
in your case...
 static class ReadTableReduce2 extends MapReduceBase implements
TableReduce<Text, IntWritable>{

  SortedMap<Text, Text> buzz = new TreeMap<Text, Text>();
  @Override
  public void reduce(Text key,
  Iterator<IntWritable> values,
  OutputCollector<ImmutableBytesWritable, BatchUpdate> output,
  Reporter report) throws IOException {

  Integer sum =0;
  while(values.hasNext()) {
  sum += values.next().get();
  }
  if (sum >=3) {
  BatchUpdate outval = new BatchUpdate(rowCounter.toString());
  String keyStr = key.toString();
  String[] keyArr=keyStr.split(":");
  outval.put("buzzcount:"+keyArr[1], sum.toString().getBytes());
  report.incrCounter(Counters.REDUCE_LINES, 1);
  report.setStatus("sum:"+sum);
  rowCounter++;
  output.collect(new ImmutableBytesWritable(key.getBytes()), outval);
  }

  }


On Fri, Jul 24, 2009 at 11:29 PM, bharath vissapragada <
bharat_v@students.iiit.ac.in> wrote:

> Hi all,
>
> i have implemented TableMap interface succesfully to emit <Text,Text> pairs
> .. so now i must implement TableReduce interface to receive those
> <Text,Text> pairs correspondingly ...  Is the following code correct
>
> public class MyTableReduce
> extends MapReduceBase
> implements TableReduce<Text, Text> {
>
>  public void reduce(Text key, Iterator<Text> values,
>      OutputCollector<ImmutableBytesWritable, BatchUpdate> output,
>      @SuppressWarnings("unused") Reporter reporter)
>      throws IOException {
> }
> }
>