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, #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, #time_partitioning?, #time_partitioning_expiration, #time_partitioning_expiration=, #time_partitioning_field, #time_partitioning_field=, #time_partitioning_type, #time_partitioning_type=, #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.



3069
3070
3071
# File 'lib/google/cloud/bigquery/table.rb', line 3069

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.



3097
3098
3099
# File 'lib/google/cloud/bigquery/table.rb', line 3097

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:



2860
2861
2862
2863
2864
# File 'lib/google/cloud/bigquery/table.rb', line 2860

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

#copyObject

Raises:

  • (RuntimeError)

    not implemented



3268
3269
3270
# File 'lib/google/cloud/bigquery/table.rb', line 3268

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

#copy_jobObject

Raises:

  • (RuntimeError)

    not implemented



3262
3263
3264
# File 'lib/google/cloud/bigquery/table.rb', line 3262

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

#dataObject

Raises:

  • (RuntimeError)

    not implemented



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

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.



3209
3210
3211
# File 'lib/google/cloud/bigquery/table.rb', line 3209

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.



3181
3182
3183
# File 'lib/google/cloud/bigquery/table.rb', line 3181

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

#deleteObject

Raises:

  • (RuntimeError)

    not implemented



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

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

#externalObject

Raises:

  • (RuntimeError)

    not implemented



3328
3329
3330
# File 'lib/google/cloud/bigquery/table.rb', line 3328

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

#extractObject

Raises:

  • (RuntimeError)

    not implemented



3280
3281
3282
# File 'lib/google/cloud/bigquery/table.rb', line 3280

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

#extract_jobObject

Raises:

  • (RuntimeError)

    not implemented



3274
3275
3276
# File 'lib/google/cloud/bigquery/table.rb', line 3274

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.



3011
3012
3013
# File 'lib/google/cloud/bigquery/table.rb', line 3011

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

#insertObject

Raises:

  • (RuntimeError)

    not implemented



3298
3299
3300
# File 'lib/google/cloud/bigquery/table.rb', line 3298

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

#insert_asyncObject

Raises:

  • (RuntimeError)

    not implemented



3304
3305
3306
# File 'lib/google/cloud/bigquery/table.rb', line 3304

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.



2983
2984
2985
# File 'lib/google/cloud/bigquery/table.rb', line 2983

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

#loadObject

Raises:

  • (RuntimeError)

    not implemented



3292
3293
3294
# File 'lib/google/cloud/bigquery/table.rb', line 3292

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

#load_jobObject

Raises:

  • (RuntimeError)

    not implemented



3286
3287
3288
# File 'lib/google/cloud/bigquery/table.rb', line 3286

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.



3041
3042
3043
# File 'lib/google/cloud/bigquery/table.rb', line 3041

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

#queryObject

Raises:

  • (RuntimeError)

    not implemented



3322
3323
3324
# File 'lib/google/cloud/bigquery/table.rb', line 3322

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

#query_jobObject

Raises:

  • (RuntimeError)

    not implemented



3316
3317
3318
# File 'lib/google/cloud/bigquery/table.rb', line 3316

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.



2807
2808
2809
2810
2811
2812
2813
2814
# File 'lib/google/cloud/bigquery/table.rb', line 2807

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.



2687
2688
2689
2690
2691
2692
2693
2694
# File 'lib/google/cloud/bigquery/table.rb', line 2687

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.



2767
2768
2769
2770
2771
2772
2773
2774
# File 'lib/google/cloud/bigquery/table.rb', line 2767

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.



2727
2728
2729
2730
2731
2732
2733
2734
# File 'lib/google/cloud/bigquery/table.rb', line 2727

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



3248
3249
3250
# File 'lib/google/cloud/bigquery/table.rb', line 3248

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



3334
3335
3336
# File 'lib/google/cloud/bigquery/table.rb', line 3334

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:



2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
# File 'lib/google/cloud/bigquery/table.rb', line 2918

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.



2955
2956
2957
# File 'lib/google/cloud/bigquery/table.rb', line 2955

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.



3153
3154
3155
# File 'lib/google/cloud/bigquery/table.rb', line 3153

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.



3125
3126
3127
# File 'lib/google/cloud/bigquery/table.rb', line 3125

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