Class: Google::Cloud::Bigquery::Table::Updater

Inherits:
Google::Cloud::Bigquery::Table show all
Defined in:
lib/google/cloud/bigquery/table.rb

Overview

Yielded to a block to accumulate changes for a create request. See Dataset#create_table.

Attributes collapse

Schema collapse

Methods inherited from Google::Cloud::Bigquery::Table

#api_url, #buffer_bytes, #buffer_oldest_at, #buffer_rows, #bytes_count, #clone, #clone?, #clone_definition, #clustering?, #clustering_fields, #created_at, #dataset_id, #description, #description=, #enable_refresh=, #enable_refresh?, #encryption, #encryption=, #etag, #exists?, #expires_at, #external=, #external?, #fields, #headers, #id, #labels, #labels=, #last_refresh_time, #location, #materialized_view?, #modified_at, #name, #name=, #param_types, #policy, #project_id, #query=, #query_id, #query_legacy_sql?, #query_standard_sql?, #query_udfs, #range_partitioning?, #range_partitioning_end, #range_partitioning_field, #range_partitioning_interval, #range_partitioning_start, #reference?, #refresh_interval_ms, #refresh_interval_ms=, #require_partition_filter, #require_partition_filter=, #resource?, #resource_full?, #resource_partial?, #restore, #rows_count, #set_query, #snapshot, #snapshot?, #snapshot_definition, #table?, #table_id, #test_iam_permissions, #time_partitioning?, #time_partitioning_expiration, #time_partitioning_expiration=, #time_partitioning_field, #time_partitioning_field=, #time_partitioning_type, #time_partitioning_type=, #type, #update_policy, #view?

Instance Method Details

#bignumeric(name, description: nil, mode: :nullable, policy_tags: nil, precision: nil, scale: nil, default_value_expression: nil) ⇒ Object

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.

See Schema#bignumeric

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
table = dataset.create_table "my_table" do |schema|
  schema.bignumeric "total_cost", mode: :required
end

Add field with default value.

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
table = dataset.create_table "my_table" do |schema|
  schema.bignumeric "total_cost", default_value_expression: "1.0e4"
end

Parameters:

  • 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.

  • default_value_expression (String) (defaults to: nil)

    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_TIMESTAMP CURRENT_TIME CURRENT_DATE CURRENT_DATETIME GENERATE_UUID RAND SESSION_USER ST_GEOPOINT
    • Struct or array composed with the above allowed functions, for example: "[CURRENT_DATE(), DATE '2020-01-01'"]


3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
# File 'lib/google/cloud/bigquery/table.rb', line 3863

def bignumeric name, description: nil, mode: :nullable, policy_tags: nil, precision: nil, scale: nil,
               default_value_expression: nil
  schema.bignumeric name,
                    description: description,
                    mode: mode,
                    policy_tags: policy_tags,
                    precision: precision,
                    scale: scale,
                    default_value_expression: default_value_expression
end

#boolean(name, description: nil, mode: :nullable, policy_tags: nil, default_value_expression: nil) ⇒ Object

Adds a boolean field to the schema.

See Schema#boolean.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
table = dataset.create_table "my_table" do |schema|
  schema.boolean "active", mode: :required
end

Add field with default value.

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
table = dataset.create_table "my_table" do |schema|
  schema.boolean "active", default_value_expression: "true"
end

Parameters:

  • 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.

  • default_value_expression (String) (defaults to: nil)

    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_TIMESTAMP CURRENT_TIME CURRENT_DATE CURRENT_DATETIME GENERATE_UUID RAND SESSION_USER ST_GEOPOINT
    • Struct or array composed with the above allowed functions, for example: "[CURRENT_DATE(), DATE '2020-01-01'"]


3927
3928
3929
3930
3931
# File 'lib/google/cloud/bigquery/table.rb', line 3927

def boolean name, description: nil, mode: :nullable, policy_tags: nil,
            default_value_expression: nil
  schema.boolean name, description: description, mode: mode, policy_tags: policy_tags,
                 default_value_expression: default_value_expression
end

#bytes(name, description: nil, mode: :nullable, policy_tags: nil, max_length: nil, default_value_expression: nil) ⇒ Object

Adds a bytes field to the schema.

See Schema#bytes.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
table = dataset.create_table "my_table" do |schema|
  schema.bytes "avatar", mode: :required
end

Add field with default value.

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
table = dataset.create_table "my_table" do |schema|
  schema.bytes "avatar", default_value_expression: "b'101'"
end

Parameters:

  • 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.

  • default_value_expression (String) (defaults to: nil)

    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_TIMESTAMP CURRENT_TIME CURRENT_DATE CURRENT_DATETIME GENERATE_UUID RAND SESSION_USER ST_GEOPOINT
    • Struct or array composed with the above allowed functions, for example: "[CURRENT_DATE(), DATE '2020-01-01'"]


3988
3989
3990
3991
3992
# File 'lib/google/cloud/bigquery/table.rb', line 3988

def bytes name, description: nil, mode: :nullable, policy_tags: nil, max_length: nil,
          default_value_expression: nil
  schema.bytes name, description: description, mode: mode, policy_tags: policy_tags, max_length: max_length,
               default_value_expression: default_value_expression
end

#clustering_fields=(fields) ⇒ Object

Sets the list of fields on which data should be clustered.

Only top-level, non-repeated, simple-type fields are supported. When you cluster a table using multiple columns, the order of columns you specify is important. The order of the specified columns determines the sort order of the data.

BigQuery supports clustering for both partitioned and non-partitioned tables.

See Google::Cloud::Bigquery::Table#clustering_fields and Google::Cloud::Bigquery::Table#clustering_fields=.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
table = dataset.create_table "my_table" do |t|
  t.schema do |schema|
    schema.timestamp "dob", mode: :required
    schema.string "first_name", mode: :required
    schema.string "last_name", mode: :required
  end
  t.time_partitioning_type  = "DAY"
  t.time_partitioning_field = "dob"
  t.clustering_fields = ["last_name", "first_name"]
end

Parameters:

  • fields (Array<String>)

    The clustering fields. Only top-level, non-repeated, simple-type fields are supported.

See Also:



3454
3455
3456
3457
3458
# File 'lib/google/cloud/bigquery/table.rb', line 3454

def clustering_fields= fields
  @gapi.clustering ||= Google::Apis::BigqueryV2::Clustering.new
  @gapi.clustering.fields = fields
  patch_gapi! :clustering
end

#copyObject

Raises:

  • (RuntimeError)

    not implemented



4430
4431
4432
# File 'lib/google/cloud/bigquery/table.rb', line 4430

def copy(*)
  raise "not implemented in #{self.class}"
end

#copy_jobObject

Raises:

  • (RuntimeError)

    not implemented



4424
4425
4426
# File 'lib/google/cloud/bigquery/table.rb', line 4424

def copy_job(*)
  raise "not implemented in #{self.class}"
end

#dataObject

Raises:

  • (RuntimeError)

    not implemented



4418
4419
4420
# File 'lib/google/cloud/bigquery/table.rb', line 4418

def data(*)
  raise "not implemented in #{self.class}"
end

#date(name, description: nil, mode: :nullable, policy_tags: nil, default_value_expression: nil) ⇒ Object

Adds a date field to the schema.

See Schema#date.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
table = dataset.create_table "my_table" do |schema|
  schema.date "birthday", mode: :required
end

Add field with default value.

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
table = dataset.create_table "my_table" do |schema|
   schema.date "birthday", default_value_expression: "CURRENT_DATE"
end

Parameters:

  • 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.

  • default_value_expression (String) (defaults to: nil)

    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_TIMESTAMP CURRENT_TIME CURRENT_DATE CURRENT_DATETIME GENERATE_UUID RAND SESSION_USER ST_GEOPOINT
    • Struct or array composed with the above allowed functions, for example: "[CURRENT_DATE(), DATE '2020-01-01'"]


4224
4225
4226
4227
4228
# File 'lib/google/cloud/bigquery/table.rb', line 4224

def date name, description: nil, mode: :nullable, policy_tags: nil,
         default_value_expression: nil
  schema.date name, description: description, mode: mode, policy_tags: policy_tags,
              default_value_expression: default_value_expression
end

#datetime(name, description: nil, mode: :nullable, policy_tags: nil, default_value_expression: nil) ⇒ Object

Adds a datetime field to the schema.

See Schema#datetime.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
table = dataset.create_table "my_table" do |schema|
  schema.datetime "target_end", mode: :required
end

Add field with default value.

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
table = dataset.create_table "my_table" do |schema|
  schema.datetime "target_end", default_value_expression: "CURRENT_DATETIME"
end

Parameters:

  • 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.

  • default_value_expression (String) (defaults to: nil)

    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_TIMESTAMP CURRENT_TIME CURRENT_DATE CURRENT_DATETIME GENERATE_UUID RAND SESSION_USER ST_GEOPOINT
    • Struct or array composed with the above allowed functions, for example: "[CURRENT_DATE(), DATE '2020-01-01'"]


4165
4166
4167
4168
4169
# File 'lib/google/cloud/bigquery/table.rb', line 4165

def datetime name, description: nil, mode: :nullable, policy_tags: nil,
             default_value_expression: nil
  schema.datetime name, description: description, mode: mode, policy_tags: policy_tags,
                  default_value_expression: default_value_expression
end

#deleteObject

Raises:

  • (RuntimeError)

    not implemented



4472
4473
4474
# File 'lib/google/cloud/bigquery/table.rb', line 4472

def delete
  raise "not implemented in #{self.class}"
end

#externalObject

Raises:

  • (RuntimeError)

    not implemented



4490
4491
4492
# File 'lib/google/cloud/bigquery/table.rb', line 4490

def external(*)
  raise "not implemented in #{self.class}"
end

#extractObject

Raises:

  • (RuntimeError)

    not implemented



4442
4443
4444
# File 'lib/google/cloud/bigquery/table.rb', line 4442

def extract(*)
  raise "not implemented in #{self.class}"
end

#extract_jobObject

Raises:

  • (RuntimeError)

    not implemented



4436
4437
4438
# File 'lib/google/cloud/bigquery/table.rb', line 4436

def extract_job(*)
  raise "not implemented in #{self.class}"
end

#float(name, description: nil, mode: :nullable, policy_tags: nil, default_value_expression: nil) ⇒ Object

Adds a floating-point number field to the schema.

See Schema#float.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
table = dataset.create_table "my_table" do |schema|
  schema.float "price", mode: :required
end

Add field with default value.

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
table = dataset.create_table "my_table" do |schema|
  schema.float "price", default_value_expression: "1.0"
end

Parameters:

  • 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.

  • default_value_expression (String) (defaults to: nil)

    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_TIMESTAMP CURRENT_TIME CURRENT_DATE CURRENT_DATETIME GENERATE_UUID RAND SESSION_USER ST_GEOPOINT
    • Struct or array composed with the above allowed functions, for example: "[CURRENT_DATE(), DATE '2020-01-01'"]


3698
3699
3700
3701
3702
# File 'lib/google/cloud/bigquery/table.rb', line 3698

def float name, description: nil, mode: :nullable, policy_tags: nil,
          default_value_expression: nil
  schema.float name, description: description, mode: mode, policy_tags: policy_tags,
               default_value_expression: default_value_expression
end

#geography(name, description: nil, mode: :nullable, policy_tags: nil, default_value_expression: nil) ⇒ Object

Adds a geography field to the schema.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
table = dataset.create_table "my_table" do |schema|
  schema.geography "home", mode: :required
end

Add field with default value.

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
table = dataset.create_table "my_table" do |schema|
  schema.geography "home", default_value_expression: "ST_GEOGPOINT(-122.084801, 37.422131)"
end

Parameters:

  • 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.

  • default_value_expression (String) (defaults to: nil)

    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_TIMESTAMP CURRENT_TIME CURRENT_DATE CURRENT_DATETIME GENERATE_UUID RAND SESSION_USER ST_GEOPOINT
    • Struct or array composed with the above allowed functions, for example: "[CURRENT_DATE(), DATE '2020-01-01'"]

See Also:



4282
4283
4284
4285
4286
# File 'lib/google/cloud/bigquery/table.rb', line 4282

def geography name, description: nil, mode: :nullable, policy_tags: nil,
              default_value_expression: nil
  schema.geography name, description: description, mode: mode, policy_tags: policy_tags,
                   default_value_expression: default_value_expression
end

#insertObject

Raises:

  • (RuntimeError)

    not implemented



4460
4461
4462
# File 'lib/google/cloud/bigquery/table.rb', line 4460

def insert(*)
  raise "not implemented in #{self.class}"
end

#insert_asyncObject

Raises:

  • (RuntimeError)

    not implemented



4466
4467
4468
# File 'lib/google/cloud/bigquery/table.rb', line 4466

def insert_async(*)
  raise "not implemented in #{self.class}"
end

#integer(name, description: nil, mode: :nullable, policy_tags: nil, default_value_expression: nil) ⇒ Object

Adds an integer field to the schema.

See Schema#integer.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
table = dataset.create_table "my_table" do |schema|
  schema.integer "age", mode: :required
end

Add field with default value.

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
table = dataset.create_table "my_table" do |schema|
  schema.integer "age", default_value_expression: "1"
end

Parameters:

  • 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.

  • default_value_expression (String) (defaults to: nil)

    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_TIMESTAMP CURRENT_TIME CURRENT_DATE CURRENT_DATETIME GENERATE_UUID RAND SESSION_USER ST_GEOPOINT
    • Struct or array composed with the above allowed functions, for example: "[CURRENT_DATE(), DATE '2020-01-01'"]


3639
3640
3641
3642
3643
# File 'lib/google/cloud/bigquery/table.rb', line 3639

def integer name, description: nil, mode: :nullable, policy_tags: nil,
            default_value_expression: nil
  schema.integer name, description: description, mode: mode, policy_tags: policy_tags,
                 default_value_expression: default_value_expression
end

#json(name, description: nil, mode: :nullable, policy_tags: nil, default_value_expression: nil) ⇒ Object

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
table = dataset.create_table "my_table" do |schema|
  schema.json "person", mode: :required
end

Add field with default value.

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
table = dataset.create_table "my_table" do |schema|
  schema.json "person", default_value_expression: "JSON '{"name": "Alice", "age": 30}'"
end

Parameters:

  • 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.

  • default_value_expression (String) (defaults to: nil)

    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_TIMESTAMP CURRENT_TIME CURRENT_DATE CURRENT_DATETIME GENERATE_UUID RAND SESSION_USER ST_GEOPOINT
    • Struct or array composed with the above allowed functions, for example: "[CURRENT_DATE(), DATE '2020-01-01'"]


4342
4343
4344
4345
4346
# File 'lib/google/cloud/bigquery/table.rb', line 4342

def json name, description: nil, mode: :nullable, policy_tags: nil,
         default_value_expression: nil
  schema.json name, description: description, mode: mode, policy_tags: policy_tags,
              default_value_expression: default_value_expression
end

#loadObject

Raises:

  • (RuntimeError)

    not implemented



4454
4455
4456
# File 'lib/google/cloud/bigquery/table.rb', line 4454

def load(*)
  raise "not implemented in #{self.class}"
end

#load_jobObject

Raises:

  • (RuntimeError)

    not implemented



4448
4449
4450
# File 'lib/google/cloud/bigquery/table.rb', line 4448

def load_job(*)
  raise "not implemented in #{self.class}"
end

#numeric(name, description: nil, mode: :nullable, policy_tags: nil, precision: nil, scale: nil, default_value_expression: nil) ⇒ Object

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.

See Schema#numeric

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
table = dataset.create_table "my_table" do |schema|
  schema.numeric "total_cost", mode: :required
end

Add field with default value.

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
table = dataset.create_table "my_table" do |schema|
  schema.numeric "total_cost", default_value_expression: "1.0e4"
end

Parameters:

  • 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.

  • default_value_expression (String) (defaults to: nil)

    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_TIMESTAMP CURRENT_TIME CURRENT_DATE CURRENT_DATETIME GENERATE_UUID RAND SESSION_USER ST_GEOPOINT
    • Struct or array composed with the above allowed functions, for example: "[CURRENT_DATE(), DATE '2020-01-01'"]


3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
# File 'lib/google/cloud/bigquery/table.rb', line 3778

def numeric name, description: nil, mode: :nullable, policy_tags: nil, precision: nil, scale: nil,
            default_value_expression: nil
  schema.numeric name,
                 description: description,
                 mode: mode,
                 policy_tags: policy_tags,
                 precision: precision,
                 scale: scale,
                 default_value_expression: default_value_expression
end

#queryObject

Raises:

  • (RuntimeError)

    not implemented



4484
4485
4486
# File 'lib/google/cloud/bigquery/table.rb', line 4484

def query(*)
  raise "not implemented in #{self.class}"
end

#query_jobObject

Raises:

  • (RuntimeError)

    not implemented



4478
4479
4480
# File 'lib/google/cloud/bigquery/table.rb', line 4478

def query_job(*)
  raise "not implemented in #{self.class}"
end

#range_partitioning_end=(range_end) ⇒ Object

Sets the end of range partitioning, exclusive, for the table. See Creating and using integer range partitioned tables.

You can only set range partitioning when creating a table as in the example below. BigQuery does not allow you to change partitioning on an existing table.

See #range_partitioning_start=, #range_partitioning_interval= and #range_partitioning_field=.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"

table = dataset.create_table "my_table" do |t|
  t.schema do |schema|
    schema.integer "my_table_id", mode: :required
    schema.string "my_table_data", mode: :required
  end
  t.range_partitioning_field = "my_table_id"
  t.range_partitioning_start = 0
  t.range_partitioning_interval = 10
  t.range_partitioning_end = 100
end

Parameters:

  • range_end (Integer)

    The end of range partitioning, exclusive.



3406
3407
3408
3409
3410
3411
3412
3413
# File 'lib/google/cloud/bigquery/table.rb', line 3406

def range_partitioning_end= range_end
  reload! unless resource_full?
  @gapi.range_partitioning ||= Google::Apis::BigqueryV2::RangePartitioning.new(
    range: Google::Apis::BigqueryV2::RangePartitioning::Range.new
  )
  @gapi.range_partitioning.range.end = range_end
  patch_gapi! :range_partitioning
end

#range_partitioning_field=(field) ⇒ Object

Sets the field on which to range partition the table. See Creating and using integer range partitioned tables.

See #range_partitioning_start=, #range_partitioning_interval= and #range_partitioning_end=.

You can only set range partitioning when creating a table as in the example below. BigQuery does not allow you to change partitioning on an existing table.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"

table = dataset.create_table "my_table" do |t|
  t.schema do |schema|
    schema.integer "my_table_id", mode: :required
    schema.string "my_table_data", mode: :required
  end
  t.range_partitioning_field = "my_table_id"
  t.range_partitioning_start = 0
  t.range_partitioning_interval = 10
  t.range_partitioning_end = 100
end

Parameters:

  • field (String)

    The range partition field. The table is partitioned by this field. The field must be a top-level NULLABLE/REQUIRED field. The only supported type is INTEGER/INT64.



3286
3287
3288
3289
3290
3291
3292
3293
# File 'lib/google/cloud/bigquery/table.rb', line 3286

def range_partitioning_field= field
  reload! unless resource_full?
  @gapi.range_partitioning ||= Google::Apis::BigqueryV2::RangePartitioning.new(
    range: Google::Apis::BigqueryV2::RangePartitioning::Range.new
  )
  @gapi.range_partitioning.field = field
  patch_gapi! :range_partitioning
end

#range_partitioning_interval=(range_interval) ⇒ Object

Sets width of each interval for data in range partitions. See Creating and using integer range partitioned tables.

You can only set range partitioning when creating a table as in the example below. BigQuery does not allow you to change partitioning on an existing table.

See #range_partitioning_field=, #range_partitioning_start= and #range_partitioning_end=.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"

table = dataset.create_table "my_table" do |t|
  t.schema do |schema|
    schema.integer "my_table_id", mode: :required
    schema.string "my_table_data", mode: :required
  end
  t.range_partitioning_field = "my_table_id"
  t.range_partitioning_start = 0
  t.range_partitioning_interval = 10
  t.range_partitioning_end = 100
end

Parameters:

  • range_interval (Integer)

    The width of each interval, for data in partitions.



3366
3367
3368
3369
3370
3371
3372
3373
# File 'lib/google/cloud/bigquery/table.rb', line 3366

def range_partitioning_interval= range_interval
  reload! unless resource_full?
  @gapi.range_partitioning ||= Google::Apis::BigqueryV2::RangePartitioning.new(
    range: Google::Apis::BigqueryV2::RangePartitioning::Range.new
  )
  @gapi.range_partitioning.range.interval = range_interval
  patch_gapi! :range_partitioning
