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, #clustering?, #clustering_fields, #created_at, #dataset_id, #description, #description=, #encryption, #encryption=, #etag, #exists?, #expires_at, #external=, #external?, #fields, #headers, #id, #labels, #labels=, #location, #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?, #require_partition_filter, #require_partition_filter=, #resource?, #resource_full?, #resource_partial?, #rows_count, #set_query, #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=, #update_policy, #view?

Instance Method Details

#boolean(name, description: nil, mode: :nullable) ⇒ 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

Parameters:

  • name (String)

    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.

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



3171
3172
3173
# File 'lib/google/cloud/bigquery/table.rb', line 3171

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

#bytes(name, description: nil, mode: :nullable) ⇒ 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

Parameters:

  • name (String)

    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.

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



3199
3200
3201
# File 'lib/google/cloud/bigquery/table.rb', line 3199

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

#clustering_fields=(fields) ⇒ Object

Sets one or more fields on which data should be clustered. Must be specified with time-based partitioning, data in the table will be first partitioned and subsequently 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.

You can only set the clustering fields while creating a table as in the example below. BigQuery does not allow you to change clustering on an existing table.

See 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:



2962
2963
2964
2965
2966
# File 'lib/google/cloud/bigquery/table.rb', line 2962

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

#copyObject

Raises:

  • (RuntimeError)

    not implemented



3370
3371
3372
# File 'lib/google/cloud/bigquery/table.rb', line 3370

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

#copy_jobObject

Raises:

  • (RuntimeError)

    not implemented



3364
3365
3366
# File 'lib/google/cloud/bigquery/table.rb', line 3364

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

#dataObject

Raises:

  • (RuntimeError)

    not implemented



3358
3359
3360
# File 'lib/google/cloud/bigquery/table.rb', line 3358

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

#date(name, description: nil, mode: :nullable) ⇒ 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

Parameters:

  • name (String)

    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.

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



3311
3312
3313
# File 'lib/google/cloud/bigquery/table.rb', line 3311

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

#datetime(name, description: nil, mode: :nullable) ⇒ 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

Parameters:

  • name (String)

    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.

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



3283
3284
3285
# File 'lib/google/cloud/bigquery/table.rb', line 3283

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

#deleteObject

Raises:

  • (RuntimeError)

    not implemented



3412
3413
3414
# File 'lib/google/cloud/bigquery/table.rb', line 3412

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

#externalObject

Raises:

  • (RuntimeError)

    not implemented



3430
3431
3432
# File 'lib/google/cloud/bigquery/table.rb', line 3430

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

#extractObject

Raises:

  • (RuntimeError)

    not implemented



3382
3383
3384
# File 'lib/google/cloud/bigquery/table.rb', line 3382

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

#extract_jobObject

Raises:

  • (RuntimeError)

    not implemented



3376
3377
3378
# File 'lib/google/cloud/bigquery/table.rb', line 3376

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

#float(name, description: nil, mode: :nullable) ⇒ 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

Parameters:

  • name (String)

    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.

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



3113
3114
3115
# File 'lib/google/cloud/bigquery/table.rb', line 3113

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

#insertObject

Raises:

  • (RuntimeError)

    not implemented



3400
3401
3402
# File 'lib/google/cloud/bigquery/table.rb', line 3400

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

#insert_asyncObject

Raises:

  • (RuntimeError)

    not implemented



3406
3407
3408
# File 'lib/google/cloud/bigquery/table.rb', line 3406

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

#integer(name, description: nil, mode: :nullable) ⇒ 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

Parameters:

  • name (String)

    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.

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



3085
3086
3087
# File 'lib/google/cloud/bigquery/table.rb', line 3085

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

#loadObject

Raises:

  • (RuntimeError)

    not implemented



3394
3395
3396
# File 'lib/google/cloud/bigquery/table.rb', line 3394

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

#load_jobObject

Raises:

  • (RuntimeError)

    not implemented



3388
3389
3390
# File 'lib/google/cloud/bigquery/table.rb', line 3388

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

#numeric(name, description: nil, mode: :nullable) ⇒ Object

Adds a numeric number field to the schema. Numeric is a fixed-precision numeric type with 38 decimal digits, 9 that follow the decimal point.

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

Parameters:

  • name (String)

    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.

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



3143
3144
3145
# File 'lib/google/cloud/bigquery/table.rb', line 3143

def numeric name, description: nil, mode: :nullable
  schema.numeric name, description: description, mode: mode
end

#queryObject

Raises:

  • (RuntimeError)

    not implemented



3424
3425
3426
# File 'lib/google/cloud/bigquery/table.rb', line 3424

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

#query_jobObject

Raises:

  • (RuntimeError)

    not implemented



3418
3419
3420
# File 'lib/google/cloud/bigquery/table.rb', line 3418

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.



2909
2910
2911
2912
2913
2914
2915
2916
# File 'lib/google/cloud/bigquery/table.rb', line 2909

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.



2789
2790
2791
2792
2793
2794
2795
2796
# File 'lib/google/cloud/bigquery/table.rb', line 2789

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.



2869
2870
2871
2872
2873
2874
2875
2876
# File 'lib/google/cloud/bigquery/table.rb', line 2869

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.



2829
2830
2831
2832
2833
2834
2835
2836
# File 'lib/google/cloud/bigquery/table.rb', line 2829

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) {|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

Parameters:

  • name (String)

    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.

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

Yields:

  • (nested_schema)

    a block for setting the nested schema

Yield Parameters:

  • nested_schema (Schema)

    the object accepting the nested schema



3350
3351
3352
# File 'lib/google/cloud/bigquery/table.rb', line 3350

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

#reload!Object Also known as: refresh!

Raises:

  • (RuntimeError)

    not implemented



3436
3437
3438
# File 'lib/google/cloud/bigquery/table.rb', line 3436

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:



3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
# File 'lib/google/cloud/bigquery/table.rb', line 3020

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) ⇒ 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

Parameters:

  • name (String)

    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.

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



3057
3058
3059
# File 'lib/google/cloud/bigquery/table.rb', line 3057

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

#time(name, description: nil, mode: :nullable) ⇒ 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

Parameters:

  • name (String)

    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.

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



3255
3256
3257
# File 'lib/google/cloud/bigquery/table.rb', line 3255

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

#timestamp(name, description: nil, mode: :nullable) ⇒ 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

Parameters:

  • name (String)

    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.

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



3227
3228
3229
# File 'lib/google/cloud/bigquery/table.rb', line 3227

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