google-cloud-bigquery 1.14.0 → 1.42.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.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/AUTHENTICATION.md +17 -54
  3. data/CHANGELOG.md +377 -0
  4. data/CONTRIBUTING.md +328 -116
  5. data/LOGGING.md +1 -1
  6. data/OVERVIEW.md +21 -20
  7. data/TROUBLESHOOTING.md +2 -8
  8. data/lib/google/cloud/bigquery/argument.rb +197 -0
  9. data/lib/google/cloud/bigquery/convert.rb +155 -173
  10. data/lib/google/cloud/bigquery/copy_job.rb +74 -26
  11. data/lib/google/cloud/bigquery/credentials.rb +5 -12
  12. data/lib/google/cloud/bigquery/data.rb +109 -18
  13. data/lib/google/cloud/bigquery/dataset/access.rb +474 -52
  14. data/lib/google/cloud/bigquery/dataset/list.rb +7 -13
  15. data/lib/google/cloud/bigquery/dataset/tag.rb +67 -0
  16. data/lib/google/cloud/bigquery/dataset.rb +1044 -287
  17. data/lib/google/cloud/bigquery/external/avro_source.rb +107 -0
  18. data/lib/google/cloud/bigquery/external/bigtable_source/column.rb +404 -0
  19. data/lib/google/cloud/bigquery/external/bigtable_source/column_family.rb +945 -0
  20. data/lib/google/cloud/bigquery/external/bigtable_source.rb +230 -0
  21. data/lib/google/cloud/bigquery/external/csv_source.rb +481 -0
  22. data/lib/google/cloud/bigquery/external/data_source.rb +771 -0
  23. data/lib/google/cloud/bigquery/external/json_source.rb +170 -0
  24. data/lib/google/cloud/bigquery/external/parquet_source.rb +148 -0
  25. data/lib/google/cloud/bigquery/external/sheets_source.rb +166 -0
  26. data/lib/google/cloud/bigquery/external.rb +50 -2256
  27. data/lib/google/cloud/bigquery/extract_job.rb +226 -61
  28. data/lib/google/cloud/bigquery/insert_response.rb +1 -3
  29. data/lib/google/cloud/bigquery/job/list.rb +10 -14
  30. data/lib/google/cloud/bigquery/job.rb +289 -14
  31. data/lib/google/cloud/bigquery/load_job.rb +810 -136
  32. data/lib/google/cloud/bigquery/model/list.rb +5 -9
  33. data/lib/google/cloud/bigquery/model.rb +247 -16
  34. data/lib/google/cloud/bigquery/policy.rb +432 -0
  35. data/lib/google/cloud/bigquery/project/list.rb +6 -11
  36. data/lib/google/cloud/bigquery/project.rb +509 -250
  37. data/lib/google/cloud/bigquery/query_job.rb +594 -128
  38. data/lib/google/cloud/bigquery/routine/list.rb +165 -0
  39. data/lib/google/cloud/bigquery/routine.rb +1227 -0
  40. data/lib/google/cloud/bigquery/schema/field.rb +413 -63
  41. data/lib/google/cloud/bigquery/schema.rb +221 -48
  42. data/lib/google/cloud/bigquery/service.rb +204 -112
  43. data/lib/google/cloud/bigquery/standard_sql.rb +269 -53
  44. data/lib/google/cloud/bigquery/table/async_inserter.rb +86 -43
  45. data/lib/google/cloud/bigquery/table/list.rb +6 -11
  46. data/lib/google/cloud/bigquery/table.rb +1470 -377
  47. data/lib/google/cloud/bigquery/time.rb +6 -0
  48. data/lib/google/cloud/bigquery/version.rb +1 -1
  49. data/lib/google/cloud/bigquery.rb +4 -6
  50. data/lib/google-cloud-bigquery.rb +14 -13
  51. metadata +66 -38
@@ -37,17 +37,34 @@ module Google
37
37
  #
38
38
  class Field
39
39
  # @private
40
- MODES = %w[NULLABLE REQUIRED REPEATED].freeze
40
+ MODES = ["NULLABLE", "REQUIRED", "REPEATED"].freeze
41
41
 
42
42
  # @private
43
- TYPES = %w[STRING INTEGER INT64 FLOAT FLOAT64 NUMERIC BOOLEAN BOOL
44
- BYTES TIMESTAMP TIME DATETIME DATE RECORD STRUCT].freeze
43
+ TYPES = [
44
+ "BIGNUMERIC",
45
+ "BOOL",
46
+ "BOOLEAN",
47
+ "BYTES",
48
+ "DATE",
49
+ "DATETIME",
50
+ "FLOAT",
51
+ "FLOAT64",
52
+ "GEOGRAPHY",
53
+ "INTEGER",
54
+ "INT64",
55
+ "NUMERIC",
56
+ "RECORD",
57
+ "STRING",
58
+ "STRUCT",
59
+ "TIME",
60
+ "TIMESTAMP"
61
+ ].freeze
45
62
 
46
63
  ##
47
64
  # The name of the field.
48
65
  #
49
66
  # @return [String] The field name. The name must contain only
50
- # letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
67
+ # letters (`[A-Za-z]`), numbers (`[0-9]`), or underscores (`_`), and must
51
68
  # start with a letter or underscore. The maximum length is 128
52
69
  # characters.
53
70
  #
@@ -59,7 +76,7 @@ module Google
59
76
  # Updates the name of the field.
60
77
  #
61
78
  # @param [String] new_name The field name. The name must contain only
62
- # letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
79
+ # letters (`[A-Za-z]`), numbers (`[0-9]`), or underscores (`_`), and must
63
80
  # start with a letter or underscore. The maximum length is 128
64
81
  # characters.
65
82
  #
@@ -70,12 +87,25 @@ module Google
70
87
  ##
71
88
  # The data type of the field.
72
89
  #
73
- # @return [String] The field data type. Possible values include
74
- # `STRING`, `BYTES`, `INTEGER`, `INT64` (same as `INTEGER`),
75
- # `FLOAT`, `FLOAT64` (same as `FLOAT`), `NUMERIC`, `BOOLEAN`, `BOOL`
76
- # (same as `BOOLEAN`), `TIMESTAMP`, `DATE`, `TIME`, `DATETIME`,
77
- # `RECORD` (where `RECORD` indicates that the field contains a
78
- # nested schema) or `STRUCT` (same as `RECORD`).
90
+ # @return [String] The field data type. Possible values include:
91
+ #
92
+ # * `BIGNUMERIC`
93
+ # * `BOOL`
94
+ # * `BOOLEAN` (same as `BOOL`)
95
+ # * `BYTES`
96
+ # * `DATE`
97
+ # * `DATETIME`
98
+ # * `FLOAT`
99
+ # * `FLOAT64` (same as `FLOAT`)
100
+ # * `GEOGRAPHY`
101
+ # * `INTEGER`
102
+ # * `INT64` (same as `INTEGER`)
103
+ # * `NUMERIC`
104
+ # * `RECORD` (where `RECORD` indicates that the field contains a nested schema)
105
+ # * `STRING`
106
+ # * `STRUCT` (same as `RECORD`)
107
+ # * `TIME`
108
+ # * `TIMESTAMP`
79
109
  #
80
110
  def type
81
111
  @gapi.type
@@ -84,12 +114,25 @@ module Google
84
114
  ##
85
115
  # Updates the data type of the field.
86
116
  #
87
- # @param [String] new_type The data type. Possible values include
88
- # `STRING`, `BYTES`, `INTEGER`, `INT64` (same as `INTEGER`),
89
- # `FLOAT`, `FLOAT64` (same as `FLOAT`), `NUMERIC`, `BOOLEAN`, `BOOL`
90
- # (same as `BOOLEAN`), `TIMESTAMP`, `DATE`, `TIME`, `DATETIME`,
91
- # `RECORD` (where `RECORD` indicates that the field contains a
92
- # nested schema) or `STRUCT` (same as `RECORD`).
117
+ # @param [String] new_type The data type. Possible values include:
118
+ #
119
+ # * `BIGNUMERIC`
120
+ # * `BOOL`
121
+ # * `BOOLEAN` (same as `BOOL`)
122
+ # * `BYTES`
123
+ # * `DATE`
124
+ # * `DATETIME`
125
+ # * `FLOAT`
126
+ # * `FLOAT64` (same as `FLOAT`)
127
+ # * `GEOGRAPHY`
128
+ # * `INTEGER`
129
+ # * `INT64` (same as `INTEGER`)
130
+ # * `NUMERIC`
131
+ # * `RECORD` (where `RECORD` indicates that the field contains a nested schema)
132
+ # * `STRING`
133
+ # * `STRUCT` (same as `RECORD`)
134
+ # * `TIME`
135
+ # * `TIMESTAMP`
93
136
  #
94
137
  def type= new_type
95
138
  @gapi.update! type: verify_type(new_type)
@@ -163,6 +206,101 @@ module Google
163
206
  @gapi.update! mode: verify_mode(new_mode)
164
207
  end
165
208
 
209
+ ##
210
+ # The policy tag list for the field. Policy tag identifiers are of the form
211
+ # `projects/*/locations/*/taxonomies/*/policyTags/*`. At most 1 policy tag
212
+ # is currently allowed.
213
+ #
214
+ # @see https://cloud.google.com/bigquery/docs/column-level-security-intro
215
+ # Introduction to BigQuery column-level security
216
+ #
217
+ # @return [Array<String>, nil] The policy tag list for the field, or `nil`.
218
+ #
219
+ # @example
220
+ # require "google/cloud/bigquery"
221
+ #
222
+ # bigquery = Google::Cloud::Bigquery.new
223
+ # dataset = bigquery.dataset "my_dataset"
224
+ # table = dataset.table "my_table"
225
+ #
226
+ # table.schema.field("age").policy_tags
227
+ #
228
+ def policy_tags
229
+ names = @gapi.policy_tags&.names
230
+ names.to_a if names && !names.empty?
231
+ end
232
+
233
+ ##
234
+ # Updates the policy tag list for the field.
235
+ #
236
+ # @see https://cloud.google.com/bigquery/docs/column-level-security-intro
237
+ # Introduction to BigQuery column-level security
238
+ #
239
+ # @param [Array<String>, String, nil] new_policy_tags The policy tag list or
240
+ # single policy tag for the field, or `nil` to remove the existing policy tags.
241
+ # Policy tag identifiers are of the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
242
+ # At most 1 policy tag is currently allowed.
243
+ #
244
+ # @example
245
+ # require "google/cloud/bigquery"
246
+ #
247
+ # bigquery = Google::Cloud::Bigquery.new
248
+ # dataset = bigquery.dataset "my_dataset"
249
+ # table = dataset.table "my_table"
250
+ #
251
+ # policy_tag = "projects/my-project/locations/us/taxonomies/my-taxonomy/policyTags/my-policy-tag"
252
+ # table.schema do |schema|
253
+ # schema.field("age").policy_tags = policy_tag
254
+ # end
255
+ #
256
+ # table.schema.field("age").policy_tags
257
+ #
258
+ def policy_tags= new_policy_tags
259
+ # If new_policy_tags is nil, send an empty array.
260
+ # Sending a nil value for policy_tags results in no change.
261
+ new_policy_tags = Array(new_policy_tags)
262
+ policy_tag_list = Google::Apis::BigqueryV2::TableFieldSchema::PolicyTags.new names: new_policy_tags
263
+ @gapi.update! policy_tags: policy_tag_list
264
+ end
265
+
266
+ ##
267
+ # The maximum length of values of this field for {#string?} or {bytes?} fields. If `max_length` is not
268
+ # specified, no maximum length constraint is imposed on this field. If type = `STRING`, then `max_length`
269
+ # represents the maximum UTF-8 length of strings in this field. If type = `BYTES`, then `max_length`
270
+ # represents the maximum number of bytes in this field.
271
+ #
272
+ # @return [Integer, nil] The maximum length of values of this field, or `nil`.
273
+ #
274
+ def max_length
275
+ @gapi.max_length
276
+ end
277
+
278
+ ##
279
+ # The precision (maximum number of total digits) for `NUMERIC` or `BIGNUMERIC` types. For {#numeric?} fields,
280
+ # acceptable values for precision must be `1 ≤ (precision - scale) ≤ 29` and values for scale must be `0 ≤
281
+ # scale ≤ 9`. For {#bignumeric?} fields, acceptable values for precision must be `1 ≤ (precision - scale) ≤
282
+ # 38` and values for scale must be `0 ≤ scale ≤ 38`. If the scale value is set, the precision value must be
283
+ # set as well.
284
+ #
285
+ # @return [Integer, nil] The precision for the field, or `nil`.
286
+ #
287
+ def precision
288
+ @gapi.precision
289
+ end
290
+
291
+ ##
292
+ # The scale (maximum number of digits in the fractional part) for `NUMERIC` or `BIGNUMERIC` types. For
293
+ # {#numeric?} fields, acceptable values for precision must be `1 ≤ (precision - scale) ≤ 29` and values for
294
+ # scale must be `0 ≤ scale ≤ 9`. For {#bignumeric?} fields, acceptable values for precision must be `1 ≤
295
+ # (precision - scale) ≤ 38` and values for scale must be `0 ≤ scale ≤ 38`. If the scale value is set, the
296
+ # precision value must be set as well.
297
+ #
298
+ # @return [Integer, nil] The scale for the field, or `nil`.
299
+ #
300
+ def scale
301
+ @gapi.scale
302
+ end
303
+
166
304
  ##
167
305
  # Checks if the type of the field is `STRING`.
168
306
  #
@@ -199,6 +337,15 @@ module Google
199
337
  type == "NUMERIC"
200
338
  end
201
339
 
340
+ ##
341
+ # Checks if the type of the field is `BIGNUMERIC`.
342
+ #
343
+ # @return [Boolean] `true` when `BIGNUMERIC`, `false` otherwise.
344
+ #
345
+ def bignumeric?
346
+ type == "BIGNUMERIC"
347
+ end
348
+
202
349
  ##
203
350
  # Checks if the type of the field is `BOOLEAN`.
204
351
  #
@@ -253,6 +400,15 @@ module Google
253
400
  type == "DATE"
254
401
  end
255
402
 
403
+ ##
404
+ # Checks if the type of the field is `GEOGRAPHY`.
405
+ #
406
+ # @return [Boolean] `true` when `GEOGRAPHY`, `false` otherwise.
407
+ #
408
+ def geography?
409
+ type == "GEOGRAPHY"
410
+ end
411
+
256
412
  ##
257
413
  # Checks if the type of the field is `RECORD`.
258
414
  #
@@ -261,6 +417,7 @@ module Google
261
417
  def record?
262
418
  type == "RECORD" || type == "STRUCT"
263
419
  end
420
+ alias struct? record?
264
421
 
265
422
  ##
266
423
  # The nested fields if the type property is set to `RECORD`. Will be
@@ -288,6 +445,37 @@ module Google
288
445
  fields.map(&:name).map(&:to_sym)
289
446
  end
290
447
 
448
+ ##
449
+ # The types of the field, using the same format as the optional query
450
+ # parameter types.
451
+ #
452
+ # The parameter types are one of the following BigQuery type codes:
453
+ #
454
+ # * `:BOOL`
455
+ # * `:INT64`
456
+ # * `:FLOAT64`
457
+ # * `:NUMERIC`
458
+ # * `:BIGNUMERIC`
459
+ # * `:STRING`
460
+ # * `:DATETIME`
461
+ # * `:DATE`
462
+ # * `:TIMESTAMP`
463
+ # * `:TIME`
464
+ # * `:BYTES`
465
+ # * `Array` - Lists are specified by providing the type code in an array. For example, an array of integers
466
+ # are specified as `[:INT64]`.
467
+ # * `Hash` - Types for STRUCT values (`Hash` objects) are specified using a `Hash` object, where the keys
468
+ # are the nested field names, and the values are the the nested field types.
469
+ #
470
+ # @return [Symbol, Array, Hash] The type.
471
+ #
472
+ def param_type
473
+ param_type = type.to_sym
474
+ param_type = fields.to_h { |field| [field.name.to_sym, field.param_type] } if record?
475
+ param_type = [param_type] if repeated?
476
+ param_type
477
+ end
478
+
291
479
  ##
292
480
  # Retrieve a nested field by name, if the type property is
293
481
  # set to `RECORD`. Will return `nil` otherwise.
@@ -307,18 +495,29 @@ module Google
307
495
  # This can only be called on fields that are of type `RECORD`.
308
496
  #
309
497
  # @param [String] name The field name. The name must contain only
310
- # letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
498
+ # letters (`[A-Za-z]`), numbers (`[0-9]`), or underscores (`_`), and must
311
499
  # start with a letter or underscore. The maximum length is 128
312
500
  # characters.
313
501
  # @param [String] description A description of the field.
314
502
  # @param [Symbol] mode The field's mode. The possible values are
315
503
  # `:nullable`, `:required`, and `:repeated`. The default value is
316
504
  # `:nullable`.
317
- #
318
- def string name, description: nil, mode: :nullable
505
+ # @param [Array<String>, String] policy_tags The policy tag list or
506
+ # single policy tag for the field. Policy tag identifiers are of
507
+ # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
508
+ # At most 1 policy tag is currently allowed.
509
+ # @param [Integer] max_length The maximum UTF-8 length of strings
510
+ # allowed in the field.
511
+ #
512
+ def string name, description: nil, mode: :nullable, policy_tags: nil, max_length: nil
319
513
  record_check!
320
514
 
321
- add_field name, :string, description: description, mode: mode
515
+ add_field name,
516
+ :string,
517
+ description: description,
518
+ mode: mode,
519
+ policy_tags: policy_tags,
520
+ max_length: max_length
322
521
  end
323
522
 
324
523
  ##
@@ -327,18 +526,22 @@ module Google
327
526
  # This can only be called on fields that are of type `RECORD`.
328
527
  #
329
528
  # @param [String] name The field name. The name must contain only
330
- # letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
529
+ # letters (`[A-Za-z]`), numbers (`[0-9]`), or underscores (`_`), and must
331
530
  # start with a letter or underscore. The maximum length is 128
332
531
  # characters.
333
532
  # @param [String] description A description of the field.
334
533
  # @param [Symbol] mode The field's mode. The possible values are
335
534
  # `:nullable`, `:required`, and `:repeated`. The default value is
336
535
  # `:nullable`.
536
+ # @param [Array<String>, String] policy_tags The policy tag list or
537
+ # single policy tag for the field. Policy tag identifiers are of
538
+ # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
539
+ # At most 1 policy tag is currently allowed.
337
540
  #
338
- def integer name, description: nil, mode: :nullable
541
+ def integer name, description: nil, mode: :nullable, policy_tags: nil
339
542
  record_check!
340
543
 
341
- add_field name, :integer, description: description, mode: mode
544
+ add_field name, :integer, description: description, mode: mode, policy_tags: policy_tags
342
545
  end
343
546
 
344
547
  ##
@@ -348,40 +551,124 @@ module Google
348
551
  # This can only be called on fields that are of type `RECORD`.
349
552
  #
350
553
  # @param [String] name The field name. The name must contain only
351
- # letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
554
+ # letters (`[A-Za-z]`), numbers (`[0-9]`), or underscores (`_`), and must
352
555
  # start with a letter or underscore. The maximum length is 128
353
556
  # characters.
354
557
  # @param [String] description A description of the field.
355
558
  # @param [Symbol] mode The field's mode. The possible values are
356
559
  # `:nullable`, `:required`, and `:repeated`. The default value is
357
560
  # `:nullable`.
561
+ # @param [Array<String>, String] policy_tags The policy tag list or
562
+ # single policy tag for the field. Policy tag identifiers are of
563
+ # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
564
+ # At most 1 policy tag is currently allowed.
358
565
  #
359
- def float name, description: nil, mode: :nullable
566
+ def float name, description: nil, mode: :nullable, policy_tags: nil
360
567
  record_check!
361
568
 
362
- add_field name, :float, description: description, mode: mode
569
+ add_field name, :float, description: description, mode: mode, policy_tags: policy_tags
363
570
  end
364
571
 
365
572
  ##
366
- # Adds a numeric number field to the schema. Numeric is a
367
- # fixed-precision numeric type with 38 decimal digits, 9 that follow
368
- # the decimal point.
573
+ # Adds a numeric number field to the schema. `NUMERIC` is a decimal
574
+ # type with fixed precision and scale. Precision is the number of
575
+ # digits that the number contains. Scale is how many of these
576
+ # digits appear after the decimal point. It supports:
577
+ #
578
+ # Precision: 38
579
+ # Scale: 9
580
+ # Min: -9.9999999999999999999999999999999999999E+28
581
+ # Max: 9.9999999999999999999999999999999999999E+28
582
+ #
583
+ # This type can represent decimal fractions exactly, and is suitable
584
+ # for financial calculations.
369
585
  #
370
586
  # This can only be called on fields that are of type `RECORD`.
371
587
  #
372
588
  # @param [String] name The field name. The name must contain only
373
- # letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
589
+ # letters (`[A-Za-z]`), numbers (`[0-9]`), or underscores (`_`), and must
374
590
  # start with a letter or underscore. The maximum length is 128
375
591
  # characters.
376
592
  # @param [String] description A description of the field.
377
593
  # @param [Symbol] mode The field's mode. The possible values are
378
594
  # `:nullable`, `:required`, and `:repeated`. The default value is
379
595
  # `:nullable`.
596
+ # @param [Array<String>, String] policy_tags The policy tag list or
597
+ # single policy tag for the field. Policy tag identifiers are of
598
+ # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
599
+ # At most 1 policy tag is currently allowed.
600
+ # @param [Integer] precision The precision (maximum number of total
601
+ # digits) for the field. Acceptable values for precision must be:
602
+ # `1 ≤ (precision - scale) ≤ 29`. Values for scale must be:
603
+ # `0 ≤ scale ≤ 9`. If the scale value is set, the precision value
604
+ # must be set as well.
605
+ # @param [Integer] scale The scale (maximum number of digits in the
606
+ # fractional part) for the field. Acceptable values for precision
607
+ # must be: `1 ≤ (precision - scale) ≤ 29`. Values for scale must
608
+ # be: `0 ≤ scale ≤ 9`. If the scale value is set, the precision
609
+ # value must be set as well.
610
+ #
611
+ def numeric name, description: nil, mode: :nullable, policy_tags: nil, precision: nil, scale: nil
612
+ record_check!
613
+
614
+ add_field name,
615
+ :numeric,
616
+ description: description,
617
+ mode: mode,
618
+ policy_tags: policy_tags,
619
+ precision: precision,
620
+ scale: scale
621
+ end
622
+
623
+ ##
624
+ # Adds a bignumeric number field to the schema. `BIGNUMERIC` is a
625
+ # decimal type with fixed precision and scale. Precision is the
626
+ # number of digits that the number contains. Scale is how many of
627
+ # these digits appear after the decimal point. It supports:
380
628
  #
381
- def numeric name, description: nil, mode: :nullable
629
+ # Precision: 76.76 (the 77th digit is partial)
630
+ # Scale: 38
631
+ # Min: -5.7896044618658097711785492504343953926634992332820282019728792003956564819968E+38
632
+ # Max: 5.7896044618658097711785492504343953926634992332820282019728792003956564819967E+38
633
+ #
634
+ # This type can represent decimal fractions exactly, and is suitable
635
+ # for financial calculations.
636
+ #
637
+ # This can only be called on fields that are of type `RECORD`.
638
+ #
639
+ # @param [String] name The field name. The name must contain only
640
+ # letters (`[A-Za-z]`), numbers (`[0-9]`), or underscores (`_`), and must
641
+ # start with a letter or underscore. The maximum length is 128
642
+ # characters.
643
+ # @param [String] description A description of the field.
644
+ # @param [Symbol] mode The field's mode. The possible values are
645
+ # `:nullable`, `:required`, and `:repeated`. The default value is
646
+ # `:nullable`.
647
+ # @param [Array<String>, String] policy_tags The policy tag list or
648
+ # single policy tag for the field. Policy tag identifiers are of
649
+ # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
650
+ # At most 1 policy tag is currently allowed.
651
+ # @param [Integer] precision The precision (maximum number of total
652
+ # digits) for the field. Acceptable values for precision must be:
653
+ # `1 ≤ (precision - scale) ≤ 38`. Values for scale must be:
654
+ # `0 ≤ scale ≤ 38`. If the scale value is set, the precision value
655
+ # must be set as well.
656
+ # @param [Integer] scale The scale (maximum number of digits in the
657
+ # fractional part) for the field. Acceptable values for precision
658
+ # must be: `1 ≤ (precision - scale) ≤ 38`. Values for scale must
659
+ # be: `0 ≤ scale ≤ 38`. If the scale value is set, the precision
660
+ # value must be set as well.
661
+ #
662
+ def bignumeric name, description: nil, mode: :nullable, policy_tags: nil, precision: nil, scale: nil
382
663
  record_check!
383
664
 
384
- add_field name, :numeric, description: description, mode: mode
665
+ add_field name,
666
+ :bignumeric,
667
+ description: description,
668
+ mode: mode,
669
+ policy_tags: policy_tags,
670
+ precision: precision,
671
+ scale: scale
385
672
  end
386
673
 
387
674
  ##
@@ -390,18 +677,22 @@ module Google
390
677
  # This can only be called on fields that are of type `RECORD`.
391
678
  #
392
679
  # @param [String] name The field name. The name must contain only
393
- # letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
680
+ # letters (`[A-Za-z]`), numbers (`[0-9]`), or underscores (`_`), and must
394
681
  # start with a letter or underscore. The maximum length is 128
395
682
  # characters.
396
683
  # @param [String] description A description of the field.
397
684
  # @param [Symbol] mode The field's mode. The possible values are
398
685
  # `:nullable`, `:required`, and `:repeated`. The default value is
399
686
  # `:nullable`.
687
+ # @param [Array<String>, String] policy_tags The policy tag list or
688
+ # single policy tag for the field. Policy tag identifiers are of
689
+ # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
690
+ # At most 1 policy tag is currently allowed.
400
691
  #
401
- def boolean name, description: nil, mode: :nullable
692
+ def boolean name, description: nil, mode: :nullable, policy_tags: nil
402
693
  record_check!
403
694
 
404
- add_field name, :boolean, description: description, mode: mode
695
+ add_field name, :boolean, description: description, mode: mode, policy_tags: policy_tags
405
696
  end
406
697
 
407
698
  ##
@@ -410,18 +701,29 @@ module Google
410
701
  # This can only be called on fields that are of type `RECORD`.
411
702
  #
412
703
  # @param [String] name The field name. The name must contain only
413
- # letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
704
+ # letters (`[A-Za-z]`), numbers (`[0-9]`), or underscores (`_`), and must
414
705
  # start with a letter or underscore. The maximum length is 128
415
706
  # characters.
416
707
  # @param [String] description A description of the field.
417
708
  # @param [Symbol] mode The field's mode. The possible values are
418
709
  # `:nullable`, `:required`, and `:repeated`. The default value is
419
710
  # `:nullable`.
420
- #
421
- def bytes name, description: nil, mode: :nullable
711
+ # @param [Array<String>, String] policy_tags The policy tag list or
712
+ # single policy tag for the field. Policy tag identifiers are of
713
+ # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
714
+ # At most 1 policy tag is currently allowed.
715
+ # @param [Integer] max_length The maximum the maximum number of
716
+ # bytes in the field.
717
+ #
718
+ def bytes name, description: nil, mode: :nullable, policy_tags: nil, max_length: nil
422
719
  record_check!