end

#range_partitioning_start=(range_start) ⇒ Object

Sets the start of range partitioning, inclusive, for the table. See Creating and using integer range partitioned tables.

You can only set range partitioning when creating a table as in the example below. BigQuery does not allow you to change partitioning on an existing table.

See #range_partitioning_field=, #range_partitioning_interval= and #range_partitioning_end=.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"

table = dataset.create_table "my_table" do |t|
  t.schema do |schema|
    schema.integer "my_table_id", mode: :required
    schema.string "my_table_data", mode: :required
  end
  t.range_partitioning_field = "my_table_id"
  t.range_partitioning_start = 0
  t.range_partitioning_interval = 10
  t.range_partitioning_end = 100
end

Parameters:

  • range_start (Integer)

    The start of range partitioning, inclusive.



3326
3327
3328
3329
3330
3331
3332
3333
# File 'lib/google/cloud/bigquery/table.rb', line 3326

def range_partitioning_start= range_start
  reload! unless resource_full?
  @gapi.range_partitioning ||= Google::Apis::BigqueryV2::RangePartitioning.new(
    range: Google::Apis::BigqueryV2::RangePartitioning::Range.new
  )
  @gapi.range_partitioning.range.start = range_start
  patch_gapi! :range_partitioning
end

#record(name, description: nil, mode: nil, default_value_expression: nil) {|nested_schema| ... } ⇒ Object

Adds a record field to the schema. A block must be passed describing the nested fields of the record. For more information about nested and repeated records, see Loading denormalized, nested, and repeated data .

See Schema#record.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
table = dataset.create_table "my_table" do |schema|
  schema.record "cities_lived", mode: :repeated do |cities_lived|
    cities_lived.string "place", mode: :required
    cities_lived.integer "number_of_years", mode: :required
  end
end

Add field with default value.

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
table = dataset.create_table "my_table" do |schema|
  schema.record "cities_lived", mode: :repeated, "[STRUCT('place',10)]" do |cities_lived|
    cities_lived.string "place", mode: :required
    cities_lived.integer "number_of_years", mode: :required
  end
end

Parameters:

  • 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.

  • default_value_expression (String) (defaults to: nil)

    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_TIMESTAMP CURRENT_TIME CURRENT_DATE CURRENT_DATETIME GENERATE_UUID RAND SESSION_USER ST_GEOPOINT
    • Struct or array composed with the above allowed functions, for example: "[CURRENT_DATE(), DATE '2020-01-01'"]

Yields:

  • (nested_schema)

    a block for setting the nested schema

Yield Parameters:

  • nested_schema (Schema)

    the object accepting the nested schema



4411
4412
4413
4414
# File 'lib/google/cloud/bigquery/table.rb', line 4411

def record name, description: nil, mode: nil, default_value_expression: nil, &block
  schema.record name, description: description, mode: mode,
                default_value_expression: default_value_expression, &block
end

#reload!Object Also known as: refresh!

Raises:

  • (RuntimeError)

    not implemented



4496
4497
4498
# File 'lib/google/cloud/bigquery/table.rb', line 4496

def reload!
  raise "not implemented in #{self.class}"
end

#schema(replace: false) {|schema| ... } ⇒ Google::Cloud::Bigquery::Schema

Returns the table's schema. This method can also be used to set, replace, or add to the schema by passing a block. See Schema for available methods.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
table = dataset.create_table "my_table" do |t|
  t.name = "My Table"
  t.description = "A description of my table."
  t.schema do |s|
    s.string "first_name", mode: :required
    s.record "cities_lived", mode: :repeated do |r|
      r.string "place", mode: :required
      r.integer "number_of_years", mode: :required
    end
  end
end

Load the schema from a file

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
table = dataset.create_table "my_table" do |t|
  t.name = "My Table"
  t.description = "A description of my table."
  t.schema do |s|
    s.load File.open("schema.json")
  end
end

Parameters:

  • replace (Boolean) (defaults to: false)

    Whether to replace the existing schema with the new schema. If true, the fields will replace the existing schema. If false, the fields will be added to the existing schema. When a table already contains data, schema changes must be additive. Thus, the default value is false. When loading from a file this will always replace the schema, no matter what replace is set to. You can update the schema (for example, for a table that already contains data) by providing a schema file that includes the existing schema plus any new fields.

