Created
November 22, 2012 17:11
-
-
Save AndyCross/4132180 to your computer and use it in GitHub Desktop.
StreamingUnit2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//example input: Hello, Andy | |
if (!inputLine.StartsWith("Hello, ")) | |
{ | |
context.Log(string.Format("The inputLine {0} is not in the correct format", inputLine)); | |
return; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Hadoop.MapReduce; | |
namespace Elastacloud.Hadoop.StreamingUnitExample.Job.Map | |
{ | |
public class HelloWorldMapper : MapperBase | |
{ | |
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 | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//example input: Hello, Andy | |
if (!inputLine.StartsWith("Hello, ")) return; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Map | |
Andy 1 | |
Andy 1 | |
Andy 1 | |
andy 1 | |
chickenface 1 | |
why doesn't this work! 1 | |
MapLog | |
The inputLine Goodbye, Andy is not in the correct format | |
Reduce | |
Andy 3 | |
andy 1 | |
chickenface 1 | |
why doesn't this work! 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Elastacloud.Hadoop.StreamingUnitExample.Job.Map; | |
using Elastacloud.Hadoop.StreamingUnitExample.Job.Reduce; | |
using Microsoft.Hadoop.MapReduce; | |
namespace Elastacloud.Hadoop.StreamingUnitExample | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var inputArray = new[] | |
{ | |
"Hello, Andy", | |
"Hello, andy", | |
"Hello, why doesn't this work!", | |
"Hello, Andy", | |
"Hello, chickenface", | |
"Hello, Andy", | |
"Goodbye, Andy" | |
}; | |
var output = | |
StreamingUnit.Execute<HelloWorldMapper, HelloWorldReducer>(inputArray); | |
Console.WriteLine("Map"); | |
foreach (var mapperResult in output.MapperResult) | |
{ | |
Console.WriteLine(mapperResult); | |
} | |
Console.WriteLine("MapLog"); | |
foreach (var mapperLog in output.MapperLog) | |
{ | |
Console.WriteLine(mapperLog); | |
} | |
Console.WriteLine("Reduce"); | |
foreach (var reducerResult in output.ReducerResult) | |
{ | |
Console.WriteLine(reducerResult); | |
} | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment