google-cloud-bigquery 0.20.2 → 0.21.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f16696b5a90b556871480222793c4e66d27c9fe6
4
- data.tar.gz: b6c55807e67d5888773bccf1dabee042b23a9abe
3
+ metadata.gz: 6329af7634e65dcd64c344c2828b68e11a104399
4
+ data.tar.gz: a9d9b8b97b9f650a24f1f9fb22a5fbe989dce6f5
5
5
  SHA512:
6
- metadata.gz: f07cece664a25f4962b72aef938fc39ff560e2aefbe32eabb375f8e98303f016d032fddce70de0a8f8887b2d4e49f5aa3e0b1e358a09a675d650a082d8984d61
7
- data.tar.gz: 7b3ebbc30c72952601caf1f293fb8913ce51e9be6b22e2b783baaf7d26b378648009a7bec603b94823d2558befbe9cadcd362de701c3b71905704f45bc0b6d0c
6
+ metadata.gz: 92ec74a841633277404218e1306de8b57aa34eb736d748682028642dfbcc36cce225b42e8d391230d1d2aaa4e3514c86b464c8eee8e30f91d87eb36afb0fc18b
7
+ data.tar.gz: e149b925e5bd3985a7fb173dca9ea762d9c98251b90786b8648b1b7c214cbae81e1fb9d9af8429ba050d99c1ed2d36379a236a9f2f191eac37c28bb017494be5
@@ -94,7 +94,7 @@ module Google
94
94
  # @return [Google::Cloud::Bigquery::Project]
95
95
  #
96
96
  # @example
97
- # require "google/cloud/bigquery"
97
+ # require "google/cloud"
98
98
  #
99
99
  # bigquery = Google::Cloud.bigquery
100
100
  # dataset = bigquery.dataset "my_dataset"
@@ -103,20 +103,9 @@ module Google
103
103
  def self.bigquery project = nil, keyfile = nil, scope: nil, retries: nil,
104
104
  timeout: nil
105
105
  require "google/cloud/bigquery"
106
- project ||= Google::Cloud::Bigquery::Project.default_project
107
- project = project.to_s # Always cast to a string
108
- fail ArgumentError, "project is missing" if project.empty?
109
-
110
- if keyfile.nil?
111
- credentials = Google::Cloud::Bigquery::Credentials.default scope: scope
112
- else
113
- credentials = Google::Cloud::Bigquery::Credentials.new(
114
- keyfile, scope: scope)
115
- end
116
-
117
- Google::Cloud::Bigquery::Project.new(
118
- Google::Cloud::Bigquery::Service.new(
119
- project, credentials, retries: retries, timeout: timeout))
106
+ Google::Cloud::Bigquery.new project: project, keyfile: keyfile,
107
+ scope: scope, retries: retries,
108
+ timeout: timeout
120
109
  end
121
110
  end
122
111
  end
@@ -48,10 +48,9 @@ module Google
48
48
  # let's connect to Google's `publicdata` project, and see what you find.
49
49
  #
50
50
  # ```ruby
51
- # require "google/cloud"
51
+ # require "google/cloud/bigquery"
52
52
  #
53
- # gcloud = Google::Cloud.new "publicdata"
54
- # bigquery = gcloud.bigquery
53
+ # bigquery = Google::Cloud::Bigquery.new project: "publicdata"
55
54
  #
56
55
  # bigquery.datasets.count #=> 1
57
56
  # bigquery.datasets.first.dataset_id #=> "samples"
@@ -69,10 +68,9 @@ module Google
69
68
  # every play written by Shakespeare.
70
69
  #
71
70
  # ```ruby
72
- # require "google/cloud"
71
+ # require "google/cloud/bigquery"
73
72
  #
74
- # gcloud = Google::Cloud.new "publicdata"
75
- # bigquery = gcloud.bigquery
73
+ # bigquery = Google::Cloud::Bigquery.new project: "publicdata"
76
74
  #
77
75
  # dataset = bigquery.dataset "samples"
78
76
  # table = dataset.table "shakespeare"
@@ -97,10 +95,9 @@ module Google
97
95
  # results.
98
96
  #
99
97
  # ```ruby
100
- # require "google/cloud"
98
+ # require "google/cloud/bigquery"
101
99
  #
102
- # gcloud = Google::Cloud.new
103
- # bigquery = gcloud.bigquery
100
+ # bigquery = Google::Cloud::Bigquery.new
104
101
  #
105
102
  # sql = "SELECT TOP(word, 50) as word, COUNT(*) as count " +
