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.



3034
3035
3036
# File 'lib/google/cloud/bigquery/table.rb', line 3034

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.



3062
3063
3064
# File 'lib/google/cloud/bigquery/table.rb', line 3062

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:



2825
2826
2827
2828
2829
# File 'lib/google/cloud/bigquery/table.rb', line 2825

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

#copyObject

Raises:

  • (RuntimeError)

    not implemented



3233
3234
3235
# File 'lib/google/cloud/bigquery/table.rb', line 3233

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

#copy_jobObject

Raises:

  • (RuntimeError)

    not implemented



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

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

#dataObject

Raises:

  • (RuntimeError)

    not implemented



3221
3222
3223
# File 'lib/google/cloud/bigquery/table.rb', line 3221

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.



3174
3175
3176
# File 'lib/google/cloud/bigquery/table.rb', line 3174

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.



3146
3147
3148
# File 'lib/google/cloud/bigquery/table.rb', line 3146

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

#deleteObject

Raises:

  • (RuntimeError)

    not implemented



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

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

#externalObject

Raises:

  • (RuntimeError)

    not implemented



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

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

#extractObject

Raises:

  • (RuntimeError)

    not implemented



3245
3246
3247
# File 'lib/google/cloud/bigquery/table.rb', line 3245

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

#extract_jobObject

Raises:

  • (RuntimeError)

    not implemented



3239
3240
3241
# File 'lib/google/cloud/bigquery/table.rb', line 3239

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.



2976
2977
2978
# File 'lib/google/cloud/bigquery/table.rb', line 2976

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

#insertObject

Raises:

  • (RuntimeError)

    not implemented



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

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

#insert_asyncObject

Raises:

  • (RuntimeError)

    not implemented



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

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.



2948
2949
2950
# File 'lib/google/cloud/bigquery/table.rb', line 2948

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

#loadObject

Raises:

  • (RuntimeError)

    not implemented



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

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

#load_jobObject

Raises:

  • (RuntimeError)

    not implemented



3251
3252
3253
# File 'lib/google/cloud/bigquery/table.rb', line 3251

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.



3006
3007
3008
# File 'lib/google/cloud/bigquery/table.rb', line 3006

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

#queryObject

Raises:

  • (RuntimeError)

    not implemented



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

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

#query_jobObject

Raises:

  • (RuntimeError)

    not implemented



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

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.



2772
2773
2774
2775
2776
2777
2778
2779
# File 'lib/google/cloud/bigquery/table.rb', line 2772

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.



2652
2653
2654
2655
2656
2657
2658
2659
# File 'lib/google/cloud/bigquery/table.rb', line 2652

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.



2732
2733
2734
2735
2736
2737
2738
2739
# File 'lib/google/cloud/bigquery/table.rb', line 2732

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.



2692
2693
2694
2695
2696
2697
2698
2699
# File 'lib/google/cloud/bigquery/table.rb', line 2692

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



3213
3214
3215
# File 'lib/google/cloud/bigquery/table.rb', line 3213

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



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

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:



2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
# File 'lib/google/cloud/bigquery/table.rb', line 2883

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.



2920
2921
2922
# File 'lib/google/cloud/bigquery/table.rb', line 2920

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.



3118
3119
3120
# File 'lib/google/cloud/bigquery/table.rb', line 3118

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.



3090
3091
3092
# File 'lib/google/cloud/bigquery/table.rb', line 3090

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