public override void Map(string inputLine, MapperContext context) { var delivery = new Delivery(); double result = 0.0; context.Log("MAPPER:::START"); context.Log(inputLine); context.Log("UTF-8: " + Encoding.UTF8.GetBytes(inputLine).Length); context.Log("ASCII: " + Encoding.ASCII.GetBytes(inputLine).Length); // Read the incoming string as a Thrift Binary serialized object var inputStream = new MemoryStream(Encoding.UTF8.GetBytes(inputLine)); using (var transport = new TStreamTransport(inputStream, null)) { delivery.Read(new TBinaryProtocol(transport)); context.Log("MAPPER:::AFTER_READ"); // Get the driven kilometers from the vehicle's odometer sensor var sensorData = delivery.Vehicle.SensorHistory; var minOdo = sensorData.Min(d => d.OdoMeter); var maxOdo = sensorData.Max(d => d.OdoMeter); result = maxOdo - minOdo; context.Log("MAPPER:::BEFORE_STREAM_CLOSE"); } context.Log("MAPPER:::AFTER_STREAM_CLOSE"); // Emit the vehicle id, and the driven kilometers. if (result > 0.1) { context.EmitKeyValue(delivery.Vehicle.VehicleId, result.ToString(CultureInfo.InvariantCulture)); } context.Log("MAPPER:::END"); }
}; //ascii 58--64 + misc. public override void Map(string inputLine, MapperContext context) { foreach (string word in inputLine.Trim().Split(this._punctuationChars)) { context.IncrementCounter("mapInputs"); context.Log(string.Format("Map:: {0},{1}", word, "1")); context.EmitKeyValue(word, "1"); } }
public override void Map(string inputLine, MapperContext context) { //example input: Hello, Andy if (!inputLine.StartsWith("Hello, ")) { context.Log(string.Format("The inputLine {0} is not in the correct format", inputLine)); context.IncrementCounter("RecoverableError", "InputFormatIncorrect", 1); return; } var key = inputLine.Substring(7); if (key.EndsWith(".")) key = key.Trim('.'); context.EmitKeyValue(key, "1");//we are going to count instances, the value is irrelevant }
public override void Map(string inputLine, MapperContext context) { //example input: Hello, Andy if (!inputLine.StartsWith("Hello, ")) { context.Log(string.Format("The inputLine {0} is not in the correct format", inputLine)); context.IncrementCounter("RecoverableError", "InputFormatIncorrect", 1); return; } var key = inputLine.Substring(7); if (key.EndsWith(".")) { key = key.Trim('.'); } context.EmitKeyValue(key, "1");//we are going to count instances, the value is irrelevant }