google-cloud-bigquery 1.41.0 → 1.43.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f13891ae7f46f3a0561140fabe4eed4cc426923258e17ed4cc10cc8155f9129
4
- data.tar.gz: 65eb5cfc6fb0feadae0d4503bcf2bd1942a0a9740a6f4f1b6f6aaddf7ee244c0
3
+ metadata.gz: d5aa7d55d1ed17508170fec706bfaf59a4434dc5ff9fa4a7ba6d3b655d441881
4
+ data.tar.gz: 865f6dc6a4a0abfed2c2c89da2a6c1021ca8e1174b6e89418da0807dca854954
5
5
  SHA512:
6
- metadata.gz: cecf4d1450deb04f33772ebc0bf18892816dda84e9e2b43668615dc37c49b3319465c3d0f3cb9c07ca9cc5a5e7a7118daab1f1aa51c25bf83ebadc925bd52eef
7
- data.tar.gz: c678e3b5420f82894c1d4935f4f89959fda4ea6e66faffa7fb649c0ff3c0e2fec91daf3e77208e02eb4747cf1a3d41ef5764a4b4da8b76b2a03328861121c7c2
6
+ metadata.gz: 3641715b30ab0897a12fab3b216944d50ae5d9468614bac41a60116470b3f8e948db6d394ff02f9dabebd5dc0a16e3cb3a7d8e0ee03b433740953ec0f5e803ac
7
+ data.tar.gz: 76a9ad13b267ea9313213a1ee3e1ad094bfd0ea81831fa0aae0e46e7dcae01443a4b76a04b20703145c7b6eaf76e6b74792358ae31984e0d73b9e1cb41bd9db9
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Release History
2
2
 
