blib/lib/SQL/Translator/Producer/GoogleBigQuery.pm

filter: Statementstmt 100% 50 / 50 Branchbran 90.0% 9 / 10 Conditioncond 100% 3 / 4 (1 uncoverable) MC/DCmcdc 100% 1 / 2 (1 uncoverable) Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 1 totaltotal 97.3% 71 / 75 (2 uncoverable) CC 10 SCAR 14.3
CC
10
Cov
98%
produce
7.0
_type
4.0
BEGIN
1.0
CRAP 4.2
↑ Summary
1 package SQL::Translator::Producer::GoogleBigQuery;
2 5 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 our $VERSION = "0.01";
7  
8 5 ▶use JSON::PP;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use DBI qw/:sql_types/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 5 my $_JSON = JSON::PP->new;
13 5 my %_NAMEMAP = map { $_ => *{$DBI::{$_}}{CODE}->() } @{ $DBI::EXPORT_TAGS{sql_types} };
14 5 my %_TYPEMAP = (
15 SQL_GUID() => 'string',
16 SQL_WLONGVARCHAR() => 'string',
17 SQL_WVARCHAR() => 'string',
18 SQL_WCHAR() => 'string',
19 SQL_BIGINT() => 'integer',
20 SQL_BIT() => 'integer',
21 SQL_TINYINT() => 'integer',
22 SQL_LONGVARBINARY() => 'string',
23 SQL_VARBINARY() => 'string',
24 SQL_BINARY() => 'string',
25 SQL_LONGVARCHAR() => 'string',
26 SQL_UNKNOWN_TYPE() => 'string',
27 SQL_ALL_TYPES() => 'string',
28 SQL_CHAR() => 'string',
29 SQL_NUMERIC() => 'float',
30 SQL_DECIMAL() => 'float',
31 SQL_INTEGER() => 'integer',
32 SQL_SMALLINT() => 'integer',
33 SQL_FLOAT() => 'float',
34 SQL_REAL() => 'float',
35 SQL_DOUBLE() => 'float',
36 SQL_DATETIME() => 'timestamp',
37 SQL_DATE() => 'timestamp',
38 SQL_INTERVAL() => 'integer',
39 SQL_TIME() => 'string',
40 SQL_TIMESTAMP() => 'timestamp',
41 SQL_VARCHAR() => 'string',
42 SQL_BOOLEAN() => 'boolean',
43 SQL_UDT() => 'string',
44 SQL_UDT_LOCATOR() => 'string',
45 SQL_ROW() => 'string',
46 SQL_REF() => 'string',
47 SQL_BLOB() => 'string',
48 SQL_BLOB_LOCATOR() => 'string',
49 SQL_CLOB() => 'string',
50 SQL_CLOB_LOCATOR() => 'string',
51 SQL_ARRAY() => 'string',
52 SQL_ARRAY_LOCATOR() => 'string',
53 SQL_MULTISET() => 'string',
54 SQL_MULTISET_LOCATOR() => 'string',
55 SQL_TYPE_DATE() => 'timestamp',
56 SQL_TYPE_TIME() => 'string',
57 SQL_TYPE_TIMESTAMP() => 'timestamp',
58 SQL_TYPE_TIME_WITH_TIMEZONE() => 'string',
59 SQL_TYPE_TIMESTAMP_WITH_TIMEZONE() => 'timestamp',
60 SQL_INTERVAL_YEAR() => 'integer',
61 SQL_INTERVAL_MONTH() => 'integer',
62 SQL_INTERVAL_DAY() => 'integer',
63 SQL_INTERVAL_HOUR() => 'integer',
64 SQL_INTERVAL_MINUTE() => 'integer',
65 SQL_INTERVAL_SECOND() => 'integer',
66 SQL_INTERVAL_YEAR_TO_MONTH() => 'integer',
67 SQL_INTERVAL_DAY_TO_HOUR() => 'integer',
68 SQL_INTERVAL_DAY_TO_MINUTE() => 'integer',
69 SQL_INTERVAL_DAY_TO_SECOND() => 'integer',
70 SQL_INTERVAL_HOUR_TO_MINUTE() => 'integer',
71 SQL_INTERVAL_HOUR_TO_SECOND() => 'integer',
72 SQL_INTERVAL_MINUTE_TO_SECOND() => 'integer',
73 );
74  
75 5 ▶sub produce {
Subroutine produce: called CC=7 SCAR=19.5
Pod undocumented
76 5 my $translator = shift;
77 5 my $schema = $translator->schema;
78 5 my $args = $translator->producer_args;
79  
80 5 my $outdir = $args->{outdir};
81 5 ▶ my $typemap = $args->{typemap} || {};
Condition100%2/2
$args->{'typemap'} || {}
l!l
14
MC/DC100%1/1
$args->{'typemap'} || {}
$args->{'typemap'}
Truth table100%2/2
A
A= $args->{'typemap'}
Aresult
11
00
82  
83 5 my @tables;
84 5 for my $table ($schema->get_tables) {
85 push @tables => {
86 name => $table->name,
87 schema => [
88 map {
89 10 +{
90 25 name => $_->name,
91 type => _type($_->sql_data_type, $typemap),
92 }
93 } $table->get_fields
94 ],
95 };
96 }
97  
98 5 ▶ return \@tables unless defined $outdir;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $outdir 3 2 5
99  
100 2 ▶ die "No such directory: $outdir" unless -d $outdir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $outdir 1 1 2
101 1 for my $table (@tables) {
102 2 my $file = File::Spec->catfile($outdir, "$table->{name}.json");
103 2 ▶ open my $fh, '>', $file or die "$file: $!"; # uncoverable branch
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $file or die "${file}: $!" 2 0 2
104 2 print {$fh} $_JSON->encode($table->{schema});
105 2 close $fh;
106 }
107  
108 1 return \@tables;
109 }
110  
111 26 ▶sub _type {
Subroutine _type: called CC=4 SCAR=13.9
112 26 my ($sql_data_type, $typemap) = @_;
113 26 ▶ return $typemap->{$sql_data_type} if exists $typemap->{$sql_data_type};
Branch: 1 branch
BranchTrueFalseTotal
if exists $typemap->{$sql_data_type} 3 23 26
114  
115 23 my $type = $_TYPEMAP{$sql_data_type};
116 23 ▶ unless (defined $type) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $type) 1 22 23
117 1 ▶ my $name = $_NAMEMAP{$sql_data_type} || "(unknown)"; # uncoverable condition left
Condition100%1/2
$_NAMEMAP{$sql_data_type} || '(unknown)'
l!l
01
MC/DC100%0/1
$_NAMEMAP{$sql_data_type} || '(unknown)'
$_NAMEMAP{$sql_data_type}
Truth table100%1/2
A
A= $_NAMEMAP{$sql_data_type}
Aresult
11
00
118 1 die "Unknown type: $name (sql_data_type: $sql_data_type)";
119 }
120 22 return $type;
121 }
122  
123 5 1;
124 __END__
↑ Summary