PageRenderTime 20ms CodeModel.GetById 9ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/release-0.2.0-rc0/hive/external/contrib/src/java/org/apache/hadoop/hive/contrib/mr/example/WordCountReduce.java

#
Java | 50 lines | 21 code | 7 blank | 22 comment | 1 complexity | 7ef5757017dee529e8279a567796e1b3 MD5 | raw file
 1/**
 2 * Licensed to the Apache Software Foundation (ASF) under one
 3 * or more contributor license agreements.  See the NOTICE file
 4 * distributed with this work for additional information
 5 * regarding copyright ownership.  The ASF licenses this file
 6 * to you under the Apache License, Version 2.0 (the
 7 * "License"); you may not use this file except in compliance
 8 * with the License.  You may obtain a copy of the License at
 9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18package org.apache.hadoop.hive.contrib.mr.example;
19
20import java.util.Iterator;
21
22import org.apache.hadoop.hive.contrib.mr.GenericMR;
23import org.apache.hadoop.hive.contrib.mr.Output;
24import org.apache.hadoop.hive.contrib.mr.Reducer;
25
26/**
27 * Example Reducer (WordCount).
28 */
29public final class WordCountReduce {
30
31  private WordCountReduce() {
32    // prevent instantiation
33  }
34
35  public static void main(final String[] args) throws Exception {
36    new GenericMR().reduce(System.in, System.out, new Reducer() {
37      public void reduce(String key, Iterator<String[]> records, Output output)
38          throws Exception {
39        int count = 0;
40
41        while (records.hasNext()) {
42          // note we use col[1] -- the key is provided again as col[0]
43          count += Integer.parseInt(records.next()[1]);
44        }
45
46        output.collect(new String[] {key, String.valueOf(count)});
47      }
48    });
49  }
50}