| 1 | package Hadoop::IO::SequenceFile; | ||||||||||||||
| 2 | 1 | $Hadoop::IO::SequenceFile::VERSION = '0.003'; | |||||||||||||
| 3 | 1 | ▶ | use 5.010; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | 1 | ▶ | use Digest::MD5 qw/md5/; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | |||||||||||||||
| 9 | |||||||||||||||
| 10 | 0 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||
| 11 | 0 | my ($class, %args) = @_; | |||||||||||||
| 12 | |||||||||||||||
| 13 | my $writer = delete $args{writer} | ||||||||||||||
| 14 | 0 | ▶ | or die "$class: missing required argument 'writer'"; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 15 | my $key_class = delete $args{key_class} | ||||||||||||||
| 16 | 0 | ▶ | // "Hadoop::IO::SequenceFile::BytesWriteable"; | ||||||||||||
|
Condition0%0/2
delete $args{"key_class"} // "Hadoop::IO::SequenceFile::BytesWriteable"
MC/DC0%0/1
delete $args{"key_class"} // "Hadoop::IO::SequenceFile::BytesWriteable"
delete $args{"key_class"}
Truth table0%0/2
A
A= delete $args{"key_class"}
| |||||||||||||||
| 17 | my $val_class = delete $args{val_class} | ||||||||||||||
| 18 | 0 | ▶ | // "Hadoop::IO::SequenceFile::Text"; | ||||||||||||
|
Condition0%0/2
delete $args{"val_class"} // "Hadoop::IO::SequenceFile::Text"
MC/DC0%0/1
delete $args{"val_class"} // "Hadoop::IO::SequenceFile::Text"
delete $args{"val_class"}
Truth table0%0/2
A
A= delete $args{"val_class"}
| |||||||||||||||
| 19 | |||||||||||||||
| 20 | 0 | my $writer_cb; | |||||||||||||
| 21 | 0 | ▶ | if (ref $writer eq "CODE") { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 22 | 0 | $writer_cb = $writer; | |||||||||||||
| 23 | 0 | } elsif (eval { $writer->can("write") }) { | |||||||||||||
| 24 | 0 | ▶ | $writer_cb = sub { $writer->write(@_) }; | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 25 | } else { | ||||||||||||||
| 26 | 0 | die "$class: bad 'writer' value: should be either coderef or instance of a writer."; | |||||||||||||
| 27 | } | ||||||||||||||
| 28 | |||||||||||||||
| 29 | |||||||||||||||
| 30 | 0 | ▶ | die "$class: bad options " . join(", ", map "'$_'", keys %args) if %args; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 31 | |||||||||||||||
| 32 | 0 | return bless { | |||||||||||||
| 33 | writer_cb => $writer_cb, | ||||||||||||||
| 34 | key_class => $key_class, | ||||||||||||||
| 35 | val_class => $val_class, | ||||||||||||||
| 36 | sync => md5(time), | ||||||||||||||
| 37 | }, $class; | ||||||||||||||
| 38 | } | ||||||||||||||
| 39 | |||||||||||||||
| 40 | 0 | ▶ | sub _write { | ||||||||||||
|
Subroutine
_write: not called CC=1 SCAR=6.9
| |||||||||||||||
| 41 | 0 | my ($self, $value, $flush) = @_; | |||||||||||||
| 42 | 0 | $self->{writer_cb}->($value, $flush); | |||||||||||||
| 43 | } | ||||||||||||||
| 44 | |||||||||||||||
| 45 | 0 | ▶ | sub _write_int { | ||||||||||||
|
Subroutine
_write_int: not called CC=1 SCAR=6.9
| |||||||||||||||
| 46 | 0 | my ($self, $value) = @_; | |||||||||||||
| 47 | 0 | $self->_write(pack "L>", $value); | |||||||||||||
| 48 | } | ||||||||||||||
| 49 | |||||||||||||||
| 50 | 0 | ▶ | sub _write_boolean { | ||||||||||||
|
Subroutine
_write_boolean: not called CC=2 SCAR=17.9
| |||||||||||||||
| 51 | 0 | my ($self, $value) = @_; | |||||||||||||
| 52 | 0 | ▶ | $self->_write($value ? "\x01" : "\x00"); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 53 | } | ||||||||||||||
| 54 | |||||||||||||||
| 55 | 0 | ▶ | sub _write_string { | ||||||||||||
|
Subroutine
_write_string: not called CC=1 SCAR=6.9
| |||||||||||||||
| 56 | 0 | my ($self, $value) = @_; | |||||||||||||
| 57 | 0 | $self->_write(Hadoop::IO::SequenceFile::Text->encode($value)); | |||||||||||||
| 58 | } | ||||||||||||||
| 59 | |||||||||||||||
| 60 | |||||||||||||||
| 61 | 0 | ▶ | sub write_header { | ||||||||||||
|
Subroutine
write_header: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||
| 62 | 0 | my ($self) = @_; | |||||||||||||
| 63 | |||||||||||||||
| 64 | 0 | my $key_class = $self->{key_class}->class_name; | |||||||||||||
| 65 | 0 | my $val_class = $self->{val_class}->class_name; | |||||||||||||
| 66 | |||||||||||||||
| 67 | 0 | my $rec_compression = 0; # "org.apache.hadoop.io.compress.GzipCodec"; | |||||||||||||
| 68 | 0 | my $blk_compression = 0; | |||||||||||||
| 69 | |||||||||||||||
| 70 | 0 | $self->_write("SEQ\x06"); | |||||||||||||
| 71 | 0 | $self->_write_string($key_class); | |||||||||||||
| 72 | 0 | $self->_write_string($val_class); | |||||||||||||
| 73 | 0 | $self->_write_boolean($rec_compression); | |||||||||||||
| 74 | 0 | $self->_write_boolean($blk_compression); | |||||||||||||
| 75 | 0 | ▶ | if ($rec_compression) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 76 | 0 | $self->_write_string($rec_compression); | |||||||||||||
| 77 | } | ||||||||||||||
| 78 | 0 | $self->_write_metadata(); | |||||||||||||
| 79 | 0 | $self->_write($self->{sync}); | |||||||||||||
| 80 | } | ||||||||||||||
| 81 | |||||||||||||||
| 82 | 0 | ▶ | sub _write_metadata { | ||||||||||||
|
Subroutine
_write_metadata: not called CC=1 SCAR=6.9
| |||||||||||||||
| 83 | 0 | my ($self) = @_; | |||||||||||||
| 84 | |||||||||||||||
| 85 | 0 | my $nkeys = 0; | |||||||||||||
| 86 | |||||||||||||||
| 87 | 0 | $self->_write_int($nkeys); | |||||||||||||
| 88 | } | ||||||||||||||
| 89 | |||||||||||||||
| 90 | 0 | ▶ | sub _write_sync { | ||||||||||||
|
Subroutine
_write_sync: not called CC=1 SCAR=6.9
| |||||||||||||||
| 91 | 0 | my ($self) = @_; | |||||||||||||
| 92 | 0 | $self->_write_int(-1); | |||||||||||||
| 93 | 0 | $self->_write($self->{sync}); | |||||||||||||
| 94 | } | ||||||||||||||
| 95 | |||||||||||||||
| 96 | |||||||||||||||
| 97 | 0 | ▶ | sub write_record { | ||||||||||||
|
Subroutine
write_record: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 98 | 0 | my ($self, $key, $val) = @_; | |||||||||||||
| 99 | |||||||||||||||
| 100 | 0 | my $buf = $self->{key_class}->encode($key); | |||||||||||||
| 101 | 0 | my $key_len = length $buf; | |||||||||||||
| 102 | 0 | $buf .= $self->{val_class}->encode($val); | |||||||||||||
| 103 | |||||||||||||||
| 104 | 0 | $self->_write(pack "L>", length $buf); | |||||||||||||
| 105 | 0 | $self->_write(pack "L>", $key_len); | |||||||||||||
| 106 | 0 | $self->_write($buf); | |||||||||||||
| 107 | |||||||||||||||
| 108 | 0 | $self->_write_sync(); | |||||||||||||
| 109 | } | ||||||||||||||
| 110 | |||||||||||||||
| 111 | |||||||||||||||
| 112 | 0 | ▶ | sub write_row { | ||||||||||||
|
Subroutine
write_row: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 113 | 0 | my ($self, @fields) = @_; | |||||||||||||
| 114 | 0 | my $val = join "\x01", @fields; | |||||||||||||
| 115 | 0 | $self->write_record("", $val); | |||||||||||||
| 116 | } | ||||||||||||||
| 117 | |||||||||||||||
| 118 | 1 | 1; | |||||||||||||
| 119 | |||||||||||||||
| 120 | __END__ | ||||||||||||||