3
+ ### 1.43.0 (2023-05-10)
4
+
5
+ #### Features
6
+
7
+ * Added support for default value expression ([#21540](https://github.com/googleapis/google-cloud-ruby/issues/21540))
8
+
9
+ ### 1.42.0 (2023-01-15)
10
+
11
+ #### Features
12
+
13
+ * Added support for authorized dataset ([#19442](https://github.com/googleapis/google-cloud-ruby/issues/19442))
14
+ * Added support for tags in dataset ([#19350](https://github.com/googleapis/google-cloud-ruby/issues/19350))
15
+
3
16
  ### 1.41.0 (2023-01-05)
4
17
 
5
18
  #### Features
@@ -61,8 +61,10 @@ module Google
61
61
  "user" => :user_by_email,
62
62
  "user_by_email" => :user_by_email,
63
63
  "userByEmail" => :user_by_email,
64
- "view" => :view
64
+ "view" => :view,
65
+ "dataset" => :dataset
65
66
  }.freeze
67
+ attr_reader :rules
66
68
 
67
69
  # @private
68
70
  GROUPS = {
@@ -267,6 +269,44 @@ module Google
267
269
  add_access_view view
268
270
  end
269
271
 
272
+ ##
273
+ # Add reader access to a dataset.
274
+ #
275
+ # @param [Google::Cloud::Bigquery::DatasetAccessEntry, Hash<String,String> ] dataset A DatasetAccessEntry
276
+ # or a Hash object. Required
277
+ #
278
+ # @example
279
+ # require "google/cloud/bigquery"
280
+ #
281
+ # bigquery = Google::Cloud::Bigquery.new
282
+ # dataset = bigquery.dataset "my_dataset"
283
+ # other_dataset = bigquery.dataset "my_other_dataset", skip_lookup: true
284
+ #
285
+ # params = {
286
+ # dataset_id: other_dataset.dataset_id,
287
+ # project_id: other_dataset.project_id,
288
+ # target_types: ["VIEWS"]
289
+ # }
290
+ #
291
+ # dataset.access do |access|
292
+ # access.add_reader_dataset params
293
+ # end
294
+ #
295
+ # @example
296
+ # require "google/cloud/bigquery"
297
+ #
298
+ # bigquery = Google::Cloud::Bigquery.new
299
+ # dataset = bigquery.dataset "my_dataset"
300
+ # other_dataset = bigquery.dataset "my_other_dataset", skip_lookup: true
301
+ #
302
+ # dataset.access do |access|
303
+ # access.add_reader_dataset other_dataset.access_entry(target_types: ["VIEWS"])
304
+ # end
305
+ #
306
+ def add_reader_dataset dataset
307
+ add_access_dataset dataset
308
+ end
309
+
270
310
  ##
271
311
  # Add writer access to a user.
272
312
  #
@@ -610,6 +650,44 @@ module Google
610
650
  remove_access_view view
611
651
  end
612
652
 
653
+ ##
654
+ # Removes reader access of a dataset.
655
+ #
656
+ # @param [Google::Cloud::Bigquery::DatasetAccessEntry, Hash<String,String> ] dataset A DatasetAccessEntry
657
+ # or a Hash object. Required
658
+ #
659
+ # @example
660
+ # require "google/cloud/bigquery"
661
+ #
662
+ # bigquery = Google::Cloud::Bigquery.new
663
+ # dataset = bigquery.dataset "my_dataset"
664
+ # other_dataset = bigquery.dataset "my_other_dataset", skip_lookup: true
665
+ #
666
+ # params = {
667
+ # dataset_id: other_dataset.dataset_id,
668
+ # project_id: other_dataset.project_id,
669
+ # target_types: ["VIEWS"]
670
+ # }
671
+ #
672
+ # dataset.access do |access|
673
+ # access.remove_reader_dataset params
674
+ # end
675
+ #
676
+ # @example
677
+ # require "google/cloud/bigquery"
678
+ #
679
+ # bigquery = Google::Cloud::Bigquery.new
680
+ # dataset = bigquery.dataset "my_dataset"
681
+ # other_dataset = bigquery.dataset "my_other_dataset", skip_lookup: true
682
+ #
683
+ # dataset.access do |access|
684
+ # access.remove_reader_dataset other_dataset.access_entry(target_types: ["VIEWS"])
685
+ # end
686
+ #
687
+ def remove_reader_dataset dataset
688
+ remove_access_dataset dataset
689
+ end
690
+
613
691
  ##
614
692
  # Remove writer access from a user.
615
693
  #
@@ -951,6 +1029,40 @@ module Google
951
1029
  lookup_access_view view
952
1030
  end
953
1031
 
1032
+ ##
1033
+ # Checks reader access for a dataset.
1034
+ #
1035
+ # @param [Google::Cloud::Bigquery::DatasetAccessEntry, Hash<String,String> ] dataset A DatasetAccessEntry
1036
+ # or a Hash object. Required
1037
+ #
1038
+ # @example
1039
+ # require "google/cloud/bigquery"
1040
+ #
1041
+ # bigquery = Google::Cloud::Bigquery.new
1042
+ # dataset = bigquery.dataset "my_dataset"
1043
+ # other_dataset = bigquery.dataset "my_other_dataset", skip_lookup: true
1044
+ #
1045
+ # params = {
1046
+ # dataset_id: other_dataset.dataset_id,
1047
+ # project_id: other_dataset.project_id,
1048
+ # target_types: ["VIEWS"]
1049
+ # }
1050
+ #
1051
+ # dataset.access.reader_dataset? params
1052
+ #
1053
+ # @example
1054
+ # require "google/cloud/bigquery"
1055
+ #
1056
+ # bigquery = Google::Cloud::Bigquery.new
1057
+ # dataset = bigquery.dataset "my_dataset"
1058
+ # other_dataset = bigquery.dataset "my_other_dataset", skip_lookup: true
1059
+ #
1060
+ # dataset.access.reader_dataset? other_dataset.access_entry(target_types: ["VIEWS"])
1061
+ #
1062
+ def reader_dataset? dataset
1063
+ lookup_access_dataset dataset
1064
+ end
1065
+
954
1066
  ##
955
1067
  # Checks writer access for a user.
956
1068
  #
@@ -1184,6 +1296,18 @@ module Google
1184
1296
  end
1185
1297
  end
1186
1298
 
1299
+ # @private
1300
+ #
1301
+ # Checks the type of user input and converts it to acceptable format.
1302
+ #
1303
+ def validate_dataset dataset
1304
+ if dataset.is_a? Google::Apis::BigqueryV2::DatasetAccessEntry
1305
+ dataset
1306
+ else
1307
+ Service.dataset_access_entry_from_hash dataset
1308
+ end
1309
+ end
1310
+
1187
1311
  # @private
1188
1312
  def add_access_role_scope_value role, scope, value
1189
1313
  role = validate_role role
@@ -1218,6 +1342,17 @@ module Google
1218
1342
  @rules << Google::Apis::BigqueryV2::Dataset::Access.new(**opts)
1219
1343
  end
1220
1344
 
1345
+ # @private
1346
+ def add_access_dataset dataset
1347
+ # scope is dataset, make sure value is in the right format
1348
+ value = validate_dataset dataset
1349
+ # Remove existing rule for input dataset, if any
1350
+ @rules.reject!(&find_by_scope_and_resource_ref(:dataset, value))
1351
+ # Add new rule for this role, scope, and value
1352
+ opts = { dataset: value }
1353
+ @rules << Google::Apis::BigqueryV2::Dataset::Access.new(**opts)
1354
+ end
1355
+
1221
1356
  # @private
1222
1357
  def remove_access_role_scope_value role, scope, value
1223
1358
  role = validate_role role
@@ -1244,6 +1379,14 @@ module Google
1244
1379
  @rules.reject!(&find_by_scope_and_resource_ref(:view, value))
1245
1380
  end
1246
1381
 
1382
+ # @private
1383
+ def remove_access_dataset dataset
1384
+ # scope is dataset, make sure value is in the right format
1385
+ value = validate_dataset dataset
1386
+ # Remove existing rule for input dataset, if any
1387
+ @rules.reject!(&find_by_scope_and_resource_ref(:dataset, value))
1388
+ end
1389
+
1247
1390
  # @private
1248
1391
  def lookup_access_role_scope_value role, scope, value
1249
1392
  role = validate_role role
@@ -1268,6 +1411,14 @@ module Google
1268
1411
  !(!@rules.detect(&find_by_scope_and_resource_ref(:view, value)))
1269
1412
  end
1270
1413
 
1414
+ # @private
1415
+ def lookup_access_dataset dataset
1416
+ # scope is dataset, make sure value is in the right format
1417
+ value = validate_dataset dataset
1418
+ # Detect existing rule for input dataset, if any
1419
+ !(!@rules.detect(&find_by_scope_and_resource_ref(:dataset, value)))
1420
+ end
1421
+
1271
1422
  # @private
1272
1423
  def find_by_role_and_scope_and_value role, scope, value
1273
1424
  lambda do |a|
@@ -0,0 +1,67 @@
1
+ # Copyright 2022 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require "google/apis/bigquery_v2"
16
+
17
+ module Google
18
+ module Cloud
19
+ module Bigquery
20
+ class Dataset
21
+ ##
22
+ # A global tag managed by Resource Manager.
23
+ #
24
+ # @see https://cloud.google.com/iam/docs/tags-access-control#definitions
25
+ #
26
+ class Tag
27
+ ##
28
+ # @private The Google API Client object.
29
+ attr_accessor :gapi
30
+
31
+ ##
32
+ # @private Create an empty Tag object.
33
+ def initialize
34
+ @gapi = Google::Apis::BigqueryV2::Dataset::Tag.new
35
+ end
36
+
37
+ ##
38
+ # The namespaced friendly name of the tag key, e.g. "12345/environment" where
39
+ # 12345 is org id.
40
+ #
41
+ # @return [String]
42
+ #
43
+ def tag_key
44
+ @gapi.tag_key
45
+ end
46
+
47
+ ##
48
+ # The friendly short name of the tag value, e.g. "production".
49
+ #
50
+ # @return [String]
51
+ #
52
+ def tag_value
53
+ @gapi.tag_value
54
+ end
55
+
56
+ ##
57
+ # @private Google API Client object.
58
+ def self.from_gapi gapi
59
+ new_tag = new
60
+ new_tag.instance_variable_set :@gapi, gapi
61
+ new_tag
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -22,6 +22,7 @@ require "google/cloud/bigquery/routine"
22
22
  require "google/cloud/bigquery/external"
23
23
  require "google/cloud/bigquery/dataset/list"
24
24
  require "google/cloud/bigquery/dataset/access"
25
+ require "google/cloud/bigquery/dataset/tag"
25
26
  require "google/cloud/bigquery/convert"
26
27
  require "google/apis/bigquery_v2"
27
28
 
@@ -466,6 +467,21 @@ module Google
466
467
  access_builder.freeze
467
468
  end
468
469
 
470
+ ##
471
+ # Retrieves the tags associated with this dataset. Tag keys are
472
+ # globally unique, and managed via the resource manager API.
473
+ #
474
+ # @see https://cloud.google.com/resource-manager/docs/tags/tags-overview
475
+ # for more information.
476
+ #
477
+ # @return [Google::Cloud::Bigquery::Dataset::Tag] The list of tags.
478
+ #
479
+ def tags
480
+ ensure_full_data!
481
+ return nil if @gapi.tags.nil?
482
+ @gapi.tags.map { |gapi| Tag.from_gapi(gapi) }
483
+ end
484
+
469
485
  ##
470
486
  # Permanently deletes the dataset. The dataset must be empty before it
471
487
  # can be deleted unless the `force` option is set to `true`.
@@ -2741,6 +2757,29 @@ module Google
2741
2757
  interval: interval, threads: threads, &block
2742
2758
  end
2743
2759
 
2760
+ ##
2761
+ # Build an object of type Google::Apis::BigqueryV2::DatasetAccessEntry from
2762
+ # the self.
2763
+ #
2764
+ # @param [Array<String>] target_types The list of target types within the dataset.
2765
+ #
2766
+ # @return [Google::Apis::BigqueryV2::DatasetAccessEntry] Returns a DatasetAccessEntry object.
2767
+ #
2768
+ # @example
2769
+ # require "google/cloud/bigquery"
2770
+ #
2771
+ # bigquery = Google::Cloud::Bigquery.new
2772
+ # dataset = bigquery.dataset "my_dataset"
2773
+ # dataset_access_entry = dataset.access_entry target_types: ["VIEWS"]
2774
+ #
2775
+ def build_access_entry target_types: nil
2776
+ params = {
2777
+ dataset: dataset_ref,
2778
+ target_types: target_types
2779
+ }.delete_if { |_, v| v.nil? }
2780
+ Google::Apis::BigqueryV2::DatasetAccessEntry.new(**params)
2781
+ end
2782
+
2744
2783
  protected
2745
2784
 
2746
2785
  def insert_data_with_autocreate table_id, rows, skip_invalid: nil, ignore_unknown: nil, insert_ids: nil