google-cloud-bigquery 1.4.0 → 1.5.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 +4 -4
- data/README.md +18 -0
- data/lib/google/cloud/bigquery.rb +30 -1
- data/lib/google/cloud/bigquery/convert.rb +14 -1
- data/lib/google/cloud/bigquery/dataset.rb +4 -2
- data/lib/google/cloud/bigquery/project.rb +4 -2
- data/lib/google/cloud/bigquery/schema.rb +157 -0
- data/lib/google/cloud/bigquery/schema/field.rb +53 -10
- data/lib/google/cloud/bigquery/table.rb +33 -0
- data/lib/google/cloud/bigquery/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af9dff48b04ef98b37b45d821fe7ea4689466762b0bd444428d4247c17265395
|
4
|
+
data.tar.gz: 284d6bf810306ef9afa8f1f369582dd88d85e754ac421955a6fe3065da1bc709
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae89b1e2cd62e4f76008601da97974ddf4fa866a05496a36b86d0a4d9124d470a1fbf6a1c374bcb704598cc1846cd251b68daa0a0d160bc6265094fd56071354
|
7
|
+
data.tar.gz: c2bdf1ee119196601002148ffa4ad3633b61224eebe677bd6c39873e9280dcca2a81ae89b5289d868bad7f242e7ade92071baf85e8bde8ea9bdaee7bc64b649f
|
data/README.md
CHANGED
@@ -47,6 +47,24 @@ data.each do |row|
|
|
47
47
|
end
|
48
48
|
```
|
49
49
|
|
50
|
+
## Enabling Logging
|
51
|
+
|
52
|
+
To enable logging for this library, set the logger for the underlying [Google API Client](https://github.com/google/google-api-ruby-client/blob/master/README.md#logging) library. The logger that you set may be a Ruby stdlib [`Logger`](https://ruby-doc.org/stdlib-2.4.0/libdoc/logger/rdoc/Logger.html) as shown below, or a [`Google::Cloud::Logging::Logger`](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-logging/latest/google/cloud/logging/logger) that will write logs to [Stackdriver Logging](https://cloud.google.com/logging/).
|
53
|
+
|
54
|
+
If you do not set the logger explicitly and your application is running in a Rails environment, it will default to `Rails.logger`. Otherwise, if you do not set the logger and you are not using Rails, logging is disabled by default.
|
55
|
+
|
56
|
+
Configuring a Ruby stdlib logger:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
require "logger"
|
60
|
+
|
61
|
+
my_logger = Logger.new $stderr
|
62
|
+
my_logger.level = Logger::WARN
|
63
|
+
|
64
|
+
# Set the Google API Client logger
|
65
|
+
Google::Apis.logger = my_logger
|
66
|
+
```
|
67
|
+
|
50
68
|
## Supported Ruby Versions
|
51
69
|
|
52
70
|
This library is supported on Ruby 2.0+.
|
@@ -44,6 +44,34 @@ module Google
|
|
44
44
|
# run these first examples without the need to set up billing or to load
|
45
45
|
# data (although we'll show you how to do that too.)
|
46
46
|
#
|
47
|
+
# ## Enabling Logging
|
48
|
+
#
|
49
|
+
# To enable logging for this library, set the logger for the underlying
|
50
|
+
# [Google API Client](https://github.com/google/google-api-ruby-client/blob/master/README.md#logging)
|
51
|
+
# library. The logger that you set may be a Ruby stdlib
|
52
|
+
# [`Logger`](https://ruby-doc.org/stdlib-2.4.0/libdoc/logger/rdoc/Logger.html)
|
53
|
+
# as shown below, or a
|
54
|
+
# [`Google::Cloud::Logging::Logger`](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-logging/latest/google/cloud/logging/logger)
|
55
|
+
# that will write logs to [Stackdriver
|
56
|
+
# Logging](https://cloud.google.com/logging/).
|
57
|
+
#
|
58
|
+
# If you do not set the logger explicitly and your application is running in
|
59
|
+
# a Rails environment, it will default to `Rails.logger`. Otherwise, if you
|
60
|
+
# do not set the logger and you are not using Rails, logging is disabled by
|
61
|
+
# default.
|
62
|
+
#
|
63
|
+
# Configuring a Ruby stdlib logger:
|
64
|
+
#
|
65
|
+
# ```ruby
|
66
|
+
# require "logger"
|
67
|
+
#
|
68
|
+
# my_logger = Logger.new $stderr
|
69
|
+
# my_logger.level = Logger::WARN
|
70
|
+
#
|
71
|
+
# # Set the Google API Client logger
|
72
|
+
# Google::Apis.logger = my_logger
|
73
|
+
# ```
|
74
|
+
#
|
47
75
|
# ## Listing Datasets and Tables
|
48
76
|
#
|
49
77
|
# A BigQuery project contains datasets, which in turn contain tables.
|
@@ -186,7 +214,8 @@ module Google
|
|
186
214
|
# | `BOOL` | `true`/`false` | |
|
187
215
|
# | `INT64` | `Integer` | |
|
188
216
|
# | `FLOAT64` | `Float` | |
|
189
|
-
# | `
|
217
|
+
# | `NUMERIC` | `BigDecimal` | Will be rounded to 9 decimal places |
|
218
|
+
# | `STRING` | `String` | |
|
190
219
|
# | `DATETIME` | `DateTime` | `DATETIME` does not support time zone. |
|
191
220
|
# | `DATE` | `Date` | |
|
192
221
|
# | `TIMESTAMP` | `Time` | |
|
@@ -16,6 +16,7 @@
|
|
16
16
|
require "google/apis/bigquery_v2"
|
17
17
|
require "stringio"
|
18
18
|
require "base64"
|
19
|
+
require "bigdecimal"
|
19
20
|
require "time"
|
20
21
|
require "date"
|
21
22
|
|
@@ -34,7 +35,8 @@ module Google
|
|
34
35
|
# | `BOOL` | `true`/`false` | |
|
35
36
|
# | `INT64` | `Integer` | |
|
36
37
|
# | `FLOAT64` | `Float` | |
|
37
|
-
# | `
|
38
|
+
# | `NUMERIC` | `BigDecimal` | Will be rounded to 9 decimal places |
|
39
|
+
# | `STRING` | `String` | |
|
38
40
|
# | `DATETIME` | `DateTime` | `DATETIME` does not support time zone. |
|
39
41
|
# | `DATE` | `Date` | |
|
40
42
|
# | `TIMESTAMP` | `Time` | |
|
@@ -84,6 +86,8 @@ module Google
|
|
84
86
|
Integer value[:v]
|
85
87
|
elsif field.type == "FLOAT"
|
86
88
|
Float value[:v]
|
89
|
+
elsif field.type == "NUMERIC"
|
90
|
+
BigDecimal value[:v]
|
87
91
|
elsif field.type == "BOOLEAN"
|
88
92
|
(value[:v] == "true" ? true : (value[:v] == "false" ? false : nil))
|
89
93
|
elsif field.type == "BYTES"
|
@@ -132,6 +136,15 @@ module Google
|
|
132
136
|
parameter_value: Google::Apis::BigqueryV2::QueryParameterValue.new(
|
133
137
|
value: value)
|
134
138
|
)
|
139
|
+
elsif BigDecimal === value
|
140
|
+
# Round to precision of 9
|
141
|
+
value_str = value.finite? ? value.round(9).to_s("F") : value.to_s
|
142
|
+
return Google::Apis::BigqueryV2::QueryParameter.new(
|
143
|
+
parameter_type: Google::Apis::BigqueryV2::QueryParameterType.new(
|
144
|
+
type: "NUMERIC"),
|
145
|
+
parameter_value: Google::Apis::BigqueryV2::QueryParameterValue.new(
|
146
|
+
value: value_str)
|
147
|
+
)
|
135
148
|
elsif String === value
|
136
149
|
return Google::Apis::BigqueryV2::QueryParameter.new(
|
137
150
|
parameter_type: Google::Apis::BigqueryV2::QueryParameterType.new(
|
@@ -686,7 +686,8 @@ module Google
|
|
686
686
|
# | `BOOL` | `true`/`false` | |
|
687
687
|
# | `INT64` | `Integer` | |
|
688
688
|
# | `FLOAT64` | `Float` | |
|
689
|
-
# | `
|
689
|
+
# | `NUMERIC` | `BigDecimal` | Will be rounded to 9 decimal places |
|
690
|
+
# | `STRING` | `String` | |
|
690
691
|
# | `DATETIME` | `DateTime` | `DATETIME` does not support time zone. |
|
691
692
|
# | `DATE` | `Date` | |
|
692
693
|
# | `TIMESTAMP` | `Time` | |
|
@@ -942,7 +943,8 @@ module Google
|
|
942
943
|
# | `BOOL` | `true`/`false` | |
|
943
944
|
# | `INT64` | `Integer` | |
|
944
945
|
# | `FLOAT64` | `Float` | |
|
945
|
-
# | `
|
946
|
+
# | `NUMERIC` | `BigDecimal` | Will be rounded to 9 decimal places |
|
947
|
+
# | `STRING` | `String` | |
|
946
948
|
# | `DATETIME` | `DateTime` | `DATETIME` does not support time zone. |
|
947
949
|
# | `DATE` | `Date` | |
|
948
950
|
# | `TIMESTAMP` | `Time` | |
|
@@ -107,7 +107,8 @@ module Google
|
|
107
107
|
# | `BOOL` | `true`/`false` | |
|
108
108
|
# | `INT64` | `Integer` | |
|
109
109
|
# | `FLOAT64` | `Float` | |
|
110
|
-
# | `
|
110
|
+
# | `NUMERIC` | `BigDecimal` | Will be rounded to 9 decimal places |
|
111
|
+
# | `STRING` | `String` | |
|
111
112
|
# | `DATETIME` | `DateTime` | `DATETIME` does not support time zone. |
|
112
113
|
# | `DATE` | `Date` | |
|
113
114
|
# | `TIMESTAMP` | `Time` | |
|
@@ -365,7 +366,8 @@ module Google
|
|
365
366
|
# | `BOOL` | `true`/`false` | |
|
366
367
|
# | `INT64` | `Integer` | |
|
367
368
|
# | `FLOAT64` | `Float` | |
|
368
|
-
# | `
|
369
|
+
# | `NUMERIC` | `BigDecimal` | Will be rounded to 9 decimal places |
|
370
|
+
# | `STRING` | `String` | |
|
369
371
|
# | `DATETIME` | `DateTime` | `DATETIME` does not support time zone. |
|
370
372
|
# | `DATE` | `Date` | |
|
371
373
|
# | `TIMESTAMP` | `Time` | |
|
@@ -14,6 +14,7 @@
|
|
14
14
|
|
15
15
|
|
16
16
|
require "google/cloud/bigquery/schema/field"
|
17
|
+
require "json"
|
17
18
|
|
18
19
|
module Google
|
19
20
|
module Cloud
|
@@ -44,6 +45,67 @@ module Google
|
|
44
45
|
# end
|
45
46
|
#
|
46
47
|
class Schema
|
48
|
+
class << self
|
49
|
+
##
|
50
|
+
# Load a schema from a JSON file.
|
51
|
+
#
|
52
|
+
# The JSON schema file is the same as for the [`bq`
|
53
|
+
# CLI](https://cloud.google.com/bigquery/docs/schemas#specifying_a_json_schema_file)
|
54
|
+
# consisting of an array of JSON objects containing the following:
|
55
|
+
# - `name`: The column [name](https://cloud.google.com/bigquery/docs/schemas#column_names)
|
56
|
+
# - `type`: The column's [data
|
57
|
+
# type](https://cloud.google.com/bigquery/docs/schemas#standard_sql_data_types)
|
58
|
+
# - `description`: (Optional) The column's [description](https://cloud.google.com/bigquery/docs/schemas#column_descriptions)
|
59
|
+
# - `mode`: (Optional) The column's [mode](https://cloud.google.com/bigquery/docs/schemas#modes)
|
60
|
+
# (if unspecified, mode defaults to `NULLABLE`)
|
61
|
+
# - `fields`: If `type` is `RECORD`, an array of objects defining
|
62
|
+
# child fields with these properties
|
63
|
+
#
|
64
|
+
# @param [IO, String, Array<Hash>] source An `IO` containing the JSON
|
65
|
+
# schema, a `String` containing the JSON schema, or an `Array` of
|
66
|
+
# `Hash`es containing the schema details.
|
67
|
+
#
|
68
|
+
# @return [Schema] A schema.
|
69
|
+
#
|
70
|
+
# @example
|
71
|
+
# require "google/cloud/bigquery"
|
72
|
+
#
|
73
|
+
# schema = Google::Cloud::Bigquery::Schema.load(
|
74
|
+
# File.read("schema.json")
|
75
|
+
# )
|
76
|
+
#
|
77
|
+
def load source
|
78
|
+
new.load source
|
79
|
+
end
|
80
|
+
|
81
|
+
##
|
82
|
+
# Write a schema as JSON to a file.
|
83
|
+
#
|
84
|
+
# The JSON schema file is the same as for the [`bq`
|
85
|
+
# CLI](https://cloud.google.com/bigquery/docs/schemas#specifying_a_json_schema_file).
|
86
|
+
#
|
87
|
+
# @param [IO, String] schema An `Google::Cloud::Bigquery::Schema`.
|
88
|
+
#
|
89
|
+
# @param [IO, String] destination An `IO` to which to write the
|
90
|
+
# schema, or a `String` containing the filename to write to.
|
91
|
+
#
|
92
|
+
# @return [Schema] The schema so that commands are chainable.
|
93
|
+
#
|
94
|
+
# @example
|
95
|
+
# require "google/cloud/bigquery"
|
96
|
+
#
|
97
|
+
# bigquery = Google::Cloud::Bigquery.new
|
98
|
+
# dataset = bigquery.dataset "my_dataset"
|
99
|
+
# table = dataset.table "my_table"
|
100
|
+
# schema = Google::Cloud::Bigquery::Schema.dump(
|
101
|
+
# table.schema,
|
102
|
+
# "schema.json"
|
103
|
+
# )
|
104
|
+
#
|
105
|
+
def dump schema, destination
|
106
|
+
schema.dump destination
|
107
|
+
end
|
108
|
+
end
|
47
109
|
##
|
48
110
|
# The fields of the table schema.
|
49
111
|
#
|
@@ -123,6 +185,83 @@ module Google
|
|
123
185
|
fields.empty?
|
124
186
|
end
|
125
187
|
|
188
|
+
##
|
189
|
+
# Load the schema from a JSON file.
|
190
|
+
#
|
191
|
+
# The JSON schema file is the same as for the [`bq`
|
192
|
+
# CLI](https://cloud.google.com/bigquery/docs/schemas#specifying_a_json_schema_file)
|
193
|
+
# consisting of an array of JSON objects containing the following:
|
194
|
+
# - `name`: The column [name](https://cloud.google.com/bigquery/docs/schemas#column_names)
|
195
|
+
# - `type`: The column's [data
|
196
|
+
# type](https://cloud.google.com/bigquery/docs/schemas#standard_sql_data_types)
|
197
|
+
# - `description`: (Optional) The column's [description](https://cloud.google.com/bigquery/docs/schemas#column_descriptions)
|
198
|
+
# - `mode`: (Optional) The column's [mode](https://cloud.google.com/bigquery/docs/schemas#modes)
|
199
|
+
# (if unspecified, mode defaults to `NULLABLE`)
|
200
|
+
# - `fields`: If `type` is `RECORD`, an array of objects defining child
|
201
|
+
# fields with these properties
|
202
|
+
#
|
203
|
+
# @param [IO, String, Array<Hash>] source An `IO` containing the JSON
|
204
|
+
# schema, a `String` containing the JSON schema, or an `Array` of
|
205
|
+
# `Hash`es containing the schema details.
|
206
|
+
#
|
207
|
+
# @return [Schema] The schema so that commands are chainable.
|
208
|
+
#
|
209
|
+
# @example
|
210
|
+
# require "google/cloud/bigquery"
|
211
|
+
#
|
212
|
+
# bigquery = Google::Cloud::Bigquery.new
|
213
|
+
# dataset = bigquery.dataset "my_dataset"
|
214
|
+
# table = dataset.table "my_table" do |table|
|
215
|
+
# table.schema.load File.read("path/to/schema.json")
|
216
|
+
# end
|
217
|
+
#
|
218
|
+
def load source
|
219
|
+
if source.respond_to?(:rewind) && source.respond_to?(:read)
|
220
|
+
source.rewind
|
221
|
+
schema_json = String source.read
|
222
|
+
elsif source.is_a? Array
|
223
|
+
schema_json = JSON.dump source
|
224
|
+
else
|
225
|
+
schema_json = String source
|
226
|
+
end
|
227
|
+
|
228
|
+
schema_json = %({"fields":#{schema_json}})
|
229
|
+
|
230
|
+
@gapi = Google::Apis::BigqueryV2::TableSchema.from_json schema_json
|
231
|
+
|
232
|
+
self
|
233
|
+
end
|
234
|
+
|
235
|
+
##
|
236
|
+
# Write the schema as JSON to a file.
|
237
|
+
#
|
238
|
+
# The JSON schema file is the same as for the [`bq`
|
239
|
+
# CLI](https://cloud.google.com/bigquery/docs/schemas#specifying_a_json_schema_file).
|
240
|
+
#
|
241
|
+
# @param [IO, String] destination An `IO` to which to write the schema,
|
242
|
+
# or a `String` containing the filename to write to.
|
243
|
+
#
|
244
|
+
# @return [Schema] The schema so that commands are chainable.
|
245
|
+
#
|
246
|
+
# @example
|
247
|
+
# require "google/cloud/bigquery"
|
248
|
+
#
|
249
|
+
# bigquery = Google::Cloud::Bigquery.new
|
250
|
+
# dataset = bigquery.dataset "my_dataset"
|
251
|
+
# table = dataset.table "my_table"
|
252
|
+
# table.schema.dump "schema.json"
|
253
|
+
#
|
254
|
+
def dump destination
|
255
|
+
if destination.respond_to?(:rewind) && destination.respond_to?(:write)
|
256
|
+
destination.rewind
|
257
|
+
destination.write JSON.dump(fields.map(&:to_hash))
|
258
|
+
else
|
259
|
+
File.write String(destination), JSON.dump(fields.map(&:to_hash))
|
260
|
+
end
|
261
|
+
|
262
|
+
self
|
263
|
+
end
|
264
|
+
|
126
265
|
##
|
127
266
|
# Adds a string field to the schema.
|
128
267
|
#
|
@@ -171,6 +310,24 @@ module Google
|
|
171
310
|
add_field name, :float, description: description, mode: mode
|
172
311
|
end
|
173
312
|
|
313
|
+
##
|
314
|
+
# Adds a numeric number field to the schema. Numeric is a
|
315
|
+
# fixed-precision numeric type with 38 decimal digits, 9 that follow the
|
316
|
+
# decimal point.
|
317
|
+
#
|
318
|
+
# @param [String] name The field name. The name must contain only
|
319
|
+
# letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
|
320
|
+
# start with a letter or underscore. The maximum length is 128
|
321
|
+
# characters.
|
322
|
+
# @param [String] description A description of the field.
|
323
|
+
# @param [Symbol] mode The field's mode. The possible values are
|
324
|
+
# `:nullable`, `:required`, and `:repeated`. The default value is
|
325
|
+
# `:nullable`.
|
326
|
+
#
|
327
|
+
def numeric name, description: nil, mode: :nullable
|
328
|
+
add_field name, :numeric, description: description, mode: mode
|
329
|
+
end
|
330
|
+
|
174
331
|
##
|
175
332
|
# Adds a boolean field to the schema.
|
176
333
|
#
|
@@ -40,8 +40,8 @@ module Google
|
|
40
40
|
MODES = %w[NULLABLE REQUIRED REPEATED].freeze
|
41
41
|
|
42
42
|
# @private
|
43
|
-
TYPES = %w[STRING INTEGER INT64 FLOAT FLOAT64 BOOLEAN BOOL
|
44
|
-
TIMESTAMP TIME DATETIME DATE RECORD STRUCT].freeze
|
43
|
+
TYPES = %w[STRING INTEGER INT64 FLOAT FLOAT64 NUMERIC BOOLEAN BOOL
|
44
|
+
BYTES TIMESTAMP TIME DATETIME DATE RECORD STRUCT].freeze
|
45
45
|
|
46
46
|
##
|
47
47
|
# The name of the field.
|
@@ -72,10 +72,10 @@ module Google
|
|
72
72
|
#
|
73
73
|
# @return [String] The field data type. Possible values include
|
74
74
|
# `STRING`, `BYTES`, `INTEGER`, `INT64` (same as `INTEGER`),
|
75
|
-
# `FLOAT`, `FLOAT64` (same as `FLOAT`), `BOOLEAN`, `BOOL`
|
76
|
-
# `BOOLEAN`), `TIMESTAMP`, `DATE`, `TIME`, `DATETIME`,
|
77
|
-
# (where `RECORD` indicates that the field contains a
|
78
|
-
# or `STRUCT` (same as `RECORD`).
|
75
|
+
# `FLOAT`, `FLOAT64` (same as `FLOAT`), `NUMERIC`, `BOOLEAN`, `BOOL`
|
76
|
+
# (same as `BOOLEAN`), `TIMESTAMP`, `DATE`, `TIME`, `DATETIME`,
|
77
|
+
# `RECORD` (where `RECORD` indicates that the field contains a
|
78
|
+
# nested schema) or `STRUCT` (same as `RECORD`).
|
79
79
|
#
|
80
80
|
def type
|
81
81
|
@gapi.type
|
@@ -86,10 +86,10 @@ module Google
|
|
86
86
|
#
|
87
87
|
# @param [String] new_type The data type. Possible values include
|
88
88
|
# `STRING`, `BYTES`, `INTEGER`, `INT64` (same as `INTEGER`),
|
89
|
-
# `FLOAT`, `FLOAT64` (same as `FLOAT`), `BOOLEAN`, `BOOL`
|
90
|
-
# `BOOLEAN`), `TIMESTAMP`, `DATE`, `TIME`, `DATETIME`,
|
91
|
-
# (where `RECORD` indicates that the field contains a
|
92
|
-
# or `STRUCT` (same as `RECORD`).
|
89
|
+
# `FLOAT`, `FLOAT64` (same as `FLOAT`), `NUMERIC`, `BOOLEAN`, `BOOL`
|
90
|
+
# (same as `BOOLEAN`), `TIMESTAMP`, `DATE`, `TIME`, `DATETIME`,
|
91
|
+
# `RECORD` (where `RECORD` indicates that the field contains a
|
92
|
+
# nested schema) or `STRUCT` (same as `RECORD`).
|
93
93
|
#
|
94
94
|
def type= new_type
|
95
95
|
@gapi.update! type: verify_type(new_type)
|
@@ -190,6 +190,15 @@ module Google
|
|
190
190
|
type == "FLOAT" || type == "FLOAT64"
|
191
191
|
end
|
192
192
|
|
193
|
+
##
|
194
|
+
# Checks if the type of the field is `NUMERIC`.
|
195
|
+
#
|
196
|
+
# @return [Boolean] `true` when `NUMERIC`, `false` otherwise.
|
197
|
+
#
|
198
|
+
def numeric?
|
199
|
+
type == "NUMERIC"
|
200
|
+
end
|
201
|
+
|
193
202
|
##
|
194
203
|
# Checks if the type of the field is `BOOLEAN`.
|
195
204
|
#
|
@@ -353,6 +362,28 @@ module Google
|
|
353
362
|
add_field name, :float, description: description, mode: mode
|
354
363
|
end
|
355
364
|
|
365
|
+
##
|
366
|
+
# Adds a numeric number field to the schema. Numeric is a
|
367
|
+
# fixed-precision numeric type with 38 decimal digits, 9 that follow
|
368
|
+
# the decimal point.
|
369
|
+
#
|
370
|
+
# This can only be called on fields that are of type `RECORD`.
|
371
|
+
#
|
372
|
+
# @param [String] name The field name. The name must contain only
|
373
|
+
# letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
|
374
|
+
# start with a letter or underscore. The maximum length is 128
|
375
|
+
# characters.
|
376
|
+
# @param [String] description A description of the field.
|
377
|
+
# @param [Symbol] mode The field's mode. The possible values are
|
378
|
+
# `:nullable`, `:required`, and `:repeated`. The default value is
|
379
|
+
# `:nullable`.
|
380
|
+
#
|
381
|
+
def numeric name, description: nil, mode: :nullable
|
382
|
+
record_check!
|
383
|
+
|
384
|
+
add_field name, :numeric, description: description, mode: mode
|
385
|
+
end
|
386
|
+
|
356
387
|
##
|
357
388
|
# Adds a boolean field to the nested schema of a record field.
|
358
389
|
#
|
@@ -542,6 +573,18 @@ module Google
|
|
542
573
|
to_gapi.to_h == other.to_gapi.to_h
|
543
574
|
end
|
544
575
|
|
576
|
+
# @private
|
577
|
+
def to_hash
|
578
|
+
h = {
|
579
|
+
name: name,
|
580
|
+
type: type,
|
581
|
+
mode: mode
|
582
|
+
}
|
583
|
+
h[:description] = description if description
|
584
|
+
h[:fields] = fields.map(&:to_hash) if record?
|
585
|
+
h
|
586
|
+
end
|
587
|
+
|
545
588
|
protected
|
546
589
|
|
547
590
|
def frozen_check!
|
@@ -700,6 +700,11 @@ module Google
|
|
700
700
|
# schema. If `false`, the fields will be added to the existing schema.
|
701
701
|
# When a table already contains data, schema changes must be additive.
|
702
702
|
# Thus, the default value is `false`.
|
703
|
+
# When loading from a file this will always replace the schema, no
|
704
|
+
# matter what `replace` is set to. You can update the schema (for
|
705
|
+
# example, for a table that already contains data) by providing a
|
706
|
+
# schema file that includes the existing schema plus any new
|
707
|
+
# fields.
|
703
708
|
# @yield [schema] a block for setting the schema
|
704
709
|
# @yieldparam [Schema] schema the object accepting the schema
|
705
710
|
#
|
@@ -720,6 +725,16 @@ module Google
|
|
720
725
|
# end
|
721
726
|
# end
|
722
727
|
#
|
728
|
+
# @example Load the schema from a file
|
729
|
+
# require "google/cloud/bigquery"
|
730
|
+
#
|
731
|
+
# bigquery = Google::Cloud::Bigquery.new
|
732
|
+
# dataset = bigquery.dataset "my_dataset"
|
733
|
+
# table = dataset.create_table "my_table"
|
734
|
+
# table.schema do |schema|
|
735
|
+
# schema.load File.open("schema.json")
|
736
|
+
# end
|
737
|
+
#
|
723
738
|
# @!group Attributes
|
724
739
|
#
|
725
740
|
def schema replace: false
|
@@ -2427,6 +2442,11 @@ module Google
|
|
2427
2442
|
# schema. If `false`, the fields will be added to the existing
|
2428
2443
|
# schema. When a table already contains data, schema changes must be
|
2429
2444
|
# additive. Thus, the default value is `false`.
|
2445
|
+
# When loading from a file this will always replace the schema, no
|
2446
|
+
# matter what `replace` is set to. You can update the schema (for
|
2447
|
+
# example, for a table that already contains data) by providing a
|
2448
|
+
# schema file that includes the existing schema plus any new
|
2449
|
+
# fields.
|
2430
2450
|
# @yield [schema] a block for setting the schema
|
2431
2451
|
# @yieldparam [Schema] schema the object accepting the schema
|
2432
2452
|
#
|
@@ -2449,6 +2469,19 @@ module Google
|
|
2449
2469
|
# end
|
2450
2470
|
# end
|
2451
2471
|
#
|
2472
|
+
# @example Load the schema from a file
|
2473
|
+
# require "google/cloud/bigquery"
|
2474
|
+
#
|
2475
|
+
# bigquery = Google::Cloud::Bigquery.new
|
2476
|
+
# dataset = bigquery.dataset "my_dataset"
|
2477
|
+
# table = dataset.create_table "my_table" do |t|
|
2478
|
+
# t.name = "My Table",
|
2479
|
+
# t.description = "A description of my table."
|
2480
|
+
# t.schema do |s|
|
2481
|
+
# s.load File.open("schema.json")
|
2482
|
+
# end
|
2483
|
+
# end
|
2484
|
+
#
|
2452
2485
|
# @!group Schema
|
2453
2486
|
#
|
2454
2487
|
def schema replace: false
|
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.5.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: 2018-05-
|
12
|
+
date: 2018-05-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: google-cloud-core
|
@@ -251,7 +251,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
251
251
|
version: '0'
|
252
252
|
requirements: []
|
253
253
|
rubyforge_project:
|
254
|
-
rubygems_version: 2.7.
|
254
|
+
rubygems_version: 2.7.7
|
255
255
|
signing_key:
|
256
256
|
specification_version: 4
|
257
257
|
summary: API Client library for Google BigQuery
|