106
103
  # "FROM publicdata:samples.shakespeare"
@@ -126,10 +123,9 @@ module Google
126
123
  # of {Google::Cloud::Bigquery::QueryData}.
127
124
  #
128
125
  # ```ruby
129
- # require "google/cloud"
126
+ # require "google/cloud/bigquery"
130
127
  #
131
- # gcloud = Google::Cloud.new
132
- # bigquery = gcloud.bigquery
128
+ # bigquery = Google::Cloud::Bigquery.new
133
129
  #
134
130
  # sql = "SELECT TOP(word, 50) as word, COUNT(*) as count " +
135
131
  # "FROM publicdata:samples.shakespeare"
@@ -159,8 +155,8 @@ module Google
159
155
  # ```ruby
160
156
  # require "google/cloud/bigquery"
161
157
  #
162
- # gcloud = Google::Cloud.new
163
- # bigquery = gcloud.bigquery
158
+ # bigquery = Google::Cloud::Bigquery.new
159
+ #
164
160
  # dataset = bigquery.create_dataset "my_dataset"
165
161
  # ```
166
162
  #
@@ -172,10 +168,9 @@ module Google
172
168
  # BigQuery](https://cloud.google.com/bigquery/preparing-data-for-bigquery).)
173
169
  #
174
170
  # ```ruby
175
- # require "google/cloud"
171
+ # require "google/cloud/bigquery"
176
172
  #
177
- # gcloud = Google::Cloud.new
178
- # bigquery = gcloud.bigquery
173
+ # bigquery = Google::Cloud::Bigquery.new
179
174
  # dataset = bigquery.dataset "my_dataset"
180
175
  #
181
176
  # table = dataset.create_table "people" do |schema|
@@ -207,10 +202,9 @@ module Google
207
202
  # application is a great approach.
208
203
  #
209
204
  # ```ruby
210
- # require "google/cloud"
205
+ # require "google/cloud/bigquery"
211
206
  #
212
- # gcloud = Google::Cloud.new
213
- # bigquery = gcloud.bigquery
207
+ # bigquery = Google::Cloud::Bigquery.new
214
208
  # dataset = bigquery.dataset "my_dataset"
215
209
  # table = dataset.table "people"
216
210
  #
@@ -254,10 +248,9 @@ module Google
254
248
  # also contained in the archive specifies the schema used below.
255
249
  #
256
250
  # ```ruby
257
- # require "google/cloud"
251
+ # require "google/cloud/bigquery"
258
252
  #
259
- # gcloud = Google::Cloud.new
260
- # bigquery = gcloud.bigquery
253
+ # bigquery = Google::Cloud::Bigquery.new
261
254
  # dataset = bigquery.dataset "my_dataset"
262
255
  # table = dataset.create_table "baby_names" do |schema|
263
256
  # schema.string "name", mode: :required
@@ -284,10 +277,9 @@ module Google
284
277
  # setting up billing.
285
278
  #
286
279
  # ```ruby
287
- # require "google/cloud"
280
+ # require "google/cloud/bigquery"
288
281
  #
289
- # gcloud = Google::Cloud.new
290
- # bigquery = gcloud.bigquery
282
+ # bigquery = Google::Cloud::Bigquery.new
291
283
  # dataset = bigquery.dataset "my_dataset"
292
284
  # source_table = dataset.table "baby_names"
293
285
  # result_table = dataset.create_table "baby_names_results"
@@ -302,7 +294,9 @@ module Google
302
294
  #
303
295
  # if !query_job.failed?
304
296
  #
305
- # storage = gcloud.storage
297
+ # require "google/cloud/bigquery"
298
+ #
299
+ # storage = Google::Cloud::Storage.new
306
300
  # bucket_id = "bigquery-exports-#{SecureRandom.uuid}"
307
301
  # bucket = storage.create_bucket bucket_id
308
302
  # extract_url = "gs://#{bucket.id}/baby-names-sam.csv"
@@ -337,10 +331,9 @@ module Google
337
331
  # You can also set the request `timeout` value in seconds.
338
332
  #
339
333
  # ```ruby
340
- # require "google/cloud"
334
+ # require "google/cloud/bigquery"
341
335
  #
342
- # gcloud = Google::Cloud.new
343
- # bigquery = gcloud.bigquery retries: 10, timeout: 120
336
+ # bigquery = Google::Cloud::Bigquery.new retries: 10, timeout: 120
344
337
  # ```
345
338
  #
346
339
  # See the [BigQuery error
@@ -348,6 +341,56 @@ module Google
348
341
  # for a list of error conditions.
