Skip to content

Instantly share code, notes, and snippets.

@libjack
Created May 16, 2013 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save libjack/5591845 to your computer and use it in GitHub Desktop.
Save libjack/5591845 to your computer and use it in GitHub Desktop.
example custom reducer script for Hive
#!/usr/bin/perl
undef $currentId;
@vals=();
while (<STDIN>) {
chomp();
processRow(split(/\t/));
}
output();
sub output() {
print $currentId . "\t" . join(",", @vals) . "\n";
}
sub processRow() {
my ($id, @ll) = @_;
if (! defined($currentId)) {
$currentId = $id;
push(@vals, @ll);
return;
}
if ($currentId ne $id) {
output();
$currentId = $id;
@vals=(@ll);
return;
}
push(@vals, @ll);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment