Class: Google::Cloud::Bigquery::External::BigtableSource::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/bigquery/external.rb

Overview

BigtableSource::Column

A Bigtable column to expose in the table schema along with its types.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new

bigtable_url = "https://googleapis.com/bigtable/projects/..."
bigtable_table = bigquery.external bigtable_url do |bt|
  bt.rowkey_as_string = true
  bt.add_family "user" do |u|
    u.add_string "name"
    u.add_string "email"
    u.add_integer "age"
    u.add_boolean "active"
  end
end

data = bigquery.query "SELECT * FROM my_ext_table",
                      external: { my_ext_table: bigtable_table }

data.each do |row|
  puts row[:name]
end

Instance Method Summary collapse

Instance Method Details

#encodingString

The encoding of the values when the type is not STRING.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new

bigtable_url = "https://googleapis.com/bigtable/projects/..."
bigtable_table = bigquery.external bigtable_url do |bt|
  bt.add_family "user" do |u|
    u.add_bytes "name" do |col|
      col.encoding = "TEXT"
      col.encoding # "TEXT"
    end
  end
end

Returns:

  • (String)


2110
2111
2112
# File 'lib/google/cloud/bigquery/external.rb', line 2110

def encoding
  @gapi.encoding
end

#encoding=(new_encoding) ⇒ Object

Set the encoding of the values when the type is not STRING. Acceptable encoding values are:

  • TEXT - indicates values are alphanumeric text strings.
  • BINARY - indicates values are encoded using HBase Bytes.toBytes family of functions. This can be overridden on a column.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new

bigtable_url = "https://googleapis.com/bigtable/projects/..."
bigtable_table = bigquery.external bigtable_url do |bt|
  bt.add_family "user" do |u|
    u.add_bytes "name" do |col|
      col.encoding = "TEXT"
      col.encoding # "TEXT"
    end
  end
end

Parameters:

  • new_encoding (String)

    New encoding value



2140
2141
2142
2143
# File 'lib/google/cloud/bigquery/external.rb', line 2140

def encoding= new_encoding
  frozen_check!
  @gapi.encoding = new_encoding
end

#field_nameString

If the qualifier is not a valid BigQuery field identifier (does not match [a-zA-Z][a-zA-Z0-9_]*) a valid identifier must be provided as the column field name and is used as field name in queries.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new

bigtable_url = "https://googleapis.com/bigtable/projects/..."
bigtable_table = bigquery.external bigtable_url do |bt|
  bt.add_family "user" do |u|
    u.add_string "001_name", as: "user" do |col|
      col.field_name # "user"
      col.field_name = "User"
      col.field_name # "User"
    end
  end
end

Returns:

  • (String)


2169
2170
2171
# File 'lib/google/cloud/bigquery/external.rb', line 2169

def field_name
  @gapi.field_name
end

#field_name=(new_field_name) ⇒ Object

Sets the identifier to be used as the column field name in queries when the qualifier is not a valid BigQuery field identifier (does not match [a-zA-Z][a-zA-Z0-9_]*).

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new

bigtable_url = "https://googleapis.com/bigtable/projects/..."
bigtable_table = bigquery.external bigtable_url do |bt|
  bt.add_family "user" do |u|
    u.add_string "001_name", as: "user" do |col|
      col.field_name # "user"
      col.field_name = "User"
      col.field_name # "User"
    end
  end
end

Parameters:

  • new_field_name (String)

    New field_name value



2196
2197
2198
2199
# File 'lib/google/cloud/bigquery/external.rb', line 2196

def field_name= new_field_name
  frozen_check!
  @gapi.field_name = new_field_name
end

#latestBoolean

Whether only the latest version of value in this column are exposed. Can also be set at the column family level. However, this value takes precedence when set at both levels.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new

bigtable_url = "https://googleapis.com/bigtable/projects/..."
bigtable_table = bigquery.external bigtable_url do |bt|
  bt.add_family "user" do |u|
    u.add_string "name" do |col|
      col.latest = true
      col.latest # true
    end
  end
end

Returns:

  • (Boolean)


2223
2224
2225
# File 'lib/google/cloud/bigquery/external.rb', line 2223

def latest
  @gapi.only_read_latest
end

#latest=(new_latest) ⇒ Object

Set whether only the latest version of value in this column are exposed. Can also be set at the column family level. However, this value takes precedence when set at both levels.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new

bigtable_url = "https://googleapis.com/bigtable/projects/..."
bigtable_table = bigquery.external bigtable_url do |bt|
  bt.add_family "user" do |u|
    u.add_string "name" do |col|
      col.latest = true
      col.latest # true
    end
  end
