google-cloud-bigquery 1.40.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/CHANGELOG.md +16 -0
- data/lib/google/cloud/bigquery/convert.rb +3 -3
- data/lib/google/cloud/bigquery/copy_job.rb +16 -4
- data/lib/google/cloud/bigquery/dataset/access.rb +152 -1
- data/lib/google/cloud/bigquery/dataset/tag.rb +67 -0
- data/lib/google/cloud/bigquery/dataset.rb +86 -10
- data/lib/google/cloud/bigquery/extract_job.rb +8 -2
- data/lib/google/cloud/bigquery/job.rb +2 -2
- data/lib/google/cloud/bigquery/load_job.rb +8 -2
- data/lib/google/cloud/bigquery/query_job.rb +9 -2
- data/lib/google/cloud/bigquery/service.rb +26 -4
- data/lib/google/cloud/bigquery/table.rb +7 -6
- data/lib/google/cloud/bigquery/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 779c0f4690b370db6eb7811fa6fb8dbca101dff34ff478dcdc51ed1e9c83c083
|
4
|
+
data.tar.gz: d1456024ae30a18c93c05d6d8be7eef88dd3f0610cdbf816cf0c46322c9574be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a5da0e2565b0c224f46a6330d138c8fb35831e874ebc2364fd3b91578d400354011d1e9df7d2986dbe2398f610776b130b7eb9305af8282bf3a6265dd84aa05
|
7
|
+
data.tar.gz: 0d14faa0d89ba6a114e247c362f8a5d4775ae4dc19de1aad0a64083da7e41fc93ac810e876b434056340b27412bb08063af05edf33355800ca1c528ff02f437b
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
# Release History
|
2
2
|
|
3
|
+
### 1.42.0 (2023-01-15)
|
4
|
+
|
5
|
+
#### Features
|
6
|
+
|
7
|
+
* Added support for authorized dataset ([#19442](https://github.com/googleapis/google-cloud-ruby/issues/19442))
|
8
|
+
* Added support for tags in dataset ([#19350](https://github.com/googleapis/google-cloud-ruby/issues/19350))
|
9
|
+
|
10
|
+
### 1.41.0 (2023-01-05)
|
11
|
+
|
12
|
+
#### Features
|
13
|
+
|
14
|
+
* Add support for partial projection of table metadata
|
15
|
+
#### Bug Fixes
|
16
|
+
|
17
|
+
* Fix querying of array of structs in named parameters ([#19466](https://github.com/googleapis/google-cloud-ruby/issues/19466))
|
18
|
+
|
3
19
|
### 1.40.0 (2022-12-14)
|
4
20
|
|
5
21
|
#### Features
|
@@ -254,11 +254,11 @@ module Google
|
|
254
254
|
|
255
255
|
##
|
256
256
|
# Lists are specified by providing the type code in an array. For example, an array of integers are specified as
|
257
|
-
# `[:INT64]`. Extracts the symbol.
|
257
|
+
# `[:INT64]`. Extracts the symbol/hash.
|
258
258
|
def self.extract_array_type type
|
259
259
|
return nil if type.nil?
|
260
|
-
unless type.is_a?(Array) && type.count == 1 && type.first.is_a?(Symbol)
|
261
|
-
raise ArgumentError, "types Array #{type.inspect} should include only a single symbol element."
|
260
|
+
unless type.is_a?(Array) && type.count == 1 && (type.first.is_a?(Symbol) || type.first.is_a?(Hash))
|
261
|
+
raise ArgumentError, "types Array #{type.inspect} should include only a single symbol or hash element."
|
262
262
|
end
|
263
263
|
type.first
|
264
264
|
end
|
@@ -64,23 +64,35 @@ module Google
|
|
64
64
|
# The table from which data is copied. This is the table on
|
65
65
|
# which {Table#copy_job} was called.
|
66
66
|
#
|
67
|
+
# @param [String] view Specifies the view that determines which table information is returned.
|
68
|
+
# By default, basic table information and storage statistics (STORAGE_STATS) are returned.
|
69
|
+
# Accepted values include `:unspecified`, `:basic`, `:storage`, and
|
70
|
+
# `:full`. For more information, see [BigQuery Classes](@todo: Update the link).
|
71
|
+
# The default value is the `:unspecified` view type.
|
72
|
+
#
|
67
73
|
# @return [Table] A table instance.
|
68
74
|
#
|
69
|
-
def source
|
75
|
+
def source view: nil
|
70
76
|
table = @gapi.configuration.copy.source_table
|
71
77
|
return nil unless table
|
72
|
-
retrieve_table table.project_id, table.dataset_id, table.table_id
|
78
|
+
retrieve_table table.project_id, table.dataset_id, table.table_id, metadata_view: view
|
73
79
|
end
|
74
80
|
|
75
81
|
##
|
76
82
|
# The table to which data is copied.
|
77
83
|
#
|
84
|
+
# @param [String] view Specifies the view that determines which table information is returned.
|
85
|
+
# By default, basic table information and storage statistics (STORAGE_STATS) are returned.
|
86
|
+
# Accepted values include `:unspecified`, `:basic`, `:storage`, and
|
87
|
+
# `:full`. For more information, see [BigQuery Classes](@todo: Update the link).
|
88
|
+
# The default value is the `:unspecified` view type.
|
89
|
+
#
|
78
90
|
# @return [Table] A table instance.
|
79
91
|
#
|
80
|
-
def destination
|
92
|
+
def destination view: nil
|
81
93
|
table = @gapi.configuration.copy.destination_table
|
82
94
|
return nil unless table
|
83
|
-
retrieve_table table.project_id, table.dataset_id, table.table_id
|
95
|
+
retrieve_table table.project_id, table.dataset_id, table.table_id, metadata_view: view
|
84
96
|
end
|
85
97
|
|
86
98
|
##
|
@@ -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`.
|
@@ -793,6 +809,11 @@ module Google
|
|
793
809
|
# object without verifying that the resource exists on the BigQuery
|
794
810
|
# service. Calls made on this object will raise errors if the resource
|
795
811
|
# does not exist. Default is `false`. Optional.
|
812
|
+
# @param [String] view Specifies the view that determines which table information is returned.
|
813
|
+
# By default, basic table information and storage statistics (STORAGE_STATS) are returned.
|
814
|
+
# Accepted values include `:unspecified`, `:basic`, `:storage`, and
|
815
|
+
# `:full`. For more information, see [BigQuery Classes](@todo: Update the link).
|
816
|
+
# The default value is the `:unspecified` view type.
|
796
817
|
#
|
797
818
|
# @return [Google::Cloud::Bigquery::Table, nil] Returns `nil` if the
|
798
819
|
# table does not exist.
|
@@ -815,13 +836,22 @@ module Google
|
|
815
836
|
#
|
816
837
|
# table = dataset.table "my_table", skip_lookup: true
|
817
838
|
#
|
839
|
+
# @example Avoid retrieving transient stats of the table with `view`:
|
840
|
+
# require "google/cloud/bigquery"
|
841
|
+
#
|
842
|
+
# bigquery = Google::Cloud::Bigquery.new
|
843
|
+
#
|
844
|
+
# dataset = bigquery.dataset "my_dataset"
|
845
|
+
#
|
846
|
+
# table = dataset.table "my_table", view: "basic"
|
847
|
+
#
|
818
848
|
# @!group Table
|
819
849
|
#
|
820
|
-
def table table_id, skip_lookup: nil
|
850
|
+
def table table_id, skip_lookup: nil, view: nil
|
821
851
|
ensure_service!
|
822
852
|
return Table.new_reference project_id, dataset_id, table_id, service if skip_lookup
|
823
|
-
gapi = service.get_table dataset_id, table_id
|
824
|
-
Table.from_gapi gapi, service
|
853
|
+
gapi = service.get_table dataset_id, table_id, metadata_view: view
|
854
|
+
Table.from_gapi gapi, service, metadata_view: view
|
825
855
|
rescue Google::Cloud::NotFoundError
|
826
856
|
nil
|
827
857
|
end
|
@@ -2658,6 +2688,11 @@ module Google
|
|
2658
2688
|
# messages before the batch is published. Default is 10.
|
2659
2689
|
# @attr_reader [Numeric] threads The number of threads used to insert
|
2660
2690
|
# batches of rows. Default is 4.
|
2691
|
+
# @param [String] view Specifies the view that determines which table information is returned.
|
2692
|
+
# By default, basic table information and storage statistics (STORAGE_STATS) are returned.
|
2693
|
+
# Accepted values include `:unspecified`, `:basic`, `:storage`, and
|
2694
|
+
# `:full`. For more information, see [BigQuery Classes](@todo: Update the link).
|
2695
|
+
# The default value is the `:unspecified` view type.
|
2661
2696
|
# @yield [response] the callback for when a batch of rows is inserted
|
2662
2697
|
# @yieldparam [Table::AsyncInserter::Result] result the result of the
|
2663
2698
|
# asynchronous insert
|
@@ -2686,13 +2721,35 @@ module Google
|
|
2686
2721
|
#
|
2687
2722
|
# inserter.stop.wait!
|
2688
2723
|
#
|
2724
|
+
# @example Avoid retrieving transient stats of the table with while inserting :
|
2725
|
+
# require "google/cloud/bigquery"
|
2726
|
+
#
|
2727
|
+
# bigquery = Google::Cloud::Bigquery.new
|
2728
|
+
# dataset = bigquery.dataset "my_dataset"
|
2729
|
+
# inserter = dataset.insert_async("my_table", view: "basic") do |result|
|
2730
|
+
# if result.error?
|
2731
|
+
# log_error result.error
|
2732
|
+
# else
|
2733
|
+
# log_insert "inserted #{result.insert_count} rows " \
|
2734
|
+
# "with #{result.error_count} errors"
|
2735
|
+
# end
|
2736
|
+
# end
|
2737
|
+
#
|
2738
|
+
# rows = [
|
2739
|
+
# { "first_name" => "Alice", "age" => 21 },
|
2740
|
+
# { "first_name" => "Bob", "age" => 22 }
|
2741
|
+
# ]
|
2742
|
+
# inserter.insert rows
|
2743
|
+
#
|
2744
|
+
# inserter.stop.wait!
|
2745
|
+
#
|
2689
2746
|
def insert_async table_id, skip_invalid: nil, ignore_unknown: nil, max_bytes: 10_000_000, max_rows: 500,
|
2690
|
-
interval: 10, threads: 4, &block
|
2747
|
+
interval: 10, threads: 4, view: nil, &block
|
2691
2748
|
ensure_service!
|
2692
2749
|
|
2693
2750
|
# Get table, don't use Dataset#table which handles NotFoundError
|
2694
|
-
gapi = service.get_table dataset_id, table_id
|
2695
|
-
table = Table.from_gapi gapi, service
|
2751
|
+
gapi = service.get_table dataset_id, table_id, metadata_view: view
|
2752
|
+
table = Table.from_gapi gapi, service, metadata_view: view
|
2696
2753
|
# Get the AsyncInserter from the table
|
2697
2754
|
table.insert_async skip_invalid: skip_invalid,
|
2698
2755
|
ignore_unknown: ignore_unknown,
|
@@ -2700,6 +2757,29 @@ module Google
|
|
2700
2757
|
interval: interval, threads: threads, &block
|
2701
2758
|
end
|
2702
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
|
+
|
2703
2783
|
protected
|
2704
2784
|
|
2705
2785
|
def insert_data_with_autocreate table_id, rows, skip_invalid: nil, ignore_unknown: nil, insert_ids: nil
|
@@ -2944,8 +3024,6 @@ module Google
|
|
2944
3024
|
@access
|
2945
3025
|
end
|
2946
3026
|
|
2947
|
-
# rubocop:disable Style/MethodDefParentheses
|
2948
|
-
|
2949
3027
|
##
|
2950
3028
|
# @raise [RuntimeError] not implemented
|
2951
3029
|
def delete(*)
|
@@ -3049,8 +3127,6 @@ module Google
|
|
3049
3127
|
end
|
3050
3128
|
alias refresh! reload!
|
3051
3129
|
|
3052
|
-
# rubocop:enable Style/MethodDefParentheses
|
3053
|
-
|
3054
3130
|
##
|
3055
3131
|
# @private Make sure any access changes are saved
|
3056
3132
|
def check_for_mutated_access!
|
@@ -65,11 +65,17 @@ module Google
|
|
65
65
|
##
|
66
66
|
# The table or model which is exported.
|
67
67
|
#
|
68
|
+
# @param [String] view Specifies the view that determines which table information is returned.
|
69
|
+
# By default, basic table information and storage statistics (STORAGE_STATS) are returned.
|
70
|
+
# Accepted values include `:unspecified`, `:basic`, `:storage`, and
|
71
|
+
# `:full`. For more information, see [BigQuery Classes](@todo: Update the link).
|
72
|
+
# The default value is the `:unspecified` view type.
|
73
|
+
#
|
68
74
|
# @return [Table, Model, nil] A table or model instance, or `nil`.
|
69
75
|
#
|
70
|
-
def source
|
76
|
+
def source view: nil
|
71
77
|
if (table = @gapi.configuration.extract.source_table)
|
72
|
-
retrieve_table table.project_id, table.dataset_id, table.table_id
|
78
|
+
retrieve_table table.project_id, table.dataset_id, table.table_id, metadata_view: view
|
73
79
|
elsif (model = @gapi.configuration.extract.source_model)
|
74
80
|
retrieve_model model.project_id, model.dataset_id, model.model_id
|
75
81
|
end
|
@@ -710,9 +710,9 @@ module Google
|
|
710
710
|
raise "Must have active connection" unless service
|
711
711
|
end
|
712
712
|
|
713
|
-
def retrieve_table project_id, dataset_id, table_id
|
713
|
+
def retrieve_table project_id, dataset_id, table_id, metadata_view: nil
|
714
714
|
ensure_service!
|
715
|
-
gapi = service.get_project_table project_id, dataset_id, table_id
|
715
|
+
gapi = service.get_project_table project_id, dataset_id, table_id, metadata_view: metadata_view
|
716
716
|
Table.from_gapi gapi, service
|
717
717
|
rescue Google::Cloud::NotFoundError
|
718
718
|
nil
|
@@ -62,12 +62,18 @@ module Google
|
|
62
62
|
# The table into which the operation loads data. This is the table on
|
63
63
|
# which {Table#load_job} was invoked.
|
64
64
|
#
|
65
|
+
# @param [String] view Specifies the view that determines which table information is returned.
|
66
|
+
# By default, basic table information and storage statistics (STORAGE_STATS) are returned.
|
67
|
+
# Accepted values include `:unspecified`, `:basic`, `:storage`, and
|
68
|
+
# `:full`. For more information, see [BigQuery Classes](@todo: Update the link).
|
69
|
+
# The default value is the `:unspecified` view type.
|
70
|
+
#
|
65
71
|
# @return [Table] A table instance.
|
66
72
|
#
|
67
|
-
def destination
|
73
|
+
def destination view: nil
|
68
74
|
table = @gapi.configuration.load.destination_table
|
69
75
|
return nil unless table
|
70
|
-
retrieve_table table.project_id, table.dataset_id, table.table_id
|
76
|
+
retrieve_table table.project_id, table.dataset_id, table.table_id, metadata_view: view
|
71
77
|
end
|
72
78
|
|
73
79
|
##
|
@@ -437,14 +437,21 @@ module Google
|
|
437
437
|
##
|
438
438
|
# The table in which the query results are stored.
|
439
439
|
#
|
440
|
+
# @param [String] view Specifies the view that determines which table information is returned.
|
441
|
+
# By default, basic table information and storage statistics (STORAGE_STATS) are returned.
|
442
|
+
# Accepted values include `:unspecified`, `:basic`, `:storage`, and
|
443
|
+
# `:full`. For more information, see [BigQuery Classes](@todo: Update the link).
|
444
|
+
# The default value is the `:unspecified` view type.
|
445
|
+
#
|
440
446
|
# @return [Table] A table instance.
|
441
447
|
#
|
442
|
-
def destination
|
448
|
+
def destination view: nil
|
443
449
|
table = @gapi.configuration.query.destination_table
|
444
450
|
return nil unless table
|
445
451
|
retrieve_table table.project_id,
|
446
452
|
table.dataset_id,
|
447
|
-
table.table_id
|
453
|
+
table.table_id,
|
454
|
+
metadata_view: view
|
448
455
|
end
|
449
456
|
|
450
457
|
##
|
@@ -144,10 +144,11 @@ module Google
|
|
144
144
|
|
145
145
|
##
|
146
146
|
# Gets the specified table resource by full table reference.
|
147
|
-
def get_project_table project_id, dataset_id, table_id
|
147
|
+
def get_project_table project_id, dataset_id, table_id, metadata_view: nil
|
148
|
+
metadata_view = table_metadata_view_type_for metadata_view
|
148
149
|
# The get operation is considered idempotent
|
149
150
|
execute backoff: true do
|
150
|
-
service.get_table project_id, dataset_id, table_id
|
151
|
+
service.get_table project_id, dataset_id, table_id, view: metadata_view
|
151
152
|
end
|
152
153
|
end
|
153
154
|
|
@@ -156,8 +157,8 @@ module Google
|
|
156
157
|
# This method does not return the data in the table,
|
157
158
|
# it only returns the table resource,
|
158
159
|
# which describes the structure of this table.
|
159
|
-
def get_table dataset_id, table_id
|
160
|
-
get_project_table @project, dataset_id, table_id
|
160
|
+
def get_table dataset_id, table_id, metadata_view: nil
|
161
|
+
get_project_table @project, dataset_id, table_id, metadata_view: metadata_view
|
161
162
|
end
|
162
163
|
|
163
164
|
##
|
@@ -496,6 +497,19 @@ module Google
|
|
496
497
|
ref
|
497
498
|
end
|
498
499
|
|
500
|
+
##
|
501
|
+
# Converts a hash to a Google::Apis::BigqueryV2::DatasetAccessEntry oject.
|
502
|
+
#
|
503
|
+
# @param [Hash<String,String>] dataset_hash Hash for a DatasetAccessEntry.
|
504
|
+
#
|
505
|
+
def self.dataset_access_entry_from_hash dataset_hash
|
506
|
+
params = {
|
507
|
+
dataset: Google::Apis::BigqueryV2::DatasetReference.new(**dataset_hash),
|
508
|
+
target_types: dataset_hash[:target_types]
|
509
|
+
}.delete_if { |_, v| v.nil? }
|
510
|
+
Google::Apis::BigqueryV2::DatasetAccessEntry.new(**params)
|
511
|
+
end
|
512
|
+
|
499
513
|
def self.validate_table_ref table_ref
|
500
514
|
[:project_id, :dataset_id, :table_id].each do |f|
|
501
515
|
raise ArgumentError, "TableReference is missing #{f}" if table_ref.send(f).nil?
|
@@ -572,6 +586,14 @@ module Google
|
|
572
586
|
raise Google::Cloud::Error.from_error e
|
573
587
|
end
|
574
588
|
|
589
|
+
def table_metadata_view_type_for str
|
590
|
+
return nil if str.nil?
|
591
|
+
{ "unspecified" => "TABLE_METADATA_VIEW_UNSPECIFIED",
|
592
|
+
"basic" => "BASIC",
|
593
|
+
"storage" => "STORAGE_STATS",
|
594
|
+
"full" => "FULL" }[str.to_s.downcase]
|
595
|
+
end
|
596
|
+
|
575
597
|
class Backoff
|
576
598
|
class << self
|
577
599
|
attr_accessor :retries
|
@@ -108,6 +108,10 @@ module Google
|
|
108
108
|
# @private A Google API Client Table Reference object.
|
109
109
|
attr_reader :reference
|
110
110
|
|
111
|
+
##
|
112
|
+
# @private The metadata view type string.
|
113
|
+
attr_accessor :metadata_view
|
114
|
+
|
111
115
|
##
|
112
116
|
# @private Create an empty Table object.
|
113
117
|
def initialize
|
@@ -2836,7 +2840,7 @@ module Google
|
|
2836
2840
|
#
|
2837
2841
|
def reload!
|
2838
2842
|
ensure_service!
|
2839
|
-
@gapi = service.get_table dataset_id, table_id
|
2843
|
+
@gapi = service.get_table dataset_id, table_id, metadata_view: metadata_view
|
2840
2844
|
@reference = nil
|
2841
2845
|
@exists = nil
|
2842
2846
|
self
|
@@ -2970,10 +2974,11 @@ module Google
|
|
2970
2974
|
|
2971
2975
|
##
|
2972
2976
|
# @private New Table from a Google API Client object.
|
2973
|
-
def self.from_gapi gapi, service
|
2977
|
+
def self.from_gapi gapi, service, metadata_view: nil
|
2974
2978
|
new.tap do |f|
|
2975
2979
|
f.gapi = gapi
|
2976
2980
|
f.service = service
|
2981
|
+
f.metadata_view = metadata_view
|
2977
2982
|
end
|
2978
2983
|
end
|
2979
2984
|
|
@@ -3982,8 +3987,6 @@ module Google
|
|
3982
3987
|
schema.record name, description: description, mode: mode, &block
|
3983
3988
|
end
|
3984
3989
|
|
3985
|
-
# rubocop:disable Style/MethodDefParentheses
|
3986
|
-
|
3987
3990
|
##
|
3988
3991
|
# @raise [RuntimeError] not implemented
|
3989
3992
|
def data(*)
|
@@ -4069,8 +4072,6 @@ module Google
|
|
4069
4072
|
end
|
4070
4073
|
alias refresh! reload!
|
4071
4074
|
|
4072
|
-
# rubocop:enable Style/MethodDefParentheses
|
4073
|
-
|
4074
4075
|
##
|
4075
4076
|
# @private Make sure any access changes are saved
|
4076
4077
|
def check_for_mutated_schema!
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-cloud-bigquery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.42.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Moore
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2023-01-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: concurrent-ruby
|
@@ -268,6 +268,7 @@ files:
|
|
268
268
|
- lib/google/cloud/bigquery/dataset.rb
|
269
269
|
- lib/google/cloud/bigquery/dataset/access.rb
|
270
270
|
- lib/google/cloud/bigquery/dataset/list.rb
|
271
|
+
- lib/google/cloud/bigquery/dataset/tag.rb
|
271
272
|
- lib/google/cloud/bigquery/encryption_configuration.rb
|
272
273
|
- lib/google/cloud/bigquery/external.rb
|
273
274
|
- lib/google/cloud/bigquery/external/avro_source.rb
|
@@ -320,7 +321,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
320
321
|
- !ruby/object:Gem::Version
|
321
322
|
version: '0'
|
322
323
|
requirements: []
|
323
|
-
rubygems_version: 3.
|
324
|
+
rubygems_version: 3.4.2
|
324
325
|
signing_key:
|
325
326
|
specification_version: 4
|
326
327
|
summary: API Client library for Google BigQuery
|