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 import java.util.Map.Entry; 024 025 import org.apache.hadoop.classification.InterfaceAudience; 026 import org.apache.hadoop.classification.InterfaceStability; 027 import org.apache.hadoop.io.Text; 028 import org.apache.hadoop.io.Writable; 029 import org.apache.hadoop.io.WritableComparable; 030 import org.apache.hadoop.mapred.OutputCollector; 031 import org.apache.hadoop.mapred.Reporter; 032 033 /** 034 * This class implements the generic mapper of Aggregate. 035 */ 036 @InterfaceAudience.Public 037 @InterfaceStability.Stable 038 public class ValueAggregatorMapper<K1 extends WritableComparable, 039 V1 extends Writable> 040 extends ValueAggregatorJobBase<K1, V1> { 041 042 /** 043 * the map function. It iterates through the value aggregator descriptor 044 * list to generate aggregation id/value pairs and emit them. 045 */ 046 public void map(K1 key, V1 value, 047 OutputCollector<Text, Text> output, Reporter reporter) throws IOException { 048 049 Iterator iter = this.aggregatorDescriptorList.iterator(); 050 while (iter.hasNext()) { 051 ValueAggregatorDescriptor ad = (ValueAggregatorDescriptor) iter.next(); 052 Iterator<Entry<Text, Text>> ens = 053 ad.generateKeyValPairs(key, value).iterator(); 054 while (ens.hasNext()) { 055 Entry<Text, Text> en = ens.next(); 056 output.collect(en.getKey(), en.getValue()); 057 } 058 } 059 } 060 061 /** 062 * Do nothing. Should not be called. 063 */ 064 public void reduce(Text arg0, Iterator<Text> arg1, 065 OutputCollector<Text, Text> arg2, 066 Reporter arg3) throws IOException { 067 throw new IOException("should not be called\n"); 068 } 069 }