class Google::Cloud::Bigquery::Table::Updater

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

Attributes

updates[R]

@private A list of attributes that were updated.

Public Class Methods

new(gapi) click to toggle source

@private Create an Updater object.

Calls superclass method Google::Cloud::Bigquery::Table::new
# File lib/google/cloud/bigquery/table.rb, line 2952
def initialize gapi
  super()
  @updates = []
  @gapi = gapi
  @schema = nil
end

Public Instance Methods

bignumeric(name, description: nil, mode: :nullable, policy_tags: nil, precision: nil, scale: nil) click to toggle source

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}

@param [String] name The field name. The name must contain only

letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
start with a letter or underscore. The maximum length is 128
characters.

@param [String] description A description of the field. @param [Symbol] mode The field's mode. The possible values are

`:nullable`, `:required`, and `:repeated`. The default value is
`:nullable`.

@param [Array<String>, String] policy_tags 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.

@param [Integer] precision 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.

@param [Integer] scale 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.

@example

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

@!group Schema

# File lib/google/cloud/bigquery/table.rb, line 3436
def bignumeric name, description: nil, mode: :nullable, policy_tags: nil, precision: nil, scale: nil
  schema.bignumeric name,
                    description: description,
                    mode: mode,
                    policy_tags: policy_tags,
                    precision: precision,
                    scale: scale
end
boolean(name, description: nil, mode: :nullable, policy_tags: nil) click to toggle source

Adds a boolean field to the schema.