423
720
 
424
- add_field name, :bytes, description: description, mode: mode
721
+ add_field name,
722
+ :bytes,
723
+ description: description,
724
+ mode: mode,
725
+ policy_tags: policy_tags,
726
+ max_length: max_length
425
727
  end
426
728
 
427
729
  ##
@@ -430,18 +732,22 @@ module Google
430
732
  # This can only be called on fields that are of type `RECORD`.
431
733
  #
432
734
  # @param [String] name The field name. The name must contain only
433
- # letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
735
+ # letters (`[A-Za-z]`), numbers (`[0-9]`), or underscores (`_`), and must
434
736
  # start with a letter or underscore. The maximum length is 128
435
737
  # characters.
436
738
  # @param [String] description A description of the field.
437
739
  # @param [Symbol] mode The field's mode. The possible values are
438
740
  # `:nullable`, `:required`, and `:repeated`. The default value is
439
741
  # `:nullable`.
742
+ # @param [Array<String>, String] policy_tags The policy tag list or
743
+ # single policy tag for the field. Policy tag identifiers are of
744
+ # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
745
+ # At most 1 policy tag is currently allowed.
440
746
  #
441
- def timestamp name, description: nil, mode: :nullable
747
+ def timestamp name, description: nil, mode: :nullable, policy_tags: nil
442
748
  record_check!
443
749
 
444
- add_field name, :timestamp, description: description, mode: mode
750
+ add_field name, :timestamp, description: description, mode: mode, policy_tags: policy_tags
445
751
  end
446
752
 
447
753
  ##
@@ -450,18 +756,22 @@ module Google
450
756
  # This can only be called on fields that are of type `RECORD`.
451
757
  #
452
758
  # @param [String] name The field name. The name must contain only
453
- # letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
759
+ # letters (`[A-Za-z]`), numbers (`[0-9]`), or underscores (`_`), and must
454
760
  # start with a letter or underscore. The maximum length is 128
455
761
  # characters.
456
762
  # @param [String] description A description of the field.
457
763
  # @param [Symbol] mode The field's mode. The possible values are
458
764
  # `:nullable`, `:required`, and `:repeated`. The default value is
459
765
  # `:nullable`.
766
+ # @param [Array<String>, String] policy_tags The policy tag list or
767
+ # single policy tag for the field. Policy tag identifiers are of
768
+ # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
769
+ # At most 1 policy tag is currently allowed.
460
770
  #
461
- def time name, description: nil, mode: :nullable
771
+ def time name, description: nil, mode: :nullable, policy_tags: nil
462
772
  record_check!
463
773
 
464
- add_field name, :time, description: description, mode: mode
774
+ add_field name, :time, description: description, mode: mode, policy_tags: policy_tags
465
775
  end
466
776
 
467
777
  ##
@@ -470,18 +780,22 @@ module Google
470
780
  # This can only be called on fields that are of type `RECORD`.
471
781
  #
472
782
  # @param [String] name The field name. The name must contain only
473
- # letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
783
+ # letters (`[A-Za-z]`), numbers (`[0-9]`), or underscores (`_`), and must
474
784
  # start with a letter or underscore. The maximum length is 128
475
785
  # characters.
476
786
  # @param [String] description A description of the field.
477
787
  # @param [Symbol] mode The field's mode. The possible values are
478
788
  # `:nullable`, `:required`, and `:repeated`. The default value is
479
789
  # `:nullable`.
790
+ # @param [Array<String>, String] policy_tags The policy tag list or
791
+ # single policy tag for the field. Policy tag identifiers are of
792
+ # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
793
+ # At most 1 policy tag is currently allowed.
480
794
  #
481
- def datetime name, description: nil, mode: :nullable
795
+ def datetime name, description: nil, mode: :nullable, policy_tags: nil
482
796
  record_check!
483
797
 
484
- add_field name, :datetime, description: description, mode: mode
798
+ add_field name, :datetime, description: description, mode: mode, policy_tags: policy_tags
485
799
  end
486
800
 
487
801
  ##
@@ -490,18 +804,46 @@ module Google
490
804
  # This can only be called on fields that are of type `RECORD`.
491
805
  #
492
806
  # @param [String] name The field name. The name must contain only
493
- # letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
807
+ # letters (`[A-Za-z]`), numbers (`[0-9]`), or underscores (`_`), and must
494
808
  # start with a letter or underscore. The maximum length is 128
495
809
  # characters.
496
810
  # @param [String] description A description of the field.
497
811
  # @param [Symbol] mode The field's mode. The possible values are
498
812
  # `:nullable`, `:required`, and `:repeated`. The default value is
