Class: Google::Cloud::Bigquery::Schema::Field
- Inherits:
-
Object
- Object
- Google::Cloud::Bigquery::Schema::Field
- Defined in:
- lib/google/cloud/bigquery/schema/field.rb
Overview
Schema Field
The fields of a table schema.
Instance Method Summary collapse
-
#boolean(name, description: nil, mode: :nullable) ⇒ Object
Adds a boolean field to the nested schema of a record field.
-
#boolean? ⇒ Boolean
Checks if the type of the field is
BOOLEAN
. -
#bytes(name, description: nil, mode: :nullable) ⇒ Object
Adds a bytes field to the nested schema of a record field.
-
#bytes? ⇒ Boolean
Checks if the type of the field is
BYTES
. -
#date(name, description: nil, mode: :nullable) ⇒ Object
Adds a date field to the nested schema of a record field.
-
#date? ⇒ Boolean
Checks if the type of the field is
DATE
. -
#datetime(name, description: nil, mode: :nullable) ⇒ Object
Adds a datetime field to the nested schema of a record field.
-
#datetime? ⇒ Boolean
Checks if the type of the field is
DATETIME
. -
#description ⇒ String
The description of the field.
-
#description=(new_description) ⇒ Object
Updates the description of the field.
-
#field(name) {|f| ... } ⇒ Field?
Retrieve a nested field by name, if the type property is set to
RECORD
. -
#fields ⇒ Array<Field>?
The nested fields if the type property is set to
RECORD
. -
#float(name, description: nil, mode: :nullable) ⇒ Object
Adds a floating-point number field to the nested schema of a record field.
-
#float? ⇒ Boolean
Checks if the type of the field is
FLOAT
. -
#headers ⇒ Array<Symbol>?
The names of the nested fields as symbols if the type property is set to
RECORD
. -
#integer(name, description: nil, mode: :nullable) ⇒ Object
Adds an integer field to the nested schema of a record field.
-
#integer? ⇒ Boolean
Checks if the type of the field is
INTEGER
. -
#mode ⇒ String
The mode of the field.
-
#mode=(new_mode) ⇒ Object
Updates the mode of the field.
-
#name ⇒ String
The name of the field.
-
#name=(new_name) ⇒ Object
Updates the name of the field.
-
#nullable? ⇒ Boolean
Checks if the type of the field is
NULLABLE
. -
#numeric(name, description: nil, mode: :nullable) ⇒ Object
Adds a numeric number field to the schema.
-
#numeric? ⇒ Boolean
Checks if the type of the field is
NUMERIC
. -
#record(name, description: nil, mode: nil) {|nested_schema| ... } ⇒ Object
Adds a record field to the nested schema of a record field.
-
#record? ⇒ Boolean
Checks if the type of the field is
RECORD
. -
#repeated? ⇒ Boolean
Checks if the type of the field is
REPEATED
. -
#required? ⇒ Boolean
Checks if the type of the field is
REQUIRED
. -
#string(name, description: nil, mode: :nullable) ⇒ Object
Adds a string field to the nested schema of a record field.
-
#string? ⇒ Boolean
Checks if the type of the field is
STRING
. -
#time(name, description: nil, mode: :nullable) ⇒ Object
Adds a time field to the nested schema of a record field.
-
#time? ⇒ Boolean
Checks if the type of the field is
TIME
. -
#timestamp(name, description: nil, mode: :nullable) ⇒ Object
Adds a timestamp field to the nested schema of a record field.
-
#timestamp? ⇒ Boolean
Checks if the type of the field is
TIMESTAMP
. -
#type ⇒ String
The data type of the field.
-
#type=(new_type) ⇒ Object
Updates the data type of the field.
Instance Method Details
#boolean(name, description: nil, mode: :nullable) ⇒ Object
Adds a boolean field to the nested schema of a record field.
This can only be called on fields that are of type RECORD
.
401 402 403 404 405 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 401 def boolean name, description: nil, mode: :nullable record_check! add_field name, :boolean, description: description, mode: mode end |
#boolean? ⇒ Boolean
Checks if the type of the field is BOOLEAN
.
207 208 209 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 207 def boolean? type == "BOOLEAN" || type == "BOOL" end |
#bytes(name, description: nil, mode: :nullable) ⇒ Object
Adds a bytes field to the nested schema of a record field.
This can only be called on fields that are of type RECORD
.
421 422 423 424 425 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 421 def bytes name, description: nil, mode: :nullable record_check! add_field name, :bytes, description: description, mode: mode end |
#bytes? ⇒ Boolean
Checks if the type of the field is BYTES
.
216 217 218 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 216 def bytes? type == "BYTES" end |
#date(name, description: nil, mode: :nullable) ⇒ Object
Adds a date field to the nested schema of a record field.
This can only be called on fields that are of type RECORD
.
501 502 503 504 505 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 501 def date name, description: nil, mode: :nullable record_check! add_field name, :date, description: description, mode: mode end |
#date? ⇒ Boolean
Checks if the type of the field is DATE
.
252 253 254 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 252 def date? type == "DATE" end |
#datetime(name, description: nil, mode: :nullable) ⇒ Object
Adds a datetime field to the nested schema of a record field.
This can only be called on fields that are of type RECORD
.
481 482 483 484 485 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 481 def datetime name, description: nil, mode: :nullable record_check! add_field name, :datetime, description: description, mode: mode end |
#datetime? ⇒ Boolean
Checks if the type of the field is DATETIME
.
243 244 245 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 243 def datetime? type == "DATETIME" end |
#description ⇒ String
The description of the field.
131 132 133 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 131 def description @gapi.description end |
#description=(new_description) ⇒ Object
Updates the description of the field.
141 142 143 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 141 def description= new_description @gapi.update! description: new_description end |
#field(name) {|f| ... } ⇒ Field?
Retrieve a nested field by name, if the type property is
set to RECORD
. Will return nil
otherwise.
297 298 299 300 301 302 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 297 def field name f = fields.find { |fld| fld.name == name.to_s } return nil if f.nil? yield f if block_given? f end |
#fields ⇒ Array<Field>?
The nested fields if the type property is set to RECORD
. Will be
empty otherwise.
272 273 274 275 276 277 278 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 272 def fields if frozen? Array(@gapi.fields).map { |f| Field.from_gapi(f).freeze }.freeze else Array(@gapi.fields).map { |f| Field.from_gapi f } end end |
#float(name, description: nil, mode: :nullable) ⇒ Object
Adds a floating-point number field to the nested schema of a record field.
This can only be called on fields that are of type RECORD
.
359 360 361 362 363 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 359 def float name, description: nil, mode: :nullable record_check! add_field name, :float, description: description, mode: mode end |
#float? ⇒ Boolean
Checks if the type of the field is FLOAT
.
189 190 191 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 189 def float? type == "FLOAT" || type == "FLOAT64" end |
#headers ⇒ Array<Symbol>?
The names of the nested fields as symbols if the type property is
set to RECORD
. Will be empty otherwise.
287 288 289 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 287 def headers fields.map(&:name).map(&:to_sym) end |
#integer(name, description: nil, mode: :nullable) ⇒ Object
Adds an integer field to the nested schema of a record field.
This can only be called on fields that are of type RECORD
.
338 339 340 341 342 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 338 def integer name, description: nil, mode: :nullable record_check! add_field name, :integer, description: description, mode: mode end |
#integer? ⇒ Boolean
Checks if the type of the field is INTEGER
.
180 181 182 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 180 def integer? type == "INTEGER" || type == "INT64" end |
#mode ⇒ String
The mode of the field.
151 152 153 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 151 def mode @gapi.mode end |
#mode=(new_mode) ⇒ Object
Updates the mode of the field.
162 163 164 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 162 def mode= new_mode @gapi.update! mode: verify_mode(new_mode) end |
#name ⇒ String
The name of the field.
54 55 56 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 54 def name @gapi.name end |
#name=(new_name) ⇒ Object
Updates the name of the field.
66 67 68 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 66 def name= new_name @gapi.update! name: String(new_name) end |
#nullable? ⇒ Boolean
Checks if the type of the field is NULLABLE
.
103 104 105 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 103 def nullable? mode == "NULLABLE" end |
#numeric(name, description: nil, mode: :nullable) ⇒ Object
Adds a numeric number field to the schema. Numeric is a fixed-precision numeric type with 38 decimal digits, 9 that follow the decimal point.
This can only be called on fields that are of type RECORD
.
381 382 383 384 385 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 381 def numeric name, description: nil, mode: :nullable record_check! add_field name, :numeric, description: description, mode: mode end |
#numeric? ⇒ Boolean
Checks if the type of the field is NUMERIC
.
198 199 200 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 198 def numeric? type == "NUMERIC" end |
#record(name, description: nil, mode: nil) {|nested_schema| ... } ⇒ Object
Adds a record field to the nested schema of a record field. A block must be passed describing the nested fields of the record. For more information about nested and repeated records, see Preparing Data for BigQuery.
This can only be called on fields that are of type RECORD
.
545 546 547 548 549 550 551 552 553 554 555 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 545 def record name, description: nil, mode: nil record_check! # TODO: do we need to raise if no block was given? raise ArgumentError, "a block is required" unless block_given? nested_field = add_field name, :record, description: description, mode: mode yield nested_field nested_field end |
#record? ⇒ Boolean
Checks if the type of the field is RECORD
.
261 262 263 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 261 def record? type == "RECORD" || type == "STRUCT" end |
#repeated? ⇒ Boolean
Checks if the type of the field is REPEATED
.
121 122 123 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 121 def repeated? mode == "REPEATED" end |
#required? ⇒ Boolean
Checks if the type of the field is REQUIRED
.
112 113 114 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 112 def required? mode == "REQUIRED" end |
#string(name, description: nil, mode: :nullable) ⇒ Object
Adds a string field to the nested schema of a record field.
This can only be called on fields that are of type RECORD
.
318 319 320 321 322 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 318 def string name, description: nil, mode: :nullable record_check! add_field name, :string, description: description, mode: mode end |
#string? ⇒ Boolean
Checks if the type of the field is STRING
.
171 172 173 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 171 def string? type == "STRING" end |
#time(name, description: nil, mode: :nullable) ⇒ Object
Adds a time field to the nested schema of a record field.
This can only be called on fields that are of type RECORD
.
461 462 463 464 465 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 461 def time name, description: nil, mode: :nullable record_check! add_field name, :time, description: description, mode: mode end |
#time? ⇒ Boolean
Checks if the type of the field is TIME
.
234 235 236 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 234 def time? type == "TIME" end |
#timestamp(name, description: nil, mode: :nullable) ⇒ Object
Adds a timestamp field to the nested schema of a record field.
This can only be called on fields that are of type RECORD
.
441 442 443 444 445 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 441 def name, description: nil, mode: :nullable record_check! add_field name, :timestamp, description: description, mode: mode end |
#timestamp? ⇒ Boolean
Checks if the type of the field is TIMESTAMP
.
225 226 227 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 225 def type == "TIMESTAMP" end |
#type ⇒ String
The data type of the field.
80 81 82 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 80 def type @gapi.type end |
#type=(new_type) ⇒ Object
Updates the data type of the field.
94 95 96 |
# File 'lib/google/cloud/bigquery/schema/field.rb', line 94 def type= new_type @gapi.update! type: verify_type(new_type) end |