Metadata/Query/default.pm

filter: Statementstmt 63.4% 168 / 265 Branchbran 41.9% 57 / 136 Conditioncond 16.6% 3 / 18 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 66.6% 12 / 18 Podpod 0.0% 0 / 9 totaltotal 52.5% 240 / 457 CC 85 SCAR 46.0
CC
85
Cov
54%
select_benchmark_values
165.1
create_select_column
80.7
create_period_check
56.0
CRAP 99.4
↑ Summary Metadata.pm »
1 package Tapper::Metadata::Query::default;
2 1 our $AUTHORITY = 'cpan:TAPPER';
3 1 $Tapper::Metadata::Query::default::VERSION = '5.0.1';
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 base 'Tapper::Metadata::Query';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use List::MoreUtils qw( any );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 my %h_used_selects;
11 1 my %h_default_columns = (
12 'TESTRUN' => { column => 't.id' },
13 'TESTPLAN' => { column => 't.testplan_id' },
14 'HEADER_ID' => { column => 'h.testrun_metadata_header_id' },
15 'STATS_FAILED' => { column => 'rgts.failed', addon => 'stats_table' },
16 );
17 0 ▶my $fn_numeric_operators = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
18 return $_[0]->{options} && $_[0]->{options}{numeric}
19 0 ▶ ? "$_[0]->{column} $_[0]->{operator} (0 + ?)"
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'options'} && $_[0]{'options'}{'numeric'} ? : 0 0 0
Condition0%0/3
$_[0]{"options"} and $_[0]{"options"}{"numeric"}
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0]{"options"} and $_[0]{"options"}{"numeric"}
$_[0]{"options"} $_[0]{"options"}{"numeric"}
Truth table0%0/3
A and B
A= $_[0]{"options"}B= $_[0]{"options"}{"numeric"}
ABresult
0X0
100
111
20 : "$_[0]->{column} $_[0]->{operator} ?"
21 ;
22 1 };
23 my %h_operators = (
24 '=' => {
25 rank => 0,
26 15 ▶ where => sub {
Subroutine __ANON__: called CC=2 SCAR=9.2
27 15 return @{$_[0]->{values}} > 1
28 0 ▶ ? "$_[0]->{column} IN (" . (join ',', map {'?'} @{$_[0]->{values}}) . ')'
Branch: 1 branch
BranchTrueFalseTotal
@{$_[0]{'values'};} > 1 ? : 0 15 15
29 : "$_[0]->{column} = ?"
30 },
31 },
32 '!=' => {
33 rank => 1,
34 0 ▶ where => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
35 0 return @{$_[0]->{values}} > 1
36 0 ▶ ? "$_[0]->{column} NOT IN (" . (join ',', map {'?'} @{$_[0]->{values}}) . ')'
Branch: 1 branch
BranchTrueFalseTotal
@{$_[0]{'values'};} > 1 ? : 0 0 0
37 : "$_[0]->{column} != ?"
38 }
39 },
40 '<=' => {
41 rank => 2,
42 numeric => 1,
43 where => $fn_numeric_operators,
44 },
45 '>=' => {
46 rank => 3,
47 numeric => 1,
48 where => $fn_numeric_operators,
49 },
50 '<' => {
51 rank => 4,
52 numeric => 1,
53 where => $fn_numeric_operators,
54 },
55 '>' => {
56 rank => 5,
57 numeric => 1,
58 where => $fn_numeric_operators,
59 },
60 'like' => {
61 rank => 6,
62 0 ▶ where => sub { return "$_[0]->{column} LIKE ?"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
63 },
64 'not like' => {
65 rank => 7,
66 0 ▶ where => sub { return "$_[0]->{column} NOT LIKE ?"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
67 },
68 1 );
69  
70 0 ▶sub default_columns {
Subroutine default_columns: not called CC=1 SCAR=6.9
Pod undocumented
71 0 return \%h_default_columns;
72 }
73  
74 23 ▶sub select_addtype_by_name {
Subroutine select_addtype_by_name: called CC=6 SCAR=21.8
Pod undocumented
75  
76 23 my ( $or_self, $s_add_type ) = @_;
77  
78 23 ▶ if ( $or_self->{cache} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($or_self->{"cache"}) 23 0 23
79 23 ▶ if ( my $i_addtype_id = $or_self->{cache}->get("addtype||$s_add_type") ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $i_addtype_id = $or_self->{"cache"}->get("addtype||$s_add_type")) 20 3 23
80 20 return $i_addtype_id;
81 }
82 }
83  
84 3 my $hr_additional_type = $or_self->selectrow_hashref(
85 "
86 SELECT $or_self->{config}{tables}{additional_type_table}{primary}
87 FROM $or_self->{config}{tables}{additional_type_table}{name}
88 WHERE bench_additional_type = ?
89 ",
90 [ $s_add_type ],
91 )
92 ;
93 3 ▶ if ( !$hr_additional_type || !$hr_additional_type->{$or_self->{config}{tables}{additional_type_table}{primary}} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($hr_additional_type and $$hr_additional_type{$or_self->{"config"}{"tables"}{"additional_type_table"}{"primary"}}) 3 0 3
Condition33%1/3
$hr_additional_type and $$hr_additional_type{$or_self->{"config"}{"tables"}{"additional_type_table"}{"primary"}}
!ll&&!rl&&r
300
MC/DC0%0/2
$hr_additional_type and $$hr_additional_type{$or_self->{"config"}{"tables"}{"additional_type_table"}{"primary"}}
$hr_additional_type $$hr_additional_type{$or_self->{"config"}{"tables"}{"additional_type_table"}{"primary"}}
Truth table33%1/3
A and B
A= $hr_additional_typeB= $$hr_additional_type{$or_self->{"config"}{"tables"}{"additional_type_table"}{"primary"}}
ABresult
0X0
100
111
94 3 return;
95 }
96 0 ▶ if ( $or_self->{cache} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($or_self->{"cache"}) 0 0 0
97 $or_self->{cache}->set(
98 "addtype||$s_add_type" => $hr_additional_type->{$or_self->{config}{tables}{additional_type_table}{primary}},
99 0 );
100 }
101  
102 0 return $hr_additional_type->{$or_self->{config}{tables}{additional_type_table}{primary}};
103  
104 }
105  
106 9 ▶sub select_addvalue_id {
Subroutine select_addvalue_id: called CC=7 SCAR=24.3
Pod undocumented
107  
108 9 my ( $or_self, $i_bench_additional_type_id, $s_bench_additional_value ) = @_;
109  
110 9 ▶ if ( $or_self->{cache} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($or_self->{"cache"}) 9 0 9
111 9 ▶ if ( my $i_bench_additional_value_id = $or_self->{cache}->get("addvalue||$i_bench_additional_type_id||$s_bench_additional_value") ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $i_bench_additional_value_id = $or_self->{"cache"}->get("addvalue||$i_bench_additional_type_id||$s_bench_additional_value")) 0 9 9
112 0 return $i_bench_additional_value_id;
113 }
114 }
115  
116 9 my $s_value_where;
117 9 my @a_values = ($i_bench_additional_type_id);
118 9 ▶ if ( defined $s_bench_additional_value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s_bench_additional_value) { } 9 0 9
119 9 $s_value_where = 'bench_additional_value = ?';
120 9 push @a_values, $s_bench_additional_value;
121 }
122 else {
123 0 $s_value_where = 'bench_additional_value IS NULL'
124 }
125  
126 9 my $ar_additional_type = $or_self->selectrow_arrayref(
127 "
128 SELECT $or_self->{config}{tables}{additional_value_table}{primary}
129 FROM $or_self->{config}{tables}{additional_value_table}{name}
130 WHERE $or_self->{config}{tables}{additional_value_table}{foreign_key}{additional_type_table} = ? AND $s_value_where
131 ",
132 \@a_values,
133 )
134 ;
135 9 ▶ if ( !$ar_additional_type || !$ar_additional_type->[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ar_additional_type and $ar_additional_type->[0]) 9 0 9
Condition33%1/3
$ar_additional_type and $ar_additional_type->[0]
!ll&&!rl&&r
900
MC/DC0%0/2
$ar_additional_type and $ar_additional_type->[0]
$ar_additional_type $ar_additional_type->[0]
Truth table33%1/3
A and B
A= $ar_additional_typeB= $ar_additional_type->[0]
ABresult
0X0
100
111
136 9 return;
137 }
138 0 ▶ if ( $or_self->{cache} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($or_self->{"cache"}) 0 0 0
139 $or_self->{cache}->set(
140 0 "addvalue||$i_bench_additional_type_id||$s_bench_additional_value" => $ar_additional_type->[0],
141 );
142 }
143  
144 0 return $ar_additional_type->[0];
145  
146 }
147  
148 8 ▶sub metadata_operators {
Subroutine metadata_operators: called CC=1 SCAR=0.0
Pod undocumented
149 8 return \%h_operators;
150 }
151  
152 11 ▶sub create_select_column {
Subroutine create_select_column: called CC=14 SCAR=43.9
Pod undocumented
153  
154 11 my ( $or_self, $hr_select ) = @_;
155  
156 11 my $s_aggregation = $hr_select->{aggregate};
157 11 my $s_return_select = $hr_select->{column_internal};
158  
159 AGGR: {
160 11 ▶ if (! $s_aggregation ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($s_aggregation) 11 0 11
161 # aggregate all columns if a single column is aggregated
162 11 ▶ if ( $hr_select->{aggregate_all} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_select->{"aggregate_all"}) 0 11 11
163 0 $s_aggregation = $or_self->{config}{default_aggregation};
164 0 redo AGGR;
165 }
166 }
167 11 ▶ if ( $s_aggregation ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s_aggregation) 0 11 11
168  
169 0 ▶ if ( $hr_select->{numeric} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_select->{"numeric"}) 0 0 0
170 0 $s_return_select = "(0 + $s_return_select)";
171 }
172  
173 0 ▶ if ( $s_aggregation eq 'min' ) {
Branch: 7 branches
BranchTrueFalseTotal
if ($s_aggregation eq 'min') { } 0 0 0
elsif ($s_aggregation eq 'max') { } 0 0 0
elsif ($s_aggregation eq 'avg') { } 0 0 0
elsif ($s_aggregation eq 'gem') { } 0 0 0
elsif ($s_aggregation eq 'sum') { } 0 0 0
elsif ($s_aggregation eq 'cnt') { } 0 0 0
elsif ($s_aggregation eq 'cnd') { } 0 0 0
174 0 $s_return_select = "MIN( $s_return_select )";
175 }
176 elsif ( $s_aggregation eq 'max' ) {
177 0 $s_return_select = "MAX( $s_return_select )";
178 }
179 elsif ( $s_aggregation eq 'avg' ) {
180 0 $s_return_select = "AVG( $s_return_select )";
181 }
182 elsif ( $s_aggregation eq 'gem' ) {
183 0 $s_return_select = "EXP( SUM( LOG( $s_return_select ) ) / COUNT( $s_return_select ) )";
184 }
185 elsif ( $s_aggregation eq 'sum' ) {
186 0 $s_return_select = "SUM( $s_return_select )";
187 }
188 elsif ( $s_aggregation eq 'cnt' ) {
189 0 $s_return_select = "COUNT( $s_return_select )";
190 }
191 elsif ( $s_aggregation eq 'cnd' ) {
192 0 $s_return_select = "COUNT( DISTINCT $s_return_select )";
193 }
194 else {
195 0 require Carp;
196 0 Carp::confess("unknown aggregate function '$s_aggregation'");
197 0 return;
198 }
199  
200 }
201 } # AGGR
202  
203 my $s_replace_as = $hr_select->{aggregate}
204 ? "$hr_select->{aggregate}_$hr_select->{column}"
205 : $hr_select->{column}
206 11 ▶ ;
Branch: 1 branch
BranchTrueFalseTotal
$hr_select->{'aggregate'} ? : 0 11 11
207  
208 # remove sub if a column has multiple calls
209 11 ▶ if ( $h_used_selects{$or_self}{$s_replace_as} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h_used_selects{$or_self}{$s_replace_as}) 0 11 11
210 0 return;
211 }
212 11 $h_used_selects{$or_self}{$s_replace_as} = 1;
213  
214 11 return "$s_return_select AS '$s_replace_as'";
215  
216 }
217  
218 0 ▶sub create_period_check {
Subroutine create_period_check: not called CC=7 SCAR=40.3
Pod undocumented
219  
220 0 my ( $s_column, $dt_from, $dt_to ) = @_;
221  
222 0 my @a_vals;
223 my $s_where;
224 0 ▶ if ( $dt_from ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dt_from) 0 0 0
225 0 ▶ if ( my ( $s_date, $s_time ) = $dt_from =~ /(\d{4}-\d{2}-\d{2})( \d{2}:\d{2}:\d{2})?/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $dt_from =~ /(\d{4}-\d{2}-\d{2})( \d{2}:\d{2}:\d{2})?/) { } 0 0 0
226 0 $s_where .= "\nAND $s_column > ?";
227 0 ▶ push @a_vals, $s_date . ( $s_time || ' 00:00:00' );
Condition0%0/2
$s_time || ' 00:00:00'
l!l
00
MC/DC0%0/1
$s_time || ' 00:00:00'
$s_time
Truth table0%0/2
A
A= $s_time
Aresult
11
00
228 }
229 else {
230 0 require Carp;
231 0 Carp::confess(q#unknown date format for 'date_from'#);
232 0 return;
233 }
234 }
235 0 ▶ if ( $dt_to ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dt_to) 0 0 0
236 0 ▶ if ( my ( $s_date, $s_time ) = $dt_to =~ /(\d{4}-\d{2}-\d{2})( \d{2}:\d{2}:\d{2})?/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $dt_to =~ /(\d{4}-\d{2}-\d{2})( \d{2}:\d{2}:\d{2})?/) { } 0 0 0
237 0 $s_where .= "\nAND $s_column < ?";
238 0 ▶ push @a_vals, $s_date . ( $s_time || ' 23:59:59' );
Condition0%0/2
$s_time || ' 23:59:59'
l!l
00
MC/DC0%0/1
$s_time || ' 23:59:59'
$s_time
Truth table0%0/2
A
A= $s_time
Aresult
11
00
239 }
240 else {
241 0 require Carp;
242 0 Carp::confess(q#unknown date format for 'date_to'#);
243 0 return;
244 }
245 }
246  
247 return {
248 0 vals => \@a_vals,
249 where => $s_where,
250 };
251  
252 }
253  
254 8 ▶sub select_benchmark_values {
Subroutine select_benchmark_values: called CC=51 SCAR=51.1
Pod undocumented
255  
256 8 my ( $or_self, $hr_search ) = @_;
257  
258 # clear selected columns
259 8 $h_used_selects{$or_self} = {};
260  
261 # deep copy hash
262 8 require JSON::XS;
263 8 $hr_search = JSON::XS::decode_json(
264 JSON::XS::encode_json( $hr_search )
265 );
266  
267 my (
268 8 $s_limit,
269 $s_offset,
270 $s_order_by,
271 @a_select,
272 @a_from,
273 @a_from_vals,
274 @a_where,
275 @a_where_vals,
276 ) = (
277 q##,
278 q##,
279 q##,
280 );
281  
282 # limit clause
283 8 ▶ if ( $hr_search->{limit} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_search->{"limit"}) 2 6 8
284 2 ▶ if ( $hr_search->{limit} =~ /^\d+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_search->{'limit'} =~ /^\d+$/) { } 2 0 2
285 2 $s_limit = "LIMIT $hr_search->{limit}";
286 }
287 else {
288 0 require Carp;
289 0 Carp::confess("invalid limit value '$hr_search->{limit}'");
290 0 return;
291 }
292 }
293  
294 # offset clause
295 8 ▶ if ( $hr_search->{offset} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_search->{"offset"}) 0 8 8
296 0 ▶ if ( $hr_search->{offset} =~ /^\d+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_search->{'offset'} =~ /^\d+$/) { } 0 0 0
297 0 $s_offset = "OFFSET $hr_search->{offset}";
298 }
299 else {
300 0 require Carp;
301 0 Carp::confess("invalid offset value '$hr_search->{offset}'");
302 0 return;
303 }
304 }
305  
306 # where clause
307 8 my %h_addon;
308 8 my $i_counter = 0;
309 8 my %h_local_from_cache;
310 8 ▶ if ( $hr_search->{where} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_search->{"where"}) 8 0 8
311  
312 8 my $hr_operators = metadata_operators();
313 8 for my $hr_where ( @{$hr_search->{where}} ) {
314 17 ▶ if (! $hr_where->{column} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($hr_where->{"column"}) 0 17 17
315 0 require Carp;
316 0 Carp::confess("column is missing in where clause [$i_counter]");
317 0 return;
318 }
319 17 ▶ if ( my $hr_operator = $hr_operators->{$hr_where->{operator}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $hr_operator = $$hr_operators{$hr_where->{'operator'}}) { } 17 0 17
320 17 $hr_where->{__operator__} = $hr_operator;
321 }
322 else {
323 0 require Carp;
324 0 Carp::confess("unknown operator '$hr_where->{operator}'");
325 0 return;
326 }
327 17 $i_counter++;
328 }
329  
330 # run search in exclusive mode
331 8 ▶ if ( $hr_search->{exclusive} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_search->{"exclusive"}) 5 3 8
332 5 my @a_testrun_vals = map { $_->{column} => 1 } grep { $_->{column} ne 'TESTRUN' } @{$hr_search->{where}};
333 5 my %h_testrun_vals = ( @a_testrun_vals );
334 5 push @a_where_vals, scalar( keys %h_testrun_vals );
335 5 push @a_where , "
336 ? = (
337 SELECT COUNT(1) FROM $or_self->{config}{tables}{lines_table}{name} bar
338 WHERE bar.$or_self->{config}{tables}{lines_table}{foreign_key}{headers_table} = h.$or_self->{config}{tables}{headers_table}{primary}
339 )
340 ";
341 }
342  
343 8 $i_counter = 0;
344 8 for my $hr_where (
345 sort {
346 $a->{__operator__}{rank} <=> $b->{__operator__}{rank}
347 13 } @{$hr_search->{where}}
348 ) {
349  
350 $hr_where->{values} =
351 ref $hr_where->{values} eq 'ARRAY'
352 ? $hr_where->{values}
353 16 ▶ : [ $hr_where->{values} ]
Branch: 1 branch
BranchTrueFalseTotal
ref $hr_where->{'values'} eq 'ARRAY' ? : 0 16 16
354 ;
355  
356 16 ▶ if ( my $hr_def_col = $h_default_columns{$hr_where->{column}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $hr_def_col = $h_default_columns{$hr_where->{'column'}}) { } 8 8 16
357 8 ▶ if ( $hr_def_col->{addon} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_def_col->{"addon"}) 0 8 8
358 0 $h_addon{$hr_def_col->{addon}} = 1;
359 }
360 8 push @a_where_vals, @{$hr_where->{values}};
361 push @a_where, $hr_where->{__operator__}{where}->({
362 8 %{$hr_where}, column => $hr_def_col->{column},
363 8 });
364 }
365 else {
366 8 my $i_add_type_id = $or_self->select_addtype_by_name($hr_where->{column});
367 8 ▶ if ( !$i_add_type_id ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($i_add_type_id) 1 7 8
368 1 require Carp;
369 1 Carp::confess("metadata additional value '$hr_where->{column}' not exists");
370 0 return;
371 }
372 7 my $s_column;
373 7 ▶ if (! $hr_where->{__operator__}{rank} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $hr_where->{'__operator__'}{'rank'}) { } 7 0 7
374  
375 my $s_where = $hr_where->{__operator__}{where}->({
376 7 %{$hr_where}, column => $h_local_from_cache{$hr_where->{column}} = "bav$i_counter.bench_additional_value",
377 });
378  
379 7 push @a_where , $s_where;
380 7 push @a_where_vals , @{$hr_where->{values}};
381 7 push @a_from_vals, $i_add_type_id;
382 7 push @a_from, "
383 JOIN (
384 $or_self->{config}{tables}{lines_table}{name} bar$i_counter
385 JOIN $or_self->{config}{tables}{additional_value_table}{name} bav$i_counter
386 ON (
387 bav$i_counter.$or_self->{config}{tables}{additional_value_table}{primary} = bar$i_counter.$or_self->{config}{tables}{lines_table}{foreign_key}{additional_value_table}
388 AND bav$i_counter.$or_self->{config}{tables}{additional_value_table}{foreign_key}{additional_type_table} = ?
389 )
390 )
391 ON (
392 bar$i_counter.$or_self->{config}{tables}{lines_table}{foreign_key}{headers_table} = h.$or_self->{config}{tables}{headers_table}{primary}
393 )
394 ";
395
396 }
397 else {
398 my $s_where = $hr_where->{__operator__}{where}->({
399 0 %{$hr_where}, column => 'bav.bench_additional_value',
400 });
401 0 push @a_where_vals, $i_add_type_id, @{$hr_where->{values}};
402 0 push @a_where, "
403 EXISTS(
404 SELECT * FROM
405 $or_self->{config}{tables}{lines_table}{name} bar
406 JOIN $or_self->{config}{tables}{additional_value_table}{name} bav
407 ON (
408 bav.$or_self->{config}{tables}{additional_value_table}{primary} = bar.$or_self->{config}{tables}{lines_table}{foreign_key}{additional_value_table}
409 AND bav.$or_self->{config}{tables}{additional_value_table}{foreign_key}{additional_type_table} = ?
410 AND $s_where
411 )
412 WHERE bar.$or_self->{config}{tables}{lines_table}{foreign_key}{headers_table} = h.$or_self->{config}{tables}{headers_table}{primary}
413 )
414 ";
415 }
416 7 $i_counter++;
417 }
418 }
419 }
420  
421 # select clause
422 7 my $b_aggregate_all = 0;
423 7 ▶ if ( $hr_search->{select} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_search->{"select"}) 7 0 7
424 7 for my $i_inner_counter ( 0..$#{$hr_search->{select}} ) {
425 10 ▶ if ( ref $hr_search->{select}[$i_inner_counter] ne 'HASH' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $hr_search->{'select'}[$i_inner_counter] ne 'HASH') { } 10 0 10
elsif (not $b_aggregate_all and $hr_search->{'select'}[$i_inner_counter]{'aggregate'}) { } 0 0 0
426 10 $hr_search->{select}[$i_inner_counter] = { column => $hr_search->{select}[$i_inner_counter] };
427 }
428 ▶ elsif ( !$b_aggregate_all && $hr_search->{select}[$i_inner_counter]{aggregate} ) {
Condition0%0/3
not $b_aggregate_all and $hr_search->{"select"}[$i_inner_counter]{"aggregate"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $b_aggregate_all and $hr_search->{"select"}[$i_inner_counter]{"aggregate"}
not $b_aggregate_all $hr_search->{"select"}[$i_inner_counter]{"aggregate"}
Truth table0%0/3
not(A) and B
A= not $b_aggregate_allB= $hr_search->{"select"}[$i_inner_counter]{"aggregate"}
ABresult
0X0
100
111
429 0 $b_aggregate_all = 1;
430 0 for my $s_clause (qw/ order_by limit offset /) {
431 0 ▶ if ( $hr_search->{$s_clause} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_search->{$s_clause}) 0 0 0
432 0 require Carp;
433 0 Carp::confess("cannot use '$s_clause' with aggregation");
434 }
435 }
436 }
437 }
438 }
439 # keys check - add all missing columns from 'keys' to 'select'
440 7 ▶ if ( $hr_search->{keys} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_search->{"keys"}) 1 6 7
441 1 for my $s_hash_key ( @{$hr_search->{'keys'}} ) {
442 2 ▶ if ( scalar( grep { $s_hash_key eq $_->{column} } @{$hr_search->{select}} ) <= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar grep({$s_hash_key eq $_->{"column"};} @{$$hr_search{"select"};}) <= 0) 1 1 2
443 1 push @{$hr_search->{select}}, { column => $s_hash_key };
444 }
445 }
446 }
447  
448 7 ▶ if ( $hr_search->{order_by} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_search->{"order_by"}) 3 4 7
449 3 for my $i_inner_counter ( 0..$#{$hr_search->{order_by}} ) {
450 3 ▶ if ( ref $hr_search->{order_by}[$i_inner_counter] ne 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $hr_search->{"order_by"}[$i_inner_counter] ne "HASH") 0 3 3
451 0 $hr_search->{order_by}[$i_inner_counter] = { column => $hr_search->{order_by}[$i_inner_counter] };
452 }
453 }
454 3 ▶ if ( $hr_search->{order_by} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_search->{"order_by"}) 3 0 3
455 3 for my $hr_hash_key ( @{$hr_search->{order_by}} ) {
456 3 ▶ if ( scalar( grep { $hr_hash_key->{column} eq $_->{column} } @{$hr_search->{select}} ) <= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar grep({$hr_hash_key->{"column"} eq $_->{"column"};} @{$$hr_search{"select"};}) <= 0) 0 3 3
457 0 push @{$hr_search->{select}}, { column => $hr_hash_key->{column} };
458 }
459 }
460 }
461 }
462  
463 7 my @a_select_vals;
464 7 for my $hr_select ( @{$hr_search->{select}} ) {
465  
466 11 my $s_column;
467 my $s_statement;
468  
469 11 ▶ if ( my $hr_def_col = $h_default_columns{$hr_select->{column}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $hr_def_col = $h_default_columns{$hr_select->{'column'}}) { } 5 6 11
470 5 ▶ if ( $hr_def_col->{addon} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_def_col->{"addon"}) 0 5 5
471 0 $h_addon{$hr_def_col->{addon}} = 1;
472 }
473 5 $s_column = $hr_def_col->{column};
474 }
475 else {
476 6 ▶ if ( $h_local_from_cache{$hr_select->{column}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h_local_from_cache{$hr_select->{'column'}}) { } 0 6 6
477 0 $s_column = $h_local_from_cache{$hr_select->{column}};
478 }
479 else {
480 6 my $i_add_type_id = $or_self->select_addtype_by_name($hr_select->{column});
481 6 ▶ if ( !$i_add_type_id ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($i_add_type_id) 0 6 6
482 0 require Carp;
483 0 Carp::confess("metadata additional value '$hr_select->{column}' not exists");
484 0 return;
485 }
486
487 6 push @a_from_vals, $i_add_type_id;
488 6 push @a_from, "
489 LEFT JOIN (
490 $or_self->{config}{tables}{lines_table}{name} bar$i_counter
491 JOIN $or_self->{config}{tables}{additional_value_table}{name} bav$i_counter
492 ON (
493 bav$i_counter.$or_self->{config}{tables}{additional_value_table}{foreign_key}{additional_type_table} = ?
494 AND bav$i_counter.$or_self->{config}{tables}{additional_value_table}{primary} = bar$i_counter.$or_self->{config}{tables}{lines_table}{foreign_key}{additional_value_table}
495 )
496 )
497 ON ( bar$i_counter.$or_self->{config}{tables}{lines_table}{foreign_key}{headers_table} = h.$or_self->{config}{tables}{headers_table}{primary} )
498 ";
499 6 $s_column = $h_local_from_cache{$hr_select->{column}} = "bav$i_counter.bench_additional_value";
500 6 $i_counter++;
501 }
502 }
503  
504 11 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (my $s_select = $or_self->create_select_column({%{$hr_select;}, "aggregate_all", $b_aggregate_all, "column_internal", $s_column})) 11 0 11
505 my $s_select = $or_self->create_select_column({
506 11 %{$hr_select},
507 aggregate_all => $b_aggregate_all,
508 column_internal => $s_column,
509 })
510 ) {
511 11 push @a_select, $s_select;
512 }
513  
514 }
515  
516 # order_by clause
517 7 ▶ if ( $hr_search->{order_by} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_search->{"order_by"}) 3 4 7
518  
519 3 my @a_order_by;
520 3 my %h_order_by_direction = ( 'ASC' => 1, 'DESC' => 1, );
521  
522 3 for my $hr_order_by ( @{$hr_search->{order_by}} ) {
523 3 my $s_column;
524 3 ▶ if ( my $hr_def_col = $h_default_columns{$hr_order_by->{column}} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $hr_def_col = $h_default_columns{$hr_order_by->{'column'}}) { } 0 3 3
elsif ($h_local_from_cache{$hr_order_by->{'column'}}) { } 3 0 3
525 0 ▶ if ( $hr_def_col->{addon} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr_def_col->{"addon"}) 0 0 0
526 0 $h_addon{$hr_def_col->{addon}} = 1;
527 }
528 0 $s_column = $hr_def_col->{column};
529 }
530 elsif ( $h_local_from_cache{$hr_order_by->{column}} ) {
531 3 $s_column = $h_local_from_cache{$hr_order_by->{column}};
532 }
533 else {
534 0 require Carp;
535 0 Carp::confess("unknown order by column '$hr_order_by->{column}'");
536 0 return;
537 }
538  
539 3 ▶ my $s_direction = $hr_order_by->{direction} || 'ASC';
Condition50%1/2
$hr_order_by->{'direction'} || 'ASC'
l!l
30
MC/DC0%0/1
$hr_order_by->{'direction'} || 'ASC'
$hr_order_by->{'direction'}
Truth table50%1/2
A
A= $hr_order_by->{'direction'}
Aresult
11
00
540 3 ▶ if (! $h_order_by_direction{$s_direction} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($h_order_by_direction{$s_direction}) 0 3 3
541 0 require Carp;
542 0 Carp::confess("unknown order by direction '$s_direction'");
543 0 return;
544 }
545  
546 push @a_order_by,
547 3 ▶ ( $hr_order_by->{numeric} ? '0 + ' : q## )
Branch: 1 branch
BranchTrueFalseTotal
$hr_order_by->{'numeric'} ? : 0 3 3
548 . $s_column
549 . ' '
550 . $s_direction
551 ;
552 }
553 3 $s_order_by = 'ORDER BY ' . (join ', ', @a_order_by)
554 }
555  
556 # replace placeholders inside of raw sql where clause
557 7 my $s_raw_where = $hr_search->{where_sql};
558 7 ▶ if ( $s_raw_where ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s_raw_where) 0 7 7
559 0 $s_raw_where =~ s/
560 \$\{(.+?)\}
561 /
562 $h_local_from_cache{$1}
563 0 ▶ ? $h_local_from_cache{$1}
Branch: 1 branch
BranchTrueFalseTotal
$h_local_from_cache{$1} ? : 0 0 0
564 : die "column '$1' not exists in SELECT clause"
565 /gex;
566 }
567  
568 7 ▶ if ( $h_addon{stats_table} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h_addon{"stats_table"}) 0 7 7
569 0 push @a_from, "
570 JOIN $or_self->{config}{tables}{stats_table}{name} rgts
571 ON ( rgts.$or_self->{config}{tables}{stats_table}{primary} = t.$or_self->{config}{tables}{stats_table}{foreign_key}{main_table} )
572 ";
573 }
574  
575 return
576 $or_self->execute_query(
577 "
578 SELECT
579 DISTINCT
580 11 ▶ " . ( join ",\n", map {"$_"} @a_select ) . "
Branch: 1 branch
BranchTrueFalseTotal
@a_where ? : 7 0 7
581 FROM
582 $or_self->{config}{tables}{main_table}{name} t
583 JOIN $or_self->{config}{tables}{headers_table}{name} h
584 ON ( t.id = h.testrun_id )
585 " . ( join "\n", @a_from ) . "
586 WHERE
587 " .
588 7 ▶ ( @a_where ? join "\nAND ", map { $_ } @a_where : q## ) .
Branch: 1 branch
BranchTrueFalseTotal
$s_raw_where ? : 0 7 7
589 ( $s_raw_where ? " $s_raw_where" : q## ) .
590 "
591 $s_order_by
592 $s_limit
593 $s_offset
594 ", [
595 @a_select_vals,
596 @a_from_vals,
597 @a_where_vals,
598 ],
599 )
600 ;
601  
602 }
603  
604 5 ▶sub insert_metadata_header {
Subroutine insert_metadata_header: called CC=1 SCAR=0.0
Pod undocumented
605  
606 5 my ( $or_self, $i_testrun_id ) = @_;
607  
608 $or_self->insert( "
609 INSERT INTO $or_self->{config}{tables}{headers_table}{name}
610 ( testrun_id, created_at )
611 VALUES
612 ( ?, ? )
613 5 ", [ $i_testrun_id, $or_self->{now} ]);
614  
615 return $or_self->last_insert_id(
616 $or_self->{config}{tables}{headers_table}{name},
617 $or_self->{config}{tables}{headers_table}{primary},
618 5 );
619  
620 }
621  
622 9 ▶sub insert_metadata_line {
Subroutine insert_metadata_line: called CC=1 SCAR=0.0
Pod undocumented
623  
624 9 my ( $or_self, @a_vals ) = @_;
625  
626 9 return $or_self->insert( "
627 INSERT INTO $or_self->{config}{tables}{lines_table}{name}
628 (
629 $or_self->{config}{tables}{headers_table}{primary},
630 $or_self->{config}{tables}{additional_value_table}{primary}
631 )
632 VALUES
633 ( ?, ? )
634 ", \@a_vals );
635  
636 }
637  
638 1 1;
639  
640 __END__
↑ Summary Metadata.pm »