PageRenderTime 44ms CodeModel.GetById 18ms 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
Possible License(s): Apache-2.0, BSD-3-Clause, JSON, CPL-1.0
  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. */
  18. package org.apache.hadoop.hive.contrib.mr.example;
  19. import java.util.Iterator;
  20. import org.apache.hadoop.hive.contrib.mr.GenericMR;
  21. import org.apache.hadoop.hive.contrib.mr.Output;
  22. import org.apache.hadoop.hive.contrib.mr.Reducer;
  23. /**
  24. * Example Reducer (WordCount).
  25. */
  26. public final class WordCountReduce {
  27. private WordCountReduce() {
  28. // prevent instantiation
  29. }
  30. public static void main(final String[] args) throws Exception {
  31. new GenericMR().reduce(System.in, System.out, new Reducer() {
  32. public void reduce(String key, Iterator<String[]> records, Output output)
  33. throws Exception {
  34. int count = 0;
  35. while (records.hasNext()) {
  36. // note we use col[1] -- the key is provided again as col[0]
  37. count += Integer.parseInt(records.next()[1]);
  38. }
  39. output.collect(new String[] {key, String.valueOf(count)});
  40. }
  41. });
  42. }
  43. }