349
342
  #
350
343
  module Bigquery
344
+ # Creates a new `Project` instance connected to the BigQuery service.
345
+ # Each call creates a new connection.
346
+ #
347
+ # For more information on connecting to Google Cloud see the
348
+ # [Authentication
349
+ # Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
350
+ #
351
+ # @param [String] project Identifier for a BigQuery project. If not
352
+ # present, the default project for the credentials is used.
353
+ # @param [String, Hash] keyfile Keyfile downloaded from Google Cloud. If
354
+ # file path the file must be readable.
355
+ # @param [String, Array<String>] scope The OAuth 2.0 scopes controlling
356
+ # the set of resources and operations that the connection can access.
357
+ # See # [Using OAuth 2.0 to Access Google #
358
+ # APIs](https://developers.google.com/identity/protocols/OAuth2).
359
+ #
360
+ # The default scope is:
361
+ #
362
+ # * `https://www.googleapis.com/auth/bigquery`
363
+ # @param [Integer] retries Number of times to retry requests on server
364
+ # error. The default value is `3`. Optional.
365
+ # @param [Integer] timeout Default timeout to use in requests. Optional.
366
+ #
367
+ # @return [Google::Cloud::Bigquery::Project]
368
+ #
369
+ # @example
370
+ # require "google/cloud/bigquery"
371
+ #
372
+ # bigquery = Google::Cloud::Bigquery.new
373
+ # dataset = bigquery.dataset "my_dataset"
374
+ # table = dataset.table "my_table"
375
+ #
376
+ def self.new project: nil, keyfile: nil, scope: nil, retries: nil,
377
+ timeout: nil
378
+ project ||= Google::Cloud::Bigquery::Project.default_project
379
+ project = project.to_s # Always cast to a string
380
+ fail ArgumentError, "project is missing" if project.empty?
381
+
382
+ if keyfile.nil?
383
+ credentials = Google::Cloud::Bigquery::Credentials.default(
384
+ scope: scope)
385
+ else
386
+ credentials = Google::Cloud::Bigquery::Credentials.new(
387
+ keyfile, scope: scope)
388
+ end
389
+
390
+ Google::Cloud::Bigquery::Project.new(
391
+ Google::Cloud::Bigquery::Service.new(
392
+ project, credentials, retries: retries, timeout: timeout))
393
+ end
351
394
  end
352
395
  end
353
396
  end
@@ -71,10 +71,9 @@ module Google
71
71
  # @return [Boolean]
72
72
  #
73
73
  # @example
74
- # require "google/cloud"
74
+ # require "google/cloud/bigquery"
75
75
  #
76
- # gcloud = Google::Cloud.new
77
- # bigquery = gcloud.bigquery
76
+ # bigquery = Google::Cloud::Bigquery.new
78
77
  # table = dataset.table "my_table"
79
78
  #
80
79
  # data = table.data
@@ -92,10 +91,9 @@ module Google
92
91
  # @return [Data]
93
92
  #
94
93
  # @example
95
- # require "google/cloud"
94
+ # require "google/cloud/bigquery"
96
95
  #
97
- # gcloud = Google::Cloud.new
98
- # bigquery = gcloud.bigquery
96
+ # bigquery = Google::Cloud::Bigquery.new
99
97
  # table = dataset.table "my_table"
100
98
  #
101
99
  # data = table.data
@@ -128,10 +126,9 @@ module Google
128
126
  # @return [Enumerator]
129
127
  #
130
128
  # @example Iterating each rows by passing a block:
131
- # require "google/cloud"
129
+ # require "google/cloud/bigquery"
132
130
  #
133
- # gcloud = Google::Cloud.new
134
- # bigquery = gcloud.bigquery
131
+ # bigquery = Google::Cloud::Bigquery.new
135
132
  # table = dataset.table "my_table"
136
133
  #
137
134
  # table.data.all do |row|
@@ -139,10 +136,9 @@ module Google
139
136
  # end
140
137
  #
141
138
  # @example Using the enumerator by not passing a block:
142
- # require "google/cloud"
139
+ # require "google/cloud/bigquery"
143
140
  #
144
- # gcloud = Google::Cloud.new
145
- # bigquery = gcloud.bigquery
141
+ # bigquery = Google::Cloud::Bigquery.new
146
142
  # table = dataset.table "my_table"
147
143
  #
148
144
  # words = table.data.all.map do |row|
@@ -150,10 +146,9 @@ module Google
150
146
  # end
151
147
  #
152
148
  # @example Limit the number of API calls made:
