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.ArrayList; 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.Mapper; 031 import org.apache.hadoop.mapred.Reducer; 032 033 /** 034 * This abstract class implements some common functionalities of the 035 * the generic mapper, reducer and combiner classes of Aggregate. 036 * @deprecated Use 037 * {@link org.apache.hadoop.mapreduce.lib.aggregate.ValueAggregatorJobBase} 038 * instead 039 */ 040 @Deprecated 041 @InterfaceAudience.Public 042 @InterfaceStability.Stable 043 public abstract class ValueAggregatorJobBase<K1 extends WritableComparable, 044 V1 extends Writable> 045 implements Mapper<K1, V1, Text, Text>, Reducer<Text, Text, Text, Text> { 046 047 protected ArrayList<ValueAggregatorDescriptor> aggregatorDescriptorList = null; 048 049 public void configure(JobConf job) { 050 this.initializeMySpec(job); 051 this.logSpec(); 052 } 053 054 private static ValueAggregatorDescriptor getValueAggregatorDescriptor( 055 String spec, JobConf job) { 056 if (spec == null) 057 return null; 058 String[] segments = spec.split(",", -1); 059 String type = segments[0]; 060 if (type.compareToIgnoreCase("UserDefined") == 0) { 061 String className = segments[1]; 062 return new UserDefinedValueAggregatorDescriptor(className, job); 063 } 064 return null; 065 } 066 067 private static ArrayList<ValueAggregatorDescriptor> getAggregatorDescriptors(JobConf job) { 068 String advn = "aggregator.descriptor"; 069 int num = job.getInt(advn + ".num", 0); 070 ArrayList<ValueAggregatorDescriptor> retv = new ArrayList<ValueAggregatorDescriptor>(num); 071 for (int i = 0; i < num; i++) { 072 String spec = job.get(advn + "." + i); 073 ValueAggregatorDescriptor ad = getValueAggregatorDescriptor(spec, job); 074 if (ad != null) { 075 retv.add(ad); 076 } 077 } 078 return retv; 079 } 080 081 private void initializeMySpec(JobConf job) { 082 this.aggregatorDescriptorList = getAggregatorDescriptors(job); 083 if (this.aggregatorDescriptorList.size() == 0) { 084 this.aggregatorDescriptorList 085 .add(new UserDefinedValueAggregatorDescriptor( 086 ValueAggregatorBaseDescriptor.class.getCanonicalName(), job)); 087 } 088 } 089 090 protected void logSpec() { 091 092 } 093 094 public void close() throws IOException { 095 } 096 }