Last active
December 29, 2015 01:49
-
-
Save soren/7596451 to your computer and use it in GitHub Desktop.
A Hadoop Word Count example implemented in Perl using Hadoop::Streaming. Tested with Java 1.6 and Hadoop 1.0.4.
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
package My::Hadoop::WordCount; | |
use Any::Moose qw(Role); | |
sub map { | |
my ($self, $line) = @_; | |
$self->emit(lc $_ => 1) foreach split /[\s.,:;!?]+/, $line; | |
} | |
sub reduce { | |
my ($self, $key, $values) = @_; | |
my $count = 0; | |
while ($values->has_next) { | |
$count++; | |
$values->next; | |
} | |
$self->emit($key, $count); | |
} | |
package My::Hadoop::WordCount::Mapper; | |
use Any::Moose; | |
with qw(Hadoop::Streaming::Mapper My::Hadoop::WordCount); | |
package My::Hadoop::WordCount::Reducer; | |
use Any::Moose; | |
with qw(Hadoop::Streaming::Reducer My::Hadoop::WordCount); | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment