| 1 | package Hadoop::IO::RCFile::Reader; | ||||||||||||||||||||||||||||||||||
| 2 | 1 | $Hadoop::IO::RCFile::Reader::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 | 1 | ▶ | use integer; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use constant { | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | 1 | CURRENT_VERSION => 1, | |||||||||||||||||||||||||||||||||
| 10 | SYNC_ESCAPE => -1, | ||||||||||||||||||||||||||||||||||
| 11 | SYNC_HASH_SIZE => 16, | ||||||||||||||||||||||||||||||||||
| 12 | 1 | }; | |||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Encode (); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Hadoop::IO::RCFile::Reader::FileStreamReader; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Log::Log4perl; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use Types::Standard qw( | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 19 | ArrayRef | ||||||||||||||||||||||||||||||||||
| 20 | Bool | ||||||||||||||||||||||||||||||||||
| 21 | Dict | ||||||||||||||||||||||||||||||||||
| 22 | HashRef | ||||||||||||||||||||||||||||||||||
| 23 | InstanceOf | ||||||||||||||||||||||||||||||||||
| 24 | Int | ||||||||||||||||||||||||||||||||||
| 25 | Str | ||||||||||||||||||||||||||||||||||
| 26 | 1 | ); | |||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||
| 28 | 1 | has webhdfs_client => ( | |||||||||||||||||||||||||||||||||
| 29 | is => 'ro', | ||||||||||||||||||||||||||||||||||
| 30 | isa => InstanceOf['Net::Hadoop::WebHDFS::LWP'], | ||||||||||||||||||||||||||||||||||
| 31 | required => 1, | ||||||||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||
| 34 | 1 | has directory => ( | |||||||||||||||||||||||||||||||||
| 35 | is => 'ro', | ||||||||||||||||||||||||||||||||||
| 36 | isa => Str, | ||||||||||||||||||||||||||||||||||
| 37 | required => 1, | ||||||||||||||||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||
| 40 | 1 | has decode_utf8 => ( | |||||||||||||||||||||||||||||||||
| 41 | is => 'rw', | ||||||||||||||||||||||||||||||||||
| 42 | isa => Bool, | ||||||||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||
| 45 | 1 | has _files => ( | |||||||||||||||||||||||||||||||||
| 46 | is => 'rw', | ||||||||||||||||||||||||||||||||||
| 47 | isa => ArrayRef[ Str ], | ||||||||||||||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||
| 50 | 1 | has _file_meta => ( | |||||||||||||||||||||||||||||||||
| 51 | is => 'rw', | ||||||||||||||||||||||||||||||||||
| 52 | isa => HashRef, | ||||||||||||||||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||
| 55 | 1 | has _current_file_info => ( | |||||||||||||||||||||||||||||||||
| 56 | is => 'rw', | ||||||||||||||||||||||||||||||||||
| 57 | isa => HashRef, # Dict? | ||||||||||||||||||||||||||||||||||
| 58 | ); | ||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||
| 60 | 1 | has _total_file_count => ( | |||||||||||||||||||||||||||||||||
| 61 | is => 'rw', | ||||||||||||||||||||||||||||||||||
| 62 | isa => Int, | ||||||||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||
| 65 | 1 | has _stream_reader => ( | |||||||||||||||||||||||||||||||||
| 66 | is => 'rw', | ||||||||||||||||||||||||||||||||||
| 67 | isa => InstanceOf['Hadoop::IO::RCFile::Reader::FileStreamReader'], | ||||||||||||||||||||||||||||||||||
| 68 | ); | ||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||
| 70 | 1 | has log => ( | |||||||||||||||||||||||||||||||||
| 71 | is => 'rw', | ||||||||||||||||||||||||||||||||||
| 72 | isa => InstanceOf['Log::Log4perl::Logger'], | ||||||||||||||||||||||||||||||||||
| 73 | ); | ||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 76 | 0 | my ($self, $args) = @_; | |||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||
| 78 | 0 | $self->log(Log::Log4perl->get_logger("Hadoop::IO::RCFile::Reader")); | |||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||
| 80 | 0 | my $directory = $self->directory; | |||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||
| 82 | 0 | $self->log->info("Retrieving file list for $directory"); | |||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||
| 84 | 0 | my $hdfs_client = $self->webhdfs_client; | |||||||||||||||||||||||||||||||||
| 85 | 0 | my $directory_info = $hdfs_client->exists($directory); | |||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | if (!$directory_info) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 87 | 0 | die "$directory does not exist!"; | |||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||
| 90 | 0 | my (@files, %file_meta); | |||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | if ($directory_info->{type} eq 'DIRECTORY') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 93 | $hdfs_client->find( | ||||||||||||||||||||||||||||||||||
| 94 | $directory, | ||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 96 | 0 | my ($cwd, $e) = @_; | |||||||||||||||||||||||||||||||||
| 97 | 0 | my $file = File::Spec->catfile($cwd, $e->{pathSuffix}); | |||||||||||||||||||||||||||||||||
| 98 | 0 | push @files, $file; | |||||||||||||||||||||||||||||||||
| 99 | 0 | $file_meta{$file} = $e; | |||||||||||||||||||||||||||||||||
| 100 | }, | ||||||||||||||||||||||||||||||||||
| 101 | 0 | { re_ignore => qr{ | |||||||||||||||||||||||||||||||||
| 102 | \A # Filter some filenames out even before reaching the callback | ||||||||||||||||||||||||||||||||||
| 103 | [_.] # logs and meta data, java junk, _SUCCESS files, etc. | ||||||||||||||||||||||||||||||||||
| 104 | }xms, | ||||||||||||||||||||||||||||||||||
| 105 | }, | ||||||||||||||||||||||||||||||||||
| 106 | ); | ||||||||||||||||||||||||||||||||||
| 107 | } else { | ||||||||||||||||||||||||||||||||||
| 108 | 0 | push @files, $directory; | |||||||||||||||||||||||||||||||||
| 109 | 0 | $file_meta{$directory} = $directory_info; | |||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||
| 112 | 0 | $self->log->info("Found " . scalar(@files) . " files to read in directory $directory"); | |||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | $self->log->info("decode_utf8 is true, will decode string to utf string using decode_utf8 method") if $self->decode_utf8; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||
| 115 | 0 | $self->_files(\@files); | |||||||||||||||||||||||||||||||||
| 116 | 0 | $self->_file_meta(\%file_meta); | |||||||||||||||||||||||||||||||||
| 117 | 0 | $self->_current_file_info({ file_pos => 0, | |||||||||||||||||||||||||||||||||
| 118 | init => 0, | ||||||||||||||||||||||||||||||||||
| 119 | row_group => { row_count => 0, | ||||||||||||||||||||||||||||||||||
| 120 | next_row_idx => 0, | ||||||||||||||||||||||||||||||||||
| 121 | current_row_idx => -1, | ||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||
| 124 | ); | ||||||||||||||||||||||||||||||||||
| 125 | 0 | $self->_total_file_count(scalar @files); | |||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | sub current_row { | ||||||||||||||||||||||||||||||||
|
Subroutine
current_row: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 129 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 130 | 0 | my $current_row_idx = $self->{_current_file_info}{row_group}{current_row_idx}; | |||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | if ($current_row_idx != -1) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 132 | 0 | my $rows = $self->{_current_file_info}{row_group}{rows}; | |||||||||||||||||||||||||||||||||
| 133 | 0 | return $rows->[$current_row_idx]; | |||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||
| 135 | 0 | return; | |||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | sub next { | ||||||||||||||||||||||||||||||||
|
Subroutine
next: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 139 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | if ($self->_has_record_in_buffer()) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 141 | 0 | my $rowgroup_info = $self->{_current_file_info}{row_group}; | |||||||||||||||||||||||||||||||||
| 142 | 0 | $rowgroup_info->{current_row_idx} = $rowgroup_info->{next_row_idx}; | |||||||||||||||||||||||||||||||||
| 143 | 0 | $rowgroup_info->{next_row_idx}++; | |||||||||||||||||||||||||||||||||
| 144 | 0 | return 1; | |||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||
| 146 | 0 | my $current_file_info = $self->{_current_file_info}; | |||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||
| 148 | #check all file readed | ||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | if ($current_file_info->{file_pos} >= $self->{_total_file_count}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 150 | 0 | return 0; | |||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||
| 153 | #check current file initiated or not | ||||||||||||||||||||||||||||||||||
| 154 | 0 | my $current_file_pos = $current_file_info->{file_pos}; | |||||||||||||||||||||||||||||||||
| 155 | 0 | my $total_file_count = $self->{_total_file_count}; | |||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | for (; $current_file_pos < $total_file_count ; $current_file_pos++, $current_file_info->{file_pos}++) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | if (!$current_file_info->{init}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 158 | 0 | my $current_file = $self->{_files}[$current_file_pos]; | |||||||||||||||||||||||||||||||||
| 159 | 0 | my $file_meta = $self->{_file_meta}{$current_file}; | |||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | if ($file_meta->{length} == 0) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||
| 162 | #The file has length, 0 ignore it for now | ||||||||||||||||||||||||||||||||||
| 163 | 0 | $self->log->debug("$current_file has length 0, ignoring it"); | |||||||||||||||||||||||||||||||||
| 164 | 0 | next; | |||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||
| 166 | eval { | ||||||||||||||||||||||||||||||||||
| 167 | 0 | $self->_init($current_file); | |||||||||||||||||||||||||||||||||
| 168 | 0 | 1; | |||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | or do { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 171 | 0 | my $eval_err = $@; | |||||||||||||||||||||||||||||||||
| 172 | 0 | die "$current_file initializatoin failed: $eval_err"; | |||||||||||||||||||||||||||||||||
| 173 | }; | ||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||
| 176 | #check if we are end of file | ||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | unless ($self->{_stream_reader}->has_more()) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 178 | 0 | $current_file_info->{init} = 0; | |||||||||||||||||||||||||||||||||
| 179 | 0 | $current_file_info->{row_group} = { row_count => 0, | |||||||||||||||||||||||||||||||||
| 180 | next_row_idx => 0, | ||||||||||||||||||||||||||||||||||
| 181 | current_row_idx => -1, | ||||||||||||||||||||||||||||||||||
| 182 | }; | ||||||||||||||||||||||||||||||||||
| 183 | 0 | $self->log->debug("Current file finished, Going to read from next file"); | |||||||||||||||||||||||||||||||||
| 184 | 0 | next; | |||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||
| 187 | 0 | my $ret = $self->_read_next_row_group(); | |||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | return ($ret > 0) && $self->next(); | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$ret > 0 && $self->next
MC/DC0%0/2
$ret > 0 && $self->next
$ret > 0
$self->next
Truth table0%0/3
A && B
A= $ret > 0B= $self->next
| |||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||
| 190 | 0 | return 0; | |||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | sub _init { | ||||||||||||||||||||||||||||||||
|
Subroutine
_init: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||
| 194 | 0 | my ($self, $file_name) = @_; | |||||||||||||||||||||||||||||||||
| 195 | my $stream_reader = Hadoop::IO::RCFile::Reader::FileStreamReader->new( | ||||||||||||||||||||||||||||||||||
| 196 | webhdfs_client => $self->{webhdfs_client}, | ||||||||||||||||||||||||||||||||||
| 197 | 0 | file => $file_name, | |||||||||||||||||||||||||||||||||
| 198 | ); | ||||||||||||||||||||||||||||||||||
| 199 | 0 | $self->_stream_reader($stream_reader); | |||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||
| 201 | #Only RCF file starts with 'RCF' are supported | ||||||||||||||||||||||||||||||||||
| 202 | 0 | my @MAGIC = unpack("c3", "RCF"); | |||||||||||||||||||||||||||||||||
| 203 | 0 | my (undef, $magic) = $stream_reader->read(3); | |||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | if (!_array_equal(\@MAGIC, $magic)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 205 | 0 | die "Not a valid RCF file or format not supported"; | |||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||
| 208 | 0 | my $version = $stream_reader->read_byte(); | |||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | if ($version > CURRENT_VERSION) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 210 | 0 | die "RCF file version $version not supported"; | |||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||
| 213 | 0 | my $decompress = $stream_reader->read_byte(); | |||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | if ($decompress) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 215 | 0 | my $codec_class = $self->_read_text(); | |||||||||||||||||||||||||||||||||
| 216 | 0 | $self->{_current_file_info}{decompress} = 1; | |||||||||||||||||||||||||||||||||
| 217 | 0 | $self->{_current_file_info}{codec_class} = $codec_class; | |||||||||||||||||||||||||||||||||
| 218 | 0 | die "RCF file with Compression not supported"; | |||||||||||||||||||||||||||||||||
| 219 | } else { | ||||||||||||||||||||||||||||||||||
| 220 | 0 | $self->{_current_file_info}{decompress} = 0; | |||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||
| 222 | 0 | $self->_read_meta_data(); | |||||||||||||||||||||||||||||||||
| 223 | 0 | $self->{_current_file_info}{meta_data}{column_count} = $self->{_current_file_info}{meta_data}{'hive.io.rcfile.column.number'}; | |||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||
| 225 | 0 | my (undef, $sync) = $stream_reader->read(SYNC_HASH_SIZE); | |||||||||||||||||||||||||||||||||
| 226 | 0 | $self->{_current_file_info}{sync_bytes} = $sync; | |||||||||||||||||||||||||||||||||
| 227 | 0 | $self->{_current_file_info}{init} = 1; | |||||||||||||||||||||||||||||||||
| 228 | 0 | $self->log->info("RC reader initialization done"); | |||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | sub _has_record_in_buffer { | ||||||||||||||||||||||||||||||||
|
Subroutine
_has_record_in_buffer: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 232 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 233 | 0 | my $rowgroup_info = $self->{_current_file_info}{row_group}; | |||||||||||||||||||||||||||||||||
| 234 | 0 | return $rowgroup_info->{next_row_idx} < $rowgroup_info->{row_count}; | |||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | sub _read_next_row_group { | ||||||||||||||||||||||||||||||||
|
Subroutine
_read_next_row_group: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 238 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||
| 240 | 0 | delete $self->{_current_file_info}{row_group}{rows}; | |||||||||||||||||||||||||||||||||
| 241 | 0 | $self->_read_key_buffer(); | |||||||||||||||||||||||||||||||||
| 242 | 0 | $self->_read_value_buffer(); | |||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||
| 244 | 0 | delete $self->{_current_file_info}{row_group}{column_info}; | |||||||||||||||||||||||||||||||||
| 245 | 0 | $self->log->info("Successfilly read a row group of " . $self->{_current_file_info}{row_group}{row_count} . " rows"); | |||||||||||||||||||||||||||||||||
| 246 | 0 | return 1; | |||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | sub _read_value_buffer { | ||||||||||||||||||||||||||||||||
|
Subroutine
_read_value_buffer: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||
| 250 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 251 | 0 | my $stream_reader = $self->{_stream_reader}; | |||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||
| 253 | 0 | my @rows; | |||||||||||||||||||||||||||||||||
| 254 | 0 | my $row_count = $self->{_current_file_info}{row_group}{row_count}; | |||||||||||||||||||||||||||||||||
| 255 | 0 | my $column_count = $self->{_current_file_info}{meta_data}{column_count} + 0; | |||||||||||||||||||||||||||||||||
| 256 | 0 | my $column_info = $self->{_current_file_info}{row_group}{column_info}; | |||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | for (my $i = 0 ; $i < $row_count ; $i++) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 258 | 0 | push @rows, []; | |||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||
| 260 | 0 | for my $i (0 .. $column_count - 1) { | |||||||||||||||||||||||||||||||||
| 261 | 0 | my $per_row_len_arr = $column_info->[$i]{column_per_value_len}; | |||||||||||||||||||||||||||||||||
| 262 | 0 | my $column_buff_len = $column_info->[$i]{column_buffer_len}; | |||||||||||||||||||||||||||||||||
| 263 | 0 | my ($n, $bytes) = $stream_reader->read($column_buff_len); | |||||||||||||||||||||||||||||||||
| 264 | 0 | my $total_string = pack 'c*', @$bytes; | |||||||||||||||||||||||||||||||||
| 265 | 0 | my $off = 0; | |||||||||||||||||||||||||||||||||
| 266 | 0 | for my $j (0 .. $row_count - 1) { | |||||||||||||||||||||||||||||||||
| 267 | 0 | my $current_row = $rows[$j]; | |||||||||||||||||||||||||||||||||
| 268 | 0 | my $len = $per_row_len_arr->[$j]; | |||||||||||||||||||||||||||||||||
| 269 | 0 | my $str = substr $total_string, $off, $len; | |||||||||||||||||||||||||||||||||
| 270 | 0 | ▶ | if ( $self->decode_utf8 ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 271 | 0 | $str = Encode::decode_utf8($str); | |||||||||||||||||||||||||||||||||
| 272 | } else { | ||||||||||||||||||||||||||||||||||
| 273 | 0 | Encode::_utf8_on($str); | |||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||
| 275 | 0 | $off += $len; | |||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | if ($str ne '\\N') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 277 | 0 | push @$current_row, $str; | |||||||||||||||||||||||||||||||||
| 278 | } else { | ||||||||||||||||||||||||||||||||||
| 279 | 0 | push @$current_row, undef; | |||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||
| 284 | 0 | $self->{_current_file_info}{row_group}{rows} = \@rows; | |||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||
| 287 | 0 | ▶ | sub _read_key_buffer { | ||||||||||||||||||||||||||||||||
|
Subroutine
_read_key_buffer: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||
| 288 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 289 | 0 | my $stream_reader = $self->{_stream_reader}; | |||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||
| 291 | 0 | my $current_record_length = $self->_read_record_length(); | |||||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | return -1 if $current_record_length == -1; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 293 | 0 | my $current_key_length = $self->_read_int(); | |||||||||||||||||||||||||||||||||
| 294 | 0 | my $compressed_key_length = $self->_read_int(); | |||||||||||||||||||||||||||||||||
| 295 | 0 | ▶ | if ($self->{_current_file_info}{decompress}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||
| 297 | #TODO for compression, key is compressed | ||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||
| 299 | } else { | ||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||
| 301 | #key is not compressed, read normally | ||||||||||||||||||||||||||||||||||
| 302 | 0 | my ($row_count, $column_info) = $self->_read_key_fields(); | |||||||||||||||||||||||||||||||||
| 303 | 0 | $self->{_current_file_info}{row_group}{column_info} = $column_info; | |||||||||||||||||||||||||||||||||
| 304 | 0 | $self->{_current_file_info}{row_group}{row_count} = $row_count; | |||||||||||||||||||||||||||||||||
| 305 | 0 | $self->{_current_file_info}{row_group}{next_row_idx} = 0; | |||||||||||||||||||||||||||||||||
| 306 | 0 | $self->{_current_file_info}{row_group}{current_row_idx} = -1; | |||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||
| 310 | 0 | ▶ | sub _read_key_fields { | ||||||||||||||||||||||||||||||||
|
Subroutine
_read_key_fields: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||||||||
| 311 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 312 | 0 | my $stream_reader = $self->{_stream_reader}; | |||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||
| 314 | 0 | my $number_of_column = $self->{_current_file_info}{meta_data}{column_count} + 0; | |||||||||||||||||||||||||||||||||
| 315 | 0 | my $number_of_rows = $self->_read_v_int(); #number of rows in this record | |||||||||||||||||||||||||||||||||
| 316 | 0 | my $column_info = []; | |||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | for (my $i = 0 ; $i < $number_of_column ; $i++) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 318 | 0 | my $column_buffer_len = $self->_read_v_int(); | |||||||||||||||||||||||||||||||||
| 319 | 0 | my $column_buffer_uncompressed_len = $self->_read_v_int(); | |||||||||||||||||||||||||||||||||
| 320 | 0 | my $key_buff_len = $self->_read_v_int(); | |||||||||||||||||||||||||||||||||
| 321 | 0 | my (undef, $all_key_buffer) = $stream_reader->read($key_buff_len); | |||||||||||||||||||||||||||||||||
| 322 | 0 | my $column_per_value_length = []; | |||||||||||||||||||||||||||||||||
| 323 | 0 | $column_per_value_length->[ $number_of_rows - 1 ] = undef; | |||||||||||||||||||||||||||||||||
| 324 | 0 | my $pos = 0; | |||||||||||||||||||||||||||||||||
| 325 | 0 | my $length = 0; | |||||||||||||||||||||||||||||||||
| 326 | 0 | my $prev = -1; | |||||||||||||||||||||||||||||||||
| 327 | 0 | my $row_count = 0; | |||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | while ($pos < $key_buff_len) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 330 | { | ||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||
| 332 | #This block will read a variable length integer number to calculate $length | ||||||||||||||||||||||||||||||||||
| 333 | #For -112 <= i <= 127, only one byte is used with the actual value. | ||||||||||||||||||||||||||||||||||
| 334 | #For other values of i, the first byte value indicates whether the | ||||||||||||||||||||||||||||||||||
| 335 | #long is positive or negative, and the number of bytes that follow. | ||||||||||||||||||||||||||||||||||
| 336 | #If the first byte value v is between -113 and -120, the following long | ||||||||||||||||||||||||||||||||||
| 337 | #is positive, with number of bytes that follow are -(v+112). | ||||||||||||||||||||||||||||||||||
| 338 | #If the first byte value v is between -121 and -128, the following long | ||||||||||||||||||||||||||||||||||
| 339 | #is negative, with number of bytes that follow are -(v+120). Bytes are | ||||||||||||||||||||||||||||||||||
| 340 | #stored in the high-non-zero-byte-first order. | ||||||||||||||||||||||||||||||||||
| 341 | #Code from here | ||||||||||||||||||||||||||||||||||
| 342 | #https://github.com/apache/hadoop/blob/branch-2.8.2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/WritableUtils.java#L307 | ||||||||||||||||||||||||||||||||||
| 343 | 0 | my $first_byte = $all_key_buffer->[ $pos++ ]; | |||||||||||||||||||||||||||||||||
| 344 | 0 | ▶ | my $len = ($first_byte >= -112) ? 1 : (($first_byte < -120) ? (-119 - $first_byte) : (-111 - $first_byte)); | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 345 | 0 | ▶ | if ($len == 1) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 346 | 0 | $length = $first_byte; | |||||||||||||||||||||||||||||||||
| 347 | } else { | ||||||||||||||||||||||||||||||||||
| 348 | 0 | my $n = 0; | |||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | for (my $i = 0 ; $i < $len - 1 ; $i++, $pos++) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 350 | 0 | my $byte = $all_key_buffer->[$pos]; | |||||||||||||||||||||||||||||||||
| 351 | 0 | $n <<= 8; | |||||||||||||||||||||||||||||||||
| 352 | 0 | $n |= ($byte & 255); | |||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||
| 355 | 0 | ▶ | if (_is_negative_v_long($first_byte)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 356 | 0 | $n = ~$n; | |||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||
| 358 | 0 | $length = $n; | |||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | if ($length < 0) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 363 | 0 | $length = ~$length; | |||||||||||||||||||||||||||||||||
| 364 | 0 | ▶ | for (my $j = 0 ; $j < $length ; $j++) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 365 | 0 | $column_per_value_length->[ $row_count++ ] = $prev; | |||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||
| 367 | } else { | ||||||||||||||||||||||||||||||||||
| 368 | 0 | $column_per_value_length->[ $row_count++ ] = $length; | |||||||||||||||||||||||||||||||||
| 369 | 0 | $prev = $length; | |||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||
| 372 | 0 | push @$column_info, { column_per_value_len => $column_per_value_length, | |||||||||||||||||||||||||||||||||
| 373 | column_buffer_len => $column_buffer_len, # I think this is the total length of values for this column | ||||||||||||||||||||||||||||||||||
| 374 | column_buffer_uncompressed_len => $column_buffer_uncompressed_len, # same as up but uncompressed | ||||||||||||||||||||||||||||||||||
| 375 | }; | ||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||
| 377 | 0 | return $number_of_rows, $column_info; | |||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||
| 380 | 0 | ▶ | sub _read_record_length { | ||||||||||||||||||||||||||||||||
|
Subroutine
_read_record_length: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||
| 381 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 382 | 0 | my $stream_reader = $self->{_stream_reader}; | |||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||
| 384 | 0 | my $length = $self->_read_int(); | |||||||||||||||||||||||||||||||||
| 385 | 0 | ▶ | if ($self->{_current_file_info}{sync_bytes} && $length == SYNC_ESCAPE) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"_current_file_info"}{"sync_bytes"} and $length == -1
MC/DC0%0/2
$self->{"_current_file_info"}{"sync_bytes"} and $length == -1
$self->{"_current_file_info"}{"sync_bytes"}
$length == -1
Truth table0%0/3
A and B
A= $self->{"_current_file_info"}{"sync_bytes"}B= $length == -1
| |||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||
| 387 | # a sync entry | ||||||||||||||||||||||||||||||||||
| 388 | 0 | $self->log->debug("New Sync entry"); | |||||||||||||||||||||||||||||||||
| 389 | 0 | my ($n, $sync_check) = $stream_reader->read(SYNC_HASH_SIZE); | |||||||||||||||||||||||||||||||||
| 390 | 0 | ▶ | if (!_array_equal($sync_check, $self->{_current_file_info}{sync_bytes})) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 391 | 0 | $self->log->error("Sync bytes does not match"); | |||||||||||||||||||||||||||||||||
| 392 | 0 | die "File is corrupted"; | |||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||
| 394 | 0 | $length = $self->_read_int(); | |||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||
| 396 | 0 | return $length; | |||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||
| 399 | 0 | ▶ | sub _read_meta_data { | ||||||||||||||||||||||||||||||||
|
Subroutine
_read_meta_data: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||
| 400 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 401 | 0 | my $stream_reader = $self->{_stream_reader}; | |||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||
| 403 | 0 | my $size = $self->_read_int(); | |||||||||||||||||||||||||||||||||
| 404 | 0 | ▶ | if ($size < 0) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 405 | 0 | die "Invalid size $size for file metadata"; | |||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||
| 407 | 0 | my $meta_data = {}; | |||||||||||||||||||||||||||||||||
| 408 | 0 | ▶ | for (my $i = 0 ; $i < $size ; $i++) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 409 | 0 | my $key = $self->_read_text(); | |||||||||||||||||||||||||||||||||
| 410 | 0 | my $value = $self->_read_text(); | |||||||||||||||||||||||||||||||||
| 411 | 0 | $meta_data->{$key} = $value; | |||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||
| 413 | 0 | $self->{_current_file_info}{meta_data} = $meta_data; | |||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||
| 416 | 0 | ▶ | sub _read_text { | ||||||||||||||||||||||||||||||||
|
Subroutine
_read_text: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 417 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 418 | 0 | my $stream_reader = $self->{_stream_reader}; | |||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||
| 420 | 0 | my $size = $self->_read_v_int(); | |||||||||||||||||||||||||||||||||
| 421 | 0 | my (undef, $bytes) = $stream_reader->read($size); | |||||||||||||||||||||||||||||||||
| 422 | 0 | my $str = pack 'c*', @$bytes; | |||||||||||||||||||||||||||||||||
| 423 | 0 | ▶ | if ( $self->decode_utf8 ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 424 | 0 | $str = Encode::decode_utf8($str); | |||||||||||||||||||||||||||||||||
| 425 | } else { | ||||||||||||||||||||||||||||||||||
| 426 | 0 | Encode::_utf8_on($str); | |||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||
| 428 | 0 | return $str; | |||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||
| 431 | 0 | ▶ | sub _read_v_long { | ||||||||||||||||||||||||||||||||
|
Subroutine
_read_v_long: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||
| 433 | #For -112 <= i <= 127, only one byte is used with the actual value. | ||||||||||||||||||||||||||||||||||
| 434 | #For other values of i, the first byte value indicates whether the | ||||||||||||||||||||||||||||||||||
| 435 | #long is positive or negative, and the number of bytes that follow. | ||||||||||||||||||||||||||||||||||
| 436 | #If the first byte value v is between -113 and -120, the following long | ||||||||||||||||||||||||||||||||||
| 437 | #is positive, with number of bytes that follow are -(v+112). | ||||||||||||||||||||||||||||||||||
| 438 | #If the first byte value v is between -121 and -128, the following long | ||||||||||||||||||||||||||||||||||
| 439 | #is negative, with number of bytes that follow are -(v+120). Bytes are | ||||||||||||||||||||||||||||||||||
| 440 | #stored in the high-non-zero-byte-first order. | ||||||||||||||||||||||||||||||||||
| 441 | #https://github.com/apache/hadoop/blob/branch-2.8.2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/WritableUtils.java#L307 | ||||||||||||||||||||||||||||||||||
| 442 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 443 | 0 | my $stream_reader = $self->{_stream_reader}; | |||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||
| 445 | 0 | my $first_byte = $stream_reader->read_byte(); | |||||||||||||||||||||||||||||||||
| 446 | 0 | my $len = _decode_v_long_size($first_byte); | |||||||||||||||||||||||||||||||||
| 447 | 0 | ▶ | if ($len == 1) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 448 | 0 | return $first_byte; | |||||||||||||||||||||||||||||||||
| 449 | } else { | ||||||||||||||||||||||||||||||||||
| 450 | 0 | my $n = 0; | |||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||
| 452 | 0 | ▶ | for (my $i = 0 ; $i < $len - 1 ; $i++) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 453 | 0 | my $byte = $stream_reader->read_byte(); | |||||||||||||||||||||||||||||||||
| 454 | 0 | $n <<= 8; | |||||||||||||||||||||||||||||||||
| 455 | 0 | $n |= ($byte & 255); | |||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||
| 458 | 0 | ▶ | if (_is_negative_v_long($first_byte)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 459 | 0 | $n = ~$n; | |||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||
| 461 | 0 | return $n; | |||||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||
| 465 | 0 | ▶ | sub _is_negative_v_long { | ||||||||||||||||||||||||||||||||
|
Subroutine
_is_negative_v_long: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||
| 467 | #Given the first byte of a vint/vlong, determine the sign | ||||||||||||||||||||||||||||||||||
| 468 | #https://github.com/apache/hadoop/blob/branch-2.8.2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/WritableUtils.java#L369 | ||||||||||||||||||||||||||||||||||
| 469 | 0 | my ($value) = @_; | |||||||||||||||||||||||||||||||||
| 470 | 0 | ▶ | return ($value < -120) || (($value >= -112) && ($value <= 0)); | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
$value < -120 || $value >= -112 && $value <= 0
$value >= -112 and $value <= 0
MC/DC0%0/3
$value < -120 || $value >= -112 && $value <= 0
$value < -120
$value >= -112
$value <= 0
Truth table0%0/4
A || B and C
A= $value < -120B= $value >= -112C= $value <= 0
| |||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||
| 473 | 0 | ▶ | sub _decode_v_long_size { | ||||||||||||||||||||||||||||||||
|
Subroutine
_decode_v_long_size: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||
| 475 | #Parse the first byte of a vint/vlong to determine the number of bytes | ||||||||||||||||||||||||||||||||||
| 476 | #https://github.com/apache/hadoop/blob/branch-2.8.2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/WritableUtils.java#L378 | ||||||||||||||||||||||||||||||||||
| 477 | 0 | my ($value) = @_; | |||||||||||||||||||||||||||||||||
| 478 | 0 | ▶ | return ($value >= -112) ? 1 : (($value < -120) ? (-119 - $value) : (-111 - $value)); | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||
| 481 | 0 | ▶ | sub _read_v_int { | ||||||||||||||||||||||||||||||||
|
Subroutine
_read_v_int: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||
| 482 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||
| 484 | 0 | my $n = $self->_read_v_long(); | |||||||||||||||||||||||||||||||||
| 485 | 0 | ▶ | if ($n <= 2147483647 && $n >= -2147483648) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$n <= 2147483647 and $n >= '-2147483648'
MC/DC0%0/2
$n <= 2147483647 and $n >= '-2147483648'
$n <= 2147483647
$n >= '-2147483648'
Truth table0%0/3
A and B
A= $n <= 2147483647B= $n >= '-2147483648'
| |||||||||||||||||||||||||||||||||||
| 486 | 0 | return $n; | |||||||||||||||||||||||||||||||||
| 487 | } else { | ||||||||||||||||||||||||||||||||||
| 488 | 0 | die "value too long to fit in integer"; | |||||||||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||
| 492 | 0 | ▶ | sub _read_int { | ||||||||||||||||||||||||||||||||
|
Subroutine
_read_int: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||
| 493 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 494 | 0 | my $stream_reader = $self->{_stream_reader}; | |||||||||||||||||||||||||||||||||
| 495 | 0 | my (undef, $bytes) = $stream_reader->read(4); | |||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||
| 497 | 0 | my $number = 0; | |||||||||||||||||||||||||||||||||
| 498 | 0 | ▶ | for (my $i = 0 ; $i < 4 ; $i++) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 499 | 0 | $number <<= 8; | |||||||||||||||||||||||||||||||||
| 500 | 0 | $number |= ($bytes->[$i] & 255); | |||||||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||||||||
| 502 | 0 | ▶ | if ($number > 2147483647) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 503 | 0 | $number = $number - 4294967296; | |||||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||||
| 505 | 0 | return $number; | |||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||
| 508 | 0 | ▶ | sub _array_equal { | ||||||||||||||||||||||||||||||||
|
Subroutine
_array_equal: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||
| 509 | 0 | my ($arr_one, $arr_two) = @_; | |||||||||||||||||||||||||||||||||
| 510 | 0 | my $len_one = scalar @$arr_one; | |||||||||||||||||||||||||||||||||
| 511 | 0 | my $len_two = scalar @$arr_two; | |||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||
| 513 | 0 | ▶ | return 0 if ($len_one != $len_two); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||
| 515 | 0 | ▶ | for (my $i = 0 ; $i < $len_one ; $i++) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 516 | 0 | ▶ | return 0 if ($arr_one->[$i] != $arr_two->[$i]); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||||||||
| 518 | 0 | return 1; | |||||||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||
| 521 | 1 | 1; | |||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||
| 523 | __END__ | ||||||||||||||||||||||||||||||||||