google-cloud-bigquery 1.14.0 → 1.42.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/AUTHENTICATION.md +17 -54
- data/CHANGELOG.md +377 -0
- data/CONTRIBUTING.md +328 -116
- data/LOGGING.md +1 -1
- data/OVERVIEW.md +21 -20
- data/TROUBLESHOOTING.md +2 -8
- data/lib/google/cloud/bigquery/argument.rb +197 -0
- data/lib/google/cloud/bigquery/convert.rb +155 -173
- data/lib/google/cloud/bigquery/copy_job.rb +74 -26
- data/lib/google/cloud/bigquery/credentials.rb +5 -12
- data/lib/google/cloud/bigquery/data.rb +109 -18
- data/lib/google/cloud/bigquery/dataset/access.rb +474 -52
- data/lib/google/cloud/bigquery/dataset/list.rb +7 -13
- data/lib/google/cloud/bigquery/dataset/tag.rb +67 -0
- data/lib/google/cloud/bigquery/dataset.rb +1044 -287
- data/lib/google/cloud/bigquery/external/avro_source.rb +107 -0
- data/lib/google/cloud/bigquery/external/bigtable_source/column.rb +404 -0
- data/lib/google/cloud/bigquery/external/bigtable_source/column_family.rb +945 -0
- data/lib/google/cloud/bigquery/external/bigtable_source.rb +230 -0
- data/lib/google/cloud/bigquery/external/csv_source.rb +481 -0
- data/lib/google/cloud/bigquery/external/data_source.rb +771 -0
- data/lib/google/cloud/bigquery/external/json_source.rb +170 -0
- data/lib/google/cloud/bigquery/external/parquet_source.rb +148 -0
- data/lib/google/cloud/bigquery/external/sheets_source.rb +166 -0
- data/lib/google/cloud/bigquery/external.rb +50 -2256
- data/lib/google/cloud/bigquery/extract_job.rb +226 -61
- data/lib/google/cloud/bigquery/insert_response.rb +1 -3
- data/lib/google/cloud/bigquery/job/list.rb +10 -14
- data/lib/google/cloud/bigquery/job.rb +289 -14
- data/lib/google/cloud/bigquery/load_job.rb +810 -136
- data/lib/google/cloud/bigquery/model/list.rb +5 -9
- data/lib/google/cloud/bigquery/model.rb +247 -16
- data/lib/google/cloud/bigquery/policy.rb +432 -0
- data/lib/google/cloud/bigquery/project/list.rb +6 -11
- data/lib/google/cloud/bigquery/project.rb +509 -250
- data/lib/google/cloud/bigquery/query_job.rb +594 -128
- data/lib/google/cloud/bigquery/routine/list.rb +165 -0
- data/lib/google/cloud/bigquery/routine.rb +1227 -0
- data/lib/google/cloud/bigquery/schema/field.rb +413 -63
- data/lib/google/cloud/bigquery/schema.rb +221 -48
- data/lib/google/cloud/bigquery/service.rb +204 -112
- data/lib/google/cloud/bigquery/standard_sql.rb +269 -53
- data/lib/google/cloud/bigquery/table/async_inserter.rb +86 -43
- data/lib/google/cloud/bigquery/table/list.rb +6 -11
- data/lib/google/cloud/bigquery/table.rb +1470 -377
- data/lib/google/cloud/bigquery/time.rb +6 -0
- data/lib/google/cloud/bigquery/version.rb +1 -1
- data/lib/google/cloud/bigquery.rb +4 -6
- data/lib/google-cloud-bigquery.rb +14 -13
- metadata +66 -38
@@ -154,6 +154,27 @@ module Google
|
|
154
154
|
fields.map(&:name).map(&:to_sym)
|
155
155
|
end
|
156
156
|
|
157
|
+
##
|
158
|
+
# The types of the fields, using the same format as the optional query
|
159
|
+
# parameter types.
|
160
|
+
#
|
161
|
+
# @return [Hash] A hash with column names as keys, and types as values.
|
162
|
+
#
|
163
|
+
# @example
|
164
|
+
# require "google/cloud/bigquery"
|
165
|
+
#
|
166
|
+
# bigquery = Google::Cloud::Bigquery.new
|
167
|
+
# dataset = bigquery.dataset "my_dataset"
|
168
|
+
# table = dataset.create_table "my_table"
|
169
|
+
#
|
170
|
+
# schema = table.schema
|
171
|
+
#
|
172
|
+
# schema.param_types
|
173
|
+
#
|
174
|
+
def param_types
|
175
|
+
fields.to_h { |field| [field.name.to_sym, field.param_type] }
|
176
|
+
end
|
177
|
+
|
157
178
|
##
|
158
179
|
# Retrieve a field by name.
|
159
180
|
#
|
@@ -211,8 +232,8 @@ module Google
|
|
211
232
|
#
|
212
233
|
# bigquery = Google::Cloud::Bigquery.new
|
213
234
|
# dataset = bigquery.dataset "my_dataset"
|
214
|
-
# table = dataset.table "my_table" do |
|
215
|
-
#
|
235
|
+
# table = dataset.table "my_table" do |t|
|
236
|
+
# t.schema.load File.read("path/to/schema.json")
|
216
237
|
# end
|
217
238
|
#
|
218
239
|
def load source
|
@@ -266,161 +287,305 @@ module Google
|
|
266
287
|
# Adds a string field to the schema.
|
267
288
|
#
|
268
289
|
# @param [String] name The field name. The name must contain only
|
269
|
-
# letters (
|
290
|
+
# letters (`[A-Za-z]`), numbers (`[0-9]`), or underscores (`_`), and must
|
270
291
|
# start with a letter or underscore. The maximum length is 128
|
271
292
|
# characters.
|
272
293
|
# @param [String] description A description of the field.
|
273
294
|
# @param [Symbol] mode The field's mode. The possible values are
|
274
295
|
# `:nullable`, `:required`, and `:repeated`. The default value is
|
275
296
|
# `:nullable`.
|
276
|
-
#
|
277
|
-
|
278
|
-
|
297
|
+
# @param [Array<String>, String] policy_tags The policy tag list or
|
298
|
+
# single policy tag for the field. Policy tag identifiers are of
|
299
|
+
# the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
|
300
|
+
# At most 1 policy tag is currently allowed.
|
301
|
+
# @param [Integer] max_length The maximum UTF-8 length of strings
|
302
|
+
# allowed in the field.
|
303
|
+
#
|
304
|
+
def string name, description: nil, mode: :nullable, policy_tags: nil, max_length: nil
|
305
|
+
add_field name,
|
306
|
+
:string,
|
307
|
+
description: description,
|
308
|
+
mode: mode,
|
309
|
+
policy_tags: policy_tags,
|
310
|
+
max_length: max_length
|
279
311
|
end
|
280
312
|
|
281
313
|
##
|
282
314
|
# Adds an integer field to the schema.
|
283
315
|
#
|
284
316
|
# @param [String] name The field name. The name must contain only
|
285
|
-
# letters (
|
317
|
+
# letters (`[A-Za-z]`), numbers (`[0-9]`), or underscores (`_`), and must
|
286
318
|
# start with a letter or underscore. The maximum length is 128
|
287
319
|
# characters.
|
288
320
|
# @param [String] description A description of the field.
|
289
321
|
# @param [Symbol] mode The field's mode. The possible values are
|
290
322
|
# `:nullable`, `:required`, and `:repeated`. The default value is
|
291
323
|
# `:nullable`.
|
324
|
+
# @param [Array<String>, String] policy_tags The policy tag list or
|
325
|
+
# single policy tag for the field. Policy tag identifiers are of
|
326
|
+
# the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
|
327
|
+
# At most 1 policy tag is currently allowed.
|
292
328
|
#
|
293
|
-
def integer name, description: nil, mode: :nullable
|
294
|
-
add_field name, :integer, description: description, mode: mode
|
329
|
+
def integer name, description: nil, mode: :nullable, policy_tags: nil
|
330
|
+
add_field name, :integer, description: description, mode: mode, policy_tags: policy_tags
|
295
331
|
end
|
296
332
|
|
297
333
|
##
|
298
334
|
# Adds a floating-point number field to the schema.
|
299
335
|
#
|
300
336
|
# @param [String] name The field name. The name must contain only
|
301
|
-
# letters (
|
337
|
+
# letters (`[A-Za-z]`), numbers (`[0-9]`), or underscores (`_`), and must
|
302
338
|
# start with a letter or underscore. The maximum length is 128
|
303
339
|
# characters.
|
304
340
|
# @param [String] description A description of the field.
|
305
341
|
# @param [Symbol] mode The field's mode. The possible values are
|
306
342
|
# `:nullable`, `:required`, and `:repeated`. The default value is
|
307
343
|
# `:nullable`.
|
344
|
+
# @param [Array<String>, String] policy_tags The policy tag list or
|
345
|
+
# single policy tag for the field. Policy tag identifiers are of
|
346
|
+
# the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
|
347
|
+
# At most 1 policy tag is currently allowed.
|
308
348
|
#
|
309
|
-
def float name, description: nil, mode: :nullable
|
310
|
-
add_field name, :float, description: description, mode: mode
|
349
|
+
def float name, description: nil, mode: :nullable, policy_tags: nil
|
350
|
+
add_field name, :float, description: description, mode: mode, policy_tags: policy_tags
|
311
351
|
end
|
312
352
|
|
313
353
|
##
|
314
|
-
# Adds a numeric number field to the schema.
|
315
|
-
#
|
316
|
-
#
|
354
|
+
# Adds a numeric number field to the schema. `NUMERIC` is a decimal
|
355
|
+
# type with fixed precision and scale. Precision is the number of
|
356
|
+
# digits that the number contains. Scale is how many of these
|
357
|
+
# digits appear after the decimal point. It supports:
|
358
|
+
#
|
359
|
+
# Precision: 38
|
360
|
+
# Scale: 9
|
361
|
+
# Min: -9.9999999999999999999999999999999999999E+28
|
362
|
+
# Max: 9.9999999999999999999999999999999999999E+28
|
363
|
+
#
|
364
|
+
# This type can represent decimal fractions exactly, and is suitable
|
365
|
+
# for financial calculations.
|
317
366
|
#
|
318
367
|
# @param [String] name The field name. The name must contain only
|
319
|
-
# letters (
|
368
|
+
# letters (`[A-Za-z]`), numbers (`[0-9]`), or underscores (`_`), and must
|
320
369
|
# start with a letter or underscore. The maximum length is 128
|
321
370
|
# characters.
|
322
371
|
# @param [String] description A description of the field.
|
323
372
|
# @param [Symbol] mode The field's mode. The possible values are
|
324
373
|
# `:nullable`, `:required`, and `:repeated`. The default value is
|
325
374
|
# `:nullable`.
|
375
|
+
# @param [Array<String>, String] policy_tags The policy tag list or
|
376
|
+
# single policy tag for the field. Policy tag identifiers are of
|
377
|
+
# the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
|
378
|
+
# At most 1 policy tag is currently allowed.
|
379
|
+
# @param [Integer] precision The precision (maximum number of total
|
380
|
+
# digits) for the field. Acceptable values for precision must be:
|
381
|
+
# `1 ≤ (precision - scale) ≤ 29`. Values for scale must be:
|
382
|
+
# `0 ≤ scale ≤ 9`. If the scale value is set, the precision value
|
383
|
+
# must be set as well.
|
384
|
+
# @param [Integer] scale The scale (maximum number of digits in the
|
385
|
+
# fractional part) for the field. Acceptable values for precision
|
386
|
+
# must be: `1 ≤ (precision - scale) ≤ 29`. Values for scale must
|
387
|
+
# be: `0 ≤ scale ≤ 9`. If the scale value is set, the precision
|
388
|
+
# value must be set as well.
|
389
|
+
#
|
390
|
+
def numeric name, description: nil, mode: :nullable, policy_tags: nil, precision: nil, scale: nil
|
391
|
+
add_field name,
|
392
|
+
:numeric,
|
393
|
+
description: description,
|
394
|
+
mode: mode,
|
395
|
+
policy_tags: policy_tags,
|
396
|
+
precision: precision,
|
397
|
+
scale: scale
|
398
|
+
end
|
399
|
+
|
400
|
+
##
|
401
|
+
# Adds a bignumeric number field to the schema. `BIGNUMERIC` is a
|
402
|
+
# decimal type with fixed precision and scale. Precision is the
|
403
|
+
# number of digits that the number contains. Scale is how many of
|
404
|
+
# these digits appear after the decimal point. It supports:
|
405
|
+
#
|
406
|
+
# Precision: 76.76 (the 77th digit is partial)
|
407
|
+
# Scale: 38
|
408
|
+
# Min: -5.7896044618658097711785492504343953926634992332820282019728792003956564819968E+38
|
409
|
+
# Max: 5.7896044618658097711785492504343953926634992332820282019728792003956564819967E+38
|
326
410
|
#
|
327
|
-
|
328
|
-
|
411
|
+
# This type can represent decimal fractions exactly, and is suitable
|
412
|
+
# for financial calculations.
|
413
|
+
#
|
414
|
+
# @param [String] name The field name. The name must contain only
|
415
|
+
# letters (`[A-Za-z]`), numbers (`[0-9]`), or underscores (`_`), and must
|
416
|
+
# start with a letter or underscore. The maximum length is 128
|
417
|
+
# characters.
|
418
|
+
# @param [String] description A description of the field.
|
419
|
+
# @param [Symbol] mode The field's mode. The possible values are
|
420
|
+
# `:nullable`, `:required`, and `:repeated`. The default value is
|
421
|
+
# `:nullable`.
|
422
|
+
# @param [Array<String>, String] policy_tags The policy tag list or
|
423
|
+
# single policy tag for the field. Policy tag identifiers are of
|
424
|
+
# the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
|
425
|
+
# At most 1 policy tag is currently allowed.
|
426
|
+
# @param [Integer] precision The precision (maximum number of total
|
427
|
+
# digits) for the field. Acceptable values for precision must be:
|
428
|
+
# `1 ≤ (precision - scale) ≤ 38`. Values for scale must be:
|
429
|
+
# `0 ≤ scale ≤ 38`. If the scale value is set, the precision value
|
430
|
+
# must be set as well.
|
431
|
+
# @param [Integer] scale The scale (maximum number of digits in the
|
432
|
+
# fractional part) for the field. Acceptable values for precision
|
433
|
+
# must be: `1 ≤ (precision - scale) ≤ 38`. Values for scale must
|
434
|
+
# be: `0 ≤ scale ≤ 38`. If the scale value is set, the precision
|
435
|
+
# value must be set as well.
|
436
|
+
#
|
437
|
+
def bignumeric name, description: nil, mode: :nullable, policy_tags: nil, precision: nil, scale: nil
|
438
|
+
add_field name,
|
439
|
+
:bignumeric,
|
440
|
+
description: description,
|
441
|
+
mode: mode,
|
442
|
+
policy_tags: policy_tags,
|
443
|
+
precision: precision,
|
444
|
+
scale: scale
|
329
445
|
end
|
330
446
|
|
331
447
|
##
|
332
448
|
# Adds a boolean field to the schema.
|
333
449
|
#
|
334
450
|
# @param [String] name The field name. The name must contain only
|
335
|
-
# letters (
|
451
|
+
# letters (`[A-Za-z]`), numbers (`[0-9]`), or underscores (`_`), and must
|
336
452
|
# start with a letter or underscore. The maximum length is 128
|
337
453
|
# characters.
|
338
454
|
# @param [String] description A description of the field.
|
339
455
|
# @param [Symbol] mode The field's mode. The possible values are
|
340
456
|
# `:nullable`, `:required`, and `:repeated`. The default value is
|
341
457
|
# `:nullable`.
|
458
|
+
# @param [Array<String>, String] policy_tags The policy tag list or
|
459
|
+
# single policy tag for the field. Policy tag identifiers are of
|
460
|
+
# the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
|
461
|
+
# At most 1 policy tag is currently allowed.
|
342
462
|
#
|
343
|
-
def boolean name, description: nil, mode: :nullable
|
344
|
-
add_field name, :boolean, description: description, mode: mode
|
463
|
+
def boolean name, description: nil, mode: :nullable, policy_tags: nil
|
464
|
+
add_field name, :boolean, description: description, mode: mode, policy_tags: policy_tags
|
345
465
|
end
|
346
466
|
|
347
467
|
##
|
348
468
|
# Adds a bytes field to the schema.
|
349
469
|
#
|
350
470
|
# @param [String] name The field name. The name must contain only
|
351
|
-
# letters (
|
471
|
+
# letters (`[A-Za-z]`), numbers (`[0-9]`), or underscores (`_`), and must
|
352
472
|
# start with a letter or underscore. The maximum length is 128
|
353
473
|
# characters.
|
354
474
|
# @param [String] description A description of the field.
|
355
475
|
# @param [Symbol] mode The field's mode. The possible values are
|
356
476
|
# `:nullable`, `:required`, and `:repeated`. The default value is
|
357
477
|
# `:nullable`.
|
358
|
-
#
|
359
|
-
|
360
|
-
|
478
|
+
# @param [Array<String>, String] policy_tags The policy tag list or
|
479
|
+
# single policy tag for the field. Policy tag identifiers are of
|
480
|
+
# the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
|
481
|
+
# At most 1 policy tag is currently allowed.
|
482
|
+
# @param [Integer] max_length The maximum the maximum number of
|
483
|
+
# bytes in the field.
|
484
|
+
#
|
485
|
+
def bytes name, description: nil, mode: :nullable, policy_tags: nil, max_length: nil
|
486
|
+
add_field name, :bytes, description: description, mode: mode, policy_tags: policy_tags, max_length: max_length
|
361
487
|
end
|
362
488
|
|
363
489
|
##
|
364
490
|
# Adds a timestamp field to the schema.
|
365
491
|
#
|
366
492
|
# @param [String] name The field name. The name must contain only
|
367
|
-
# letters (
|
493
|
+
# letters (`[A-Za-z]`), numbers (`[0-9]`), or underscores (`_`), and must
|
368
494
|
# start with a letter or underscore. The maximum length is 128
|
369
495
|
# characters.
|
370
496
|
# @param [String] description A description of the field.
|
371
497
|
# @param [Symbol] mode The field's mode. The possible values are
|
372
498
|
# `:nullable`, `:required`, and `:repeated`. The default value is
|
373
499
|
# `:nullable`.
|
374
|
-
|
375
|
-
|
500
|
+
# @param [Array<String>, String] policy_tags The policy tag list or
|
501
|
+
# single policy tag for the field. Policy tag identifiers are of
|
502
|
+
# the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
|
503
|
+
# At most 1 policy tag is currently allowed.
|
504
|
+
#
|
505
|
+
def timestamp name, description: nil, mode: :nullable, policy_tags: nil
|
506
|
+
add_field name, :timestamp, description: description, mode: mode, policy_tags: policy_tags
|
376
507
|
end
|
377
508
|
|
378
509
|
##
|
379
510
|
# Adds a time field to the schema.
|
380
511
|
#
|
381
512
|
# @param [String] name The field name. The name must contain only
|
382
|
-
# letters (
|
513
|
+
# letters (`[A-Za-z]`), numbers (`[0-9]`), or underscores (`_`), and must
|
383
514
|
# start with a letter or underscore. The maximum length is 128
|
384
515
|
# characters.
|
385
516
|
# @param [String] description A description of the field.
|
386
517
|
# @param [Symbol] mode The field's mode. The possible values are
|
387
518
|
# `:nullable`, `:required`, and `:repeated`. The default value is
|
388
519
|
# `:nullable`.
|
520
|
+
# @param [Array<String>, String] policy_tags The policy tag list or
|
521
|
+
# single policy tag for the field. Policy tag identifiers are of
|
522
|
+
# the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
|
523
|
+
# At most 1 policy tag is currently allowed.
|
389
524
|
#
|
390
|
-
def time name, description: nil, mode: :nullable
|
391
|
-
add_field name, :time, description: description, mode: mode
|
525
|
+
def time name, description: nil, mode: :nullable, policy_tags: nil
|
526
|
+
add_field name, :time, description: description, mode: mode, policy_tags: policy_tags
|
392
527
|
end
|
393
528
|
|
394
529
|
##
|
395
530
|
# Adds a datetime field to the schema.
|
396
531
|
#
|
397
532
|
# @param [String] name The field name. The name must contain only
|
398
|
-
# letters (
|
533
|
+
# letters (`[A-Za-z]`), numbers (`[0-9]`), or underscores (`_`), and must
|
399
534
|
# start with a letter or underscore. The maximum length is 128
|
400
535
|
# characters.
|
401
536
|
# @param [String] description A description of the field.
|
402
537
|
# @param [Symbol] mode The field's mode. The possible values are
|
403
538
|
# `:nullable`, `:required`, and `:repeated`. The default value is
|
404
539
|
# `:nullable`.
|
540
|
+
# @param [Array<String>, String] policy_tags The policy tag list or
|
541
|
+
# single policy tag for the field. Policy tag identifiers are of
|
542
|
+
# the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
|
543
|
+
# At most 1 policy tag is currently allowed.
|
405
544
|
#
|
406
|
-
def datetime name, description: nil, mode: :nullable
|
407
|
-
add_field name, :datetime, description: description, mode: mode
|
545
|
+
def datetime name, description: nil, mode: :nullable, policy_tags: nil
|
546
|
+
add_field name, :datetime, description: description, mode: mode, policy_tags: policy_tags
|
408
547
|
end
|
409
548
|
|
410
549
|
##
|
411
550
|
# Adds a date field to the schema.
|
412
551
|
#
|
413
552
|
# @param [String] name The field name. The name must contain only
|
414
|
-
# letters (
|
553
|
+
# letters (`[A-Za-z]`), numbers (`[0-9]`), or underscores (`_`), and must
|
554
|
+
# start with a letter or underscore. The maximum length is 128
|
555
|
+
# characters.
|
556
|
+
# @param [String] description A description of the field.
|
557
|
+
# @param [Symbol] mode The field's mode. The possible values are
|
558
|
+
# `:nullable`, `:required`, and `:repeated`. The default value is
|
559
|
+
# `:nullable`.
|
560
|
+
# @param [Array<String>, String] policy_tags The policy tag list or
|
561
|
+
# single policy tag for the field. Policy tag identifiers are of
|
562
|
+
# the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
|
563
|
+
# At most 1 policy tag is currently allowed.
|
564
|
+
#
|
565
|
+
def date name, description: nil, mode: :nullable, policy_tags: nil
|
566
|
+
add_field name, :date, description: description, mode: mode, policy_tags: policy_tags
|
567
|
+
end
|
568
|
+
|
569
|
+
##
|
570
|
+
# Adds a geography field to the schema.
|
571
|
+
#
|
572
|
+
# @see https://cloud.google.com/bigquery/docs/gis-data Working with BigQuery GIS data
|
573
|
+
#
|
574
|
+
# @param [String] name The field name. The name must contain only
|
575
|
+
# letters (`[A-Za-z]`), numbers (`[0-9]`), or underscores (`_`), and must
|
415
576
|
# start with a letter or underscore. The maximum length is 128
|
416
577
|
# characters.
|
417
578
|
# @param [String] description A description of the field.
|
418
579
|
# @param [Symbol] mode The field's mode. The possible values are
|
419
580
|
# `:nullable`, `:required`, and `:repeated`. The default value is
|
420
581
|
# `:nullable`.
|
582
|
+
# @param [Array<String>, String] policy_tags The policy tag list or
|
583
|
+
# single policy tag for the field. Policy tag identifiers are of
|
584
|
+
# the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
|
585
|
+
# At most 1 policy tag is currently allowed.
|
421
586
|
#
|
422
|
-
def
|
423
|
-
add_field name, :
|
587
|
+
def geography name, description: nil, mode: :nullable, policy_tags: nil
|
588
|
+
add_field name, :geography, description: description, mode: mode, policy_tags: policy_tags
|
424
589
|
end
|
425
590
|
|
426
591
|
##
|
@@ -431,7 +596,7 @@ module Google
|
|
431
596
|
# ](https://cloud.google.com/bigquery/docs/loading-data#loading_denormalized_nested_and_repeated_data).
|
432
597
|
#
|
433
598
|
# @param [String] name The field name. The name must contain only
|
434
|
-
# letters (
|
599
|
+
# letters (`[A-Za-z]`), numbers (`[0-9]`), or underscores (`_`), and must
|
435
600
|
# start with a letter or underscore. The maximum length is 128
|
436
601
|
# characters.
|
437
602
|
# @param [String] description A description of the field.
|
@@ -461,8 +626,7 @@ module Google
|
|
461
626
|
# TODO: do we need to raise if no block was given?
|
462
627
|
raise ArgumentError, "a block is required" unless block_given?
|
463
628
|
|
464
|
-
nested_field = add_field name, :record, description: description,
|
465
|
-
mode: mode
|
629
|
+
nested_field = add_field name, :record, description: description, mode: mode
|
466
630
|
yield nested_field
|
467
631
|
nested_field
|
468
632
|
end
|
@@ -504,7 +668,14 @@ module Google
|
|
504
668
|
raise ArgumentError, "Cannot modify a frozen schema"
|
505
669
|
end
|
506
670
|
|
507
|
-
def add_field name,
|
671
|
+
def add_field name,
|
672
|
+
type,
|
673
|
+
description: nil,
|
674
|
+
mode: :nullable,
|
675
|
+
policy_tags: nil,
|
676
|
+
max_length: nil,
|
677
|
+
precision: nil,
|
678
|
+
scale: nil
|
508
679
|
frozen_check!
|
509
680
|
|
510
681
|
new_gapi = Google::Apis::BigqueryV2::TableFieldSchema.new(
|
@@ -514,7 +685,13 @@ module Google
|
|
514
685
|
mode: verify_mode(mode),
|
515
686
|
fields: []
|
516
687
|
)
|
517
|
-
|
688
|
+
if policy_tags
|
689
|
+
policy_tags = Array(policy_tags)
|
690
|
+
new_gapi.policy_tags = Google::Apis::BigqueryV2::TableFieldSchema::PolicyTags.new names: policy_tags
|
691
|
+
end
|
692
|
+
new_gapi.max_length = max_length if max_length
|
693
|
+
new_gapi.precision = precision if precision
|
694
|
+
new_gapi.scale = scale if scale
|
518
695
|
# Remove any existing field of this name
|
519
696
|
@gapi.fields ||= []
|
520
697
|
@gapi.fields.reject! { |f| f.name == new_gapi.name }
|
@@ -528,18 +705,14 @@ module Google
|
|
528
705
|
|
529
706
|
def verify_type type
|
530
707
|
type = type.to_s.upcase
|
531
|
-
unless Field::TYPES.include? type
|
532
|
-
raise ArgumentError, "Type '#{type}' not found"
|
533
|
-
end
|
708
|
+
raise ArgumentError, "Type '#{type}' not found" unless Field::TYPES.include? type
|
534
709
|
type
|
535
710
|
end
|
536
711
|
|
537
712
|
def verify_mode mode
|
538
713
|
mode = :nullable if mode.nil?
|
539
714
|
mode = mode.to_s.upcase
|
540
|
-
unless Field::MODES.include? mode
|
541
|
-
raise ArgumentError "Unable to determine mode for '#{mode}'"
|
542
|
-
end
|
715
|
+
raise ArgumentError "Unable to determine mode for '#{mode}'" unless Field::MODES.include? mode
|
543
716
|
mode
|
544
717
|
end
|
545
718
|
end
|