Streaming/Reducer.pm

filter: Statementstmt 95.8% 23 / 24 Branchbran 66.6% 4 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 91.4% 32 / 35 SCAR 13.9
CC
4
Cov
90%
run
4.1
BEGIN
1.0
BEGIN
1.0
CRAP 4.0
« Streaming/Combiner.pm ↑ Summary Streaming/Mapper.pm »
1 package Hadoop::Streaming::Reducer;
2 {
3 5 $Hadoop::Streaming::Reducer::VERSION = '0.122420';
4 }
5 5 ▶use Any::Moose qw(Role);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 5 ▶use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Hadoop::Streaming::Reducer::Input;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 5 with 'Hadoop::Streaming::Role::Emitter';
11 5 requires qw/reduce/;
12  
13 # ABSTRACT: Simplify writing Hadoop Streaming jobs. Write a reduce() function and let this role handle the Stream interface. This Reducer roll provides an iterator over the multiple values for a given key.
14  
15  
16  
17 sub run {
18 4 ▶ my $class = shift;
Subroutine run: called CC=4 SCAR=14.1
Pod documented
19 4 my $self = $class->new;
20  
21 4 my $input = Hadoop::Streaming::Reducer::Input->new(handle => \*STDIN);
22 4 my $iter = $input->iterator;
23  
24 4 ▶ while ($iter->has_next) {
Branch: 1 branch
BranchTrueFalseTotal
if ($iter->has_next) 60 4 64
25 60 ▶ my ($key, $values_iter) = $iter->next or last;
Branch: 1 branch
BranchTrueFalseTotal
() = $iter->next or last 0 60 60
26 60 eval {
27 60 $self->reduce( $key => $values_iter );
28 };
29 60 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 60 60
30 0 warn $@;
31 }
32 }
33 }
34  
35 5 1;
36  
37  
38 __END__
39 =pod
40  
41 =head1 NAME
42  
43 Hadoop::Streaming::Reducer - Simplify writing Hadoop Streaming jobs. Write a reduce() function and let this role handle the Stream interface. This Reducer roll provides an iterator over the multiple values for a given key.
44  
45 =head1 VERSION
46  
47 version 0.122420
48  
49 =head1 SYNOPSIS
50  
51 #!/usr/bin/env perl
52  
53 package WordCount::Reducer;
54 use Any::Moose;
55 with qw/Hadoop::Streaming::Reducer/;
56  
57 sub reduce {
58 my ($self, $key, $values) = @_;
59  
60 my $count = 0;
61 while ( $values->has_next ) {
62 $count++;
63 $values->next;
64 }
65  
66 $self->emit( $key => $count );
67 }
68  
69 package main;
70 WordCount::Reducer->run;
71  
72 Your mapper class must implement map($key,$value) and your reducer must
73 implement reduce($key,$value). Your classes will have emit() and run()
74 methods added via the role.
75  
76 =head1 METHODS
77  
78 =head2 run
79  
80 Package->run();
81  
82 This method starts the Hadoop::Streaming::Reducer instance.
83  
84 After creating a new object instance, it reads from STDIN and calls $object->reduce( ) passing in the key and an iterator of values for that key.
85  
86 Subclasses need only implement reduce() to produce a complete Hadoop Streaming compatible reducer.
87  
88 =head1 AUTHORS
89  
90 =over 4
91  
92 =item *
93  
94 andrew grangaard <spazm@cpan.org>
95  
96 =item *
97  
98 Naoya Ito <naoya@hatena.ne.jp>
99  
100 =back
101  
102 =head1 COPYRIGHT AND LICENSE
103  
104 This software is copyright (c) 2012 by Naoya Ito <naoya@hatena.ne.jp>.
105  
106 This is free software; you can redistribute it and/or modify it under
107 the same terms as the Perl 5 programming language system itself.
108  
109 =cut
110  
« Streaming/Combiner.pm ↑ Summary Streaming/Mapper.pm »