end

Parameters:

  • new_latest (Boolean)

    New latest value



2249
2250
2251
2252
# File 'lib/google/cloud/bigquery/external.rb', line 2249

def latest= new_latest
  frozen_check!
  @gapi.only_read_latest = new_latest
end

#qualifierString

Qualifier of the column. Columns in the parent column family that has this exact qualifier are exposed as . field. If the qualifier is valid UTF-8 string, it will be represented as a UTF-8 string. Otherwise, it will represented as a ASCII-8BIT string.

If the qualifier is not a valid BigQuery field identifier (does not match [a-zA-Z][a-zA-Z0-9_]*) a valid identifier must be provided as field_name.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new

bigtable_url = "https://googleapis.com/bigtable/projects/..."
bigtable_table = bigquery.external bigtable_url do |bt|
  bt.add_family "user" do |u|
    u.add_string "name" do |col|
      col.qualifier # "user"
      col.qualifier = "User"
      col.qualifier # "User"
    end
  end
end

Returns:

  • (String)


2038
2039
2040
2041
# File 'lib/google/cloud/bigquery/external.rb', line 2038

def qualifier
  @gapi.qualifier_string || \
    Base64.strict_decode64(@gapi.qualifier_encoded.to_s)
end

#qualifier=(new_qualifier) ⇒ Object

Set the qualifier of the column. Columns in the parent column family that has this exact qualifier are exposed as . field. Values that are valid UTF-8 strings will be treated as such. All other values will be treated as BINARY.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new

bigtable_url = "https://googleapis.com/bigtable/projects/..."
bigtable_table = bigquery.external bigtable_url do |bt|
  bt.add_family "user" do |u|
    u.add_string "name" do |col|
      col.qualifier # "user"
      col.qualifier = "User"
      col.qualifier # "User"
    end
  end
end

Parameters:

  • new_qualifier (String)

    New qualifier value



2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
# File 'lib/google/cloud/bigquery/external.rb', line 2067

def qualifier= new_qualifier
  frozen_check!
  raise ArgumentError if new_qualifier.nil?

  utf8_qualifier = new_qualifier.encode Encoding::UTF_8
  if utf8_qualifier.valid_encoding?
    @gapi.qualifier_string = utf8_qualifier
    if @gapi.instance_variables.include? :@qualifier_encoded
      @gapi.remove_instance_variable :@qualifier_encoded
    end
  else
    @gapi.qualifier_encoded = Base64.strict_encode64 new_qualifier
    if @gapi.instance_variables.include? :@qualifier_string
      @gapi.remove_instance_variable :@qualifier_string
    end
  end
rescue EncodingError
  @gapi.qualifier_encoded = Base64.strict_encode64 new_qualifier
  if @gapi.instance_variables.include? :@qualifier_string
    @gapi.remove_instance_variable :@qualifier_string
  end
end

#typeString

The type to convert the value in cells of this column. The values are expected to be encoded using HBase Bytes.toBytes function when using the BINARY encoding value. The following BigQuery types are allowed:

  • BYTES
  • STRING
  • INTEGER
  • FLOAT
  • BOOLEAN

Default type is BYTES. Can also be set at the column family level. However, this value takes precedence when set at both levels.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new

bigtable_url = "https://googleapis.com/bigtable/projects/..."
bigtable_table = bigquery.external bigtable_url do |bt|
  bt.add_family "user" do |u|
    u.add_string "name" do |col|
      col.type # "STRING"
    end
  end
end

Returns:

  • (String)


2286
2287
2288
# File 'lib/google/cloud/bigquery/external.rb', line 2286

def type
  @gapi.type
end

#type=(new_type) ⇒ Object

Set the type to convert the value in cells of this column. The values are expected to be encoded using HBase Bytes.toBytes function when using the BINARY encoding value. The following BigQuery types are allowed:

  • BYTES
  • STRING
  • INTEGER
  • FLOAT
  • BOOLEAN

Default type is BYTES. Can also be set at the column family level. However, this value takes precedence when set at both levels.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new

bigtable_url = "https://googleapis.com/bigtable/projects/..."
bigtable_table = bigquery.external bigtable_url do |bt|
  bt.add_family "user" do |u|
    u.add_string "name" do |col|
      col.type # "STRING"
      col.type = "BYTES"
      col.type # "BYTES"
    end
  end
end

Parameters:

  • new_type (String)

    New type value



2324
2325
2326
2327
# File 'lib/google/cloud/bigquery/external.rb', line 2324

def type= new_type
  frozen_check!
  @gapi.type = new_type
end