/// <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())); } } }
/// <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="output">to collect combined values</param> /// <exception cref="System.IO.IOException"/> public override void Reduce(Text key, IEnumerator <Text> values, OutputCollector <Text , Text> output, Reporter reporter) { string keyStr = key.ToString(); int pos = keyStr.IndexOf(ValueAggregatorDescriptor.TypeSeparator); string type = Sharpen.Runtime.Substring(keyStr, 0, pos); ValueAggregator aggregator = ValueAggregatorBaseDescriptor.GenerateValueAggregator (type); while (values.HasNext()) { aggregator.AddNextValue(values.Next()); } IEnumerator outputs = aggregator.GetCombinerOutput().GetEnumerator(); while (outputs.HasNext()) { object v = outputs.Next(); if (v is Text) { output.Collect(key, (Text)v); } else { output.Collect(key, new Text(v.ToString())); } } }