google-cloud-bigquery 1.32.0 → 1.35.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.
@@ -40,8 +40,25 @@ module Google
40
40
  MODES = ["NULLABLE", "REQUIRED", "REPEATED"].freeze
41
41
 
42
42
  # @private
43
- TYPES = ["STRING", "INTEGER", "INT64", "FLOAT", "FLOAT64", "NUMERIC", "BIGNUMERIC", "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.
@@ -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`, `BIGNUMERIC`,
76
- # `BOOLEAN`, `BOOL` (same as `BOOLEAN`), `TIMESTAMP`, `DATE`,
77
- # `TIME`, `DATETIME`, `RECORD` (where `RECORD` indicates that the
78
- # field contains a 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`, `BIGNUMERIC`,
90
- # `BOOLEAN`, `BOOL` (same as `BOOLEAN`), `TIMESTAMP`, `DATE`,
91
- # `TIME`, `DATETIME`, `RECORD` (where `RECORD` indicates that the
92
- # field contains a 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
  #
@@ -262,6 +400,15 @@ module Google
262
400
  type == "DATE"
263
401
  end
264
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
+
265
412
  ##
266
413
  # Checks if the type of the field is `RECORD`.
267
414
  #
@@ -355,11 +502,22 @@ module Google
355
502
  # @param [Symbol] mode The field's mode. The possible values are
356
503
  # `:nullable`, `:required`, and `:repeated`. The default value is
357
504
  # `:nullable`.
358
- #
359
- 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
360
513
  record_check!
361
514
 
362
- 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
363
521
  end
364
522
 
365
523
  ##
@@ -375,11 +533,15 @@ module Google
375
533
  # @param [Symbol] mode The field's mode. The possible values are
376
534
  # `:nullable`, `:required`, and `:repeated`. The default value is
377
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.
378
540
  #
379
- def integer name, description: nil, mode: :nullable
541
+ def integer name, description: nil, mode: :nullable, policy_tags: nil
380
542
  record_check!
381
543
 
382
- add_field name, :integer, description: description, mode: mode
544
+ add_field name, :integer, description: description, mode: mode, policy_tags: policy_tags
383
545
  end
384
546
 
385
547
  ##
@@ -396,11 +558,15 @@ module Google
396
558
  # @param [Symbol] mode The field's mode. The possible values are
397
559
  # `:nullable`, `:required`, and `:repeated`. The default value is
398
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.
399
565
  #
400
- def float name, description: nil, mode: :nullable
566
+ def float name, description: nil, mode: :nullable, policy_tags: nil
401
567
  record_check!
402
568
 
403
- add_field name, :float, description: description, mode: mode
569
+ add_field name, :float, description: description, mode: mode, policy_tags: policy_tags
404
570
  end
405
571
 
406
572
  ##
@@ -427,11 +593,31 @@ module Google
427
593
  # @param [Symbol] mode The field's mode. The possible values are
428
594
  # `:nullable`, `:required`, and `:repeated`. The default value is
429
595
  # `:nullable`.
430
- #
431
- def numeric name, description: nil, mode: :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
432
612
  record_check!
433
613
 
434
- add_field name, :numeric, description: description, mode: mode
614
+ add_field name,
615
+ :numeric,
616
+ description: description,
617
+ mode: mode,
618
+ policy_tags: policy_tags,
619
+ precision: precision,
620
+ scale: scale
435
621
  end
436
622
 
437
623
  ##
@@ -458,11 +644,31 @@ module Google
458
644
  # @param [Symbol] mode The field's mode. The possible values are
459
645
  # `:nullable`, `:required`, and `:repeated`. The default value is
460
646
  # `:nullable`.
461
- #
462
- def bignumeric name, description: nil, mode: :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
463
663
  record_check!
464
664
 
465
- add_field name, :bignumeric, 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
466
672
  end
467
673
 
468
674
  ##
@@ -478,11 +684,15 @@ module Google
478
684
  # @param [Symbol] mode The field's mode. The possible values are
479
685
  # `:nullable`, `:required`, and `:repeated`. The default value is
480
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.
481
691
  #
482
- def boolean name, description: nil, mode: :nullable
692
+ def boolean name, description: nil, mode: :nullable, policy_tags: nil
483
693
  record_check!
484
694
 
485
- add_field name, :boolean, description: description, mode: mode
695
+ add_field name, :boolean, description: description, mode: mode, policy_tags: policy_tags
486
696
  end
487
697
 
488
698
  ##
@@ -498,11 +708,22 @@ module Google
498
708
  # @param [Symbol] mode The field's mode. The possible values are
499
709
  # `:nullable`, `:required`, and `:repeated`. The default value is
500
710
  # `:nullable`.
501
- #
502
- 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
503
719
  record_check!
504
720
 
505
- 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
506
727
  end
507
728
 
508
729
  ##
@@ -518,11 +739,15 @@ module Google
518
739
  # @param [Symbol] mode The field's mode. The possible values are
519
740
  # `:nullable`, `:required`, and `:repeated`. The default value is
520
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.
521
746
  #
522
- def timestamp name, description: nil, mode: :nullable
747
+ def timestamp name, description: nil, mode: :nullable, policy_tags: nil
523
748
  record_check!
524
749
 
525
- add_field name, :timestamp, description: description, mode: mode
750
+ add_field name, :timestamp, description: description, mode: mode, policy_tags: policy_tags
526
751
  end
527
752
 
528
753
  ##
@@ -538,11 +763,15 @@ module Google
538
763
  # @param [Symbol] mode The field's mode. The possible values are
539
764
  # `:nullable`, `:required`, and `:repeated`. The default value is
540
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.
541
770
  #
542
- def time name, description: nil, mode: :nullable
771
+ def time name, description: nil, mode: :nullable, policy_tags: nil
543
772
  record_check!
544
773
 
545
- add_field name, :time, description: description, mode: mode
774
+ add_field name, :time, description: description, mode: mode, policy_tags: policy_tags
546
775
  end
547
776
 
548
777
  ##
@@ -558,11 +787,15 @@ module Google
558
787
  # @param [Symbol] mode The field's mode. The possible values are
559
788
  # `:nullable`, `:required`, and `:repeated`. The default value is
560
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.
561
794
  #
562
- def datetime name, description: nil, mode: :nullable
795
+ def datetime name, description: nil, mode: :nullable, policy_tags: nil
563
796
  record_check!
564
797
 
565
- add_field name, :datetime, description: description, mode: mode
798
+ add_field name, :datetime, description: description, mode: mode, policy_tags: policy_tags
566
799
  end
567
800
 
568
801
  ##
@@ -578,11 +811,39 @@ module Google
578
811
  # @param [Symbol] mode The field's mode. The possible values are
579
812
  # `:nullable`, `:required`, and `:repeated`. The default value is
580
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.
581
818
  #
582
- def date name, description: nil, mode: :nullable
819
+ def date name, description: nil, mode: :nullable, policy_tags: nil
583
820
  record_check!
584
821
 
585
- 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-z, A-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
586
847
  end
587
848
 
588
849
  ##
@@ -678,7 +939,7 @@ module Google
678
939
  "Cannot add fields to a non-RECORD field (#{type})"
679
940
  end
680
941
 
681
- def add_field name, type, description: nil, mode: :nullable
942
+ def add_field name, type, description: nil, mode: :nullable, policy_tags: nil, max_length: nil
682
943
  frozen_check!
683
944
 
684
945
  new_gapi = Google::Apis::BigqueryV2::TableFieldSchema.new(
@@ -688,7 +949,11 @@ module Google
688
949
  mode: verify_mode(mode),
689
950
  fields: []
690
951
  )
691
-
952
+ if policy_tags
953
+ policy_tags = Array(policy_tags)
954
+ new_gapi.policy_tags = Google::Apis::BigqueryV2::TableFieldSchema::PolicyTags.new names: policy_tags
955
+ end
956
+ new_gapi.max_length = max_length if max_length
692
957
  # Remove any existing field of this name
693
958
  @gapi.fields ||= []
694
959
  @gapi.fields.reject! { |f| f.name == new_gapi.name }