BigQuery.pm

filter: Statementstmt 5.2% 25 / 474 Branchbran 0.0% 0 / 288 Conditioncond 0.0% 0 / 97 MC/DCmcdc 0.0% 0 / 63 Subroutinesub 25.8% 8 / 31 Podpod 90.0% 18 / 20 totaltotal 5.2% 51 / 973 CC 188 SCAR 61.5
CC
188
Cov
3%
load
1560.0
extract
870.0
selectall_arrayref
240.0
CRAP 468.0
↑ Summary BigQuery/V2.pm »
1 package Google::BigQuery;
2 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = "1.02";
7  
8 1 ▶use Class::Load qw(load_class);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Crypt::OpenSSL::PKCS12;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use JSON qw(decode_json encode_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use JSON::WebToken;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 0 ▶sub create {
Subroutine create: not called CC=3 SCAR=24.8
Pod documented
15 0 my (%args) = @_;
16  
17 0 ▶ my $version = $args{version} // 'v2';
Condition0%0/2
$args{"version"} // "v2"
l!l
00
MC/DC0%0/1
$args{"version"} // "v2"
$args{"version"}
Truth table0%0/2
A
A= $args{"version"}
Aresult
11
00
18 0 my $class = 'Google::BigQuery::' . ucfirst($version);
19  
20 0 ▶ if (load_class($class)) {
Branch: 1 branch
BranchTrueFalseTotal
if (load_class($class)) { } 0 0 0
21 0 return $class->new(%args);
22 } else {
23 0 die "Can't load class: $class";
24 }
25 }
26  
27 0 ▶sub new {
Subroutine new: not called CC=7 SCAR=40.3
Pod undocumented
28 0 my ($class, %args) = @_;
29  
30 0 ▶ die "undefined client_eamil" if !defined $args{client_email};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"client_email"} 0 0 0
31 0 ▶ die "undefined private_key_file" if !defined $args{private_key_file};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"private_key_file"} 0 0 0
32 0 ▶ die "not found private_key_file" if !-f $args{private_key_file};
Branch: 1 branch
BranchTrueFalseTotal
unless -f $args{"private_key_file"} 0 0 0
33  
34 0 my $self = bless { %args }, $class;
35  
36 0 $self->{GOOGLE_API_TOKEN_URI} = 'https://accounts.google.com/o/oauth2/token';
37 0 $self->{GOOGLE_API_GRANT_TYPE} = 'urn:ietf:params:oauth:grant-type:jwt-bearer';
38  
39 0 ▶ if ($self->{private_key_file} =~ /\.json$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'private_key_file'} =~ /\.json$/) { } 0 0 0
elsif ($self->{'private_key_file'} =~ /\.p12$/) { } 0 0 0
40 0 ▶ open my $in, "<", $self->{private_key_file} or die "can't open $self->{private_key_file} : $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $in, "<", $self->{"private_key_file"} or die qq[can't open $self->{"private_key_file"} : $!] 0 0 0
41 0 my $private_key_json = decode_json(join('', <$in>));
42 0 close $in;
43 0 $self->{private_key} = $private_key_json->{private_key};
44 } elsif ($self->{private_key_file} =~ /\.p12$/) {
45 0 my $password = "notasecret";
46 0 my $pkcs12 = Crypt::OpenSSL::PKCS12->new_from_file($self->{private_key_file});
47 0 $self->{private_key} = $pkcs12->private_key($password);
48 } else {
49 0 die "invalid private_key_file format";
50 }
51  
52 0 $self->_auth;
53 0 $self->_set_rest_description;
54  
55 0 return $self;
56 }
57  
58 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=0.0
59 }
60  
61 0 ▶sub _auth {
Subroutine _auth: not called CC=3 SCAR=24.8
62 0 my ($self) = @_;
63  
64 0 ▶ $self->{scope} //= [qw(https://www.googleapis.com/auth/bigquery)];
Condition0%0/2
$self->{"scope"} //= ["https://www.googleapis.com/auth/bigquery"]
l!l
00
MC/DC0%0/1
$self->{"scope"} //= ["https://www.googleapis.com/auth/bigquery"]
$self->{"scope"}
Truth table0%0/2
A
A= $self->{"scope"}
Aresult
11
00
65 0 $self->{exp} = time + 3600;
66 0 $self->{iat} = time;
67 0 $self->{ua} = LWP::UserAgent->new;
68  
69 my $claim = {
70 iss => $self->{client_email},
71 0 scope => join(" ", @{$self->{scope}}),
72 aud => $self->{GOOGLE_API_TOKEN_URI},
73 exp => $self->{exp},
74 iat => $self->{iat},
75 0 };
76  
77 0 my $jwt = JSON::WebToken::encode_jwt($claim, $self->{private_key}, 'RS256', { type => 'JWT' });
78  
79 my $response = $self->{ua}->post(
80 $self->{GOOGLE_API_TOKEN_URI},
81 0 { grant_type => $self->{GOOGLE_API_GRANT_TYPE}, assertion => $jwt }
82 );
83  
84 0 ▶ if ($response->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) { } 0 0 0
85 0 $self->{access_token} = decode_json($response->decoded_content);
86 } else {
87 0 my $error = decode_json($response->decoded_content);
88 0 die $error->{error};
89 }
90 }
91  
92 0 ▶sub _set_rest_description {
Subroutine _set_rest_description: not called CC=1 SCAR=6.9
93 0 my ($self) = @_;
94 0 my $response = $self->{ua}->get($self->{GOOGLE_BIGQUERY_REST_DESCRIPTION});
95 0 $self->{rest_description} = decode_json($response->decoded_content);
96 }
97  
98 0 ▶sub use_project {
Subroutine use_project: not called CC=2 SCAR=17.9
Pod documented
99 0 my ($self, $project_id) = @_;
100 0 ▶ $self->{project_id} = $project_id // return;
Condition0%0/2
$project_id // (return)
l!l
00
MC/DC0%0/1
$project_id // (return)
$project_id
Truth table0%0/2
A
A= $project_id
Aresult
11
00
101 }
102  
103 0 ▶sub use_dataset {
Subroutine use_dataset: not called CC=2 SCAR=17.9
Pod documented
104 0 my ($self, $dataset_id) = @_;
105 0 ▶ $self->{dataset_id} = $dataset_id // return;
Condition0%0/2
$dataset_id // (return)
l!l
00
MC/DC0%0/1
$dataset_id // (return)
$dataset_id
Truth table0%0/2
A
A= $dataset_id
Aresult
11
00
106 }
107  
108 0 ▶sub create_dataset {
Subroutine create_dataset: not called CC=9 SCAR=45.0
Pod documented
109 0 my ($self, %args) = @_;
110  
111 0 ▶ my $project_id = $args{project_id} // $self->{project_id};
Condition0%0/3
$args{"project_id"} // $self->{"project_id"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"project_id"} // $self->{"project_id"}
$args{"project_id"} $self->{"project_id"}
Truth table0%0/3
A // B
A= $args{"project_id"}B= $self->{"project_id"}
ABresult
1X1
011
000
112 0 ▶ my $dataset_id = $args{dataset_id} // $self->{dataset_id};
Condition0%0/3
$args{"dataset_id"} // $self->{"dataset_id"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"dataset_id"} // $self->{"dataset_id"}
$args{"dataset_id"} $self->{"dataset_id"}
Truth table0%0/3
A // B
A= $args{"dataset_id"}B= $self->{"dataset_id"}
ABresult
1X1
011
000
113  
114 0 ▶ unless ($project_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($project_id) 0 0 0
115 0 warn "no project\n";
116 0 return 0;
117 }
118 0 ▶ unless ($dataset_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dataset_id) 0 0 0
119 0 warn "no dataset\n";
120 0 return 0;
121 }
122  
123 0 my $content = {
124 datasetReference => {
125 projectId => $project_id,
126 datasetId => $dataset_id
127 }
128 };
129  
130 # option
131 0 ▶ $content->{access} = $args{access} if defined $args{access};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"access"} 0 0 0
132 0 ▶ $content->{description} = $args{description} if defined $args{description};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"description"} 0 0 0
133 0 ▶ $content->{friendlyName} = $args{friendlyName} if defined $args{friendlyName};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"friendlyName"} 0 0 0
134  
135 0 my $response = $self->request(
136 resource => 'datasets',
137 method => 'insert',
138 project_id => $project_id,
139 dataset_id => $dataset_id,
140 content => $content,
141 );
142 0 $self->{response} = $response;
143  
144 0 ▶ if (defined $response->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $response->{'error'}) { } 0 0 0
145 0 warn $response->{error}{message};
146 0 return 0;
147 } else {
148 0 return 1;
149 }
150 }
151  
152 0 ▶sub drop_dataset {
Subroutine drop_dataset: not called CC=7 SCAR=40.3
Pod documented
153 0 my ($self, %args) = @_;
154  
155 0 ▶ my $project_id = $args{project_id} // $self->{project_id};
Condition0%0/3
$args{"project_id"} // $self->{"project_id"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"project_id"} // $self->{"project_id"}
$args{"project_id"} $self->{"project_id"}
Truth table0%0/3
A // B
A= $args{"project_id"}B= $self->{"project_id"}
ABresult
1X1
011
000
156 0 my $dataset_id = $args{dataset_id};
157  
158 0 ▶ unless ($project_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($project_id) 0 0 0
159 0 warn "no project\n";
160 0 return 0;
161 }
162 0 ▶ unless ($dataset_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dataset_id) 0 0 0
163 0 warn "no dataset\n";
164 0 return 0;
165 }
166  
167 # option
168 0 my $query_string = {};
169 0 ▶ if (defined $args{deleteContents}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"deleteContents"}) 0 0 0
170 0 ▶ $query_string->{deleteContents} = $args{deleteContents} ? 'true' : 'false';
Branch: 1 branch
BranchTrueFalseTotal
$args{'deleteContents'} ? : 0 0 0
171 }
172  
173 0 my $response = $self->request(
174 resource => 'datasets',
175 method => 'delete',
176 project_id => $project_id,
177 dataset_id => $dataset_id,
178 query_string => $query_string,
179 );
180 0 $self->{response} = $response;
181  
182 0 ▶ if (defined $response->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $response->{'error'}) { } 0 0 0
183 0 warn $response->{error}{message};
184 0 return 0;
185 } else {
186 0 return 1;
187 }
188 }
189  
190 0 ▶sub show_datasets {
Subroutine show_datasets: not called CC=9 SCAR=45.0
Pod documented
191 0 my ($self, %args) = @_;
192  
193 0 ▶ my $project_id = $args{project_id} // $self->{project_id};
Condition0%0/3
$args{"project_id"} // $self->{"project_id"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"project_id"} // $self->{"project_id"}
$args{"project_id"} $self->{"project_id"}
Truth table0%0/3
A // B
A= $args{"project_id"}B= $self->{"project_id"}
ABresult
1X1
011
000
194  
195 0 ▶ unless ($project_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($project_id) 0 0 0
196 0 warn "no project\n";
197 0 return undef;
198 }
199  
200 # option
201 0 my $query_string = {};
202 0 ▶ if (defined $args{all}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"all"}) 0 0 0
203 0 ▶ $query_string->{all} = $args{all} ? 'true' : 'false';
Branch: 1 branch
BranchTrueFalseTotal
$args{'all'} ? : 0 0 0
204 }
205 0 ▶ $query_string->{maxResults} = $args{maxResults} if defined $args{maxResults};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"maxResults"} 0 0 0
206 0 ▶ $query_string->{pageToken} = $args{pageToken} if defined $args{pageToken};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"pageToken"} 0 0 0
207  
208 0 my $response = $self->request(
209 resource => 'datasets',
210 method => 'list',
211 project_id => $project_id,
212 query_string => $query_string,
213 );
214 0 $self->{response} = $response;
215  
216 0 ▶ if (defined $response->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $response->{"error"}) 0 0 0
217 0 warn $response->{error}{message};
218 0 return undef;
219 }
220  
221 0 my @ret = ();
222 0 foreach my $dataset (@{$response->{datasets}}) {
223 0 push @ret, $dataset->{datasetReference}{datasetId};
224 }
225  
226 0 return @ret;
227 }
228  
229 0 ▶sub desc_dataset {
Subroutine desc_dataset: not called CC=6 SCAR=37.4
Pod documented
230 0 my ($self, %args) = @_;
231  
232 0 ▶ my $project_id = $args{project_id} // $self->{project_id};
Condition0%0/3
$args{"project_id"} // $self->{"project_id"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"project_id"} // $self->{"project_id"}
$args{"project_id"} $self->{"project_id"}
Truth table0%0/3
A // B
A= $args{"project_id"}B= $self->{"project_id"}
ABresult
1X1
011
000
233 0 ▶ my $dataset_id = $args{dataset_id} // $self->{dataset_id};
Condition0%0/3
$args{"dataset_id"} // $self->{"dataset_id"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"dataset_id"} // $self->{"dataset_id"}
$args{"dataset_id"} $self->{"dataset_id"}
Truth table0%0/3
A // B
A= $args{"dataset_id"}B= $self->{"dataset_id"}
ABresult
1X1
011
000
234  
235 0 ▶ unless ($project_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($project_id) 0 0 0
236 0 warn "no project\n";
237 0 return 0;
238 }
239 0 ▶ unless ($dataset_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dataset_id) 0 0 0
240 0 warn "no dataset\n";
241 0 return 0;
242 }
243  
244 0 my $response = $self->request(
245 resource => 'datasets',
246 method => 'get',
247 project_id => $project_id,
248 dataset_id => $dataset_id,
249 );
250 0 $self->{response} = $response;
251  
252 0 ▶ if (defined $response->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $response->{'error'}) { } 0 0 0
253 0 warn $response->{error}{message};
254 0 return undef;
255 } else {
256 0 return $response;
257 }
258 }
259  
260 0 ▶sub create_table {
Subroutine create_table: not called CC=14 SCAR=53.5
Pod documented
261 0 my ($self, %args) = @_;
262  
263 0 ▶ my $project_id = $args{project_id} // $self->{project_id};
Condition0%0/3
$args{"project_id"} // $self->{"project_id"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"project_id"} // $self->{"project_id"}
$args{"project_id"} $self->{"project_id"}
Truth table0%0/3
A // B
A= $args{"project_id"}B= $self->{"project_id"}
ABresult
1X1
011
000
264 0 ▶ my $dataset_id = $args{dataset_id} // $self->{dataset_id};
Condition0%0/3
$args{"dataset_id"} // $self->{"dataset_id"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"dataset_id"} // $self->{"dataset_id"}
$args{"dataset_id"} $self->{"dataset_id"}
Truth table0%0/3
A // B
A= $args{"dataset_id"}B= $self->{"dataset_id"}
ABresult
1X1
011
000
265 0 my $table_id = $args{table_id};
266  
267 0 ▶ unless ($project_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($project_id) 0 0 0
268 0 warn "no project\n";
269 0 return 0;
270 }
271 0 ▶ unless ($dataset_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dataset_id) 0 0 0
272 0 warn "no dataset\n";
273 0 return 0;
274 }
275 0 ▶ unless ($table_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($table_id) 0 0 0
276 0 warn "no table\n";
277 0 return 0;
278 }
279  
280 0 my $content = {
281 tableReference => {
282 projectId => $project_id,
283 datasetId => $dataset_id,
284 tableId => $table_id
285 },
286 };
287  
288 # option
289 0 ▶ $content->{description} = $args{description} if defined $args{description};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"description"} 0 0 0
290 0 ▶ $content->{expirationTime} = $args{expirationTime} if defined $args{expirationTime};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"expirationTime"} 0 0 0
291 0 ▶ $content->{friendlyName} = $args{friendlyName} if defined $args{friendlyName};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"friendlyName"} 0 0 0
292 0 ▶ $content->{schema}{fields} = $args{schema} if defined $args{schema};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"schema"} 0 0 0
293 0 ▶ $content->{view}{query} = $args{view} if defined $args{view};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"view"} 0 0 0
294  
295 0 my $response = $self->request(
296 resource => 'tables',
297 method => 'insert',
298 project_id => $project_id,
299 dataset_id => $dataset_id,
300 table_id => $table_id,
301 content => $content,
302 );
303 0 $self->{response} = $response;
304  
305 0 ▶ if (defined $response->{error}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $response->{'error'}) { } 0 0 0
elsif (defined $args{'schema'} and not defined $response->{'schema'}) { } 0 0 0
306 0 warn $response->{error}{message};
307 0 return 0;
308 ▶ } elsif (defined $args{schema} && !defined $response->{schema}) {
Condition0%0/3
defined $args{"schema"} and not defined $response->{"schema"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $args{"schema"} and not defined $response->{"schema"}
defined $args{"schema"} not defined $response->{"schema"}
Truth table0%0/3
A and not(B)
A= defined $args{"schema"}B= not defined $response->{"schema"}
ABresult
0X0
100
111
309 0 warn "no create schema";
310 0 return 0;
311 } else {
312 0 return 1;
313 }
314 }
315  
316 0 ▶sub drop_table {
Subroutine drop_table: not called CC=7 SCAR=40.3
Pod documented
317 0 my ($self, %args) = @_;
318  
319 0 ▶ my $project_id = $args{project_id} // $self->{project_id};
Condition0%0/3
$args{"project_id"} // $self->{"project_id"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"project_id"} // $self->{"project_id"}
$args{"project_id"} $self->{"project_id"}
Truth table0%0/3
A // B
A= $args{"project_id"}B= $self->{"project_id"}
ABresult
1X1
011
000
320 0 ▶ my $dataset_id = $args{dataset_id} // $self->{dataset_id};
Condition0%0/3
$args{"dataset_id"} // $self->{"dataset_id"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"dataset_id"} // $self->{"dataset_id"}
$args{"dataset_id"} $self->{"dataset_id"}
Truth table0%0/3
A // B
A= $args{"dataset_id"}B= $self->{"dataset_id"}
ABresult
1X1
011
000
321 0 my $table_id = $args{table_id};
322  
323 0 ▶ unless ($project_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($project_id) 0 0 0
324 0 warn "no project\n";
325 0 return 0;
326 }
327 0 ▶ unless ($dataset_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dataset_id) 0 0 0
328 0 warn "no dataset\n";
329 0 return 0;
330 }
331 0 ▶ unless ($table_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($table_id) 0 0 0
332 0 warn "no table\n";
333 0 return 0;
334 }
335  
336 0 my $response = $self->request(
337 resource => 'tables',
338 method => 'delete',
339 project_id => $project_id,
340 dataset_id => $dataset_id,
341 table_id => $table_id
342 );
343 0 $self->{response} = $response;
344  
345 0 ▶ if (defined $response->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $response->{'error'}) { } 0 0 0
346 0 warn $response->{error}{message};
347 0 return 0;
348 } else {
349 0 return 1;
350 }
351 }
352  
353 0 ▶sub show_tables {
Subroutine show_tables: not called CC=9 SCAR=45.0
Pod documented
354 0 my ($self, %args) = @_;
355  
356 0 ▶ my $project_id = $args{project_id} // $self->{project_id};
Condition0%0/3
$args{"project_id"} // $self->{"project_id"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"project_id"} // $self->{"project_id"}
$args{"project_id"} $self->{"project_id"}
Truth table0%0/3
A // B
A= $args{"project_id"}B= $self->{"project_id"}
ABresult
1X1
011
000
357 0 ▶ my $dataset_id = $args{dataset_id} // $self->{dataset_id};
Condition0%0/3
$args{"dataset_id"} // $self->{"dataset_id"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"dataset_id"} // $self->{"dataset_id"}
$args{"dataset_id"} $self->{"dataset_id"}
Truth table0%0/3
A // B
A= $args{"dataset_id"}B= $self->{"dataset_id"}
ABresult
1X1
011
000
358  
359 0 ▶ unless ($project_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($project_id) 0 0 0
360 0 warn "no project\n";
361 0 return undef;
362 }
363 0 ▶ unless ($dataset_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dataset_id) 0 0 0
364 0 warn "no dataset\n";
365 0 return undef;
366 }
367  
368 # option
369 0 my $query_string = {};
370 0 ▶ $query_string->{maxResults} = $args{maxResults} if defined $args{maxResults};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"maxResults"} 0 0 0
371 0 ▶ $query_string->{pageToken} = $args{pageToken} if defined $args{pageToken};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"pageToken"} 0 0 0
372  
373 0 my $response = $self->request(
374 resource => 'tables',
375 method => 'list',
376 project_id => $project_id,
377 dataset_id => $dataset_id,
378 query_string => $query_string,
379 );
380 0 $self->{response} = $response;
381  
382 0 ▶ if (defined $response->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $response->{"error"}) 0 0 0
383 0 warn $response->{error}{message};
384 0 return undef;
385 }
386  
387 0 my @ret = ();
388 0 foreach my $table (@{$response->{tables}}) {
389 0 push @ret, $table->{tableReference}{tableId};
390 }
391  
392 0 return @ret;
393 }
394  
395 0 ▶sub desc_table {
Subroutine desc_table: not called CC=7 SCAR=40.3
Pod documented
396 0 my ($self, %args) = @_;
397  
398 0 ▶ my $project_id = $args{project_id} // $self->{project_id};
Condition0%0/3
$args{"project_id"} // $self->{"project_id"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"project_id"} // $self->{"project_id"}
$args{"project_id"} $self->{"project_id"}
Truth table0%0/3
A // B
A= $args{"project_id"}B= $self->{"project_id"}
ABresult
1X1
011
000
399 0 ▶ my $dataset_id = $args{dataset_id} // $self->{dataset_id};
Condition0%0/3
$args{"dataset_id"} // $self->{"dataset_id"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"dataset_id"} // $self->{"dataset_id"}
$args{"dataset_id"} $self->{"dataset_id"}
Truth table0%0/3
A // B
A= $args{"dataset_id"}B= $self->{"dataset_id"}
ABresult
1X1
011
000
400 0 my $table_id = $args{table_id};
401  
402 0 ▶ unless ($project_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($project_id) 0 0 0
403 0 warn "no project\n";
404 0 return 0;
405 }
406 0 ▶ unless ($dataset_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dataset_id) 0 0 0
407 0 warn "no dataset\n";
408 0 return 0;
409 }
410 0 ▶ unless ($table_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($table_id) 0 0 0
411 0 warn "no table\n";
412 0 return 0;
413 }
414  
415 0 my $response = $self->request(
416 resource => 'tables',
417 method => 'get',
418 project_id => $project_id,
419 dataset_id => $dataset_id,
420 table_id => $table_id,
421 );
422 0 $self->{response} = $response;
423  
424 0 ▶ if (defined $response->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $response->{'error'}) { } 0 0 0
425 0 warn $response->{error}{message};
426 0 return undef;
427 } else {
428 0 return $response;
429 }
430 }
431  
432 0 ▶sub load {
Subroutine load: not called CC=39 SCAR=73.5
Pod documented
433 0 my ($self, %args) = @_;
434  
435 0 ▶ my $project_id = $args{project_id} // $self->{project_id};
Condition0%0/3
$args{"project_id"} // $self->{"project_id"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"project_id"} // $self->{"project_id"}
$args{"project_id"} $self->{"project_id"}
Truth table0%0/3
A // B
A= $args{"project_id"}B= $self->{"project_id"}
ABresult
1X1
011
000
436 0 ▶ my $dataset_id = $args{dataset_id} // $self->{dataset_id};
Condition0%0/3
$args{"dataset_id"} // $self->{"dataset_id"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"dataset_id"} // $self->{"dataset_id"}
$args{"dataset_id"} $self->{"dataset_id"}
Truth table0%0/3
A // B
A= $args{"dataset_id"}B= $self->{"dataset_id"}
ABresult
1X1
011
000
437 0 my $table_id = $args{table_id};
438 0 my $data = $args{data};
439 0 ▶ my $async = $args{async} // 0;
Condition0%0/2
$args{"async"} // 0
l!l
00
MC/DC0%0/1
$args{"async"} // 0
$args{"async"}
Truth table0%0/2
A
A= $args{"async"}
Aresult
11
00
440  
441 0 ▶ unless ($project_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($project_id) 0 0 0
442 0 warn "no project\n";
443 0 return 0;
444 }
445 0 ▶ unless ($dataset_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dataset_id) 0 0 0
446 0 warn "no dataset\n";
447 0 return 0;
448 }
449 0 ▶ unless ($table_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($table_id) 0 0 0
450 0 warn "no table\n";
451 0 return 0;
452 }
453 0 ▶ unless ($data) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($data) 0 0 0
454 0 warn "no data\n";
455 0 return 0;
456 }
457  
458 0 my $content = {
459 configuration => {
460 load => {
461 destinationTable => {
462 projectId => $project_id,
463 datasetId => $dataset_id,
464 tableId => $table_id,
465 }
466 }
467 }
468 };
469  
470 0 ▶ if (ref($data) =~ /ARRAY/) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref($data) =~ /ARRAY/) { } 0 0 0
elsif ($data =~ m[^gs://]) { } 0 0 0
471 0 $content->{configuration}{load}{sourceUris} = $data;
472 } elsif ($data =~ /^gs:\/\//) {
473 0 $content->{configuration}{load}{sourceUris} = [($data)];
474 }
475  
476 0 my $suffix;
477 0 ▶ if (defined $content->{configuration}{load}{sourceUris}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $content->{'configuration'}{'load'}{'sourceUris'}) { } 0 0 0
478 0 ▶ $suffix = $1 if $content->{configuration}{load}{sourceUris}[0] =~ /\.(tsv|csv|json)(?:\.gz)?$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $content->{"configuration"}{"load"}{"sourceUris"}[0] =~ /\.(tsv|csv|json)(?:\.gz)?$/i 0 0 0
479 } else {
480 0 ▶ $suffix = $1 if $data =~ /\.(tsv|csv|json)(?:\.gz)?$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $data =~ /\.(tsv|csv|json)(?:\.gz)?$/i 0 0 0
481 }
482  
483 0 ▶ if (defined $suffix) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $suffix) 0 0 0
484 0 my $source_format;
485 my $field_delimiter;
486 0 ▶ if ($suffix =~ /^tsv$/i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($suffix =~ /^tsv$/i) { } 0 0 0
elsif ($suffix =~ /^json$/i) { } 0 0 0
487 0 $field_delimiter = "\t";
488 } elsif ($suffix =~ /^json$/i) {
489 0 $source_format = "NEWLINE_DELIMITED_JSON";
490 }
491 0 ▶ $content->{configuration}{load}{sourceFormat} = $source_format if defined $source_format;
Branch: 1 branch
BranchTrueFalseTotal
if defined $source_format 0 0 0
492 0 ▶ $content->{configuration}{load}{fieldDelimiter} = $field_delimiter if defined $field_delimiter;
Branch: 1 branch
BranchTrueFalseTotal
if defined $field_delimiter 0 0 0
493 }
494  
495 # load options
496 0 ▶ if (defined $args{allowJaggedRows}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"allowJaggedRows"}) 0 0 0
497 0 ▶ $content->{configuration}{load}{allowJaggedRows} = $args{allowJaggedRows} ? 'true' : 'false';
Branch: 1 branch
BranchTrueFalseTotal
$args{'allowJaggedRows'} ? : 0 0 0
498 }
499 0 ▶ if (defined $args{allowQuotedNewlines}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"allowQuotedNewlines"}) 0 0 0
500 0 ▶ $content->{configuration}{load}{allowQuotedNewlines} = $args{allowQuotedNewlines} ? 'true' : 'false';
Branch: 1 branch
BranchTrueFalseTotal
$args{'allowQuotedNewlines'} ? : 0 0 0
501 }
502 0 ▶ $content->{configuration}{load}{createDisposition} = $args{createDisposition} if defined $args{createDisposition};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"createDisposition"} 0 0 0
503 0 ▶ $content->{configuration}{load}{encoding} = $args{encoding} if defined $args{encoding};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"encoding"} 0 0 0
504 0 ▶ $content->{configuration}{load}{fieldDelimiter} = $args{fieldDelimiter} if defined $args{fieldDelimiter};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"fieldDelimiter"} 0 0 0
505 0 ▶ if (defined $args{ignoreUnknownValues}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"ignoreUnknownValues"}) 0 0 0
506 0 ▶ $content->{configuration}{load}{ignoreUnknownValues} = $args{ignoreUnknownValues} ? 'true' : 'false';
Branch: 1 branch
BranchTrueFalseTotal
$args{'ignoreUnknownValues'} ? : 0 0 0
507 }
508 0 ▶ $content->{configuration}{load}{maxBadRecords} = $args{maxBadRecords} if defined $args{maxBadRecords};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"maxBadRecords"} 0 0 0
509 0 ▶ $content->{configuration}{load}{quote} = $args{quote} if defined $args{quote};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"quote"} 0 0 0
510 0 ▶ $content->{configuration}{load}{schema}{fields} = $args{schema} if defined $args{schema};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"schema"} 0 0 0
511 0 ▶ $content->{configuration}{load}{skipLeadingRows} = $args{skipLeadingRows} if defined $args{skipLeadingRows};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"skipLeadingRows"} 0 0 0
512 0 ▶ $content->{configuration}{load}{sourceFormat} = $args{sourceFormat} if defined $args{sourceFormat};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"sourceFormat"} 0 0 0
513 0 ▶ $content->{configuration}{load}{sourceUris} = $args{sourceUris} if defined $args{sourceUris};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"sourceUris"} 0 0 0
514 0 ▶ $content->{configuration}{load}{writeDisposition} = $args{writeDisposition} if defined $args{writeDisposition};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"writeDisposition"} 0 0 0
515  
516 0 my $response = $self->request(
517 resource => 'jobs',
518 method => 'insert',
519 project_id => $project_id,
520 dataset_id => $dataset_id,
521 talbe_id => $table_id,
522 content => $content,
523 data => $data,
524 async => $async
525 );
526 0 $self->{response} = $response;
527  
528 0 ▶ if (defined $response->{error}) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $response->{'error'}) { } 0 0 0
elsif ($async) { } 0 0 0
elsif ($response->{'status'}{'state'} eq 'DONE') { } 0 0 0
529 0 warn $response->{error}{message};
530 0 return 0;
531 } elsif ($async) {
532 # return job_id if async is true.
533 0 return $response->{jobReference}{jobId};
534 } elsif ($response->{status}{state} eq 'DONE') {
535 0 ▶ if (defined $response->{status}{errors}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $response->{'status'}{'errors'}) { } 0 0 0
536 0 foreach my $error (@{$response->{status}{errors}}) {
537 0 warn encode_json($error), "\n";
538 }
539 0 return 0;
540 } else {
541 0 return 1;
542 }
543 } else {
544 0 return 0;
545 }
546 }
547  
548 0 ▶sub insert {
Subroutine insert: not called CC=11 SCAR=48.8
Pod documented
549 0 my ($self, %args) = @_;
550  
551 0 ▶ my $project_id = $args{project_id} // $self->{project_id};
Condition0%0/3
$args{"project_id"} // $self->{"project_id"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"project_id"} // $self->{"project_id"}
$args{"project_id"} $self->{"project_id"}
Truth table0%0/3
A // B
A= $args{"project_id"}B= $self->{"project_id"}
ABresult
1X1
011
000
552 0 ▶ my $dataset_id = $args{dataset_id} // $self->{dataset_id};
Condition0%0/3
$args{"dataset_id"} // $self->{"dataset_id"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"dataset_id"} // $self->{"dataset_id"}
$args{"dataset_id"} $self->{"dataset_id"}
Truth table0%0/3
A // B
A= $args{"dataset_id"}B= $self->{"dataset_id"}
ABresult
1X1
011
000
553 0 my $table_id = $args{table_id};
554 0 my $values = $args{values};
555  
556 0 ▶ unless ($project_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($project_id) 0 0 0
557 0 warn "no project\n";
558 0 return 0;
559 }
560 0 ▶ unless ($dataset_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dataset_id) 0 0 0
561 0 warn "no dataset\n";
562 0 return 0;
563 }
564 0 ▶ unless ($table_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($table_id) 0 0 0
565 0 warn "no table\n";
566 0 return 0;
567 }
568 0 ▶ unless ($values) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($values) 0 0 0
569 0 warn "no values\n";
570 0 return 0;
571 }
572  
573 0 my $rows = [];
574 0 foreach my $value (@$values) {
575 0 push @$rows, { json => $value };
576 }
577  
578 0 my $response = $self->request(
579 resource => 'tabledata',
580 method => 'insertAll',
581 project_id => $project_id,
582 dataset_id => $dataset_id,
583 table_id => $table_id,
584 content => {
585 rows => $rows
586 }
587 );
588 0 $self->{response} = $response;
589  
590 0 ▶ if (defined $response->{error}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $response->{'error'}) { } 0 0 0
elsif (defined $response->{'insertErrors'}) { } 0 0 0
591 0 warn $response->{error}{message};
592 0 return 0;
593 } elsif (defined $response->{insertErrors}) {
594 0 foreach my $error (@{$response->{insertErrors}}) {
595 0 warn encode_json($error), "\n";
596 }
597 0 return 0;
598 } else {
599 0 return 1;
600 }
601 }
602  
603 0 ▶sub selectrow_array {
Subroutine selectrow_array: not called CC=14 SCAR=53.5
Pod documented
604 0 my ($self, %args) = @_;
605  
606 0 my $query = $args{query};
607 0 ▶ my $project_id = $args{project_id} // $self->{project_id};
Condition0%0/3
$args{"project_id"} // $self->{"project_id"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"project_id"} // $self->{"project_id"}
$args{"project_id"} $self->{"project_id"}
Truth table0%0/3
A // B
A= $args{"project_id"}B= $self->{"project_id"}
ABresult
1X1
011
000
608 0 ▶ my $dataset_id = $args{dataset_id} // $self->{dataset_id};
Condition0%0/3
$args{"dataset_id"} // $self->{"dataset_id"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"dataset_id"} // $self->{"dataset_id"}
$args{"dataset_id"} $self->{"dataset_id"}
Truth table0%0/3
A // B
A= $args{"dataset_id"}B= $self->{"dataset_id"}
ABresult
1X1
011
000
609  
610 0 ▶ unless ($query) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($query) 0 0 0
611 0 warn "no query\n";
612 0 return 0;
613 }
614 0 ▶ unless ($project_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($project_id) 0 0 0
615 0 warn "no project\n";
616 0 return 0;
617 }
618  
619 0 my $content = {
620 query => $query,
621 };
622  
623 # option
624 0 ▶ if (defined $dataset_id) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dataset_id) 0 0 0
625 0 $content->{defaultDataset}{projectId} = $project_id;
626 0 $content->{defaultDataset}{datasetId} = $dataset_id;
627 }
628 0 ▶ $content->{maxResults} = $args{maxResults} if defined $args{maxResults};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"maxResults"} 0 0 0
629 0 ▶ $content->{timeoutMs} = $args{timeoutMs} if defined $args{timeoutMs};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"timeoutMs"} 0 0 0
630 0 ▶ if (defined $args{dryRun}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"dryRun"}) 0 0 0
631 0 ▶ $content->{dryRun} = $args{dryRun} ? 'true' : 'false';
Branch: 1 branch
BranchTrueFalseTotal
$args{'dryRun'} ? : 0 0 0
632 }
633 0 ▶ if (defined $args{useQueryCache}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"useQueryCache"}) 0 0 0
634 0 ▶ $content->{useQueryCache} = $args{useQueryCache} ? 'true' : 'false';
Branch: 1 branch
BranchTrueFalseTotal
$args{'useQueryCache'} ? : 0 0 0
635 }
636  
637 0 my $response = $self->request(
638 resource => 'jobs',
639 method => 'query',
640 content => $content
641 );
642 0 $self->{response} = $response;
643  
644 0 ▶ if (defined $response->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $response->{"error"}) 0 0 0
645 0 warn $response->{error}{message};
646 0 return 0;
647 }
648  
649 0 my @ret = ();
650 0 foreach my $field (@{$response->{rows}[0]{f}}) {
651 0 push @ret, $field->{v};
652 }
653  
654 0 return @ret;
655 }
656  
657 0 ▶sub selectall_arrayref {
Subroutine selectall_arrayref: not called CC=15 SCAR=54.8
Pod documented
658 0 my ($self, %args) = @_;
659  
660 0 my $query = $args{query};
661 0 ▶ my $project_id = $args{project_id} // $self->{project_id};
Condition0%0/3
$args{"project_id"} // $self->{"project_id"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"project_id"} // $self->{"project_id"}
$args{"project_id"} $self->{"project_id"}
Truth table0%0/3
A // B
A= $args{"project_id"}B= $self->{"project_id"}
ABresult
1X1
011
000
662 0 ▶ my $dataset_id = $args{dataset_id} // $self->{dataset_id};
Condition0%0/3
$args{"dataset_id"} // $self->{"dataset_id"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"dataset_id"} // $self->{"dataset_id"}
$args{"dataset_id"} $self->{"dataset_id"}
Truth table0%0/3
A // B
A= $args{"dataset_id"}B= $self->{"dataset_id"}
ABresult
1X1
011
000
663  
664 0 ▶ unless ($query) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($query) 0 0 0
665 0 warn "no query\n";
666 0 return 0;
667 }
668 0 ▶ unless ($project_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($project_id) 0 0 0
669 0 warn "no project\n";
670 0 return 0;
671 }
672  
673 0 my $content = {
674 query => $query,
675 };
676  
677 # option
678 0 ▶ if (defined $dataset_id) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dataset_id) 0 0 0
679 0 $content->{defaultDataset}{projectId} = $project_id;
680 0 $content->{defaultDataset}{datasetId} = $dataset_id;
681 }
682 0 ▶ $content->{maxResults} = $args{maxResults} if defined $args{maxResults};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"maxResults"} 0 0 0
683 0 ▶ $content->{timeoutMs} = $args{timeoutMs} if defined $args{timeoutMs};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"timeoutMs"} 0 0 0
684 0 ▶ if (defined $args{dryRun}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"dryRun"}) 0 0 0
685 0 ▶ $content->{dryRun} = $args{dryRun} ? 'true' : 'false';
Branch: 1 branch
BranchTrueFalseTotal
$args{'dryRun'} ? : 0 0 0
686 }
687 0 ▶ if (defined $args{useQueryCache}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"useQueryCache"}) 0 0 0
688 0 ▶ $content->{useQueryCache} = $args{useQueryCache} ? 'true' : 'false';
Branch: 1 branch
BranchTrueFalseTotal
$args{'useQueryCache'} ? : 0 0 0
689 }
690  
691 0 my $response = $self->request(
692 resource => 'jobs',
693 method => 'query',
694 content => $content
695 );
696 0 $self->{response} = $response;
697  
698 0 ▶ if (defined $response->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $response->{"error"}) 0 0 0
699 0 warn $response->{error}{message};
700 0 return 0;
701 }
702  
703 0 my $ret = [];
704 0 foreach my $rows (@{$response->{rows}}) {
705 0 my $row = [];
706 0 foreach my $field (@{$rows->{f}}) {
707 0 push @$row, $field->{v};
708 }
709 0 push @$ret, $row;
710 }
711  
712 0 return $ret;
713 }
714  
715 0 ▶sub is_exists_dataset {
Subroutine is_exists_dataset: not called CC=6 SCAR=37.4
Pod documented
716 0 my ($self, %args) = @_;
717  
718 0 ▶ my $project_id = $args{project_id} // $self->{project_id};
Condition0%0/3
$args{"project_id"} // $self->{"project_id"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"project_id"} // $self->{"project_id"}
$args{"project_id"} $self->{"project_id"}
Truth table0%0/3
A // B
A= $args{"project_id"}B= $self->{"project_id"}
ABresult
1X1
011
000
719 0 ▶ my $dataset_id = $args{dataset_id} // $self->{dataset_id};
Condition0%0/3
$args{"dataset_id"} // $self->{"dataset_id"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"dataset_id"} // $self->{"dataset_id"}
$args{"dataset_id"} $self->{"dataset_id"}
Truth table0%0/3
A // B
A= $args{"dataset_id"}B= $self->{"dataset_id"}
ABresult
1X1
011
000
720  
721 0 ▶ unless ($project_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($project_id) 0 0 0
722 0 warn "no project\n";
723 0 return 0;
724 }
725 0 ▶ unless ($dataset_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dataset_id) 0 0 0
726 0 warn "no dataset\n";
727 0 return 0;
728 }
729  
730 0 my $response = $self->request(
731 resource => 'datasets',
732 method => 'get',
733 project_id => $project_id,
734 dataset_id => $dataset_id
735 );
736 0 $self->{response} = $response;
737  
738 0 ▶ if (defined $response->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $response->{'error'}) { } 0 0 0
739 #warn $response->{error}{message};
740 0 return 0;
741 } else {
742 0 return 1;
743 }
744 }
745  
746 0 ▶sub is_exists_table {
Subroutine is_exists_table: not called CC=7 SCAR=40.3
Pod documented
747 0 my ($self, %args) = @_;
748  
749 0 ▶ my $project_id = $args{project_id} // $self->{project_id};
Condition0%0/3
$args{"project_id"} // $self->{"project_id"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"project_id"} // $self->{"project_id"}
$args{"project_id"} $self->{"project_id"}
Truth table0%0/3
A // B
A= $args{"project_id"}B= $self->{"project_id"}
ABresult
1X1
011
000
750 0 ▶ my $dataset_id = $args{dataset_id} // $self->{dataset_id};
Condition0%0/3
$args{"dataset_id"} // $self->{"dataset_id"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"dataset_id"} // $self->{"dataset_id"}
$args{"dataset_id"} $self->{"dataset_id"}
Truth table0%0/3
A // B
A= $args{"dataset_id"}B= $self->{"dataset_id"}
ABresult
1X1
011
000
751 0 my $table_id = $args{table_id};
752  
753 0 ▶ unless ($project_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($project_id) 0 0 0
754 0 warn "no project\n";
755 0 return 0;
756 }
757 0 ▶ unless ($dataset_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dataset_id) 0 0 0
758 0 warn "no dataset\n";
759 0 return 0;
760 }
761 0 ▶ unless ($table_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($table_id) 0 0 0
762 0 warn "no table\n";
763 0 return 0;
764 }
765  
766 0 my $response = $self->request(
767 resource => 'tables',
768 method => 'get',
769 project_id => $project_id,
770 dataset_id => $dataset_id,
771 table_id => $table_id
772 );
773 0 $self->{response} = $response;
774  
775 0 ▶ if (defined $response->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $response->{'error'}) { } 0 0 0
776 #warn $response->{error}{message};
777 0 return 0;
778 } else {
779 0 return 1;
780 }
781 }
782  
783 0 ▶sub extract {
Subroutine extract: not called CC=29 SCAR=67.7
Pod documented
784 0 my ($self, %args) = @_;
785  
786 0 ▶ my $project_id = $args{project_id} // $self->{project_id};
Condition0%0/3
$args{"project_id"} // $self->{"project_id"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"project_id"} // $self->{"project_id"}
$args{"project_id"} $self->{"project_id"}
Truth table0%0/3
A // B
A= $args{"project_id"}B= $self->{"project_id"}
ABresult
1X1
011
000
787 0 ▶ my $dataset_id = $args{dataset_id} // $self->{dataset_id};
Condition0%0/3
$args{"dataset_id"} // $self->{"dataset_id"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"dataset_id"} // $self->{"dataset_id"}
$args{"dataset_id"} $self->{"dataset_id"}
Truth table0%0/3
A // B
A= $args{"dataset_id"}B= $self->{"dataset_id"}
ABresult
1X1
011
000
788 0 my $table_id = $args{table_id};
789 0 my $data = $args{data};
790  
791 0 ▶ unless ($project_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($project_id) 0 0 0
792 0 warn "no project\n";
793 0 return 0;
794 }
795 0 ▶ unless ($dataset_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dataset_id) 0 0 0
796 0 warn "no dataset\n";
797 0 return 0;
798 }
799 0 ▶ unless ($table_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($table_id) 0 0 0
800 0 warn "no table\n";
801 0 return 0;
802 }
803 0 ▶ unless ($data) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($data) 0 0 0
804 0 warn "no data\n";
805 0 return 0;
806 }
807  
808 0 my $content = {
809 configuration => {
810 extract => {
811 sourceTable => {
812 projectId => $project_id,
813 datasetId => $dataset_id,
814 tableId => $table_id,
815 }
816 }
817 }
818 };
819  
820 0 ▶ if (ref($data) =~ /ARRAY/) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref($data) =~ /ARRAY/) { } 0 0 0
elsif ($data =~ m[^gs://]) { } 0 0 0
821 0 $content->{configuration}{extract}{destinationUris} = $data;
822 } elsif ($data =~ /^gs:\/\//) {
823 0 $content->{configuration}{extract}{destinationUris} = [($data)];
824 } else {
825 0 $content->{configuration}{extract}{destinationUris} = [('')];
826 }
827  
828 0 my $suffix;
829 my $compression;
830 0 ▶ if (defined $content->{configuration}{extract}{destinationUris}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $content->{"configuration"}{"extract"}{"destinationUris"}) 0 0 0
831 0 ▶ $suffix = $1 if $content->{configuration}{extract}{destinationUris}[0] =~ /\.(tsv|csv|json|avro)(?:\.gz)?$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $content->{"configuration"}{"extract"}{"destinationUris"}[0] =~ /\.(tsv|csv|json|avro)(?:\.gz)?$/i 0 0 0
832 0 ▶ $compression = 'GZIP' if $content->{configuration}{extract}{destinationUris}[0] =~ /\.gz$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $content->{"configuration"}{"extract"}{"destinationUris"}[0] =~ /\.gz$/i 0 0 0
833 }
834  
835 0 ▶ if (defined $suffix) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $suffix) 0 0 0
836 0 my $destination_format;
837 my $field_delimiter;
838 0 ▶ if ($suffix =~ /^tsv$/i) {
Branch: 3 branches
BranchTrueFalseTotal
if ($suffix =~ /^tsv$/i) { } 0 0 0
elsif ($suffix =~ /^json$/i) { } 0 0 0
elsif ($suffix =~ /^avro$/) { } 0 0 0
839 0 $field_delimiter = "\t";
840 } elsif ($suffix =~ /^json$/i) {
841 0 $destination_format = "NEWLINE_DELIMITED_JSON";
842 } elsif ($suffix =~ /^avro$/) {
843 0 $destination_format = "AVRO";
844 }
845 0 ▶ $content->{configuration}{extract}{destinationFormat} = $destination_format if defined $destination_format;
Branch: 1 branch
BranchTrueFalseTotal
if defined $destination_format 0 0 0
846 0 ▶ $content->{configuration}{extract}{fieldDelimiter} = $field_delimiter if defined $field_delimiter;
Branch: 1 branch
BranchTrueFalseTotal
if defined $field_delimiter 0 0 0
847 }
848 0 ▶ $content->{configuration}{extract}{compression} = $compression if defined $compression;
Branch: 1 branch
BranchTrueFalseTotal
if defined $compression 0 0 0
849  
850 # extract options
851 0 ▶ $content->{configuration}{extract}{compression} = $args{compression} if defined $args{compression};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"compression"} 0 0 0
852 0 ▶ $content->{configuration}{extract}{destinationFormat} = $args{destinationFormat} if defined $args{destinationFormat};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"destinationFormat"} 0 0 0
853 0 ▶ $content->{configuration}{extract}{destinationUris} = $args{destinationUris} if defined $args{destinationUris};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"destinationUris"} 0 0 0
854 0 ▶ $content->{configuration}{extract}{fieldDelimiter} = $args{fieldDelimiter} if defined $args{fieldDelimiter};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"fieldDelimiter"} 0 0 0
855 0 ▶ if (defined $args{printHeader}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"printHeader"}) 0 0 0
856 0 ▶ $content->{configuration}{extract}{printHeader} = $args{printHeader} ? 'true' : 'false';
Branch: 1 branch
BranchTrueFalseTotal
$args{'printHeader'} ? : 0 0 0
857 }
858  
859 0 my $response = $self->request(
860 resource => 'jobs',
861 method => 'insert',
862 project_id => $project_id,
863 dataset_id => $dataset_id,
864 talbe_id => $table_id,
865 content => $content,
866 data => $data
867 );
868 0 $self->{response} = $response;
869  
870 0 ▶ if (defined $response->{error}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $response->{'error'}) { } 0 0 0
elsif ($response->{'status'}{'state'} eq 'DONE') { } 0 0 0
871 0 warn $response->{error}{message};
872 0 return 0;
873 } elsif ($response->{status}{state} eq 'DONE') {
874 0 ▶ if (defined $response->{status}{errors}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $response->{'status'}{'errors'}) { } 0 0 0
875 0 foreach my $error (@{$response->{status}{errors}}) {
876 0 warn encode_json($error), "\n";
877 }
878 0 return 0;
879 } else {
880 0 return 1;
881 }
882 } else {
883 0 return 0;
884 }
885 }
886  
887 0 ▶sub get_nextPageToken {
Subroutine get_nextPageToken: not called CC=2 SCAR=17.9
Pod undocumented
888 0 my $self = shift;
889  
890 0 ▶ if (defined $self->{response}{nextPageToken}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'response'}{'nextPageToken'}) { } 0 0 0
891 0 return $self->{response}{nextPageToken};
892 } else {
893 0 return undef;
894 }
895 }
896  
897 1 1;
898 __END__
↑ Summary BigQuery/V2.pm »