Ejemplo n.º 1
0
        /// <summary>Combines values for a given key.</summary>
        /// <param name="key">
        /// the key is expected to be a Text object, whose prefix indicates
        /// the type of aggregation to aggregate the values.
        /// </param>
        /// <param name="values">the values to combine</param>
        /// <param name="context">to collect combined values</param>
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.Exception"/>
        protected internal override void Reduce(Text key, IEnumerable <Text> values, Reducer.Context
                                                context)
        {
            string keyStr    = key.ToString();
            int    pos       = keyStr.IndexOf(ValueAggregatorDescriptor.TypeSeparator);
            string type      = Sharpen.Runtime.Substring(keyStr, 0, pos);
            long   uniqCount = context.GetConfiguration().GetLong(UniqValueCount.MaxNumUniqueValues
                                                                  , long.MaxValue);
            ValueAggregator aggregator = ValueAggregatorBaseDescriptor.GenerateValueAggregator
                                             (type, uniqCount);

            foreach (Text val in values)
            {
                aggregator.AddNextValue(val);
            }
            IEnumerator <object> outputs = aggregator.GetCombinerOutput().GetEnumerator();

            while (outputs.HasNext())
            {
                object v = outputs.Next();
                if (v is Text)
                {
                    context.Write(key, (Text)v);
                }
                else
                {
                    context.Write(key, new Text(v.ToString()));
                }
            }
        }
Ejemplo n.º 2
0
        /// <param name="key">
        /// the key is expected to be a Text object, whose prefix indicates
        /// the type of aggregation to aggregate the values. In effect, data
        /// driven computing is achieved. It is assumed that each aggregator's
        /// getReport method emits appropriate output for the aggregator. This
        /// may be further customized.
        /// </param>
        /// <param name="values">the values to be aggregated</param>
        /// <param name="context"></param>
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.Exception"/>
        protected internal override void Reduce(Text key, IEnumerable <Text> values, Reducer.Context
                                                context)
        {
            string keyStr = key.ToString();
            int    pos    = keyStr.IndexOf(ValueAggregatorDescriptor.TypeSeparator);
            string type   = Sharpen.Runtime.Substring(keyStr, 0, pos);

            keyStr = Sharpen.Runtime.Substring(keyStr, pos + ValueAggregatorDescriptor.TypeSeparator
                                               .Length);
            long uniqCount = context.GetConfiguration().GetLong(UniqValueCount.MaxNumUniqueValues
                                                                , long.MaxValue);
            ValueAggregator aggregator = ValueAggregatorBaseDescriptor.GenerateValueAggregator
                                             (type, uniqCount);

            foreach (Text value in values)
            {
                aggregator.AddNextValue(value);
            }
            string val = aggregator.GetReport();

            key = new Text(keyStr);
            context.Write(key, new Text(val));
        }