153
- # require "google/cloud"
149
+ # require "google/cloud/bigquery"
154
150
  #
155
- # gcloud = Google::Cloud.new
156
- # bigquery = gcloud.bigquery
151
+ # bigquery = Google::Cloud::Bigquery.new
157
152
  # table = dataset.table "my_table"
158
153
  #
159
154
  # table.data.all(request_limit: 10) do |row|
@@ -33,10 +33,9 @@ module Google
33
33
  # within a specific project.
34
34
  #
35
35
  # @example
36
- # require "google/cloud"
36
+ # require "google/cloud/bigquery"
37
37
  #
38
- # gcloud = Google::Cloud.new
39
- # bigquery = gcloud.bigquery
38
+ # bigquery = Google::Cloud::Bigquery.new
40
39
  #
41
40
  # dataset = bigquery.create_dataset "my_dataset",
42
41
  # name: "My Dataset",
@@ -225,10 +224,9 @@ module Google
225
224
  # @return [Google::Cloud::Bigquery::Dataset::Access]
226
225
  #
227
226
  # @example
228
- # require "google/cloud"
227
+ # require "google/cloud/bigquery"
229
228
  #
230
- # gcloud = Google::Cloud.new
231
- # bigquery = gcloud.bigquery
229
+ # bigquery = Google::Cloud::Bigquery.new
232
230
  # dataset = bigquery.dataset "my_dataset"
233
231
  #
234
232
  # dataset.access #=> [{"role"=>"OWNER",
@@ -241,10 +239,9 @@ module Google
241
239
  # # "userByEmail"=>"123456789-...com"}]
242
240
  #
243
241
  # @example Manage the access rules by passing a block:
244
- # require "google/cloud"
242
+ # require "google/cloud/bigquery"
245
243
  #
246
- # gcloud = Google::Cloud.new
247
- # bigquery = gcloud.bigquery
244
+ # bigquery = Google::Cloud::Bigquery.new
248
245
  # dataset = bigquery.dataset "my_dataset"
249
246
  #
250
247
  # dataset.access do |access|
@@ -279,10 +276,9 @@ module Google
279
276
  # @return [Boolean] Returns `true` if the dataset was deleted.
280
277
  #
281
278
  # @example
282
- # require "google/cloud"
279
+ # require "google/cloud/bigquery"
283
280
  #
284
- # gcloud = Google::Cloud.new
285
- # bigquery = gcloud.bigquery
281
+ # bigquery = Google::Cloud::Bigquery.new
286
282
  #
287
283
  # dataset = bigquery.dataset "my_dataset"
288
284
  # dataset.delete
@@ -315,28 +311,25 @@ module Google
315
311
  # @return [Google::Cloud::Bigquery::Table]
316
312
  #
317
313
  # @example
318
- # require "google/cloud"
314
+ # require "google/cloud/bigquery"
319
315
  #
320
- # gcloud = Google::Cloud.new
321
- # bigquery = gcloud.bigquery
316
+ # bigquery = Google::Cloud::Bigquery.new
322
317
  # dataset = bigquery.dataset "my_dataset"
323
318
  # table = dataset.create_table "my_table"
324
319
  #
325
320
  # @example You can also pass name and description options.
326
- # require "google/cloud"
321
+ # require "google/cloud/bigquery"
327
322
  #
328
- # gcloud = Google::Cloud.new
329
- # bigquery = gcloud.bigquery
323
+ # bigquery = Google::Cloud::Bigquery.new
330
324
  # dataset = bigquery.dataset "my_dataset"
331
325
  # table = dataset.create_table "my_table"
332
326
  # name: "My Table",
333
327
  # description: "A description of table."
334
328
  #
335
329
  # @example The table's schema fields can be passed as an argument.
336
- # require "google/cloud"
330
+ # require "google/cloud/bigquery"
337
331
  #
338
- # gcloud = Google::Cloud.new
339
- # bigquery = gcloud.bigquery
332
+ # bigquery = Google::Cloud::Bigquery.new
340
333
  # dataset = bigquery.dataset "my_dataset"
341
334
  #
342
335
  # schema_fields = [
@@ -354,10 +347,9 @@ module Google
354
347
  # table = dataset.create_table "my_table", fields: schema_fields
355
348
  #
356
349
  # @example Or the table's schema can be configured with the block.
357
- # require "google/cloud"
350
+ # require "google/cloud/bigquery"
358
351
  #
359
- # gcloud = Google::Cloud.new
360
- # bigquery = gcloud.bigquery
352
+ # bigquery = Google::Cloud::Bigquery.new
361
353
  # dataset = bigquery.dataset "my_dataset"
