001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019 package org.apache.hadoop.mapred.lib.aggregate; 020 021 import java.io.IOException; 022 import java.util.Iterator; 023 024 import org.apache.hadoop.classification.InterfaceAudience; 025 import org.apache.hadoop.classification.InterfaceStability; 026 import org.apache.hadoop.io.Text; 027 import org.apache.hadoop.io.Writable; 028 import org.apache.hadoop.io.WritableComparable; 029 import org.apache.hadoop.mapred.JobConf; 030 import org.apache.hadoop.mapred.OutputCollector; 031 import org.apache.hadoop.mapred.Reporter; 032 033 /** 034 * This class implements the generic combiner of Aggregate. 035 * @deprecated Use 036 * {@link org.apache.hadoop.mapreduce.lib.aggregate.ValueAggregatorCombiner} 037 * instead 038 */ 039 @Deprecated 040 @InterfaceAudience.Public 041 @InterfaceStability.Stable 042 public class ValueAggregatorCombiner<K1 extends WritableComparable, 043 V1 extends Writable> 044 extends ValueAggregatorJobBase<K1, V1> { 045 046 /** 047 * Combiner does not need to configure. 048 */ 049 public void configure(JobConf job) { 050 051 } 052 053 /** Combines values for a given key. 054 * @param key the key is expected to be a Text object, whose prefix indicates 055 * the type of aggregation to aggregate the values. 056 * @param values the values to combine 057 * @param output to collect combined values 058 */ 059 public void reduce(Text key, Iterator<Text> values, 060 OutputCollector<Text, Text> output, Reporter reporter) throws IOException { 061 String keyStr = key.toString(); 062 int pos = keyStr.indexOf(ValueAggregatorDescriptor.TYPE_SEPARATOR); 063 String type = keyStr.substring(0, pos); 064 ValueAggregator aggregator = ValueAggregatorBaseDescriptor 065 .generateValueAggregator(type); 066 while (values.hasNext()) { 067 aggregator.addNextValue(values.next()); 068 } 069 Iterator outputs = aggregator.getCombinerOutput().iterator(); 070 071 while (outputs.hasNext()) { 072 Object v = outputs.next(); 073 if (v instanceof Text) { 074 output.collect(key, (Text)v); 075 } else { 076 output.collect(key, new Text(v.toString())); 077 } 078 } 079 } 080 081 /** 082 * Do nothing. 083 * 084 */ 085 public void close() throws IOException { 086 087 } 088 089 /** 090 * Do nothing. Should not be called. 091 * 092 */ 093 public void map(K1 arg0, V1 arg1, OutputCollector<Text, Text> arg2, 094 Reporter arg3) throws IOException { 095 throw new IOException ("should not be called\n"); 096 } 097 }