|
Revision 19262, 0.6 kB
(checked in by lopnor, 5 years ago)
|
|
lang/perl/App-Hachero: hadoop streaming support, but not tested yet.
|
| Line | |
|---|
| 1 | package App::Hachero::Plugin::OutputLine::HadoopMap; |
|---|
| 2 | use strict; |
|---|
| 3 | use warnings; |
|---|
| 4 | use base qw(App::Hachero::Plugin::Base); |
|---|
| 5 | use JSON; |
|---|
| 6 | |
|---|
| 7 | sub output_line : Hook { |
|---|
| 8 | my ($self, $context) = @_; |
|---|
| 9 | for my $prime_key (keys %{$context->result}) { |
|---|
| 10 | my $result = $context->result->{$prime_key}; |
|---|
| 11 | for my $second_key (keys %{$result}) { |
|---|
| 12 | my $value = JSON->new->allow_blessed->encode($result->{$second_key}); |
|---|
| 13 | $self->_writeline("$prime_key-$second_key", $value); |
|---|
| 14 | } |
|---|
| 15 | } |
|---|
| 16 | $context->result( {} ); |
|---|
| 17 | } |
|---|
| 18 | |
|---|
| 19 | sub _writeline { |
|---|
| 20 | my ($self, $key, $value) = @_; |
|---|
| 21 | my $fh = \*STDOUT; |
|---|
| 22 | printf $fh "%s\t%s\n", $key, $value; |
|---|
| 23 | } |
|---|
| 24 | |
|---|
| 25 | 1; |
|---|