362
354
  #
363
355
  # table = dataset.create_table "my_table" do |t|
@@ -369,10 +361,9 @@ module Google
369
361
  # end
370
362
  #
371
363
  # @example You can define the schema using a nested block.
372
- # require "google/cloud"
364
+ # require "google/cloud/bigquery"
373
365
  #
374
- # gcloud = Google::Cloud.new
375
- # bigquery = gcloud.bigquery
366
+ # bigquery = Google::Cloud::Bigquery.new
376
367
  # dataset = bigquery.dataset "my_dataset"
377
368
  # table = dataset.create_table "my_table" do |t|
378
369
  # t.name = "My Table",
@@ -420,19 +411,17 @@ module Google
420
411
  # @return [Google::Cloud::Bigquery::View]
421
412
  #
422
413
  # @example
423
- # require "google/cloud"
414
+ # require "google/cloud/bigquery"
424
415
  #
425
- # gcloud = Google::Cloud.new
426
- # bigquery = gcloud.bigquery
416
+ # bigquery = Google::Cloud::Bigquery.new
427
417
  # dataset = bigquery.dataset "my_dataset"
428
418
  # view = dataset.create_view "my_view",
429
419
  # "SELECT name, age FROM [proj:dataset.users]"
430
420
  #
431
421
  # @example A name and description can be provided:
432
- # require "google/cloud"
422
+ # require "google/cloud/bigquery"
433
423
  #
434
- # gcloud = Google::Cloud.new
435
- # bigquery = gcloud.bigquery
424
+ # bigquery = Google::Cloud::Bigquery.new
436
425
  # dataset = bigquery.dataset "my_dataset"
437
426
  # view = dataset.create_view "my_view",
438
427
  # "SELECT name, age FROM [proj:dataset.users]",
@@ -467,10 +456,9 @@ module Google
467
456
  # not exist
468
457
  #
469
458
  # @example
470
- # require "google/cloud"
459
+ # require "google/cloud/bigquery"
471
460
  #
472
- # gcloud = Google::Cloud.new
473
- # bigquery = gcloud.bigquery
461
+ # bigquery = Google::Cloud::Bigquery.new
474
462
  # dataset = bigquery.dataset "my_dataset"
475
463
  # table = dataset.table "my_table"
476
464
  # puts table.name
@@ -497,10 +485,9 @@ module Google
497
485
  # {Google::Cloud::Bigquery::Table::List})
498
486
  #
499
487
  # @example
500
- # require "google/cloud"
488
+ # require "google/cloud/bigquery"
501
489
  #
502
- # gcloud = Google::Cloud.new
503
- # bigquery = gcloud.bigquery
490
+ # bigquery = Google::Cloud::Bigquery.new
504
491
  # dataset = bigquery.dataset "my_dataset"
505
492
  # tables = dataset.tables
506
493
  # tables.each do |table|
@@ -508,10 +495,9 @@ module Google
508
495
  # end
509
496
  #
510
497
  # @example Retrieve all tables: (See {Table::List#all})
511
- # require "google/cloud"
498
+ # require "google/cloud/bigquery"
512
499
  #
513
- # gcloud = Google::Cloud.new
514
- # bigquery = gcloud.bigquery
500
+ # bigquery = Google::Cloud::Bigquery.new
515
501
  # dataset = bigquery.dataset "my_dataset"
516
502
  # tables = dataset.tables
517
503
  # tables.all do |table|
@@ -576,10 +562,9 @@ module Google
576
562
  # @return [Google::Cloud::Bigquery::QueryJob]
577
563
  #
578
564
  # @example
579
- # require "google/cloud"
565
+ # require "google/cloud/bigquery"
580
566
  #
581
- # gcloud = Google::Cloud.new
582
- # bigquery = gcloud.bigquery
567
+ # bigquery = Google::Cloud::Bigquery.new
583
568
  #
584
569
  # job = bigquery.query_job "SELECT name FROM my_table"
585
570
  #
@@ -639,10 +624,9 @@ module Google
639
624
  # @return [Google::Cloud::Bigquery::QueryData]
640
625
  #
641
626
  # @example
642
- # require "google/cloud"
627
+ # require "google/cloud/bigquery"
643
628
  #
644
- # gcloud = Google::Cloud.new
645
- # bigquery = gcloud.bigquery
629
+ # bigquery = Google::Cloud::Bigquery.new
646
630
  #
647
631
  # data = bigquery.query "SELECT name FROM my_table"
648
632
  # data.each do |row|