Class: Google::Cloud::Bigquery::External::BigtableSource::ColumnFamily

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

Overview

BigtableSource::ColumnFamily

A Bigtable column family used to expose in the table schema along with its types and columns.

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 }

# Iterate over the first page of results
data.each do |row|
  puts row[:name]
end
# Retrieve the next page of results
data = data.next if data.next?

Instance Method Summary collapse

Instance Method Details

#add_boolean(qualifier, as: nil) {|column| ... } ⇒ Array<BigtableSource::Column>

Add a column to the column family to expose in the table schema that is specified as the BOOLEAN type.

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_boolean "active"
  end
end

Parameters:

Yields:

  • (column)

    a block for setting the column

Yield Parameters:

Returns:



2013
2014
2015
2016
2017
# File 'lib/google/cloud/bigquery/external.rb', line 2013

def add_boolean qualifier, as: nil
  col = add_column qualifier, as: as, type: "BOOLEAN"
  yield col if block_given?
  col
end

#add_bytes(qualifier, as: nil) {|column| ... } ⇒ Array<BigtableSource::Column>

Add a column to the column family to expose in the table schema that is specified as the BYTES type.

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_bytes "avatar"
  end
end

Parameters:

Yields:

  • (column)

    a block for setting the column

Yield Parameters:

Returns:



1873
1874
1875
1876
1877
# File 'lib/google/cloud/bigquery/external.rb', line 1873

def add_bytes qualifier, as: nil
  col = add_column qualifier, as: as, type: "BYTES"
  yield col if block_given?
  col
end

#add_column(qualifier, as: nil, type: nil) {|column| ... } ⇒ Array<BigtableSource::Column>

Add a column to the column family to expose in the table schema along with its types.

  • BYTES
  • STRING
  • INTEGER
  • FLOAT
  • BOOLEAN

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_column "name", type: "STRING"
  end
end

Parameters:

Yields:

  • (column)

    a block for setting the column

Yield Parameters:

Returns:



1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
# File 'lib/google/cloud/bigquery/external.rb', line 1833

def add_column qualifier, as: nil, type: nil
  frozen_check!
  col = BigtableSource::Column.new
  col.qualifier = qualifier
  col.field_name = as if as
  col.type = type if type
  yield col if block_given?
  @columns << col
  col
end

#add_float(qualifier, as: nil) {|column| ... } ⇒ Array<BigtableSource::Column>

Add a column to the column family to expose in the table schema that is specified as the FLOAT type.

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_float "score"
  end
end

Parameters:

Yields:

  • (column)

    a block for setting the column

Yield Parameters:

Returns:



1978
1979
1980
1981
1982
# File 'lib/google/cloud/bigquery/external.rb', line 1978

def add_float qualifier, as: nil
  col = add_column qualifier, as: as, type: "FLOAT"
  yield col if block_given?
  col
end

#add_integer(qualifier, as: nil) {|column| ... } ⇒ Array<BigtableSource::Column>

Add a column to the column family to expose in the table schema that is specified as the INTEGER type.

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_integer "age"
  end
end

Parameters:

Yields:

  • (column)

    a block for setting the column

Yield Parameters:

Returns:



1943
1944
1945
1946
1947
# File 'lib/google/cloud/bigquery/external.rb', line 1943

def add_integer qualifier, as: nil
  col = add_column qualifier, as: as, type: "INTEGER"
  yield col if block_given?
  col
end

#add_string(qualifier, as: nil) {|column| ... } ⇒ Array<BigtableSource::Column>

Add a column to the column family to expose in the table schema that is specified as the STRING type.

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"
  end
end

Parameters:

Yields:

  • (column)

    a block for setting the column

Yield Parameters:

Returns:



1908
1909
1910
1911
1912
# File 'lib/google/cloud/bigquery/external.rb', line 1908

def add_string qualifier, as: nil
  col = add_column qualifier, as: as, type: "STRING"
  yield col if block_given?
  col
end

#columnsArray<BigtableSource::Column>

Lists of columns that should be exposed as individual fields.

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

bigtable_table.families[0].columns.count #=> 4

Returns:



1791
1792
1793
# File 'lib/google/cloud/bigquery/external.rb', line 1791

def columns
  @columns
end

#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.encoding = "UTF-8"
  end
end

bigtable_table.families[0].encoding #=> "UTF-8"

Returns:

  • (String)


1571
1572
1573
# File 'lib/google/cloud/bigquery/external.rb', line 1571

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.encoding = "UTF-8"
  end
end

bigtable_table.families[0].encoding #=> "UTF-8"

Parameters:

  • new_encoding (String)

    New encoding value



1600
1601
1602
1603
# File 'lib/google/cloud/bigquery/external.rb', line 1600

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

#family_idString

Identifier of the column family.

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"
end

bigtable_table.families[0].family_id #=> "user"

Returns:

  • (String)


1622
1623
1624
# File 'lib/google/cloud/bigquery/external.rb', line 1622

def family_id
  @gapi.family_id
end

#family_id=(new_family_id) ⇒ Object

Set the identifier of the column family.

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"
end

bigtable_table.families[0].family_id #=> "user"
bigtable_table.families[0].family_id = "User"
bigtable_table.families[0].family_id #=> "User"

Parameters:

  • new_family_id (String)

    New family_id value



1645
1646
1647
1648
# File 'lib/google/cloud/bigquery/external.rb', line 1645

def family_id= new_family_id
  frozen_check!
  @gapi.family_id = new_family_id
end

#latestBoolean

Whether only the latest version of value are exposed for all columns in this column family.

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.latest = true
  end
end

bigtable_table.families[0].latest #=> true

Returns:

  • (Boolean)


1670
1671
1672
# File 'lib/google/cloud/bigquery/external.rb', line 1670

def latest
  @gapi.only_read_latest
end

#latest=(new_latest) ⇒ Object

Set whether only the latest version of value are exposed for all columns in this column family.

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.latest = true
  end
end

bigtable_table.families[0].latest #=> true

Parameters:

  • new_latest (Boolean)

    New latest value



1694
1695
1696
1697
# File 'lib/google/cloud/bigquery/external.rb', line 1694

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

#typeString

The type to convert the value in cells of this column family. 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. 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.type = "STRING"
  end
end

bigtable_table.families[0].type #=> "STRING"

Returns:

  • (String)


1729
1730
1731
# File 'lib/google/cloud/bigquery/external.rb', line 1729

def type
  @gapi.type
end

#type=(new_type) ⇒ Object

Set the type to convert the value in cells of this column family. 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. 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.type = "STRING"
  end
end

bigtable_table.families[0].type #=> "STRING"

Parameters:

  • new_type (String)

    New type value



1763
1764
1765
1766
# File 'lib/google/cloud/bigquery/external.rb', line 1763

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