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
019package org.apache.hadoop.mapreduce.lib.aggregate;
020
021import java.util.ArrayList;
022import java.util.Map.Entry;
023
024import org.apache.hadoop.classification.InterfaceAudience;
025import org.apache.hadoop.classification.InterfaceStability;
026import org.apache.hadoop.conf.Configuration;
027import org.apache.hadoop.io.Text;
028
029/**
030 * This interface defines the contract a value aggregator descriptor must
031 * support. Such a descriptor can be configured with a {@link Configuration}
032 * object. Its main function is to generate a list of aggregation-id/value 
033 * pairs. An aggregation id encodes an aggregation type which is used to 
034 * guide the way to aggregate the value in the reduce/combiner phrase of an
035 * Aggregate based job. 
036 * The mapper in an Aggregate based map/reduce job may create one or more of
037 * ValueAggregatorDescriptor objects at configuration time. For each input
038 * key/value pair, the mapper will use those objects to create aggregation
039 * id/value pairs.
040 * 
041 */
042@InterfaceAudience.Public
043@InterfaceStability.Stable
044public interface ValueAggregatorDescriptor {
045
046  public static final String TYPE_SEPARATOR = ":";
047
048  public static final Text ONE = new Text("1");
049
050  /**
051   * Generate a list of aggregation-id/value pairs for 
052   * the given key/value pair.
053   * This function is usually called by the mapper of an Aggregate based job.
054   * 
055   * @param key
056   *          input key
057   * @param val
058   *          input value
059   * @return a list of aggregation id/value pairs. An aggregation id encodes an
060   *         aggregation type which is used to guide the way to aggregate the
061   *         value in the reduce/combiner phrase of an Aggregate based job.
062   */
063  public ArrayList<Entry<Text, Text>> generateKeyValPairs(Object key,
064                                                          Object val);
065
066  /**
067   * Configure the object
068   * 
069   * @param conf
070   *          a Configuration object that may contain the information 
071   *          that can be used to configure the object.
072   */
073  public void configure(Configuration conf);
074}