gcloud 0.12.2 → 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/lib/gcloud.rb +27 -456
- data/lib/gcloud/bigquery.rb +2 -382
- data/lib/gcloud/datastore.rb +2 -576
- data/lib/gcloud/dns.rb +2 -321
- data/lib/gcloud/logging.rb +1 -322
- data/lib/gcloud/pubsub.rb +2 -476
- data/lib/gcloud/resource_manager.rb +2 -273
- data/lib/gcloud/storage.rb +2 -440
- data/lib/gcloud/translate.rb +1 -250
- data/lib/gcloud/version.rb +2 -2
- data/lib/gcloud/vision.rb +1 -501
- metadata +36 -332
- data/AUTHENTICATION.md +0 -75
- data/CHANGELOG.md +0 -382
- data/OVERVIEW.md +0 -259
- data/lib/gcloud/backoff.rb +0 -150
- data/lib/gcloud/bigquery/copy_job.rb +0 -97
- data/lib/gcloud/bigquery/credentials.rb +0 -29
- data/lib/gcloud/bigquery/data.rb +0 -239
- data/lib/gcloud/bigquery/dataset.rb +0 -753
- data/lib/gcloud/bigquery/dataset/access.rb +0 -507
- data/lib/gcloud/bigquery/dataset/list.rb +0 -169
- data/lib/gcloud/bigquery/extract_job.rb +0 -117
- data/lib/gcloud/bigquery/insert_response.rb +0 -81
- data/lib/gcloud/bigquery/job.rb +0 -299
- data/lib/gcloud/bigquery/job/list.rb +0 -172
- data/lib/gcloud/bigquery/load_job.rb +0 -202
- data/lib/gcloud/bigquery/project.rb +0 -475
- data/lib/gcloud/bigquery/query_data.rb +0 -234
- data/lib/gcloud/bigquery/query_job.rb +0 -137
- data/lib/gcloud/bigquery/schema.rb +0 -359
- data/lib/gcloud/bigquery/service.rb +0 -506
- data/lib/gcloud/bigquery/table.rb +0 -1141
- data/lib/gcloud/bigquery/table/list.rb +0 -180
- data/lib/gcloud/bigquery/view.rb +0 -475
- data/lib/gcloud/credentials.rb +0 -129
- data/lib/gcloud/datastore/commit.rb +0 -148
- data/lib/gcloud/datastore/credentials.rb +0 -35
- data/lib/gcloud/datastore/cursor.rb +0 -76
- data/lib/gcloud/datastore/dataset.rb +0 -660
- data/lib/gcloud/datastore/dataset/lookup_results.rb +0 -219
- data/lib/gcloud/datastore/dataset/query_results.rb +0 -386
- data/lib/gcloud/datastore/entity.rb +0 -449
- data/lib/gcloud/datastore/errors.rb +0 -41
- data/lib/gcloud/datastore/gql_query.rb +0 -211
- data/lib/gcloud/datastore/grpc_utils.rb +0 -132
- data/lib/gcloud/datastore/key.rb +0 -281
- data/lib/gcloud/datastore/properties.rb +0 -128
- data/lib/gcloud/datastore/query.rb +0 -348
- data/lib/gcloud/datastore/service.rb +0 -167
- data/lib/gcloud/datastore/transaction.rb +0 -362
- data/lib/gcloud/dns/change.rb +0 -158
- data/lib/gcloud/dns/change/list.rb +0 -173
- data/lib/gcloud/dns/credentials.rb +0 -29
- data/lib/gcloud/dns/importer.rb +0 -183
- data/lib/gcloud/dns/project.rb +0 -247
- data/lib/gcloud/dns/record.rb +0 -170
- data/lib/gcloud/dns/record/list.rb +0 -174
- data/lib/gcloud/dns/service.rb +0 -167
- data/lib/gcloud/dns/zone.rb +0 -759
- data/lib/gcloud/dns/zone/list.rb +0 -168
- data/lib/gcloud/dns/zone/transaction.rb +0 -176
- data/lib/gcloud/errors.rb +0 -206
- data/lib/gcloud/gce.rb +0 -56
- data/lib/gcloud/grpc_utils.rb +0 -87
- data/lib/gcloud/logging/credentials.rb +0 -29
- data/lib/gcloud/logging/entry.rb +0 -465
- data/lib/gcloud/logging/entry/http_request.rb +0 -141
- data/lib/gcloud/logging/entry/list.rb +0 -177
- data/lib/gcloud/logging/entry/operation.rb +0 -90
- data/lib/gcloud/logging/logger.rb +0 -307
- data/lib/gcloud/logging/metric.rb +0 -169
- data/lib/gcloud/logging/metric/list.rb +0 -172
- data/lib/gcloud/logging/project.rb +0 -642
- data/lib/gcloud/logging/resource.rb +0 -84
- data/lib/gcloud/logging/resource_descriptor.rb +0 -137
- data/lib/gcloud/logging/resource_descriptor/list.rb +0 -174
- data/lib/gcloud/logging/service.rb +0 -267
- data/lib/gcloud/logging/sink.rb +0 -227
- data/lib/gcloud/logging/sink/list.rb +0 -171
- data/lib/gcloud/pubsub/credentials.rb +0 -29
- data/lib/gcloud/pubsub/message.rb +0 -94
- data/lib/gcloud/pubsub/policy.rb +0 -204
- data/lib/gcloud/pubsub/project.rb +0 -482
- data/lib/gcloud/pubsub/received_message.rb +0 -160
- data/lib/gcloud/pubsub/service.rb +0 -334
- data/lib/gcloud/pubsub/subscription.rb +0 -565
- data/lib/gcloud/pubsub/subscription/list.rb +0 -208
- data/lib/gcloud/pubsub/topic.rb +0 -511
- data/lib/gcloud/pubsub/topic/list.rb +0 -174
- data/lib/gcloud/pubsub/topic/publisher.rb +0 -85
- data/lib/gcloud/resource_manager/credentials.rb +0 -30
- data/lib/gcloud/resource_manager/manager.rb +0 -266
- data/lib/gcloud/resource_manager/policy.rb +0 -211
- data/lib/gcloud/resource_manager/project.rb +0 -484
- data/lib/gcloud/resource_manager/project/list.rb +0 -167
- data/lib/gcloud/resource_manager/project/updater.rb +0 -130
- data/lib/gcloud/resource_manager/service.rb +0 -127
- data/lib/gcloud/storage/bucket.rb +0 -775
- data/lib/gcloud/storage/bucket/acl.rb +0 -810
- data/lib/gcloud/storage/bucket/cors.rb +0 -153
- data/lib/gcloud/storage/bucket/list.rb +0 -172
- data/lib/gcloud/storage/credentials.rb +0 -29
- data/lib/gcloud/storage/errors.rb +0 -65
- data/lib/gcloud/storage/file.rb +0 -842
- data/lib/gcloud/storage/file/acl.rb +0 -425
- data/lib/gcloud/storage/file/list.rb +0 -191
- data/lib/gcloud/storage/file/verifier.rb +0 -67
- data/lib/gcloud/storage/project.rb +0 -316
- data/lib/gcloud/storage/service.rb +0 -347
- data/lib/gcloud/translate/api.rb +0 -241
- data/lib/gcloud/translate/detection.rb +0 -137
- data/lib/gcloud/translate/language.rb +0 -69
- data/lib/gcloud/translate/service.rb +0 -80
- data/lib/gcloud/translate/translation.rb +0 -112
- data/lib/gcloud/vision/annotate.rb +0 -224
- data/lib/gcloud/vision/annotation.rb +0 -455
- data/lib/gcloud/vision/annotation/entity.rb +0 -234
- data/lib/gcloud/vision/annotation/face.rb +0 -1750
- data/lib/gcloud/vision/annotation/properties.rb +0 -245
- data/lib/gcloud/vision/annotation/safe_search.rb +0 -161
- data/lib/gcloud/vision/annotation/text.rb +0 -236
- data/lib/gcloud/vision/annotation/vertex.rb +0 -108
- data/lib/gcloud/vision/credentials.rb +0 -29
- data/lib/gcloud/vision/image.rb +0 -590
- data/lib/gcloud/vision/location.rb +0 -115
- data/lib/gcloud/vision/project.rb +0 -278
- data/lib/gcloud/vision/service.rb +0 -66
- data/lib/google/api/annotations.rb +0 -14
- data/lib/google/api/http.rb +0 -30
- data/lib/google/api/label.rb +0 -24
- data/lib/google/api/monitored_resource.rb +0 -25
- data/lib/google/datastore/v1beta3/datastore.rb +0 -115
- data/lib/google/datastore/v1beta3/datastore_services.rb +0 -33
- data/lib/google/datastore/v1beta3/entity.rb +0 -63
- data/lib/google/datastore/v1beta3/query.rb +0 -128
- data/lib/google/devtools/cloudtrace/v1/trace.rb +0 -78
- data/lib/google/devtools/cloudtrace/v1/trace_services.rb +0 -32
- data/lib/google/example/library/v1/library.rb +0 -91
- data/lib/google/example/library/v1/library_services.rb +0 -40
- data/lib/google/iam/v1/iam_policy.rb +0 -33
- data/lib/google/iam/v1/iam_policy_services.rb +0 -30
- data/lib/google/iam/v1/policy.rb +0 -25
- data/lib/google/logging/type/http_request.rb +0 -28
- data/lib/google/logging/type/log_severity.rb +0 -27
- data/lib/google/logging/v2/log_entry.rb +0 -44
- data/lib/google/logging/v2/logging.rb +0 -56
- data/lib/google/logging/v2/logging_config.rb +0 -59
- data/lib/google/logging/v2/logging_config_services.rb +0 -32
- data/lib/google/logging/v2/logging_metrics.rb +0 -51
- data/lib/google/logging/v2/logging_metrics_services.rb +0 -32
- data/lib/google/logging/v2/logging_services.rb +0 -31
- data/lib/google/longrunning/operations.rb +0 -50
- data/lib/google/longrunning/operations_services.rb +0 -29
- data/lib/google/protobuf/descriptor.rb +0 -0
- data/lib/google/pubsub/v1/pubsub.rb +0 -129
- data/lib/google/pubsub/v1/pubsub_services.rb +0 -56
- data/lib/google/pubsub/v1beta2/pubsub.rb +0 -126
- data/lib/google/pubsub/v1beta2/pubsub_services.rb +0 -56
- data/lib/google/rpc/code.rb +0 -32
- data/lib/google/rpc/error_details.rb +0 -61
- data/lib/google/rpc/status.rb +0 -19
- data/lib/google/type/color.rb +0 -20
- data/lib/google/type/date.rb +0 -18
- data/lib/google/type/dayofweek.rb +0 -23
- data/lib/google/type/latlng.rb +0 -17
- data/lib/google/type/money.rb +0 -18
- data/lib/google/type/timeofday.rb +0 -19
@@ -1,180 +0,0 @@
|
|
1
|
-
# Copyright 2015 Google Inc. All rights reserved.
|
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
|
-
# http://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
|
-
|
16
|
-
require "delegate"
|
17
|
-
|
18
|
-
module Gcloud
|
19
|
-
module Bigquery
|
20
|
-
class Table
|
21
|
-
##
|
22
|
-
# Table::List is a special case Array with additional values.
|
23
|
-
class List < DelegateClass(::Array)
|
24
|
-
##
|
25
|
-
# If not empty, indicates that there are more records that match
|
26
|
-
# the request and this value should be passed to continue.
|
27
|
-
attr_accessor :token
|
28
|
-
|
29
|
-
# A hash of this page of results.
|
30
|
-
attr_accessor :etag
|
31
|
-
|
32
|
-
# Total number of tables in this collection.
|
33
|
-
attr_accessor :total
|
34
|
-
|
35
|
-
##
|
36
|
-
# @private Create a new Table::List with an array of tables.
|
37
|
-
def initialize arr = []
|
38
|
-
super arr
|
39
|
-
end
|
40
|
-
|
41
|
-
##
|
42
|
-
# Whether there is a next page of tables.
|
43
|
-
#
|
44
|
-
# @return [Boolean]
|
45
|
-
#
|
46
|
-
# @example
|
47
|
-
# require "gcloud"
|
48
|
-
#
|
49
|
-
# gcloud = Gcloud.new
|
50
|
-
# bigquery = gcloud.bigquery
|
51
|
-
# dataset = bigquery.dataset "my_dataset"
|
52
|
-
#
|
53
|
-
# tables = dataset.tables
|
54
|
-
# if tables.next?
|
55
|
-
# next_tables = tables.next
|
56
|
-
# end
|
57
|
-
#
|
58
|
-
def next?
|
59
|
-
!token.nil?
|
60
|
-
end
|
61
|
-
|
62
|
-
##
|
63
|
-
# Retrieve the next page of tables.
|
64
|
-
#
|
65
|
-
# @return [Table::List]
|
66
|
-
#
|
67
|
-
# @example
|
68
|
-
# require "gcloud"
|
69
|
-
#
|
70
|
-
# gcloud = Gcloud.new
|
71
|
-
# bigquery = gcloud.bigquery
|
72
|
-
# dataset = bigquery.dataset "my_dataset"
|
73
|
-
#
|
74
|
-
# tables = dataset.tables
|
75
|
-
# if tables.next?
|
76
|
-
# next_tables = tables.next
|
77
|
-
# end
|
78
|
-
#
|
79
|
-
def next
|
80
|
-
return nil unless next?
|
81
|
-
ensure_service!
|
82
|
-
options = { token: token, max: @max }
|
83
|
-
gapi = @service.list_tables @dataset_id, options
|
84
|
-
self.class.from_gapi gapi, @service, @dataset_id, @max
|
85
|
-
end
|
86
|
-
|
87
|
-
##
|
88
|
-
# Retrieves all tables by repeatedly loading {#next} until {#next?}
|
89
|
-
# returns `false`. Calls the given block once for each table, which is
|
90
|
-
# passed as the parameter.
|
91
|
-
#
|
92
|
-
# An Enumerator is returned if no block is given.
|
93
|
-
#
|
94
|
-
# This method may make several API calls until all tables are retrieved.
|
95
|
-
# Be sure to use as narrow a search criteria as possible. Please use
|
96
|
-
# with caution.
|
97
|
-
#
|
98
|
-
# @param [Integer] request_limit The upper limit of API requests to make
|
99
|
-
# to load all tables. Default is no limit.
|
100
|
-
# @yield [table] The block for accessing each table.
|
101
|
-
# @yieldparam [Table] table The table object.
|
102
|
-
#
|
103
|
-
# @return [Enumerator]
|
104
|
-
#
|
105
|
-
# @example Iterating each result by passing a block:
|
106
|
-
# require "gcloud"
|
107
|
-
#
|
108
|
-
# gcloud = Gcloud.new
|
109
|
-
# bigquery = gcloud.bigquery
|
110
|
-
# dataset = bigquery.dataset "my_dataset"
|
111
|
-
#
|
112
|
-
# dataset.tables.all do |table|
|
113
|
-
# puts table.name
|
114
|
-
# end
|
115
|
-
#
|
116
|
-
# @example Using the enumerator by not passing a block:
|
117
|
-
# require "gcloud"
|
118
|
-
#
|
119
|
-
# gcloud = Gcloud.new
|
120
|
-
# bigquery = gcloud.bigquery
|
121
|
-
# dataset = bigquery.dataset "my_dataset"
|
122
|
-
#
|
123
|
-
# all_names = dataset.tables.all.map do |table|
|
124
|
-
# table.name
|
125
|
-
# end
|
126
|
-
#
|
127
|
-
# @example Limit the number of API requests made:
|
128
|
-
# require "gcloud"
|
129
|
-
#
|
130
|
-
# gcloud = Gcloud.new
|
131
|
-
# bigquery = gcloud.bigquery
|
132
|
-
# dataset = bigquery.dataset "my_dataset"
|
133
|
-
#
|
134
|
-
# dataset.tables.all(request_limit: 10) do |table|
|
135
|
-
# puts table.name
|
136
|
-
# end
|
137
|
-
#
|
138
|
-
def all request_limit: nil
|
139
|
-
request_limit = request_limit.to_i if request_limit
|
140
|
-
unless block_given?
|
141
|
-
return enum_for(:all, request_limit: request_limit)
|
142
|
-
end
|
143
|
-
results = self
|
144
|
-
loop do
|
145
|
-
results.each { |r| yield r }
|
146
|
-
if request_limit
|
147
|
-
request_limit -= 1
|
148
|
-
break if request_limit < 0
|
149
|
-
end
|
150
|
-
break unless results.next?
|
151
|
-
results = results.next
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
##
|
156
|
-
# @private New Table::List from a response object.
|
157
|
-
def self.from_gapi gapi_list, service, dataset_id = nil, max = nil
|
158
|
-
tables = List.new(Array(gapi_list.tables).map do |gapi_object|
|
159
|
-
Table.from_gapi gapi_object, service
|
160
|
-
end)
|
161
|
-
tables.instance_variable_set :@token, gapi_list.next_page_token
|
162
|
-
tables.instance_variable_set :@etag, gapi_list.etag
|
163
|
-
tables.instance_variable_set :@total, gapi_list.total_items
|
164
|
-
tables.instance_variable_set :@service, service
|
165
|
-
tables.instance_variable_set :@dataset_id, dataset_id
|
166
|
-
tables.instance_variable_set :@max, max
|
167
|
-
tables
|
168
|
-
end
|
169
|
-
|
170
|
-
protected
|
171
|
-
|
172
|
-
##
|
173
|
-
# Raise an error unless an active service is available.
|
174
|
-
def ensure_service!
|
175
|
-
fail "Must have active connection" unless @service
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
data/lib/gcloud/bigquery/view.rb
DELETED
@@ -1,475 +0,0 @@
|
|
1
|
-
# Copyright 2015 Google Inc. All rights reserved.
|
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
|
-
# http://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
|
-
|
16
|
-
require "gcloud/errors"
|
17
|
-
require "gcloud/bigquery/service"
|
18
|
-
require "gcloud/bigquery/data"
|
19
|
-
require "gcloud/bigquery/table/list"
|
20
|
-
require "google/apis/bigquery_v2"
|
21
|
-
|
22
|
-
module Gcloud
|
23
|
-
module Bigquery
|
24
|
-
##
|
25
|
-
# # View
|
26
|
-
#
|
27
|
-
# A view is a virtual table defined by a SQL query. You can query views in
|
28
|
-
# the browser tool, or by using a query job.
|
29
|
-
#
|
30
|
-
# BigQuery's views are logical views, not materialized views, which means
|
31
|
-
# that the query that defines the view is re-executed every time the view is
|
32
|
-
# queried. Queries are billed according to the total amount of data in all
|
33
|
-
# table fields referenced directly or indirectly by the top-level query.
|
34
|
-
#
|
35
|
-
# @example
|
36
|
-
# require "gcloud"
|
37
|
-
#
|
38
|
-
# gcloud = Gcloud.new
|
39
|
-
# bigquery = gcloud.bigquery
|
40
|
-
# dataset = bigquery.dataset "my_dataset"
|
41
|
-
# view = dataset.create_view "my_view",
|
42
|
-
# "SELECT name, age FROM [proj:dataset.users]"
|
43
|
-
#
|
44
|
-
class View
|
45
|
-
##
|
46
|
-
# @private The Service object.
|
47
|
-
attr_accessor :service
|
48
|
-
|
49
|
-
##
|
50
|
-
# @private The Google API Client object.
|
51
|
-
attr_accessor :gapi
|
52
|
-
|
53
|
-
##
|
54
|
-
# @private Create an empty Table object.
|
55
|
-
def initialize
|
56
|
-
@service = nil
|
57
|
-
@gapi = Google::Apis::BigqueryV2::Table.new
|
58
|
-
end
|
59
|
-
|
60
|
-
##
|
61
|
-
# A unique ID for this table.
|
62
|
-
# The ID must contain only letters (a-z, A-Z), numbers (0-9),
|
63
|
-
# or underscores (_). The maximum length is 1,024 characters.
|
64
|
-
#
|
65
|
-
# @!group Attributes
|
66
|
-
#
|
67
|
-
def table_id
|
68
|
-
@gapi.table_reference.table_id
|
69
|
-
end
|
70
|
-
|
71
|
-
##
|
72
|
-
# The ID of the `Dataset` containing this table.
|
73
|
-
#
|
74
|
-
# @!group Attributes
|
75
|
-
#
|
76
|
-
def dataset_id
|
77
|
-
@gapi.table_reference.dataset_id
|
78
|
-
end
|
79
|
-
|
80
|
-
##
|
81
|
-
# The ID of the `Project` containing this table.
|
82
|
-
#
|
83
|
-
# @!group Attributes
|
84
|
-
#
|
85
|
-
def project_id
|
86
|
-
@gapi.table_reference.project_id
|
87
|
-
end
|
88
|
-
|
89
|
-
##
|
90
|
-
# @private
|
91
|
-
# The gapi fragment containing the Project ID, Dataset ID, and Table ID as
|
92
|
-
# a camel-cased hash.
|
93
|
-
def table_ref
|
94
|
-
table_ref = @gapi.table_reference
|
95
|
-
table_ref = table_ref.to_hash if table_ref.respond_to? :to_hash
|
96
|
-
table_ref
|
97
|
-
end
|
98
|
-
|
99
|
-
##
|
100
|
-
# The combined Project ID, Dataset ID, and Table ID for this table, in the
|
101
|
-
# format specified by the [Query
|
102
|
-
# Reference](https://cloud.google.com/bigquery/query-reference#from):
|
103
|
-
# `project_name:datasetId.tableId`. To use this value in queries see
|
104
|
-
# {#query_id}.
|
105
|
-
#
|
106
|
-
# @!group Attributes
|
107
|
-
#
|
108
|
-
def id
|
109
|
-
@gapi.id
|
110
|
-
end
|
111
|
-
|
112
|
-
##
|
113
|
-
# The value returned by {#id}, wrapped in square brackets if the Project
|
114
|
-
# ID contains dashes, as specified by the [Query
|
115
|
-
# Reference](https://cloud.google.com/bigquery/query-reference#from).
|
116
|
-
# Useful in queries.
|
117
|
-
#
|
118
|
-
# @example
|
119
|
-
# require "gcloud"
|
120
|
-
#
|
121
|
-
# gcloud = Gcloud.new
|
122
|
-
# bigquery = gcloud.bigquery
|
123
|
-
# dataset = bigquery.dataset "my_dataset"
|
124
|
-
# table = dataset.table "my_table"
|
125
|
-
#
|
126
|
-
# data = bigquery.query "SELECT name FROM #{table.query_id}"
|
127
|
-
#
|
128
|
-
# @!group Attributes
|
129
|
-
#
|
130
|
-
def query_id
|
131
|
-
project_id["-"] ? "[#{id}]" : id
|
132
|
-
end
|
133
|
-
|
134
|
-
##
|
135
|
-
# The name of the table.
|
136
|
-
#
|
137
|
-
# @!group Attributes
|
138
|
-
#
|
139
|
-
def name
|
140
|
-
@gapi.friendly_name
|
141
|
-
end
|
142
|
-
|
143
|
-
##
|
144
|
-
# Updates the name of the table.
|
145
|
-
#
|
146
|
-
# @!group Attributes
|
147
|
-
#
|
148
|
-
def name= new_name
|
149
|
-
@gapi.update! friendly_name: new_name
|
150
|
-
patch_gapi! :friendly_name
|
151
|
-
end
|
152
|
-
|
153
|
-
##
|
154
|
-
# A string hash of the dataset.
|
155
|
-
#
|
156
|
-
# @!group Attributes
|
157
|
-
#
|
158
|
-
def etag
|
159
|
-
ensure_full_data!
|
160
|
-
@gapi.etag
|
161
|
-
end
|
162
|
-
|
163
|
-
##
|
164
|
-
# A URL that can be used to access the dataset using the REST API.
|
165
|
-
#
|
166
|
-
# @!group Attributes
|
167
|
-
#
|
168
|
-
def api_url
|
169
|
-
ensure_full_data!
|
170
|
-
@gapi.self_link
|
171
|
-
end
|
172
|
-
|
173
|
-
##
|
174
|
-
# The description of the table.
|
175
|
-
#
|
176
|
-
# @!group Attributes
|
177
|
-
#
|
178
|
-
def description
|
179
|
-
ensure_full_data!
|
180
|
-
@gapi.description
|
181
|
-
end
|
182
|
-
|
183
|
-
##
|
184
|
-
# Updates the description of the table.
|
185
|
-
#
|
186
|
-
# @!group Attributes
|
187
|
-
#
|
188
|
-
def description= new_description
|
189
|
-
@gapi.update! description: new_description
|
190
|
-
patch_gapi! :description
|
191
|
-
end
|
192
|
-
|
193
|
-
##
|
194
|
-
# The time when this table was created.
|
195
|
-
#
|
196
|
-
# @!group Attributes
|
197
|
-
#
|
198
|
-
def created_at
|
199
|
-
ensure_full_data!
|
200
|
-
begin
|
201
|
-
Time.at(Integer(@gapi.creation_time) / 1000.0)
|
202
|
-
rescue
|
203
|
-
nil
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
##
|
208
|
-
# The time when this table expires.
|
209
|
-
# If not present, the table will persist indefinitely.
|
210
|
-
# Expired tables will be deleted and their storage reclaimed.
|
211
|
-
#
|
212
|
-
# @!group Attributes
|
213
|
-
#
|
214
|
-
def expires_at
|
215
|
-
ensure_full_data!
|
216
|
-
begin
|
217
|
-
Time.at(Integer(@gapi.expiration_time) / 1000.0)
|
218
|
-
rescue
|
219
|
-
nil
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
##
|
224
|
-
# The date when this table was last modified.
|
225
|
-
#
|
226
|
-
# @!group Attributes
|
227
|
-
#
|
228
|
-
def modified_at
|
229
|
-
ensure_full_data!
|
230
|
-
begin
|
231
|
-
Time.at(Integer(@gapi.last_modified_time) / 1000.0)
|
232
|
-
rescue
|
233
|
-
nil
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
##
|
238
|
-
# Checks if the table's type is "TABLE".
|
239
|
-
#
|
240
|
-
# @!group Attributes
|
241
|
-
#
|
242
|
-
def table?
|
243
|
-
@gapi.type == "TABLE"
|
244
|
-
end
|
245
|
-
|
246
|
-
##
|
247
|
-
# Checks if the table's type is "VIEW".
|
248
|
-
#
|
249
|
-
# @!group Attributes
|
250
|
-
#
|
251
|
-
def view?
|
252
|
-
@gapi.type == "VIEW"
|
253
|
-
end
|
254
|
-
|
255
|
-
##
|
256
|
-
# The geographic location where the table should reside. Possible
|
257
|
-
# values include EU and US. The default value is US.
|
258
|
-
#
|
259
|
-
# @!group Attributes
|
260
|
-
#
|
261
|
-
def location
|
262
|
-
ensure_full_data!
|
263
|
-
@gapi.location
|
264
|
-
end
|
265
|
-
|
266
|
-
##
|
267
|
-
# The schema of the view.
|
268
|
-
#
|
269
|
-
# @!group Attributes
|
270
|
-
#
|
271
|
-
def schema
|
272
|
-
ensure_full_data!
|
273
|
-
Schema.from_gapi(@gapi.schema).freeze
|
274
|
-
end
|
275
|
-
|
276
|
-
##
|
277
|
-
# The fields of the view.
|
278
|
-
#
|
279
|
-
# @!group Attributes
|
280
|
-
#
|
281
|
-
def fields
|
282
|
-
schema.fields
|
283
|
-
end
|
284
|
-
|
285
|
-
##
|
286
|
-
# The names of the columns in the view.
|
287
|
-
#
|
288
|
-
# @!group Attributes
|
289
|
-
#
|
290
|
-
def headers
|
291
|
-
fields.map(&:name)
|
292
|
-
end
|
293
|
-
|
294
|
-
##
|
295
|
-
# The query that executes each time the view is loaded.
|
296
|
-
#
|
297
|
-
# @!group Attributes
|
298
|
-
#
|
299
|
-
def query
|
300
|
-
@gapi.view.query if @gapi.view
|
301
|
-
end
|
302
|
-
|
303
|
-
##
|
304
|
-
# Updates the query that executes each time the view is loaded.
|
305
|
-
#
|
306
|
-
# @see https://cloud.google.com/bigquery/query-reference BigQuery Query
|
307
|
-
# Reference
|
308
|
-
#
|
309
|
-
# @param [String] new_query The query that defines the view.
|
310
|
-
#
|
311
|
-
# @example
|
312
|
-
# require "gcloud"
|
313
|
-
#
|
314
|
-
# gcloud = Gcloud.new
|
315
|
-
# bigquery = gcloud.bigquery
|
316
|
-
# dataset = bigquery.dataset "my_dataset"
|
317
|
-
# view = dataset.table "my_view"
|
318
|
-
#
|
319
|
-
# view.query = "SELECT first_name FROM [my_project:my_dataset.my_table]"
|
320
|
-
#
|
321
|
-
# @!group Lifecycle
|
322
|
-
#
|
323
|
-
def query= new_query
|
324
|
-
@gapi.view ||= Google::Apis::BigqueryV2::ViewDefinition.new
|
325
|
-
@gapi.view.update! query: new_query
|
326
|
-
patch_view_gapi! :query
|
327
|
-
end
|
328
|
-
|
329
|
-
##
|
330
|
-
# Runs a query to retrieve all data from the view.
|
331
|
-
#
|
332
|
-
# @param [Integer] max The maximum number of rows of data to return per
|
333
|
-
# page of results. Setting this flag to a small value such as 1000 and
|
334
|
-
# then paging through results might improve reliability when the query
|
335
|
-
# result set is large. In addition to this limit, responses are also
|
336
|
-
# limited to 10 MB. By default, there is no maximum row count, and only
|
337
|
-
# the byte limit applies.
|
338
|
-
# @param [Integer] timeout How long to wait for the query to complete, in
|
339
|
-
# milliseconds, before the request times out and returns. Note that this
|
340
|
-
# is only a timeout for the request, not the query. If the query takes
|
341
|
-
# longer to run than the timeout value, the call returns without any
|
342
|
-
# results and with QueryData#complete? set to false. The default value
|
343
|
-
# is 10000 milliseconds (10 seconds).
|
344
|
-
# @param [Boolean] cache Whether to look for the result in the query
|
345
|
-
# cache. The query cache is a best-effort cache that will be flushed
|
346
|
-
# whenever tables in the query are modified. The default value is true.
|
347
|
-
# For more information, see [query
|
348
|
-
# caching](https://developers.google.com/bigquery/querying-data).
|
349
|
-
# @param [Boolean] dryrun If set to `true`, BigQuery doesn't run the job.
|
350
|
-
# Instead, if the query is valid, BigQuery returns statistics about the
|
351
|
-
# job such as how many bytes would be processed. If the query is
|
352
|
-
# invalid, an error returns. The default value is `false`.
|
353
|
-
#
|
354
|
-
# @return [Gcloud::Bigquery::QueryData]
|
355
|
-
#
|
356
|
-
# @example
|
357
|
-
# require "gcloud"
|
358
|
-
#
|
359
|
-
# gcloud = Gcloud.new
|
360
|
-
# bigquery = gcloud.bigquery
|
361
|
-
# dataset = bigquery.dataset "my_dataset"
|
362
|
-
# view = dataset.table "my_view"
|
363
|
-
#
|
364
|
-
# data = view.data
|
365
|
-
# data.each do |row|
|
366
|
-
# puts row["first_name"]
|
367
|
-
# end
|
368
|
-
# more_data = data.next if data.next?
|
369
|
-
#
|
370
|
-
# @!group Data
|
371
|
-
#
|
372
|
-
def data max: nil, timeout: 10000, cache: true, dryrun: nil
|
373
|
-
sql = "SELECT * FROM #{query_id}"
|
374
|
-
ensure_service!
|
375
|
-
options = { max: max, timeout: timeout, cache: cache, dryrun: dryrun }
|
376
|
-
gapi = service.query sql, options
|
377
|
-
QueryData.from_gapi gapi, service
|
378
|
-
end
|
379
|
-
|
380
|
-
##
|
381
|
-
# Permanently deletes the table.
|
382
|
-
#
|
383
|
-
# @return [Boolean] Returns `true` if the table was deleted.
|
384
|
-
#
|
385
|
-
# @example
|
386
|
-
# require "gcloud"
|
387
|
-
#
|
388
|
-
# gcloud = Gcloud.new
|
389
|
-
# bigquery = gcloud.bigquery
|
390
|
-
# dataset = bigquery.dataset "my_dataset"
|
391
|
-
# table = dataset.table "my_table"
|
392
|
-
#
|
393
|
-
# table.delete
|
394
|
-
#
|
395
|
-
# @!group Lifecycle
|
396
|
-
#
|
397
|
-
def delete
|
398
|
-
ensure_service!
|
399
|
-
service.delete_table dataset_id, table_id
|
400
|
-
true
|
401
|
-
end
|
402
|
-
|
403
|
-
##
|
404
|
-
# Reloads the table with current data from the BigQuery service.
|
405
|
-
#
|
406
|
-
# @!group Lifecycle
|
407
|
-
#
|
408
|
-
def reload!
|
409
|
-
ensure_service!
|
410
|
-
gapi = service.get_table dataset_id, table_id
|
411
|
-
@gapi = gapi
|
412
|
-
end
|
413
|
-
alias_method :refresh!, :reload!
|
414
|
-
|
415
|
-
##
|
416
|
-
# @private New Table from a Google API Client object.
|
417
|
-
def self.from_gapi gapi, conn
|
418
|
-
new.tap do |f|
|
419
|
-
f.gapi = gapi
|
420
|
-
f.service = conn
|
421
|
-
end
|
422
|
-
end
|
423
|
-
|
424
|
-
protected
|
425
|
-
|
426
|
-
##
|
427
|
-
# Raise an error unless an active service is available.
|
428
|
-
def ensure_service!
|
429
|
-
fail "Must have active connection" unless service
|
430
|
-
end
|
431
|
-
|
432
|
-
def patch_gapi! *attributes
|
433
|
-
return if attributes.empty?
|
434
|
-
patch_args = Hash[attributes.map do |attr|
|
435
|
-
[attr, @gapi.send(attr)]
|
436
|
-
end]
|
437
|
-
patch_table_gapi patch_args
|
438
|
-
end
|
439
|
-
|
440
|
-
def patch_view_gapi! *attributes
|
441
|
-
return if attributes.empty?
|
442
|
-
patch_args = Hash[attributes.map do |attr|
|
443
|
-
[attr, @gapi.view.send(attr)]
|
444
|
-
end]
|
445
|
-
patch_view_args = Google::Apis::BigqueryV2::ViewDefinition.new(
|
446
|
-
patch_args
|
447
|
-
)
|
448
|
-
patch_table_gapi view: patch_view_args
|
449
|
-
end
|
450
|
-
|
451
|
-
def patch_table_gapi patch_args
|
452
|
-
ensure_service!
|
453
|
-
patch_gapi = Google::Apis::BigqueryV2::Table.new patch_args
|
454
|
-
@gapi = service.patch_table dataset_id, table_id, patch_gapi
|
455
|
-
end
|
456
|
-
|
457
|
-
##
|
458
|
-
# Load the complete representation of the table if it has been
|
459
|
-
# only partially loaded by a request to the API list method.
|
460
|
-
def ensure_full_data!
|
461
|
-
reload_gapi! unless data_complete?
|
462
|
-
end
|
463
|
-
|
464
|
-
def reload_gapi!
|
465
|
-
ensure_service!
|
466
|
-
gapi = service.get_table dataset_id, table_id
|
467
|
-
@gapi = gapi
|
468
|
-
end
|
469
|
-
|
470
|
-
def data_complete?
|
471
|
-
@gapi.is_a? Google::Apis::BigqueryV2::Table
|
472
|
-
end
|
473
|
-
end
|
474
|
-
end
|
475
|
-
end
|