See {Schema#boolean}.

@param [String] name The field name. The name must contain only

letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
start with a letter or underscore. The maximum length is 128
characters.

@param [String] description A description of the field. @param [Symbol] mode The field's mode. The possible values are

`:nullable`, `:required`, and `:repeated`. The default value is
`:nullable`.

@param [Array<String>, String] policy_tags 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.

@example

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

@!group Schema

# File lib/google/cloud/bigquery/table.rb, line 3473
def boolean name, description: nil, mode: :nullable, policy_tags: nil
  schema.boolean name, description: description, mode: mode, policy_tags: policy_tags
end
bytes(name, description: nil, mode: :nullable, policy_tags: nil, max_length: nil) click to toggle source

Adds a bytes field to the schema.

See {Schema#bytes}.

@param [String] name The field name. The name must contain only

letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
start with a letter or underscore. The maximum length is 128
characters.

@param [String] description A description of the field. @param [Symbol] mode The field's mode. The possible values are

`:nullable`, `:required`, and `:repeated`. The default value is
`:nullable`.

@param [Array<String>, String] policy_tags 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.

@param [Integer] max_length The maximum the maximum number of

bytes in the field.

@example

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

@!group Schema

# File lib/google/cloud/bigquery/table.rb, line 3507
def bytes name, description: nil, mode: :nullable, policy_tags: nil, max_length: nil
  schema.bytes name, description: description, mode: mode, policy_tags: policy_tags, max_length: max_length
end
check_for_mutated_schema!() click to toggle source

@private Make sure any access changes are saved

# File lib/google/cloud/bigquery/table.rb, line 3800
def check_for_mutated_schema!
  return if @schema.nil?
  return unless @schema.changed?
  @gapi.schema = @schema.to_gapi
  patch_gapi! :schema
end
clustering_fields=(fields) click to toggle source

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 {Table#clustering_fields} and {Table#clustering_fields=}.

@see cloud.google.com/bigquery/docs/clustered-tables

Introduction to clustered tables

@see cloud.google.com/bigquery/docs/creating-clustered-tables

Creating and using clustered tables

@param [Array<String>] fields The clustering fields. Only top-level,

non-repeated, simple-type fields are supported.

@example

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

@!group Attributes

# File lib/google/cloud/bigquery/table.rb, line 3160
def clustering_fields= fields
  @gapi.clustering ||= Google::Apis::BigqueryV2::Clustering.new
  @gapi.clustering.fields = fields
  patch_gapi! :clustering
end
copy(*) click to toggle source

@raise [RuntimeError] not implemented

# File lib/google/cloud/bigquery/table.rb, line 3725
def copy(*)
  raise "not implemented in #{self.class}"
end
copy_job(*) click to toggle source

@raise [RuntimeError] not implemented

# File lib/google/cloud/bigquery/table.rb, line 3719
def copy_job(*)
  raise "not implemented in #{self.class}"
end
data(*) click to toggle source

@raise [RuntimeError] not implemented

# File lib/google/cloud/bigquery/table.rb, line 3713
def data(*)
  raise "not implemented in #{self.class}"
end
date(name, description: nil, mode: :nullable, policy_tags: nil) click to toggle source

Adds a date field to the schema.

See {Schema#date}.

@param [String] name The field name. The name must contain only

letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
start with a letter or underscore. The maximum length is 128
characters.

@param [String] description A description of the field. @param [Symbol] mode The field's mode. The possible values are

`:nullable`, `:required`, and `:repeated`. The default value is
`:nullable`.

@param [Array<String>, String] policy_tags 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.

@example

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

@!group Schema

# File lib/google/cloud/bigquery/table.rb, line 3635
def date name, description: nil, mode: :nullable, policy_tags: nil
  schema.date name, description: description, mode: mode, policy_tags: policy_tags
end
datetime(name, description: nil, mode: :nullable, policy_tags: nil) click to toggle source

Adds a datetime field to the schema.

See {Schema#datetime}.

@param [String] name The field name. The name must contain only

letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
start with a letter or underscore. The maximum length is 128
characters.

@param [String] description A description of the field. @param [Symbol] mode The field's mode. The possible values are

`:nullable`, `:required`, and `:repeated`. The default value is
`:nullable`.

@param [Array<String>, String] policy_tags 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.

@example

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

@!group Schema

# File lib/google/cloud/bigquery/table.rb, line 3603
def datetime name, description: nil, mode: :nullable, policy_tags: nil
  schema.datetime name, description: description, mode: mode, policy_tags: policy_tags
end
delete() click to toggle source

@raise [RuntimeError] not implemented

# File lib/google/cloud/bigquery/table.rb, line 3767
def delete
  raise "not implemented in #{self.class}"
end
external(*) click to toggle source

@raise [RuntimeError] not implemented

# File lib/google/cloud/bigquery/table.rb, line 3785
def external(*)
  raise "not implemented in #{self.class}"
end
extract(*) click to toggle source

@raise [RuntimeError] not implemented

# File lib/google/cloud/bigquery/table.rb, line 3737
def extract(*)
  raise "not implemented in #{self.class}"
end
extract_job(*) click to toggle source

@raise [RuntimeError] not implemented

# File lib/google/cloud/bigquery/table.rb, line 3731
def extract_job(*)
  raise "not implemented in #{self.class}"
end
float(name, description: nil, mode: :nullable, policy_tags: nil) click to toggle source

Adds a floating-point number field to the schema.

See {Schema#float}.

@param [String] name The field name. The name must contain only

letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
start with a letter or underscore. The maximum length is 128
characters.

@param [String] description A description of the field. @param [Symbol] mode The field's mode. The possible values are

`:nullable`, `:required`, and `:repeated`. The default value is
`:nullable`.

@param [Array<String>, String] policy_tags 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.

@example

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

@!group Schema

# File lib/google/cloud/bigquery/table.rb, line 3325
def float name, description: nil, mode: :nullable, policy_tags: nil
  schema.float name, description: description, mode: mode, policy_tags: policy_tags
end
geography(name, description: nil, mode: :nullable, policy_tags: nil) click to toggle source

Adds a geography field to the schema.

@see cloud.google.com/bigquery/docs/gis-data Working with BigQuery GIS data

@param [String] name The field name. The name must contain only

letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
start with a letter or underscore. The maximum length is 128
characters.

@param [String] description A description of the field. @param [Symbol] mode The field's mode. The possible values are

`:nullable`, `:required`, and `:repeated`. The default value is
`:nullable`.

@param [Array<String>, String] policy_tags 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.

@example

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
# File lib/google/cloud/bigquery/table.rb, line 3666
def geography name, description: nil, mode: :nullable, policy_tags: nil
  schema.geography name, description: description, mode: mode, policy_tags: policy_tags
end
insert(*) click to toggle source

@raise [RuntimeError] not implemented

# File lib/google/cloud/bigquery/table.rb, line 3755
def insert(*)
  raise "not implemented in #{self.class}"
end
insert_async(*) click to toggle source

@raise [RuntimeError] not implemented

# File lib/google/cloud/bigquery/table.rb, line 3761
def insert_async(*)
  raise "not implemented in #{self.class}"
end
integer(name, description: nil, mode: :nullable, policy_tags: nil) click to toggle source

Adds an integer field to the schema.

See {Schema#integer}.

@param [String] name The field name. The name must contain only

letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
start with a letter or underscore. The maximum length is 128
characters.

@param [String] description A description of the field. @param [Symbol] mode The field's mode. The possible values are

`:nullable`, `:required`, and `:repeated`. The default value is
`:nullable`.

@param [Array<String>, String] policy_tags 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.

@example

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

@!group Schema

# File lib/google/cloud/bigquery/table.rb, line 3293
def integer name, description: nil, mode: :nullable, policy_tags: nil
  schema.integer name, description: description, mode: mode, policy_tags: policy_tags
end
load(*) click to toggle source

@raise [RuntimeError] not implemented

# File lib/google/cloud/bigquery/table.rb, line 3749
def load(*)
  raise "not implemented in #{self.class}"
end
load_job(*) click to toggle source

@raise [RuntimeError] not implemented

# File lib/google/cloud/bigquery/table.rb, line 3743
def load_job(*)
  raise "not implemented in #{self.class}"
end
numeric(name, description: nil, mode: :nullable, policy_tags: nil, precision: nil, scale: nil) click to toggle source

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}

@param [String] name The field name. The name must contain only

letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
start with a letter or underscore. The maximum length is 128
characters.

@param [String] description A description of the field. @param [Symbol] mode The field's mode. The possible values are

`:nullable`, `:required`, and `:repeated`. The default value is
`:nullable`.

@param [Array<String>, String] policy_tags 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.

@param [Integer] precision 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.

@param [Integer] scale 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.

@example

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

@!group Schema

# File lib/google/cloud/bigquery/table.rb, line 3378
def numeric name, description: nil, mode: :nullable, policy_tags: nil, precision: nil, scale: nil
  schema.numeric name,
                 description: description,
                 mode: mode,
                 policy_tags: policy_tags,
                 precision: precision,
                 scale: scale
end
query(*) click to toggle source

@raise [RuntimeError] not implemented

# File lib/google/cloud/bigquery/table.rb, line 3779
def query(*)
  raise "not implemented in #{self.class}"
end
query_job(*) click to toggle source

@raise [RuntimeError] not implemented

# File lib/google/cloud/bigquery/table.rb, line 3773
def query_job(*)
  raise "not implemented in #{self.class}"
end
range_partitioning_end=(range_end) click to toggle source

Sets the end of range partitioning, exclusive, for the table. See [Creating and using integer range partitioned tables](cloud.google.com/bigquery/docs/creating-integer-range-partitions).

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 {Table::Updater#range_partitioning_start=}, {Table::Updater#range_partitioning_interval=} and {Table::Updater#range_partitioning_field=}.

@param [Integer] range_end The end of range partitioning, exclusive.

@example

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

@!group Attributes

# File lib/google/cloud/bigquery/table.rb, line 3112
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) click to toggle source

Sets the field on which to range partition the table. See [Creating and using integer range partitioned tables](cloud.google.com/bigquery/docs/creating-integer-range-partitions).

See {Table::Updater#range_partitioning_start=}, {Table::Updater#range_partitioning_interval=} and {Table::Updater#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.

@param [String] field 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`.

@example

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

@!group Attributes

# File lib/google/cloud/bigquery/table.rb, line 2992
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) click to toggle source

Sets width of each interval for data in range partitions. See [Creating and using integer range partitioned tables](cloud.google.com/bigquery/docs/creating-integer-range-partitions).

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 {Table::Updater#range_partitioning_field=}, {Table::Updater#range_partitioning_start=} and {Table::Updater#range_partitioning_end=}.

@param [Integer] range_interval The width of each interval, for data in partitions.

@example

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

@!group Attributes

# File lib/google/cloud/bigquery/table.rb, line 3072
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) click to toggle source

Sets the start of range partitioning, inclusive, for the table. See [Creating and using integer range partitioned tables](cloud.google.com/bigquery/docs/creating-integer-range-partitions).

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 {Table::Updater#range_partitioning_field=}, {Table::Updater#range_partitioning_interval=} and {Table::Updater#range_partitioning_end=}.

@param [Integer] range_start The start of range partitioning, inclusive.

@example

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

@!group Attributes

# File lib/google/cloud/bigquery/table.rb, line 3032
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, &block) click to toggle source

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 ](cloud.google.com/bigquery/docs/loading-data#loading_denormalized_nested_and_repeated_data).

See {Schema#record}.

@param [String] name The field name. The name must contain only

letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
start with a letter or underscore. The maximum length is 128
characters.

@param [String] description A description of the field. @param [Symbol] mode The field's mode. The possible values are

`:nullable`, `:required`, and `:repeated`. The default value is
`:nullable`.

@yield [nested_schema] a block for setting the nested schema @yieldparam [Schema] nested_schema the object accepting the

nested schema

@example

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

@!group Schema

# File lib/google/cloud/bigquery/table.rb, line 3705
def record name, description: nil, mode: nil, &block
  schema.record name, description: description, mode: mode, &block
end
refresh!()
Alias for: reload!
reload!() click to toggle source

@raise [RuntimeError] not implemented

# File lib/google/cloud/bigquery/table.rb, line 3791
def reload!
  raise "not implemented in #{self.class}"
end
Also aliased as: refresh!
schema(replace: false) { |schema| ... } click to toggle source

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.

@param [Boolean] replace 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.

@yield [schema] a block for setting the schema @yieldparam [Schema] schema the object accepting the schema

@return [Google::Cloud::Bigquery::Schema]

@example

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

@example 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

@!group Schema

# File lib/google/cloud/bigquery/table.rb, line 3218
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) click to toggle source

Adds a string field to the schema.

See {Schema#string}.

@param [String] name The field name. The name must contain only

letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
start with a letter or underscore. The maximum length is 128
characters.

@param [String] description A description of the field. @param [Symbol] mode The field's mode. The possible values are

`:nullable`, `:required`, and `:repeated`. The default value is
`:nullable`.

@param [Array<String>, String] policy_tags 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.

@param [Integer] max_length The maximum UTF-8 length of strings

allowed in the field.

@example

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

@!group Schema

# File lib/google/cloud/bigquery/table.rb, line 3261
def string name, description: nil, mode: :nullable, policy_tags: nil, max_length: nil
  schema.string name, description: description, mode: mode, policy_tags: policy_tags, max_length: max_length
end
time(name, description: nil, mode: :nullable, policy_tags: nil) click to toggle source

Adds a time field to the schema.

See {Schema#time}.

@param [String] name The field name. The name must contain only

letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
start with a letter or underscore. The maximum length is 128
characters.

@param [String] description A description of the field. @param [Symbol] mode The field's mode. The possible values are

`:nullable`, `:required`, and `:repeated`. The default value is
`:nullable`.

@param [Array<String>, String] policy_tags 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.

@example

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

@!group Schema

# File lib/google/cloud/bigquery/table.rb, line 3571
def time name, description: nil, mode: :nullable, policy_tags: nil
  schema.time name, description: description, mode: mode, policy_tags: policy_tags
end
timestamp(name, description: nil, mode: :nullable, policy_tags: nil) click to toggle source

Adds a timestamp field to the schema.

See {Schema#timestamp}.

@param [String] name The field name. The name must contain only

letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
start with a letter or underscore. The maximum length is 128
characters.

@param [String] description A description of the field. @param [Symbol] mode The field's mode. The possible values are

`:nullable`, `:required`, and `:repeated`. The default value is
`:nullable`.

@param [Array<String>, String] policy_tags 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.

@example

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

@!group Schema

# File lib/google/cloud/bigquery/table.rb, line 3539
def timestamp name, description: nil, mode: :nullable, policy_tags: nil
  schema.timestamp name, description: description, mode: mode, policy_tags: policy_tags
end
to_gapi() click to toggle source

@private

# File lib/google/cloud/bigquery/table.rb, line 3809
def to_gapi
  check_for_mutated_schema!
  @gapi
end

Protected Instance Methods

ensure_full_data!() click to toggle source

Change to a NOOP

# File lib/google/cloud/bigquery/table.rb, line 3818
def ensure_full_data!
  # Do nothing because we trust the gapi is full before we get here.
end
patch_gapi!(attribute) click to toggle source

Queue up all the updates instead of making them.

# File lib/google/cloud/bigquery/table.rb, line 3824
def patch_gapi! attribute
  @updates << attribute
  @updates.uniq!
end