google-cloud-bigquery 1.52.1 → 1.61.1

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: eebf05291009387d9603457ebcd1012db3b5090e229847394ac56dec3fdb478a
4
- data.tar.gz: 37e8964677c24c906bc766d2d94f6fffeee743990013c47d73faff07bb591c46
3
+ metadata.gz: 3b011fdd6daa487b99c4c1bf684f3952f9cd380743048c5a314241750a01fbf3
4
+ data.tar.gz: d7668277ad007c19d12b06c8cf6fd02695345dea12a1e6f9d3ac573bc5c70e45
5
5
  SHA512:
6
- metadata.gz: 6b7e701313f055af34b881cf8fbad6bb11cf86a5782a3e65d0849eaf8b596cd9ffe046de536f9b222fdfc1fb3024d8db398f860330e60372244b06e6c996c83e
7
- data.tar.gz: 118423b6a2db399957b190395e0ea1e44fb4474d1215cd126c2d564607ac7429a93a1a509d3682ba15b8027f0ee58f30fdddba253bb8fdbabc4ed999343444b4
6
+ metadata.gz: a85f76563d165c7fecb23040c2f46a55edb0a89bb0564520fe1d95ac2a5e34862f5375adbefabd1764cab3fb888dfe40574b7b92d7292a297db5647d7e9fb121
7
+ data.tar.gz: ac10adf9544cf44fa4f7dee744340db9976fc86e09c458eb209692561fc9fb05abd350ceb358bfae3bb3bb06b2f7bc5a1804a7ef8811eca16c7d9f92c3e6002d
data/AUTHENTICATION.md CHANGED
@@ -28,6 +28,12 @@ providing **Project ID** and **Service Account Credentials** directly in code.
28
28
 
29
29
  **Credentials** are discovered in the following order:
30
30
 
31
+ > [!WARNING]
32
+ > If you accept a credential configuration (JSON file or Hash) from an
33
+ > external source for authentication to Google Cloud, you must validate it before
34
+ > providing it to a Google API client library. Providing an unvalidated credential
35
+ > configuration to Google APIs can compromise the security of your systems and data.
36
+
31
37
  1. Specify credentials in method arguments
32
38
  2. Specify credentials in configuration
33
39
  3. Discover credentials path in environment variables
@@ -81,11 +87,16 @@ The **Project ID** and the path to the **Credentials JSON** file can be configur
81
87
  instead of placing them in environment variables or providing them as arguments.
82
88
 
83
89
  ```ruby
90
+ require "googleauth"
84
91
  require "google/cloud/bigquery"
85
92
 
93
+ credentials = ::Google::Auth::ServiceAccountCredentials.make_creds(
94
+ json_key_io: ::File.open("/path/to/keyfile.json")
95
+ )
96
+
86
97
  Google::Cloud::Bigquery.configure do |config|
87
98
  config.project_id = "my-project-id"
88
- config.credentials = "path/to/keyfile.json"
99
+ config.credentials = credentials
89
100
  end
90
101
 
91
102
  bigquery = Google::Cloud::Bigquery.new
data/CHANGELOG.md CHANGED
@@ -1,5 +1,74 @@
1
1
  # Release History
2
2
 
3
+ ### 1.61.1 (2025-11-21)
4
+
5
+ #### Bug Fixes
6
+
7
+ * Fix broken links
8
+ #### Documentation
9
+
10
+ * Clarify comments on job error status
11
+
12
+ ### 1.61.0 (2025-11-04)
13
+
14
+ #### Features
15
+
16
+ * Support fine grained ACLs ([#31772](https://github.com/googleapis/google-cloud-ruby/issues/31772))
17
+ #### Documentation
18
+
19
+ * add warning about loading unvalidated credentials ([#32121](https://github.com/googleapis/google-cloud-ruby/issues/32121))
20
+
21
+ ### 1.60.0 (2025-10-24)
22
+
23
+ #### Features
24
+
25
+ * Exposing reservation field in JobConfiguration ([#31777](https://github.com/googleapis/google-cloud-ruby/issues/31777))
26
+
27
+ ### 1.59.0 (2025-09-17)
28
+
29
+ #### Features
30
+
31
+ * Support collation feature ([#30919](https://github.com/googleapis/google-cloud-ruby/issues/30919))
32
+
33
+ ### 1.58.0 (2025-09-03)
34
+
35
+ #### Features
36
+
37
+ * Add support for remote function options ([#30822](https://github.com/googleapis/google-cloud-ruby/issues/30822))
38
+
39
+ ### 1.57.0 (2025-08-28)
40
+
41
+ #### Features
42
+
43
+ * Add support for reference_file_schema_uri for LoadJobConfig and ExternalDataSource ([#30859](https://github.com/googleapis/google-cloud-ruby/issues/30859))
44
+
45
+ ### 1.56.0 (2025-08-27)
46
+
47
+ #### Features
48
+
49
+ * Add support for preserve_ascii_control_characters in CSVOptions and LoadJobConfiguration ([#30857](https://github.com/googleapis/google-cloud-ruby/issues/30857))
50
+
51
+ ### 1.55.0 (2025-08-26)
52
+
53
+ #### Features
54
+
55
+ * Add support for IAM Condition in Dataset Access ([#30854](https://github.com/googleapis/google-cloud-ruby/issues/30854))
56
+
57
+ ### 1.54.0 (2025-08-15)
58
+
59
+ #### Features
60
+
61
+ * Add support for format_options_use_int64_timestamp ([#30755](https://github.com/googleapis/google-cloud-ruby/issues/30755))
62
+ * load job external table options ([#30743](https://github.com/googleapis/google-cloud-ruby/issues/30743))
63
+
64
+ ### 1.53.0 (2025-08-12)
65
+
66
+ #### Features
67
+
68
+ * add data governance type to routine ([#30732](https://github.com/googleapis/google-cloud-ruby/issues/30732))
69
+ * Add table resource tags support ([#30804](https://github.com/googleapis/google-cloud-ruby/issues/30804))
70
+ * Support for using Faraday for HTTP requests ([#30760](https://github.com/googleapis/google-cloud-ruby/issues/30760))
71
+
3
72
  ### 1.52.1 (2025-04-25)
4
73
 
5
74
  #### Documentation
data/OVERVIEW.md CHANGED
@@ -14,7 +14,7 @@ connecting in the {file:AUTHENTICATION.md Authentication Guide}.
14
14
 
15
15
  To help you get started quickly, the first few examples below use a public
16
16
  dataset provided by Google. As soon as you have [signed
17
- up](https://cloud.google.com/bigquery/sign-up) to use BigQuery, and provided
17
+ up](https://cloud.google.com/bigquery) to use BigQuery, and provided
18
18
  that you stay in the free tier for queries, you should be able to run these
19
19
  first examples without the need to set up billing or to load data (although
20
20
  we'll show you how to do that too.)
@@ -249,8 +249,8 @@ dataset = bigquery.create_dataset "my_dataset"
249
249
  Now that you have a dataset, you can use it to create a table. Every table is
250
250
  defined by a schema that may contain nested and repeated fields. The example
251
251
  below shows a schema with a repeated record field named `cities_lived`. (For
252
- more information about nested and repeated fields, see [Preparing Data for
253
- Loading](https://cloud.google.com/bigquery/preparing-data-for-loading).)
252
+ more information about nested and repeated fields, see
253
+ [Using Nested and Repeated Fields](https://docs.cloud.google.com/bigquery/docs/best-practices-performance-nested).)
254
254
 
255
255
  ```ruby
256
256
  require "google/cloud/bigquery"
@@ -455,7 +455,7 @@ bigquery = Google::Cloud::Bigquery.new retries: 10, timeout: 120
455
455
  ```
456
456
 
457
457
  See the [BigQuery error
458
- table](https://cloud.google.com/bigquery/troubleshooting-errors#errortable) for
458
+ table](https://docs.cloud.google.com/bigquery/docs/error-messages) for
459
459
  a list of error conditions.
460
460
 
461
461
  ## Additional information
@@ -0,0 +1,218 @@
1
+ # Copyright 2025 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
+ ##
21
+ # # Condition
22
+ #
23
+ # Represents a textual expression in the Common Expression Language (CEL) syntax.
24
+ # CEL is a C-like expression language. The syntax and semantics of CEL are documented
25
+ # at https://github.com/google/cel-spec
26
+ #
27
+ # Used to define condition for {Dataset::Access} rules
28
+ #
29
+ class Condition
30
+ ##
31
+ # Returns the textual representation of an expression in Common Expression Language syntax.
32
+ #
33
+ # @return [String] The expression of the condition.
34
+ #
35
+ # @example
36
+ # condition = Google::Cloud::Bigquery::Condition.new(
37
+ # "resource.name.startsWith('projects/my-project')"
38
+ # )
39
+ # puts condition.expression # => "resource.name.startsWith('projects/my-project')"
40
+ #
41
+ def expression
42
+ @expression
43
+ end
44
+
45
+ ##
46
+ # Sets the textual representation of an expression in Common Expression Language syntax.
47
+ #
48
+ # @param [String] val The expression to set.
49
+ #
50
+ # @raise [ArgumentError] if the expression is nil or empty.
51
+ #
52
+ # @example
53
+ # condition = Google::Cloud::Bigquery::Condition.new(
54
+ # "resource.name.startsWith('projects/my-project')"
55
+ # )
56
+ # condition.expression = "document.summary.size() < 100"
57
+ #
58
+ def expression= val
59
+ if val.nil? || val.strip.empty?
60
+ raise ArgumentError, "Expression cannot be nil or empty"
61
+ end
62
+ @expression = val
63
+ end
64
+
65
+ ##
66
+ # Returns the optional description of the expression. This is a longer text which describes
67
+ # the expression, e.g. when hovered over it in a UI.
68
+ #
69
+ # @return [String, nil] The description of the condition. nil if not set.
70
+ #
71
+ # @example
72
+ # condition = Google::Cloud::Bigquery::Condition.new(
73
+ # "document.summary.size() < 100",
74
+ # description: "Checks if summary is less than 100 chars"
75
+ # )
76
+ # puts condition.description # => "Checks if summary is less than 100 chars"
77
+ #
78
+ def description
79
+ @description
80
+ end
81
+
82
+ ##
83
+ # Sets the optional description of the expression. This is a longer text which describes
84
+ # the expression, e.g. when hovered over it in a UI.
85
+ #
86
+ # @param [String, nil] val The description to set. nil to unset.
87
+ #
88
+ # @example
89
+ # condition = Google::Cloud::Bigquery::Condition.new(
90
+ # "document.summary.size() < 100"
91
+ # )
92
+ # condition.description = "Checks if summary is less than 100 chars"
93
+ #
94
+ def description= val
95
+ @description = val
96
+ end
97
+
98
+ ##
99
+ # Returns the optional string indicating the location of the expression for error reporting,
100
+ # e.g. a file name and a position in the file.
101
+ #
102
+ # @return [String, nil] The location of the condition. nil if not set.
103
+ #
104
+ # @example
105
+ # condition = Google::Cloud::Bigquery::Condition.new(
106
+ # "document.summary.size() < 100",
107
+ # location: "document/summary"
108
+ # )
109
+ # puts condition.location # => "document/summary"
110
+ #
111
+ def location
112
+ @location
113
+ end
114
+
115
+ ##
116
+ # Sets the optional string indicating the location of the expression for error reporting,
117
+ # e.g. a file name and a position in the file.
118
+ #
119
+ # @param [String, nil] val The location to set. nil to unset.
120
+ #
121
+ # @example
122
+ # condition = Google::Cloud::Bigquery::Condition.new(
123
+ # "document.summary.size() < 100"
124
+ # )
125
+ # condition.location = "document/summary"
126
+ #
127
+ def location= val
128
+ @location = val
129
+ end
130
+
131
+ ##
132
+ # Returns the optional title for the expression, i.e. a short string describing its purpose.
133
+ # This can be used e.g. in UIs which allow to enter the expression.
134
+ #
135
+ # @return [String, nil] The title of the condition. nil if not set.
136
+ #
137
+ # @example
138
+ # condition = Google::Cloud::Bigquery::Condition.new(
139
+ # "document.summary.size() < 100",
140
+ # title: "Summary size limit"
141
+ # )
142
+ # puts condition.title # => "Summary size limit"
143
+ #
144
+ def title
145
+ @title
146
+ end
147
+
148
+ ##
149
+ # Sets the optional title for the expression, i.e. a short string describing its purpose.
150
+ # This can be used e.g. in UIs which allow to enter the expression.
151
+ #
152
+ # @param [String, nil] val The title to set. nil to unset.
153
+ #
154
+ # @example
155
+ # condition = Google::Cloud::Bigquery::Condition.new(
156
+ # "document.summary.size() < 100"
157
+ # )
158
+ # condition.title = "Summary size limit"
159
+ #
160
+ def title= val
161
+ @title = val
162
+ end
163
+
164
+ ##
165
+ # Create a new Condition object.
166
+ #
167
+ # @param [String] expression The expression in CEL syntax.
168
+ # @param [String] description Optional description of the expression.
169
+ # @param [String] location Optional location of the expression for error reporting.
170
+ # @param [String] title Optional title for the expression.
171
+ #
172
+ # @raise [ArgumentError] if expression is nil or empty.
173
+ #
174
+ # @example
175
+ # condition = Google::Cloud::Bigquery::Condition.new(
176
+ # "document.summary.size() < 100",
177
+ # description: "Determines if a summary is less than 100 chars",
178
+ # location: "document/summary",
179
+ # title: "Summary size limit"
180
+ # )
181
+ #
182
+ # @see https://cloud.google.com/bigquery/docs/reference/auditlogs/rest/Shared.Types/Expr
183
+ #
184
+ def initialize expression, description: nil, location: nil, title: nil
185
+ if expression.nil? || expression.strip.empty?
186
+ raise ArgumentError, "Expression cannot be nil or empty"
187
+ end
188
+ @expression = expression
189
+ @description = description
190
+ @location = location
191
+ @title = title
192
+ end
193
+
194
+ ##
195
+ # @private Convert the Condition object to a Google API Client object.
196
+ #
197
+ # @return [Google::Apis::BigqueryV2::Expr] The Google API Client object representing the condition.
198
+ #
199
+ # @example
200
+ # condition = Google::Cloud::Bigquery::Condition.new(
201
+ # "resource.name.startsWith('projects/my-project')"
202
+ # )
203
+ # gapi_condition = condition.to_gapi
204
+ #
205
+ # @see https://cloud.google.com/bigquery/docs/reference/auditlogs/rest/Shared.Types/Expr
206
+ #
207
+ def to_gapi
208
+ gapi = Google::Apis::BigqueryV2::Expr.new
209
+ gapi.description = @description unless @description.nil?
210
+ gapi.expression = @expression
211
+ gapi.location = @location unless @location.nil?
212
+ gapi.title = @title unless @title.nil?
213
+ gapi
214
+ end
215
+ end
216
+ end
217
+ end
218
+ end
@@ -60,6 +60,10 @@ module Google
60
60
  end
61
61
  end
62
62
 
63
+ def self.is_int? value
64
+ /\A\s*[-+]?\d+\s*\z/.match? value.to_s
65
+ end
66
+
63
67
  # rubocop:disable all
64
68
 
65
69
  def self.format_value value, field
@@ -96,7 +100,12 @@ module Google
96
100
  elsif field.type == "BYTES"
97
101
  StringIO.new Base64.decode64 value[:v]
98
102
  elsif field.type == "TIMESTAMP"
99
- ::Time.at Float(value[:v])
103
+ if is_int?(value[:v])
104
+ # Convert microseconds to seconds
105
+ ::Time.at Rational(Integer(value[:v]), 1_000_000)
106
+ else
107
+ ::Time.at Rational(value[:v])
108
+ end
100
109
  elsif field.type == "TIME"
101
110
  Bigquery::Time.new value[:v]
102
111
  elsif field.type == "DATETIME"
@@ -194,7 +194,8 @@ module Google
194
194
  job_reference: job_ref,
195
195
  configuration: Google::Apis::BigqueryV2::JobConfiguration.new(
196
196
  copy: copy_cfg,
197
- dry_run: options[:dryrun]
197
+ dry_run: options[:dryrun],
198
+ reservation: options[:reservation]
198
199
  )
199
200
  )
200
201
 
@@ -325,6 +326,18 @@ module Google
325
326
  @gapi.configuration.update! labels: value
326
327
  end
327
328
 
329
+ ##
330
+ # Sets the reservation that job would use. User can specify a reservation
331
+ # to execute the job. If reservation is not set, reservation is determined
332
+ # based on the rules defined by the reservation assignments. The expected
333
+ # format is `projects/`project`/locations/`location`/reservations/`reservation``.
334
+ # @param [String] value The reservation name.
335
+ #
336
+ # @!group Attributes
337
+ def reservation= value
338
+ @gapi.configuration.update! reservation: value
339
+ end
340
+
328
341
  def cancel
329
342
  raise "not implemented in #{self.class}"
330
343
  end
@@ -66,6 +66,10 @@ module Google
66
66
  # @private The query Job gapi object, or nil if from Table#data.
67
67
  attr_accessor :job_gapi
68
68
 
69
+ ##
70
+ # @private Whether to output timestamp as usec int64.
71
+ attr_accessor :format_options_use_int64_timestamp
72
+
69
73
  # @private
70
74
  def initialize arr = []
71
75
  @service = nil
@@ -473,8 +477,9 @@ module Google
473
477
  data_json = service.list_tabledata \
474
478
  @table_gapi.table_reference.dataset_id,
475
479
  @table_gapi.table_reference.table_id,
476
- token: token
477
- self.class.from_gapi_json data_json, @table_gapi, job_gapi, @service
480
+ token: token,
481
+ format_options_use_int64_timestamp: @format_options_use_int64_timestamp
482
+ self.class.from_gapi_json data_json, @table_gapi, job_gapi, @service, @format_options_use_int64_timestamp
478
483
  end
479
484
 
480
485
  ##
@@ -549,7 +554,7 @@ module Google
549
554
 
550
555
  ##
551
556
  # @private New Data from a response object.
552
- def self.from_gapi_json gapi_json, table_gapi, job_gapi, service
557
+ def self.from_gapi_json gapi_json, table_gapi, job_gapi, service, format_options_use_int64_timestamp
553
558
  rows = gapi_json[:rows] || []
554
559
  rows = Convert.format_rows rows, table_gapi.schema.fields unless rows.empty?
555
560
 
@@ -558,6 +563,7 @@ module Google
558
563
  data.gapi_json = gapi_json
559
564
  data.job_gapi = job_gapi
560
565
  data.service = service
566
+ data.format_options_use_int64_timestamp = format_options_use_int64_timestamp
561
567
  data
562
568
  end
563
569