google-cloud-bigquery 1.20.0 → 1.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/lib/google/cloud/bigquery/job.rb +198 -0
- data/lib/google/cloud/bigquery/project.rb +66 -12
- data/lib/google/cloud/bigquery/query_job.rb +38 -0
- data/lib/google/cloud/bigquery/service.rb +4 -2
- data/lib/google/cloud/bigquery/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41107fdb920537ef29f375d86dea227cf33bbf8ca29ac17daa228e1a0df2367e
|
4
|
+
data.tar.gz: 632289096e6fca9acefda0a767c377a7f04a5e25698e696651c6cedaa2f254e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d565666e1b6f242603ee8f3e05960219d2d5345fd7e1730214f45ea835e7116327a09a7814831390fd2e1fcea507d97ed098cdfd2e251d7679011812cd49090e
|
7
|
+
data.tar.gz: 7d3136310a7fa8ff8474b021e348e4dcb933dcfa80a764e53984cd390cf8a2ad38015ffe31450f88e2d7bc57f6dde3c11c568a17348c30833b8dc32dfb754cd9
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# Release History
|
2
2
|
|
3
|
+
### 1.21.0 / 2020-03-31
|
4
|
+
|
5
|
+
#### Features
|
6
|
+
|
7
|
+
* Add Job#parent_job_id and Job#script_statistics
|
8
|
+
* Add parent_job to Project#jobs
|
9
|
+
* Add Job#num_child_jobs
|
10
|
+
* Add Job#parent_job_id
|
11
|
+
* Add Job#script_statistics
|
12
|
+
|
3
13
|
### 1.20.0 / 2020-03-11
|
4
14
|
|
5
15
|
#### Features
|
@@ -197,6 +197,72 @@ module Google
|
|
197
197
|
Convert.millis_to_time @gapi.statistics.end_time
|
198
198
|
end
|
199
199
|
|
200
|
+
##
|
201
|
+
# The number of child jobs executed.
|
202
|
+
#
|
203
|
+
# @return [Integer] The number of child jobs executed.
|
204
|
+
#
|
205
|
+
def num_child_jobs
|
206
|
+
@gapi.statistics.num_child_jobs || 0
|
207
|
+
end
|
208
|
+
|
209
|
+
##
|
210
|
+
# If this is a child job, the id of the parent.
|
211
|
+
#
|
212
|
+
# @return [String, nil] The ID of the parent job, or `nil` if not a child job.
|
213
|
+
#
|
214
|
+
def parent_job_id
|
215
|
+
@gapi.statistics.parent_job_id
|
216
|
+
end
|
217
|
+
|
218
|
+
##
|
219
|
+
# The statistics including stack frames for a child job of a script.
|
220
|
+
#
|
221
|
+
# @return [Google::Cloud::Bigquery::Job::ScriptStatistics, nil] The script statistics, or `nil` if the job is
|
222
|
+
# not a child job.
|
223
|
+
#
|
224
|
+
# @example
|
225
|
+
# require "google/cloud/bigquery"
|
226
|
+
#
|
227
|
+
# bigquery = Google::Cloud::Bigquery.new
|
228
|
+
#
|
229
|
+
# multi_statement_sql = <<~SQL
|
230
|
+
# -- Declare a variable to hold names as an array.
|
231
|
+
# DECLARE top_names ARRAY<STRING>;
|
232
|
+
# -- Build an array of the top 100 names from the year 2017.
|
233
|
+
# SET top_names = (
|
234
|
+
# SELECT ARRAY_AGG(name ORDER BY number DESC LIMIT 100)
|
235
|
+
# FROM `bigquery-public-data.usa_names.usa_1910_current`
|
236
|
+
# WHERE year = 2017
|
237
|
+
# );
|
238
|
+
# -- Which names appear as words in Shakespeare's plays?
|
239
|
+
# SELECT
|
240
|
+
# name AS shakespeare_name
|
241
|
+
# FROM UNNEST(top_names) AS name
|
242
|
+
# WHERE name IN (
|
243
|
+
# SELECT word
|
244
|
+
# FROM `bigquery-public-data.samples.shakespeare`
|
245
|
+
# );
|
246
|
+
# SQL
|
247
|
+
#
|
248
|
+
# job = bigquery.query_job multi_statement_sql
|
249
|
+
#
|
250
|
+
# job.wait_until_done!
|
251
|
+
#
|
252
|
+
# child_jobs = bigquery.jobs parent_job: job
|
253
|
+
#
|
254
|
+
# child_jobs.each do |child_job|
|
255
|
+
# script_statistics = child_job.script_statistics
|
256
|
+
# puts script_statistics.evaluation_kind
|
257
|
+
# script_statistics.stack_frames.each do |stack_frame|
|
258
|
+
# puts stack_frame.text
|
259
|
+
# end
|
260
|
+
# end
|
261
|
+
#
|
262
|
+
def script_statistics
|
263
|
+
ScriptStatistics.from_gapi @gapi.statistics.script_statistics if @gapi.statistics.script_statistics
|
264
|
+
end
|
265
|
+
|
200
266
|
##
|
201
267
|
# The configuration for the job. Returns a hash.
|
202
268
|
#
|
@@ -423,6 +489,138 @@ module Google
|
|
423
489
|
end
|
424
490
|
end
|
425
491
|
|
492
|
+
##
|
493
|
+
# Represents statistics for a child job of a script.
|
494
|
+
#
|
495
|
+
# @attr_reader [String] evaluation_kind Indicates the type of child job. Possible values include `STATEMENT` and
|
496
|
+
# `EXPRESSION`.
|
497
|
+
# @attr_reader [Array<Google::Cloud::Bigquery::Job::ScriptStackFrame>] stack_frames Stack trace where the
|
498
|
+
# current evaluation happened. Shows line/column/procedure name of each frame on the stack at the point where
|
499
|
+
# the current evaluation happened. The leaf frame is first, the primary script is last.
|
500
|
+
#
|
501
|
+
# @example
|
502
|
+
# require "google/cloud/bigquery"
|
503
|
+
#
|
504
|
+
# bigquery = Google::Cloud::Bigquery.new
|
505
|
+
#
|
506
|
+
# multi_statement_sql = <<~SQL
|
507
|
+
# -- Declare a variable to hold names as an array.
|
508
|
+
# DECLARE top_names ARRAY<STRING>;
|
509
|
+
# -- Build an array of the top 100 names from the year 2017.
|
510
|
+
# SET top_names = (
|
511
|
+
# SELECT ARRAY_AGG(name ORDER BY number DESC LIMIT 100)
|
512
|
+
# FROM `bigquery-public-data.usa_names.usa_1910_current`
|
513
|
+
# WHERE year = 2017
|
514
|
+
# );
|
515
|
+
# -- Which names appear as words in Shakespeare's plays?
|
516
|
+
# SELECT
|
517
|
+
# name AS shakespeare_name
|
518
|
+
# FROM UNNEST(top_names) AS name
|
519
|
+
# WHERE name IN (
|
520
|
+
# SELECT word
|
521
|
+
# FROM `bigquery-public-data.samples.shakespeare`
|
522
|
+
# );
|
523
|
+
# SQL
|
524
|
+
#
|
525
|
+
# job = bigquery.query_job multi_statement_sql
|
526
|
+
#
|
527
|
+
# job.wait_until_done!
|
528
|
+
#
|
529
|
+
# child_jobs = bigquery.jobs parent_job: job
|
530
|
+
#
|
531
|
+
# child_jobs.each do |child_job|
|
532
|
+
# script_statistics = child_job.script_statistics
|
533
|
+
# puts script_statistics.evaluation_kind
|
534
|
+
# script_statistics.stack_frames.each do |stack_frame|
|
535
|
+
# puts stack_frame.text
|
536
|
+
# end
|
537
|
+
# end
|
538
|
+
#
|
539
|
+
class ScriptStatistics
|
540
|
+
attr_reader :evaluation_kind, :stack_frames
|
541
|
+
|
542
|
+
##
|
543
|
+
# @private Creates a new ScriptStatistics instance.
|
544
|
+
def initialize evaluation_kind, stack_frames
|
545
|
+
@evaluation_kind = evaluation_kind
|
546
|
+
@stack_frames = stack_frames
|
547
|
+
end
|
548
|
+
|
549
|
+
##
|
550
|
+
# @private New ScriptStatistics from a statistics.script_statistics object.
|
551
|
+
def self.from_gapi gapi
|
552
|
+
frames = Array(gapi.stack_frames).map { |g| ScriptStackFrame.from_gapi g }
|
553
|
+
new gapi.evaluation_kind, frames
|
554
|
+
end
|
555
|
+
end
|
556
|
+
|
557
|
+
##
|
558
|
+
# Represents a stack frame showing the line/column/procedure name where the current evaluation happened.
|
559
|
+
#
|
560
|
+
# @attr_reader [Integer] start_line One-based start line.
|
561
|
+
# @attr_reader [Integer] start_column One-based start column.
|
562
|
+
# @attr_reader [Integer] end_line One-based end line.
|
563
|
+
# @attr_reader [Integer] end_column One-based end column.
|
564
|
+
# @attr_reader [String] text Text of the current statement/expression.
|
565
|
+
#
|
566
|
+
# @example
|
567
|
+
# require "google/cloud/bigquery"
|
568
|
+
#
|
569
|
+
# bigquery = Google::Cloud::Bigquery.new
|
570
|
+
#
|
571
|
+
# multi_statement_sql = <<~SQL
|
572
|
+
# -- Declare a variable to hold names as an array.
|
573
|
+
# DECLARE top_names ARRAY<STRING>;
|
574
|
+
# -- Build an array of the top 100 names from the year 2017.
|
575
|
+
# SET top_names = (
|
576
|
+
# SELECT ARRAY_AGG(name ORDER BY number DESC LIMIT 100)
|
577
|
+
# FROM `bigquery-public-data.usa_names.usa_1910_current`
|
578
|
+
# WHERE year = 2017
|
579
|
+
# );
|
580
|
+
# -- Which names appear as words in Shakespeare's plays?
|
581
|
+
# SELECT
|
582
|
+
# name AS shakespeare_name
|
583
|
+
# FROM UNNEST(top_names) AS name
|
584
|
+
# WHERE name IN (
|
585
|
+
# SELECT word
|
586
|
+
# FROM `bigquery-public-data.samples.shakespeare`
|
587
|
+
# );
|
588
|
+
# SQL
|
589
|
+
#
|
590
|
+
# job = bigquery.query_job multi_statement_sql
|
591
|
+
#
|
592
|
+
# job.wait_until_done!
|
593
|
+
#
|
594
|
+
# child_jobs = bigquery.jobs parent_job: job
|
595
|
+
#
|
596
|
+
# child_jobs.each do |child_job|
|
597
|
+
# script_statistics = child_job.script_statistics
|
598
|
+
# puts script_statistics.evaluation_kind
|
599
|
+
# script_statistics.stack_frames.each do |stack_frame|
|
600
|
+
# puts stack_frame.text
|
601
|
+
# end
|
602
|
+
# end
|
603
|
+
#
|
604
|
+
class ScriptStackFrame
|
605
|
+
attr_reader :start_line, :start_column, :end_line, :end_column, :text
|
606
|
+
|
607
|
+
##
|
608
|
+
# @private Creates a new ScriptStackFrame instance.
|
609
|
+
def initialize start_line, start_column, end_line, end_column, text
|
610
|
+
@start_line = start_line
|
611
|
+
@start_column = start_column
|
612
|
+
@end_line = end_line
|
613
|
+
@end_column = end_column
|
614
|
+
@text = text
|
615
|
+
end
|
616
|
+
|
617
|
+
##
|
618
|
+
# @private New ScriptStackFrame from a statistics.script_statistics[].stack_frames element.
|
619
|
+
def self.from_gapi gapi
|
620
|
+
new gapi.start_line, gapi.start_column, gapi.end_line, gapi.end_column, gapi.text
|
621
|
+
end
|
622
|
+
end
|
623
|
+
|
426
624
|
protected
|
427
625
|
|
428
626
|
##
|
@@ -1084,18 +1084,22 @@ module Google
|
|
1084
1084
|
# part of the larger set of results to view. Optional.
|
1085
1085
|
# @param [Integer] max Maximum number of jobs to return. Optional.
|
1086
1086
|
# @param [String] filter A filter for job state. Optional.
|
1087
|
-
# @param [Time] min_created_at Min value for {Job#created_at}. When
|
1088
|
-
# provided, only jobs created after or at this time are returned.
|
1089
|
-
# Optional.
|
1090
|
-
# @param [Time] max_created_at Max value for {Job#created_at}. When
|
1091
|
-
# provided, only jobs created before or at this time are returned.
|
1092
|
-
# Optional.
|
1093
1087
|
#
|
1094
1088
|
# Acceptable values are:
|
1095
1089
|
#
|
1096
1090
|
# * `done` - Finished jobs
|
1097
1091
|
# * `pending` - Pending jobs
|
1098
1092
|
# * `running` - Running jobs
|
1093
|
+
# @param [Time] min_created_at Min value for {Job#created_at}. When
|
1094
|
+
# provided, only jobs created after or at this time are returned.
|
1095
|
+
# Optional.
|
1096
|
+
# @param [Time] max_created_at Max value for {Job#created_at}. When
|
1097
|
+
# provided, only jobs created before or at this time are returned.
|
1098
|
+
# Optional.
|
1099
|
+
# @param [Google::Cloud::Bigquery::Job, String] parent_job A job
|
1100
|
+
# object or a job ID. If set, retrieve only child jobs of the
|
1101
|
+
# specified parent. Optional. See {Job#job_id}, {Job#num_child_jobs},
|
1102
|
+
# and {Job#parent_job_id}.
|
1099
1103
|
#
|
1100
1104
|
# @return [Array<Google::Cloud::Bigquery::Job>] (See
|
1101
1105
|
# {Google::Cloud::Bigquery::Job::List})
|
@@ -1144,13 +1148,63 @@ module Google
|
|
1144
1148
|
# # process job
|
1145
1149
|
# end
|
1146
1150
|
#
|
1147
|
-
|
1148
|
-
|
1151
|
+
# @example Retrieve child jobs by setting `parent_job`:
|
1152
|
+
# require "google/cloud/bigquery"
|
1153
|
+
#
|
1154
|
+
# bigquery = Google::Cloud::Bigquery.new
|
1155
|
+
#
|
1156
|
+
# multi_statement_sql = <<~SQL
|
1157
|
+
# -- Declare a variable to hold names as an array.
|
1158
|
+
# DECLARE top_names ARRAY<STRING>;
|
1159
|
+
# -- Build an array of the top 100 names from the year 2017.
|
1160
|
+
# SET top_names = (
|
1161
|
+
# SELECT ARRAY_AGG(name ORDER BY number DESC LIMIT 100)
|
1162
|
+
# FROM `bigquery-public-data.usa_names.usa_1910_current`
|
1163
|
+
# WHERE year = 2017
|
1164
|
+
# );
|
1165
|
+
# -- Which names appear as words in Shakespeare's plays?
|
1166
|
+
# SELECT
|
1167
|
+
# name AS shakespeare_name
|
1168
|
+
# FROM UNNEST(top_names) AS name
|
1169
|
+
# WHERE name IN (
|
1170
|
+
# SELECT word
|
1171
|
+
# FROM `bigquery-public-data.samples.shakespeare`
|
1172
|
+
# );
|
1173
|
+
# SQL
|
1174
|
+
#
|
1175
|
+
# job = bigquery.query_job multi_statement_sql
|
1176
|
+
#
|
1177
|
+
# job.wait_until_done!
|
1178
|
+
#
|
1179
|
+
# child_jobs = bigquery.jobs parent_job: job
|
1180
|
+
#
|
1181
|
+
# child_jobs.each do |child_job|
|
1182
|
+
# script_statistics = child_job.script_statistics
|
1183
|
+
# puts script_statistics.evaluation_kind
|
1184
|
+
# script_statistics.stack_frames.each do |stack_frame|
|
1185
|
+
# puts stack_frame.text
|
1186
|
+
# end
|
1187
|
+
# end
|
1188
|
+
#
|
1189
|
+
def jobs all: nil,
|
1190
|
+
token: nil,
|
1191
|
+
max: nil,
|
1192
|
+
filter: nil,
|
1193
|
+
min_created_at: nil,
|
1194
|
+
max_created_at: nil,
|
1195
|
+
parent_job: nil
|
1149
1196
|
ensure_service!
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1197
|
+
parent_job = parent_job.job_id if parent_job.is_a? Job
|
1198
|
+
options = {
|
1199
|
+
parent_job_id: parent_job,
|
1200
|
+
all: all,
|
1201
|
+
token: token,
|
1202
|
+
max: max, filter: filter,
|
1203
|
+
min_created_at: min_created_at,
|
1204
|
+
max_created_at: max_created_at
|
1205
|
+
}
|
1206
|
+
gapi = service.list_jobs(**options)
|
1207
|
+
Job::List.from_gapi gapi, service, **options
|
1154
1208
|
end
|
1155
1209
|
|
1156
1210
|
##
|
@@ -48,6 +48,44 @@ module Google
|
|
48
48
|
# puts job.data.first
|
49
49
|
# end
|
50
50
|
#
|
51
|
+
# @example With multiple statements and child jobs:
|
52
|
+
# require "google/cloud/bigquery"
|
53
|
+
#
|
54
|
+
# bigquery = Google::Cloud::Bigquery.new
|
55
|
+
#
|
56
|
+
# multi_statement_sql = <<~SQL
|
57
|
+
# -- Declare a variable to hold names as an array.
|
58
|
+
# DECLARE top_names ARRAY<STRING>;
|
59
|
+
# -- Build an array of the top 100 names from the year 2017.
|
60
|
+
# SET top_names = (
|
61
|
+
# SELECT ARRAY_AGG(name ORDER BY number DESC LIMIT 100)
|
62
|
+
# FROM `bigquery-public-data.usa_names.usa_1910_current`
|
63
|
+
# WHERE year = 2017
|
64
|
+
# );
|
65
|
+
# -- Which names appear as words in Shakespeare's plays?
|
66
|
+
# SELECT
|
67
|
+
# name AS shakespeare_name
|
68
|
+
# FROM UNNEST(top_names) AS name
|
69
|
+
# WHERE name IN (
|
70
|
+
# SELECT word
|
71
|
+
# FROM `bigquery-public-data.samples.shakespeare`
|
72
|
+
# );
|
73
|
+
# SQL
|
74
|
+
#
|
75
|
+
# job = bigquery.query_job multi_statement_sql
|
76
|
+
#
|
77
|
+
# job.wait_until_done!
|
78
|
+
#
|
79
|
+
# child_jobs = bigquery.jobs parent_job: job
|
80
|
+
#
|
81
|
+
# child_jobs.each do |child_job|
|
82
|
+
# script_statistics = child_job.script_statistics
|
83
|
+
# puts script_statistics.evaluation_kind
|
84
|
+
# script_statistics.stack_frames.each do |stack_frame|
|
85
|
+
# puts stack_frame.text
|
86
|
+
# end
|
87
|
+
# end
|
88
|
+
#
|
51
89
|
class QueryJob < Job
|
52
90
|
##
|
53
91
|
# Checks if the priority for the query is `BATCH`.
|
@@ -339,14 +339,16 @@ module Google
|
|
339
339
|
##
|
340
340
|
# Lists all jobs in the specified project to which you have
|
341
341
|
# been granted the READER job role.
|
342
|
-
def list_jobs all: nil,
|
342
|
+
def list_jobs all: nil, token: nil, max: nil, filter: nil, min_created_at: nil, max_created_at: nil,
|
343
|
+
parent_job_id: nil
|
343
344
|
# The list operation is considered idempotent
|
344
345
|
min_creation_time = Convert.time_to_millis min_created_at
|
345
346
|
max_creation_time = Convert.time_to_millis max_created_at
|
346
347
|
execute backoff: true do
|
347
348
|
service.list_jobs @project, all_users: all, max_results: max,
|
348
349
|
page_token: token, projection: "full", state_filter: filter,
|
349
|
-
min_creation_time: min_creation_time, max_creation_time: max_creation_time
|
350
|
+
min_creation_time: min_creation_time, max_creation_time: max_creation_time,
|
351
|
+
parent_job_id: parent_job_id
|
350
352
|
end
|
351
353
|
end
|
352
354
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-cloud-bigquery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.21.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Moore
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-03-
|
12
|
+
date: 2020-03-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: concurrent-ruby
|