line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Hadoop::Streaming::Reducer::Input; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$Hadoop::Streaming::Reducer::Input::VERSION = '0.122420'; |
4
|
|
|
|
|
|
|
} |
5
|
1
|
|
|
1
|
|
7
|
use Any::Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
6
|
1
|
|
|
1
|
|
963
|
use Hadoop::Streaming::Reducer::Input::Iterator; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
314
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
#ABSTRACT: Parse input stream for reducer |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has handle => ( |
11
|
|
|
|
|
|
|
is => 'ro', |
12
|
|
|
|
|
|
|
does => 'FileHandle', |
13
|
|
|
|
|
|
|
required => 1, |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has buffer => ( |
17
|
|
|
|
|
|
|
is => 'rw', |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub next_key |
22
|
|
|
|
|
|
|
{ |
23
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
24
|
0
|
0
|
|
|
|
|
my $line = $self->buffer ? $self->buffer : $self->next_line; |
25
|
0
|
0
|
|
|
|
|
return if not defined $line; |
26
|
0
|
|
|
|
|
|
my ( $key, $value ) = split /\t/, $line, 2; |
27
|
0
|
|
|
|
|
|
return $key; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub next_line { |
32
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
33
|
0
|
0
|
|
|
|
|
return if $self->handle->eof; |
34
|
0
|
|
|
|
|
|
$self->buffer( $self->handle->getline ); |
35
|
0
|
|
|
|
|
|
$self->buffer; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub getline { |
40
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
41
|
0
|
0
|
|
|
|
|
if (defined $self->buffer) { |
42
|
0
|
|
|
|
|
|
my $buf = $self->buffer; |
43
|
0
|
|
|
|
|
|
$self->buffer(undef); |
44
|
0
|
|
|
|
|
|
return $buf; |
45
|
|
|
|
|
|
|
} else { |
46
|
0
|
|
|
|
|
|
return $self->next_line; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub iterator { |
52
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
53
|
0
|
|
|
|
|
|
Hadoop::Streaming::Reducer::Input::Iterator->new( input => $self ); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub each |
58
|
|
|
|
|
|
|
{ |
59
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
60
|
0
|
0
|
|
|
|
|
my $line = $self->getline or return; |
61
|
0
|
|
|
|
|
|
chomp $line; |
62
|
0
|
|
|
|
|
|
split /\t/, $line, 2; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
__END__ |
70
|
|
|
|
|
|
|
=pod |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 NAME |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Hadoop::Streaming::Reducer::Input - Parse input stream for reducer |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 VERSION |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
version 0.122420 |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 METHODS |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 next_key |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
$Input->next_key(); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Parses the next line into key/value (splits on tab) and returns the key portion. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Returns undef if there is no next line. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 next_line |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
$Input->next_line(); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Reads the next line into buffer and returns it. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Returns undef if there are no more lines (end of file). |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head2 getline |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
$Input->getline(); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Returns the next available line. Clears the internal line buffer if set. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head2 iterator |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
$Input->iterator(); |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Returns a new Hadoop::Streaming::Reducer::Input::Iterator for this object. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 each |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
$Input->each(); |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Grabs the next line and splits on tabs. Returns an array containing the output of the split. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 AUTHORS |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=over 4 |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item * |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
andrew grangaard <spazm@cpan.org> |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item * |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Naoya Ito <naoya@hatena.ne.jp> |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=back |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
This software is copyright (c) 2012 by Naoya Ito <naoya@hatena.ne.jp>. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
135
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=cut |
138
|
|
|
|
|
|
|
|