Yields:

  • (schema)

    a block for setting the schema

Yield Parameters:

  • schema (Schema)

    the object accepting the schema

Returns:



3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
# File 'lib/google/cloud/bigquery/table.rb', line 3512

def schema replace: false
  # Same as Table#schema, but not frozen
  # TODO: make sure to call ensure_full_data! on Dataset#update
  @schema ||= Schema.from_gapi @gapi.schema
  if block_given?
    @schema = Schema.from_gapi if replace
    yield @schema
    check_for_mutated_schema!
  end
  # Do not freeze on updater, allow modifications
  @schema
end

#string(name, description: nil, mode: :nullable, policy_tags: nil, max_length: nil, default_value_expression: nil) ⇒ Object

Adds a string field to the schema.

See Schema#string.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
table = dataset.create_table "my_table" do |schema|
  schema.string "first_name", mode: :required
end

Add field with default value.

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
table = dataset.create_table "my_table" do |schema|
  schema.string "first_name", default_value_expression: "'name'"
end

Parameters:

  • 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.

  • default_value_expression (String) (defaults to: nil)

    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_TIMESTAMP CURRENT_TIME CURRENT_DATE CURRENT_DATETIME GENERATE_UUID RAND SESSION_USER ST_GEOPOINT
    • Struct or array composed with the above allowed functions, for example: "[CURRENT_DATE(), DATE '2020-01-01'"]


3580
3581
3582
3583
3584
# File 'lib/google/cloud/bigquery/table.rb', line 3580

def string name, description: nil, mode: :nullable, policy_tags: nil, max_length: nil,
           default_value_expression: nil
  schema.string name, description: description, mode: mode, policy_tags: policy_tags, max_length: max_length,
                default_value_expression: default_value_expression
end

#time(name, description: nil, mode: :nullable, policy_tags: nil, default_value_expression: nil) ⇒ Object

Adds a time field to the schema.

See Schema#time.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
table = dataset.create_table "my_table" do |schema|
  schema.time "duration", mode: :required
end

Add field with default value.

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
table = dataset.create_table "my_table" do |schema|
  schema.time "duration", default_value_expression: "CURRENT_TIME"
end

Parameters:

  • 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.

  • default_value_expression (String) (defaults to: nil)

    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_TIMESTAMP CURRENT_TIME CURRENT_DATE CURRENT_DATETIME GENERATE_UUID RAND SESSION_USER ST_GEOPOINT
    • Struct or array composed with the above allowed functions, for example: "[CURRENT_DATE(), DATE '2020-01-01'"]


4106
4107
4108
4109
4110
# File 'lib/google/cloud/bigquery/table.rb', line 4106

def time name, description: nil, mode: :nullable, policy_tags: nil,
         default_value_expression: nil
  schema.time name, description: description, mode: mode, policy_tags: policy_tags,
              default_value_expression: default_value_expression
end

#timestamp(name, description: nil, mode: :nullable, policy_tags: nil, default_value_expression: nil) ⇒ Object

Adds a timestamp field to the schema.

See Schema#timestamp.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
table = dataset.create_table "my_table" do |schema|
  schema.timestamp "creation_date", mode: :required
end

Add field with default value.

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
table = dataset.create_table "my_table" do |schema|
  schema.timestamp "creation_date", default_value_expression: "CURRENT_TIMESTAMP"
end

Parameters:

  • 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.

  • default_value_expression (String) (defaults to: nil)

    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_TIMESTAMP CURRENT_TIME CURRENT_DATE CURRENT_DATETIME GENERATE_UUID RAND SESSION_USER ST_GEOPOINT
    • Struct or array composed with the above allowed functions, for example: "[CURRENT_DATE(), DATE '2020-01-01'"]


4047
4048
4049
4050
4051
# File 'lib/google/cloud/bigquery/table.rb', line 4047

def timestamp name, description: nil, mode: :nullable, policy_tags: nil,
              default_value_expression: nil
  schema.timestamp name, description: description, mode: mode, policy_tags: policy_tags,
                   default_value_expression: default_value_expression
end