google-cloud-bigquery 1.14.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/AUTHENTICATION.md +17 -54
- data/CHANGELOG.md +377 -0
- data/CONTRIBUTING.md +328 -116
- data/LOGGING.md +1 -1
- data/OVERVIEW.md +21 -20
- data/TROUBLESHOOTING.md +2 -8
- data/lib/google/cloud/bigquery/argument.rb +197 -0
- data/lib/google/cloud/bigquery/convert.rb +155 -173
- data/lib/google/cloud/bigquery/copy_job.rb +74 -26
- data/lib/google/cloud/bigquery/credentials.rb +5 -12
- data/lib/google/cloud/bigquery/data.rb +109 -18
- data/lib/google/cloud/bigquery/dataset/access.rb +474 -52
- data/lib/google/cloud/bigquery/dataset/list.rb +7 -13
- data/lib/google/cloud/bigquery/dataset/tag.rb +67 -0
- data/lib/google/cloud/bigquery/dataset.rb +1044 -287
- data/lib/google/cloud/bigquery/external/avro_source.rb +107 -0
- data/lib/google/cloud/bigquery/external/bigtable_source/column.rb +404 -0
- data/lib/google/cloud/bigquery/external/bigtable_source/column_family.rb +945 -0
- data/lib/google/cloud/bigquery/external/bigtable_source.rb +230 -0
- data/lib/google/cloud/bigquery/external/csv_source.rb +481 -0
- data/lib/google/cloud/bigquery/external/data_source.rb +771 -0
- data/lib/google/cloud/bigquery/external/json_source.rb +170 -0
- data/lib/google/cloud/bigquery/external/parquet_source.rb +148 -0
- data/lib/google/cloud/bigquery/external/sheets_source.rb +166 -0
- data/lib/google/cloud/bigquery/external.rb +50 -2256
- data/lib/google/cloud/bigquery/extract_job.rb +226 -61
- data/lib/google/cloud/bigquery/insert_response.rb +1 -3
- data/lib/google/cloud/bigquery/job/list.rb +10 -14
- data/lib/google/cloud/bigquery/job.rb +289 -14
- data/lib/google/cloud/bigquery/load_job.rb +810 -136
- data/lib/google/cloud/bigquery/model/list.rb +5 -9
- data/lib/google/cloud/bigquery/model.rb +247 -16
- data/lib/google/cloud/bigquery/policy.rb +432 -0
- data/lib/google/cloud/bigquery/project/list.rb +6 -11
- data/lib/google/cloud/bigquery/project.rb +509 -250
- data/lib/google/cloud/bigquery/query_job.rb +594 -128
- data/lib/google/cloud/bigquery/routine/list.rb +165 -0
- data/lib/google/cloud/bigquery/routine.rb +1227 -0
- data/lib/google/cloud/bigquery/schema/field.rb +413 -63
- data/lib/google/cloud/bigquery/schema.rb +221 -48
- data/lib/google/cloud/bigquery/service.rb +204 -112
- data/lib/google/cloud/bigquery/standard_sql.rb +269 -53
- data/lib/google/cloud/bigquery/table/async_inserter.rb +86 -43
- data/lib/google/cloud/bigquery/table/list.rb +6 -11
- data/lib/google/cloud/bigquery/table.rb +1470 -377
- data/lib/google/cloud/bigquery/time.rb +6 -0
- data/lib/google/cloud/bigquery/version.rb +1 -1
- data/lib/google/cloud/bigquery.rb +4 -6
- data/lib/google-cloud-bigquery.rb +14 -13
- metadata +66 -38
@@ -0,0 +1,165 @@
|
|
1
|
+
# Copyright 2020 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
|
+
|
16
|
+
require "delegate"
|
17
|
+
|
18
|
+
module Google
|
19
|
+
module Cloud
|
20
|
+
module Bigquery
|
21
|
+
class Routine
|
22
|
+
##
|
23
|
+
# Routine::List is a special case Array with additional values.
|
24
|
+
class List < DelegateClass(::Array)
|
25
|
+
##
|
26
|
+
# If not empty, indicates that there are more records that match
|
27
|
+
# the request and this value should be passed to continue.
|
28
|
+
attr_accessor :token
|
29
|
+
|
30
|
+
##
|
31
|
+
# @private Create a new Routine::List with an array of routines.
|
32
|
+
def initialize arr = []
|
33
|
+
super arr
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# Whether there is a next page of routines.
|
38
|
+
#
|
39
|
+
# @return [Boolean]
|
40
|
+
#
|
41
|
+
# @example
|
42
|
+
# require "google/cloud/bigquery"
|
43
|
+
#
|
44
|
+
# bigquery = Google::Cloud::Bigquery.new
|
45
|
+
# dataset = bigquery.dataset "my_dataset"
|
46
|
+
#
|
47
|
+
# routines = dataset.routines
|
48
|
+
# if routines.next?
|
49
|
+
# next_routines = routines.next
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
def next?
|
53
|
+
!token.nil?
|
54
|
+
end
|
55
|
+
|
56
|
+
##
|
57
|
+
# Retrieve the next page of routines.
|
58
|
+
#
|
59
|
+
# @return [Routine::List]
|
60
|
+
#
|
61
|
+
# @example
|
62
|
+
# require "google/cloud/bigquery"
|
63
|
+
#
|
64
|
+
# bigquery = Google::Cloud::Bigquery.new
|
65
|
+
# dataset = bigquery.dataset "my_dataset"
|
66
|
+
#
|
67
|
+
# routines = dataset.routines
|
68
|
+
# if routines.next?
|
69
|
+
# next_routines = routines.next
|
70
|
+
# end
|
71
|
+
#
|
72
|
+
def next
|
73
|
+
return nil unless next?
|
74
|
+
ensure_service!
|
75
|
+
gapi = @service.list_routines @dataset_id, token: token, max: @max, filter: @filter
|
76
|
+
self.class.from_gapi gapi, @service, @dataset_id, @max, filter: @filter
|
77
|
+
end
|
78
|
+
|
79
|
+
##
|
80
|
+
# Retrieves remaining results by repeatedly invoking {#next} until
|
81
|
+
# {#next?} returns `false`. Calls the given block once for each
|
82
|
+
# result, which is passed as the argument to the block.
|
83
|
+
#
|
84
|
+
# An Enumerator is returned if no block is given.
|
85
|
+
#
|
86
|
+
# This method will make repeated API calls until all remaining results
|
87
|
+
# are retrieved. (Unlike `#each`, for example, which merely iterates
|
88
|
+
# over the results returned by a single API call.) Use with caution.
|
89
|
+
#
|
90
|
+
# @param [Integer] request_limit The upper limit of API requests to
|
91
|
+
# make to load all routines. Default is no limit.
|
92
|
+
# @yield [routine] The block for accessing each routine.
|
93
|
+
# @yieldparam [Routine] routine The routine object.
|
94
|
+
#
|
95
|
+
# @return [Enumerator]
|
96
|
+
#
|
97
|
+
# @example Iterating each result by passing a block:
|
98
|
+
# require "google/cloud/bigquery"
|
99
|
+
#
|
100
|
+
# bigquery = Google::Cloud::Bigquery.new
|
101
|
+
# dataset = bigquery.dataset "my_dataset"
|
102
|
+
#
|
103
|
+
# dataset.routines.all do |routine|
|
104
|
+
# puts routine.routine_id
|
105
|
+
# end
|
106
|
+
#
|
107
|
+
# @example Using the enumerator by not passing a block:
|
108
|
+
# require "google/cloud/bigquery"
|
109
|
+
#
|
110
|
+
# bigquery = Google::Cloud::Bigquery.new
|
111
|
+
# dataset = bigquery.dataset "my_dataset"
|
112
|
+
#
|
113
|
+
# all_names = dataset.routines.all.map do |routine|
|
114
|
+
# routine.routine_id
|
115
|
+
# end
|
116
|
+
#
|
117
|
+
# @example Limit the number of API requests made:
|
118
|
+
# require "google/cloud/bigquery"
|
119
|
+
#
|
120
|
+
# bigquery = Google::Cloud::Bigquery.new
|
121
|
+
# dataset = bigquery.dataset "my_dataset"
|
122
|
+
#
|
123
|
+
# dataset.routines.all(request_limit: 10) do |routine|
|
124
|
+
# puts routine.routine_id
|
125
|
+
# end
|
126
|
+
#
|
127
|
+
def all request_limit: nil, &block
|
128
|
+
request_limit = request_limit.to_i if request_limit
|
129
|
+
return enum_for :all, request_limit: request_limit unless block_given?
|
130
|
+
results = self
|
131
|
+
loop do
|
132
|
+
results.each(&block)
|
133
|
+
if request_limit
|
134
|
+
request_limit -= 1
|
135
|
+
break if request_limit.negative?
|
136
|
+
end
|
137
|
+
break unless results.next?
|
138
|
+
results = results.next
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
##
|
143
|
+
# @private New Routine::List from a response object.
|
144
|
+
def self.from_gapi gapi_list, service, dataset_id = nil, max = nil, filter: nil
|
145
|
+
routines = List.new(Array(gapi_list.routines).map { |gapi| Routine.from_gapi gapi, service })
|
146
|
+
routines.instance_variable_set :@token, gapi_list.next_page_token
|
147
|
+
routines.instance_variable_set :@service, service
|
148
|
+
routines.instance_variable_set :@dataset_id, dataset_id
|
149
|
+
routines.instance_variable_set :@max, max
|
150
|
+
routines.instance_variable_set :@filter, filter
|
151
|
+
routines
|
152
|
+
end
|
153
|
+
|
154
|
+
protected
|
155
|
+
|
156
|
+
##
|
157
|
+
# Raise an error unless an active service is available.
|
158
|
+
def ensure_service!
|
159
|
+
raise "Must have active connection" unless @service
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|