Reference documentation and code samples for the BigQuery API class Google::Cloud::Bigquery::Schema::Field.
Schema Field
The fields of a table schema.
Inherits
- Object
Example
require "google/cloud/bigquery" bigquery = Google::Cloud::Bigquery.new dataset = bigquery.dataset "my_dataset" table = dataset.table "my_table" field = table.schema.field "name" field.required? #=> true
Methods
#bignumeric
def bignumeric(name, description: nil, mode: :nullable, policy_tags: nil, precision: nil, scale: nil)Adds a bignumeric number field to the schema. BIGNUMERIC is a
decimal type with fixed precision and scale. Precision is the
number of digits that the number contains. Scale is how many of
these digits appear after the decimal point. It supports:
Precision: 76.76 (the 77th digit is partial) Scale: 38 Min: -5.7896044618658097711785492504343953926634992332820282019728792003956564819968E+38 Max: 5.7896044618658097711785492504343953926634992332820282019728792003956564819967E+38
This type can represent decimal fractions exactly, and is suitable for financial calculations.
This can only be called on fields that are of type RECORD.
-
name (String) — The field name. The name must contain only
letters (
[A-Za-z]), numbers ([0-9]), or underscores (_), and must start with a letter or underscore. The maximum length is 128 characters. - description (String) (defaults to: nil) — A description of the field.
-
mode (Symbol) (defaults to: :nullable) — The field's mode. The possible values are
:nullable,:required, and:repeated. The default value is:nullable. -
policy_tags (Array<String>, String) (defaults to: nil) — The policy tag list or
single policy tag for the field. Policy tag identifiers are of
the form
projects/*/locations/*/taxonomies/*/policyTags/*. At most 1 policy tag is currently allowed. -
precision (Integer) (defaults to: nil) — The precision (maximum number of total
digits) for the field. Acceptable values for precision must be:
1 ≤ (precision - scale) ≤ 38. Values for scale must be:0 ≤ scale ≤ 38. If the scale value is set, the precision value must be set as well. -
scale (Integer) (defaults to: nil) — The scale (maximum number of digits in the
fractional part) for the field. Acceptable values for precision
must be:
1 ≤ (precision - scale) ≤ 38. Values for scale must be:0 ≤ scale ≤ 38. If the scale value is set, the precision value must be set as well.
#bignumeric?
def bignumeric?() -> BooleanChecks if the type of the field is BIGNUMERIC.
-
(Boolean) —
truewhenBIGNUMERIC,falseotherwise.
#boolean
def boolean(name, description: nil, mode: :nullable, policy_tags: nil)Adds a boolean field to the nested schema of a record field.
This can only be called on fields that are of type RECORD.
-
name (String) — The field name. The name must contain only
letters (
[A-Za-z]), numbers ([0-9]), or underscores (_), and must start with a letter or underscore. The maximum length is 128 characters. - description (String) (defaults to: nil) — A description of the field.
-
mode (Symbol) (defaults to: :nullable) — The field's mode. The possible values are
:nullable,:required, and:repeated. The default value is:nullable. -
policy_tags (Array<String>, String) (defaults to: nil) — The policy tag list or
single policy tag for the field. Policy tag identifiers are of
the form
projects/*/locations/*/taxonomies/*/policyTags/*. At most 1 policy tag is currently allowed.
#boolean?
def boolean?() -> BooleanChecks if the type of the field is BOOLEAN.
-
(Boolean) —
truewhenBOOLEAN,falseotherwise.
#bytes
def bytes(name, description: nil, mode: :nullable, policy_tags: nil, max_length: nil)Adds a bytes field to the nested schema of a record field.
This can only be called on fields that are of type RECORD.
-
name (String) — The field name. The name must contain only
letters (
[A-Za-z]), numbers ([0-9]), or underscores (_), and must start with a letter or underscore. The maximum length is 128 characters. - description (String) (defaults to: nil) — A description of the field.
-
mode (Symbol) (defaults to: :nullable) — The field's mode. The possible values are
:nullable,:required, and:repeated. The default value is:nullable. -
policy_tags (Array<String>, String) (defaults to: nil) — The policy tag list or
single policy tag for the field. Policy tag identifiers are of
the form
projects/*/locations/*/taxonomies/*/policyTags/*. At most 1 policy tag is currently allowed. - max_length (Integer) (defaults to: nil) — The maximum the maximum number of bytes in the field.
#bytes?
def bytes?() -> BooleanChecks if the type of the field is BYTES.
-
(Boolean) —
truewhenBYTES,falseotherwise.
#date
def date(name, description: nil, mode: :nullable, policy_tags: nil)Adds a date field to the nested schema of a record field.
This can only be called on fields that are of type RECORD.
-
name (String) — The field name. The name must contain only
letters (
[A-Za-z]), numbers ([0-9]), or underscores (_), and must start with a letter or underscore. The maximum length is 128 characters. - description (String) (defaults to: nil) — A description of the field.
-
mode (Symbol) (defaults to: :nullable) — The field's mode. The possible values are
:nullable,:required, and:repeated. The default value is:nullable. -
policy_tags (Array<String>, String) (defaults to: nil) — The policy tag list or
single policy tag for the field. Policy tag identifiers are of
the form
projects/*/locations/*/taxonomies/*/policyTags/*. At most 1 policy tag is currently allowed.
#date?
def date?() -> BooleanChecks if the type of the field is DATE.
-
(Boolean) —
truewhenDATE,falseotherwise.
#datetime
def datetime(name, description: nil, mode: :nullable, policy_tags: nil)Adds a datetime field to the nested schema of a record field.
This can only be called on fields that are of type RECORD.
-
name (String) — The field name. The name must contain only
letters (
[A-Za-z]), numbers ([0-9]), or underscores (_), and must start with a letter or underscore. The maximum length is 128 characters. - description (String) (defaults to: nil) — A description of the field.
-
mode (Symbol) (defaults to: :nullable) — The field's mode. The possible values are
:nullable,:required, and:repeated. The default value is:nullable. -
policy_tags (Array<String>, String) (defaults to: nil) — The policy tag list or
single policy tag for the field. Policy tag identifiers are of
the form
projects/*/locations/*/taxonomies/*/policyTags/*. At most 1 policy tag is currently allowed.
#datetime?
def datetime?() -> BooleanChecks if the type of the field is DATETIME.
-
(Boolean) —
truewhenDATETIME,falseotherwise.
#default_value_expression
def default_value_expression() -> StringThe default value of a field using a SQL expression. It can only be set for top level fields (columns). Default value for the entire struct or array is set using a struct or array expression. The valid SQL expressions are:
- Literals for all data types, including STRUCT and ARRAY.
- The following functions:
CURRENT_TIMESTAMPCURRENT_TIMECURRENT_DATECURRENT_DATETIMEGENERATE_UUIDRANDSESSION_USERST_GEOPOINT - Struct or array composed with the above allowed functions, for example: "[CURRENT_DATE(), DATE '2020-01-01'"]
- (String) — The default value expression of the field.
#default_value_expression=
def default_value_expression=(default_value_expression)Updates the default value expression of the field.
-
default_value_expression (String) —
The default value of a field using a SQL expression. It can only be set for top level fields (columns). Use a struct or array expression to specify default value for the entire struct or array. The valid SQL expressions are:
- Literals for all data types, including STRUCT and ARRAY.
- The following functions:
CURRENT_TIMESTAMPCURRENT_TIMECURRENT_DATECURRENT_DATETIMEGENERATE_UUIDRANDSESSION_USERST_GEOPOINT - Struct or array composed with the above allowed functions, for example: "[CURRENT_DATE(), DATE '2020-01-01'"]
#description
def description() -> StringThe description of the field.
- (String) — The field description. The maximum length is 1,024 characters.
#description=
def description=(new_description)Updates the description of the field.
- new_description (String) — The field description. The maximum length is 1,024 characters.
#field
def field(name) -> Field, nilRetrieve a nested field by name, if the type property is
set to RECORD. Will return nil otherwise.
- (f)
-
(Field, nil) — The nested schema field object, or
nil.
#fields
def fields() -> Array<Field>, nilThe nested fields if the type property is set to RECORD. Will be
empty otherwise.
-
(Array<Field>, nil) — The nested schema fields if the type
is set to
RECORD.
#float
def float(name, description: nil, mode: :nullable, policy_tags: nil)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.
-
name (String) — The field name. The name must contain only
letters (
[A-Za-z]), numbers ([0-9]), or underscores (_), and must start with a letter or underscore. The maximum length is 128 characters. - description (String) (defaults to: nil) — A description of the field.
-
mode (Symbol) (defaults to: :nullable) — The field's mode. The possible values are
:nullable,:required, and:repeated. The default value is:nullable. -
policy_tags (Array<String>, String) (defaults to: nil) — The policy tag list or
single policy tag for the field. Policy tag identifiers are of
the form
projects/*/locations/*/taxonomies/*/policyTags/*. At most 1 policy tag is currently allowed.
#float?
def float?() -> BooleanChecks if the type of the field is FLOAT.
-
(Boolean) —
truewhenFLOAT,falseotherwise.
#geography
def geography(name, description: nil, mode: :nullable, policy_tags: nil)Adds a geography field to the nested schema of a record field.
-
name (String) — The field name. The name must contain only
letters (
[A-Za-z]), numbers ([0-9]), or underscores (_), and must start with a letter or underscore. The maximum length is 128 characters. - description (String) (defaults to: nil) — A description of the field.
-
mode (Symbol) (defaults to: :nullable) — The field's mode. The possible values are
:nullable,:required, and:repeated. The default value is:nullable. -
policy_tags (Array<String>, String) (defaults to: nil) — The policy tag list or
single policy tag for the field. Policy tag identifiers are of
the form
projects/*/locations/*/taxonomies/*/policyTags/*. At most 1 policy tag is currently allowed.
#geography?
def geography?() -> BooleanChecks if the type of the field is GEOGRAPHY.
-
(Boolean) —
truewhenGEOGRAPHY,falseotherwise.
#headers
def headers() -> Array<Symbol>, nilThe names of the nested fields as symbols if the type property is
set to RECORD. Will be empty otherwise.
-
(Array<Symbol>, nil) — The names of the nested schema fields
if the type is set to
RECORD.
#integer
def integer(name, description: nil, mode: :nullable, policy_tags: nil)Adds an integer field to the nested schema of a record field.
This can only be called on fields that are of type RECORD.
-
name (String) — The field name. The name must contain only
letters (
[A-Za-z]), numbers ([0-9]), or underscores (_), and must start with a letter or underscore. The maximum length is 128 characters. - description (String) (defaults to: nil) — A description of the field.
-
mode (Symbol) (defaults to: :nullable) — The field's mode. The possible values are
:nullable,:required, and:repeated. The default value is:nullable. -
policy_tags (Array<String>, String) (defaults to: nil) — The policy tag list or
single policy tag for the field. Policy tag identifiers are of
the form
projects/*/locations/*/taxonomies/*/policyTags/*. At most 1 policy tag is currently allowed.
#integer?
def integer?() -> BooleanChecks if the type of the field is INTEGER.
-
(Boolean) —
truewhenINTEGER,falseotherwise.
#max_length
def max_length() -> Integer, nilThe maximum length of values of this field for #string? or #bytes? fields. If max_length is not
specified, no maximum length constraint is imposed on this field. If type = STRING, then max_length
represents the maximum UTF-8 length of strings in this field. If type = BYTES, then max_length
represents the maximum number of bytes in this field.
-
(Integer, nil) — The maximum length of values of this field, or
nil.
#mode
def mode() -> StringThe mode of the field.
-
(String) — The field mode. Possible values include
NULLABLE,REQUIREDandREPEATED. The default value isNULLABLE.
#mode=
def mode=(new_mode)Updates the mode of the field.
-
new_mode (String) — The field mode. Possible values include
NULLABLE,REQUIREDandREPEATED. The default value isNULLABLE.
#name
def name() -> StringThe name of the field.
-
(String) — The field name. The name must contain only
letters (
[A-Za-z]), numbers ([0-9]), or underscores (_), and must start with a letter or underscore. The maximum length is 128 characters.
#name=
def name=(new_name)Updates the name of the field.
-
new_name (String) — The field name. The name must contain only
letters (
[A-Za-z]), numbers ([0-9]), or underscores (_), and must start with a letter or underscore. The maximum length is 128 characters.
#nullable?
def nullable?() -> BooleanChecks if the type of the field is NULLABLE.
-
(Boolean) —
truewhenNULLABLE,falseotherwise.
#numeric
def numeric(name, description: nil, mode: :nullable, policy_tags: nil, precision: nil, scale: nil)Adds a numeric number field to the schema. NUMERIC is a decimal
type with fixed precision and scale. Precision is the number of
digits that the number contains. Scale is how many of these
digits appear after the decimal point. It supports:
Precision: 38 Scale: 9 Min: -9.9999999999999999999999999999999999999E+28 Max: 9.9999999999999999999999999999999999999E+28
This type can represent decimal fractions exactly, and is suitable for financial calculations.
This can only be called on fields that are of type RECORD.
-
name (String) — The field name. The name must contain only
letters (
[A-Za-z]), numbers ([0-9]), or underscores (_), and must start with a letter or underscore. The maximum length is 128 characters. - description (String) (defaults to: nil) — A description of the field.
-
mode (Symbol) (defaults to: :nullable) — The field's mode. The possible values are
:nullable,:required, and:repeated. The default value is:nullable. -
policy_tags (Array<String>, String) (defaults to: nil) — The policy tag list or
single policy tag for the field. Policy tag identifiers are of
the form
projects/*/locations/*/taxonomies/*/policyTags/*. At most 1 policy tag is currently allowed. -
precision (Integer) (defaults to: nil) — The precision (maximum number of total
digits) for the field. Acceptable values for precision must be:
1 ≤ (precision - scale) ≤ 29. Values for scale must be:0 ≤ scale ≤ 9. If the scale value is set, the precision value must be set as well. -
scale (Integer) (defaults to: nil) — The scale (maximum number of digits in the
fractional part) for the field. Acceptable values for precision
must be:
1 ≤ (precision - scale) ≤ 29. Values for scale must be:0 ≤ scale ≤ 9. If the scale value is set, the precision value must be set as well.
#numeric?
def numeric?() -> BooleanChecks if the type of the field is NUMERIC.
-
(Boolean) —
truewhenNUMERIC,falseotherwise.
#param_type
def param_type() -> Symbol, Array, HashThe types of the field, using the same format as the optional query parameter types.
The parameter types are one of the following BigQuery type codes:
:BOOL:INT64:FLOAT64:NUMERIC:BIGNUMERIC:STRING:DATETIME:DATE:TIMESTAMP:TIME:BYTESArray- Lists are specified by providing the type code in an array. For example, an array of integers are specified as[:INT64].Hash- Types for STRUCT values (Hashobjects) are specified using aHashobject, where the keys are the nested field names, and the values are the the nested field types.
- (Symbol, Array, Hash) — The type.
#policy_tags
def policy_tags() -> Array<String>, nilThe policy tag list for the field. Policy tag identifiers are of the form
projects//locations//taxonomies//policyTags/. At most 1 policy tag
is currently allowed.
-
(Array<String>, nil) — The policy tag list for the field, or
nil.
require "google/cloud/bigquery" bigquery = Google::Cloud::Bigquery.new dataset = bigquery.dataset "my_dataset" table = dataset.table "my_table" table.schema.field("age").policy_tags
#policy_tags=
def policy_tags=(new_policy_tags)Updates the policy tag list for the field.
-
new_policy_tags (Array<String>, String, nil) — The policy tag list or
single policy tag for the field, or
nilto remove the existing policy tags. Policy tag identifiers are of the formprojects/*/locations/*/taxonomies/*/policyTags/*. At most 1 policy tag is currently allowed.
require "google/cloud/bigquery" bigquery = Google::Cloud::Bigquery.new dataset = bigquery.dataset "my_dataset" table = dataset.table "my_table" policy_tag = "projects/my-project/locations/us/taxonomies/my-taxonomy/policyTags/my-policy-tag" table.schema do |schema| schema.field("age").policy_tags = policy_tag end table.schema.field("age").policy_tags
#precision
def precision() -> Integer, nilThe precision (maximum number of total digits) for NUMERIC or BIGNUMERIC types. For #numeric? fields,
acceptable values for precision must be 1 ≤ (precision - scale) ≤ 29 and values for scale must be 0 ≤
scale ≤ 9. For #bignumeric? fields, acceptable values for precision must be 1 ≤ (precision - scale) ≤
38 and values for scale must be 0 ≤ scale ≤ 38. If the scale value is set, the precision value must be
set as well.
-
(Integer, nil) — The precision for the field, or
nil.
#record
def record(name, description: nil, mode: nil) { |nested_schema| ... }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.
-
name (String) — The field name. The name must contain only
letters (
[A-Za-z]), numbers ([0-9]), or underscores (_), and must start with a letter or underscore. The maximum length is 128 characters. - description (String) (defaults to: nil) — A description of the field.
-
mode (Symbol) (defaults to: nil) — The field's mode. The possible values are
:nullable,:required, and:repeated. The default value is:nullable.
- (nested_schema) — a block for setting the nested schema
- nested_schema (Schema) — the object accepting the nested schema
- (ArgumentError)
require "google/cloud/bigquery" bigquery = Google::Cloud::Bigquery.new dataset = bigquery.dataset "my_dataset" table = dataset.create_table "my_table" table.schema do |schema| schema.string "first_name", mode: :required schema.record "cities_lived", mode: :repeated do |cities_lived| cities_lived.record "city", mode: :required do |city| city.string "name", mode: :required city.string "country", mode: :required end cities_lived.integer "number_of_years", mode: :required end end
#record?
def record?() -> BooleanChecks if the type of the field is RECORD.
-
(Boolean) —
truewhenRECORD,falseotherwise.
#repeated?
def repeated?() -> BooleanChecks if the type of the field is REPEATED.
-
(Boolean) —
truewhenREPEATED,falseotherwise.
#required?
def required?() -> BooleanChecks if the type of the field is REQUIRED.
-
(Boolean) —
truewhenREQUIRED,falseotherwise.
#scale
def scale() -> Integer, nilThe scale (maximum number of digits in the fractional part) for NUMERIC or BIGNUMERIC types. For
#numeric? fields, acceptable values for precision must be 1 ≤ (precision - scale) ≤ 29 and values for
scale must be 0 ≤ scale ≤ 9. For #bignumeric? fields, acceptable values for precision must be 1 ≤
(precision - scale) ≤ 38 and values for scale must be 0 ≤ scale ≤ 38. If the scale value is set, the
precision value must be set as well.
-
(Integer, nil) — The scale for the field, or
nil.
#string
def string(name, description: nil, mode: :nullable, policy_tags: nil, max_length: nil)Adds a string field to the nested schema of a record field.
This can only be called on fields that are of type RECORD.
-
name (String) — The field name. The name must contain only
letters (
[A-Za-z]), numbers ([0-9]), or underscores (_), and must start with a letter or underscore. The maximum length is 128 characters. - description (String) (defaults to: nil) — A description of the field.
-
mode (Symbol) (defaults to: :nullable) — The field's mode. The possible values are
:nullable,:required, and:repeated. The default value is:nullable. -
policy_tags (Array<String>, String) (defaults to: nil) — The policy tag list or
single policy tag for the field. Policy tag identifiers are of
the form
projects/*/locations/*/taxonomies/*/policyTags/*. At most 1 policy tag is currently allowed. - max_length (Integer) (defaults to: nil) — The maximum UTF-8 length of strings allowed in the field.
#string?
def string?() -> BooleanChecks if the type of the field is STRING.
-
(Boolean) —
truewhenSTRING,falseotherwise.
#struct?
def struct?() -> BooleanChecks if the type of the field is RECORD.
-
(Boolean) —
truewhenRECORD,falseotherwise.
#time
def time(name, description: nil, mode: :nullable, policy_tags: nil)Adds a time field to the nested schema of a record field.
This can only be called on fields that are of type RECORD.
-
name (String) — The field name. The name must contain only
letters (
[A-Za-z]), numbers ([0-9]), or underscores (_), and must start with a letter or underscore. The maximum length is 128 characters. - description (String) (defaults to: nil) — A description of the field.
-
mode (Symbol) (defaults to: :nullable) — The field's mode. The possible values are
:nullable,:required, and:repeated. The default value is:nullable. -
policy_tags (Array<String>, String) (defaults to: nil) — The policy tag list or
single policy tag for the field. Policy tag identifiers are of
the form
projects/*/locations/*/taxonomies/*/policyTags/*. At most 1 policy tag is currently allowed.
#time?
def time?() -> BooleanChecks if the type of the field is TIME.
-
(Boolean) —
truewhenTIME,falseotherwise.
#timestamp
def timestamp(name, description: nil, mode: :nullable, policy_tags: nil)Adds a timestamp field to the nested schema of a record field.
This can only be called on fields that are of type RECORD.
-
name (String) — The field name. The name must contain only
letters (
[A-Za-z]), numbers ([0-9]), or underscores (_), and must start with a letter or underscore. The maximum length is 128 characters. - description (String) (defaults to: nil) — A description of the field.
-
mode (Symbol) (defaults to: :nullable) — The field's mode. The possible values are
:nullable,:required, and:repeated. The default value is:nullable. -
policy_tags (Array<String>, String) (defaults to: nil) — The policy tag list or
single policy tag for the field. Policy tag identifiers are of
the form
projects/*/locations/*/taxonomies/*/policyTags/*. At most 1 policy tag is currently allowed.
#timestamp?
def timestamp?() -> BooleanChecks if the type of the field is TIMESTAMP.
-
(Boolean) —
truewhenTIMESTAMP,falseotherwise.
#type
def type() -> StringThe data type of the field.
-
(String) —
The field data type. Possible values include:
BIGNUMERICBOOLBOOLEAN(same asBOOL)BYTESDATEDATETIMEFLOATFLOAT64(same asFLOAT)GEOGRAPHYINTEGERINT64(same asINTEGER)NUMERICRECORD(whereRECORDindicates that the field contains a nested schema)STRINGSTRUCT(same asRECORD)TIMETIMESTAMP
#type=
def type=(new_type)Updates the data type of the field.
-
new_type (String) —
The data type. Possible values include:
BIGNUMERICBOOLBOOLEAN(same asBOOL)BYTESDATEDATETIMEFLOATFLOAT64(same asFLOAT)GEOGRAPHYINTEGERINT64(same asINTEGER)NUMERICRECORD(whereRECORDindicates that the field contains a nested schema)STRINGSTRUCT(same asRECORD)TIMETIMESTAMP