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.util.Map.Entry;
022    
023    import org.apache.hadoop.classification.InterfaceAudience;
024    import org.apache.hadoop.classification.InterfaceStability;
025    import org.apache.hadoop.io.Text;
026    import org.apache.hadoop.mapred.JobConf;
027    
028    /** 
029     * This class implements the common functionalities of 
030     * the subclasses of ValueAggregatorDescriptor class.
031     * 
032     * @deprecated Use 
033     * {@link org.apache.hadoop.mapreduce.lib.aggregate.ValueAggregatorBaseDescriptor}
034     * instead
035     */
036    @Deprecated
037    @InterfaceAudience.Public
038    @InterfaceStability.Stable
039    public class ValueAggregatorBaseDescriptor extends org.apache.hadoop.mapreduce.
040        lib.aggregate.ValueAggregatorBaseDescriptor 
041        implements ValueAggregatorDescriptor {
042    
043      static public final String UNIQ_VALUE_COUNT = org.apache.hadoop.mapreduce.
044        lib.aggregate.ValueAggregatorBaseDescriptor.UNIQ_VALUE_COUNT;
045    
046      static public final String LONG_VALUE_SUM = org.apache.hadoop.mapreduce.
047        lib.aggregate.ValueAggregatorBaseDescriptor.LONG_VALUE_SUM;
048    
049      static public final String DOUBLE_VALUE_SUM = org.apache.hadoop.mapreduce.
050        lib.aggregate.ValueAggregatorBaseDescriptor.DOUBLE_VALUE_SUM;
051    
052      static public final String VALUE_HISTOGRAM = org.apache.hadoop.mapreduce.
053        lib.aggregate.ValueAggregatorBaseDescriptor.VALUE_HISTOGRAM;
054      
055      static public final String LONG_VALUE_MAX = org.apache.hadoop.mapreduce.
056        lib.aggregate.ValueAggregatorBaseDescriptor.LONG_VALUE_MAX;
057      
058      static public final String LONG_VALUE_MIN = org.apache.hadoop.mapreduce.
059        lib.aggregate.ValueAggregatorBaseDescriptor.LONG_VALUE_MIN;
060      
061      static public final String STRING_VALUE_MAX = org.apache.hadoop.mapreduce.
062        lib.aggregate.ValueAggregatorBaseDescriptor.STRING_VALUE_MAX;
063      
064      static public final String STRING_VALUE_MIN = org.apache.hadoop.mapreduce.
065        lib.aggregate.ValueAggregatorBaseDescriptor.STRING_VALUE_MIN;
066    
067      private static long maxNumItems = Long.MAX_VALUE; 
068      
069     /**
070       * 
071       * @param type the aggregation type
072       * @param id the aggregation id
073       * @param val the val associated with the id to be aggregated
074       * @return an Entry whose key is the aggregation id prefixed with 
075       * the aggregation type.
076       */
077      public static Entry<Text, Text> generateEntry(String type, String id, Text val) {
078        return org.apache.hadoop.mapreduce.lib.aggregate.
079          ValueAggregatorBaseDescriptor.generateEntry(type, id, val);
080      }
081    
082      /**
083       * 
084       * @param type the aggregation type
085       * @return a value aggregator of the given type.
086       */
087      static public ValueAggregator generateValueAggregator(String type) {
088        ValueAggregator retv = null;
089        if (type.compareToIgnoreCase(LONG_VALUE_SUM) == 0) {
090          retv = new LongValueSum();
091        } if (type.compareToIgnoreCase(LONG_VALUE_MAX) == 0) {
092          retv = new LongValueMax();
093        } else if (type.compareToIgnoreCase(LONG_VALUE_MIN) == 0) {
094          retv = new LongValueMin();
095        } else if (type.compareToIgnoreCase(STRING_VALUE_MAX) == 0) {
096          retv = new StringValueMax();
097        } else if (type.compareToIgnoreCase(STRING_VALUE_MIN) == 0) {
098          retv = new StringValueMin();
099        } else if (type.compareToIgnoreCase(DOUBLE_VALUE_SUM) == 0) {
100          retv = new DoubleValueSum();
101        } else if (type.compareToIgnoreCase(UNIQ_VALUE_COUNT) == 0) {
102          retv = new UniqValueCount(maxNumItems);
103        } else if (type.compareToIgnoreCase(VALUE_HISTOGRAM) == 0) {
104          retv = new ValueHistogram();
105        }
106        return retv;
107      }
108    
109      /**
110       * get the input file name.
111       * 
112       * @param job a job configuration object
113       */
114      public void configure(JobConf job) {
115        super.configure(job);
116        maxNumItems = job.getLong("aggregate.max.num.unique.values",
117                                  Long.MAX_VALUE);
118      }
119    }