499
813
  # `:nullable`.
814
+ # @param [Array<String>, String] policy_tags The policy tag list or
815
+ # single policy tag for the field. Policy tag identifiers are of
816
+ # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
817
+ # At most 1 policy tag is currently allowed.
500
818
  #
501
- def date name, description: nil, mode: :nullable
819
+ def date name, description: nil, mode: :nullable, policy_tags: nil
502
820
  record_check!
503
821
 
504
- add_field name, :date, description: description, mode: mode
822
+ add_field name, :date, description: description, mode: mode, policy_tags: policy_tags
823
+ end
824
+
825
+ ##
826
+ # Adds a geography field to the nested schema of a record field.
827
+ #
828
+ # @see https://cloud.google.com/bigquery/docs/gis-data Working with BigQuery GIS data
829
+ #
830
+ # @param [String] name The field name. The name must contain only
831
+ # letters (`[A-Za-z]`), numbers (`[0-9]`), or underscores (`_`), and must
832
+ # start with a letter or underscore. The maximum length is 128
833
+ # characters.
834
+ # @param [String] description A description of the field.
835
+ # @param [Symbol] mode The field's mode. The possible values are
836
+ # `:nullable`, `:required`, and `:repeated`. The default value is
837
+ # `:nullable`.
838
+ # @param [Array<String>, String] policy_tags The policy tag list or
839
+ # single policy tag for the field. Policy tag identifiers are of
840
+ # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
841
+ # At most 1 policy tag is currently allowed.
842
+ #
843
+ def geography name, description: nil, mode: :nullable, policy_tags: nil
844
+ record_check!
845
+
846
+ add_field name, :geography, description: description, mode: mode, policy_tags: policy_tags
505
847
  end
506
848
 
507
849
  ##
@@ -513,7 +855,7 @@ module Google
513
855
  # This can only be called on fields that are of type `RECORD`.
514
856
  #
515
857
  # @param [String] name The field name. The name must contain only
516
- # letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
858
+ # letters (`[A-Za-z]`), numbers (`[0-9]`), or underscores (`_`), and must
517
859
  # start with a letter or underscore. The maximum length is 128
518
860
  # characters.
519
861
  # @param [String] description A description of the field.
@@ -548,8 +890,7 @@ module Google
548
890
  # TODO: do we need to raise if no block was given?
549
891
  raise ArgumentError, "a block is required" unless block_given?
550
892
 
551
- nested_field = add_field name, :record, description: description,
552
- mode: mode
893
+ nested_field = add_field name, :record, description: description, mode: mode
553
894
  yield nested_field
554
895
  nested_field
555
896
  end
@@ -598,7 +939,14 @@ module Google
598
939
  "Cannot add fields to a non-RECORD field (#{type})"
599
940
  end
600
941
 
601
- def add_field name, type, description: nil, mode: :nullable
942
+ def add_field name,
943
+ type,
944
+ description: nil,
945
+ mode: :nullable,
946
+ policy_tags: nil,
947
+ max_length: nil,
948
+ precision: nil,
949
+ scale: nil
602
950
  frozen_check!
603
951
 
604
952
  new_gapi = Google::Apis::BigqueryV2::TableFieldSchema.new(
@@ -608,7 +956,13 @@ module Google
608
956
  mode: verify_mode(mode),
609
957
  fields: []
610
958
  )
611
-
959
+ if policy_tags
960
+ policy_tags = Array(policy_tags)
961
+ new_gapi.policy_tags = Google::Apis::BigqueryV2::TableFieldSchema::PolicyTags.new names: policy_tags
962
+ end
963
+ new_gapi.max_length = max_length if max_length
964
+ new_gapi.precision = precision if precision
965
+ new_gapi.scale = scale if scale
612
966
  # Remove any existing field of this name
613
967
  @gapi.fields ||= []
614
968
  @gapi.fields.reject! { |f| f.name == new_gapi.name }
@@ -621,18 +975,14 @@ module Google
621
975
 
622
976
  def verify_type type
623
977
  type = type.to_s.upcase
624
- unless TYPES.include? type
625
- raise ArgumentError, "Type '#{type}' not found"
626
- end
978
+ raise ArgumentError, "Type '#{type}' not found" unless TYPES.include? type
627
979
  type
628
980
  end
629
981
 
630
982
  def verify_mode mode
631
983
  mode = :nullable if mode.nil?
632
984
  mode = mode.to_s.upcase
633
- unless MODES.include? mode
634
- raise ArgumentError "Unable to determine mode for '#{mode}'"
635
- end
985
+ raise ArgumentError "Unable to determine mode for '#{mode}'" unless MODES.include? mode
636
986
  mode
637
987
  end
638
988
  end