Reference documentation and code samples for the BigQuery API class Google::Cloud::Bigquery::External::BigtableSource.
BigtableSource
BigtableSource is a subclass of DataSource and
represents a Bigtable external data source that can be queried from
directly, even though the data is not stored in BigQuery. Instead of
loading or streaming the data, this object references the external
data source.
require"google/cloud/bigquery"bigquery=Google::Cloud::Bigquery.newbigtable_url="https://googleapis.com/bigtable/projects/..."bigtable_table=bigquery.externalbigtable_urldo|bt|bt.rowkey_as_string=truebt.add_family"user"do|u|u.add_string"name"u.add_string"email"u.add_integer"age"u.add_boolean"active"endenddata=bigquery.query"SELECT * FROM my_ext_table",external:{my_ext_table:bigtable_table}# Iterate over the first page of resultsdata.eachdo|row|putsrow[:name]end# Retrieve the next page of resultsdata=data.nextifdata.next?
encoding (String) (defaults to: nil) — The encoding of the values when the type is
not STRING. See ColumnFamily#encoding.
latest (Boolean) (defaults to: nil) — Whether only the latest version of value are
exposed for all columns in this column family. See
ColumnFamily#latest.
type (String) (defaults to: nil) — The type to convert the value in cells of this
column. See ColumnFamily#type.
List of column families to expose in the table schema along with
their types. This list restricts the column families that can be
referenced in queries and specifies their value types. You can use
this list to do type conversions - see
ColumnFamily#type for more details. If you leave
this list empty, all column families are present in the table schema
and their values are read as BYTES. During a query only the column
families referenced in that query are read from Bigtable.
Whether the rowkey column families will be read and converted to
string. Otherwise they are read with BYTES type values and users
need to manually cast them with CAST if necessary. The default
value is false.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-09 UTC."],[],[],null,["# BigQuery API - Class Google::Cloud::Bigquery::External::BigtableSource (v1.55.0)\n\nVersion latestkeyboard_arrow_down\n\n- [1.55.0 (latest)](/ruby/docs/reference/google-cloud-bigquery/latest/Google-Cloud-Bigquery-External-BigtableSource)\n- [1.54.0](/ruby/docs/reference/google-cloud-bigquery/1.54.0/Google-Cloud-Bigquery-External-BigtableSource)\n- [1.53.0](/ruby/docs/reference/google-cloud-bigquery/1.53.0/Google-Cloud-Bigquery-External-BigtableSource)\n- [1.52.1](/ruby/docs/reference/google-cloud-bigquery/1.52.1/Google-Cloud-Bigquery-External-BigtableSource)\n- [1.51.1](/ruby/docs/reference/google-cloud-bigquery/1.51.1/Google-Cloud-Bigquery-External-BigtableSource)\n- [1.50.0](/ruby/docs/reference/google-cloud-bigquery/1.50.0/Google-Cloud-Bigquery-External-BigtableSource)\n- [1.49.1](/ruby/docs/reference/google-cloud-bigquery/1.49.1/Google-Cloud-Bigquery-External-BigtableSource)\n- [1.48.1](/ruby/docs/reference/google-cloud-bigquery/1.48.1/Google-Cloud-Bigquery-External-BigtableSource)\n- [1.47.0](/ruby/docs/reference/google-cloud-bigquery/1.47.0/Google-Cloud-Bigquery-External-BigtableSource)\n- [1.46.1](/ruby/docs/reference/google-cloud-bigquery/1.46.1/Google-Cloud-Bigquery-External-BigtableSource)\n- [1.45.0](/ruby/docs/reference/google-cloud-bigquery/1.45.0/Google-Cloud-Bigquery-External-BigtableSource)\n- [1.44.2](/ruby/docs/reference/google-cloud-bigquery/1.44.2/Google-Cloud-Bigquery-External-BigtableSource)\n- [1.43.1](/ruby/docs/reference/google-cloud-bigquery/1.43.1/Google-Cloud-Bigquery-External-BigtableSource)\n- [1.42.0](/ruby/docs/reference/google-cloud-bigquery/1.42.0/Google-Cloud-Bigquery-External-BigtableSource)\n- [1.41.0](/ruby/docs/reference/google-cloud-bigquery/1.41.0/Google-Cloud-Bigquery-External-BigtableSource)\n- [1.40.0](/ruby/docs/reference/google-cloud-bigquery/1.40.0/Google-Cloud-Bigquery-External-BigtableSource)\n- [1.39.0](/ruby/docs/reference/google-cloud-bigquery/1.39.0/Google-Cloud-Bigquery-External-BigtableSource)\n- [1.38.1](/ruby/docs/reference/google-cloud-bigquery/1.38.1/Google-Cloud-Bigquery-External-BigtableSource) \nReference documentation and code samples for the BigQuery API class Google::Cloud::Bigquery::External::BigtableSource.\n\nBigtableSource\n--------------\n\n[BigtableSource](/ruby/docs/reference/google-cloud-bigquery/latest/Google-Cloud-Bigquery-External-BigtableSource \"Google::Cloud::Bigquery::External::BigtableSource (class)\") is a subclass of [DataSource](/ruby/docs/reference/google-cloud-bigquery/latest/Google-Cloud-Bigquery-External-DataSource \"Google::Cloud::Bigquery::External::DataSource (class)\") and\nrepresents a Bigtable external data source that can be queried from\ndirectly, even though the data is not stored in BigQuery. Instead of\nloading or streaming the data, this object references the external\ndata source. \n\nInherits\n--------\n\n- [Google::Cloud::Bigquery::External::DataSource](./Google-Cloud-Bigquery-External-DataSource)\n\nExample\n-------\n\n```ruby\nrequire \"google/cloud/bigquery\"\n\nbigquery = Google::Cloud::Bigquery.new\n\nbigtable_url = \"https://googleapis.com/bigtable/projects/...\"\nbigtable_table = bigquery.external bigtable_url do |bt|\n bt.rowkey_as_string = true\n bt.add_family \"user\" do |u|\n u.add_string \"name\"\n u.add_string \"email\"\n u.add_integer \"age\"\n u.add_boolean \"active\"\n end\nend\n\ndata = bigquery.query \"SELECT * FROM my_ext_table\",\n external: { my_ext_table: bigtable_table }\n\n# Iterate over the first page of results\ndata.each do |row|\n puts row[:name]\nend\n# Retrieve the next page of results\ndata = data.next if data.next?\n```\n\nMethods\n-------\n\n### #add_family\n\n def add_family(family_id, encoding: nil, latest: nil, type: nil) { |family| ... } -\u003e BigtableSource::ColumnFamily\n\nAdd a column family to expose in the table schema along with its\ntypes. Columns belonging to the column family may also be exposed. \n**Parameters**\n\n- **family_id** (String) --- Identifier of the column family. See [ColumnFamily#family_id](/ruby/docs/reference/google-cloud-bigquery/latest/Google-Cloud-Bigquery-External-BigtableSource-ColumnFamily#Google__Cloud__Bigquery__External__BigtableSource__ColumnFamily_family_id_instance_ \"Google::Cloud::Bigquery::External::BigtableSource::ColumnFamily#family_id (method)\").\n- **encoding** (String) *(defaults to: nil)* --- The encoding of the values when the type is not `STRING`. See [ColumnFamily#encoding](/ruby/docs/reference/google-cloud-bigquery/latest/Google-Cloud-Bigquery-External-BigtableSource-ColumnFamily#Google__Cloud__Bigquery__External__BigtableSource__ColumnFamily_encoding_instance_ \"Google::Cloud::Bigquery::External::BigtableSource::ColumnFamily#encoding (method)\").\n- **latest** (Boolean) *(defaults to: nil)* --- Whether only the latest version of value are exposed for all columns in this column family. See [ColumnFamily#latest](/ruby/docs/reference/google-cloud-bigquery/latest/Google-Cloud-Bigquery-External-BigtableSource-ColumnFamily#Google__Cloud__Bigquery__External__BigtableSource__ColumnFamily_latest_instance_ \"Google::Cloud::Bigquery::External::BigtableSource::ColumnFamily#latest (method)\").\n- **type** (String) *(defaults to: nil)* --- The type to convert the value in cells of this column. See [ColumnFamily#type](/ruby/docs/reference/google-cloud-bigquery/latest/Google-Cloud-Bigquery-External-BigtableSource-ColumnFamily#Google__Cloud__Bigquery__External__BigtableSource__ColumnFamily_type_instance_ \"Google::Cloud::Bigquery::External::BigtableSource::ColumnFamily#type (method)\"). \n**Yields**\n\n- (family) --- a block for setting the family \n**Yield Parameter**\n\n- **family** ([BigtableSource::ColumnFamily](./Google-Cloud-Bigquery-External-BigtableSource-ColumnFamily)) --- the family object \n**Returns**\n\n- ([BigtableSource::ColumnFamily](./Google-Cloud-Bigquery-External-BigtableSource-ColumnFamily))\n**Example** \n\n```ruby\nrequire \"google/cloud/bigquery\"\n\nbigquery = Google::Cloud::Bigquery.new\n\nbigtable_url = \"https://googleapis.com/bigtable/projects/...\"\nbigtable_table = bigquery.external bigtable_url do |bt|\n bt.rowkey_as_string = true\n bt.add_family \"user\" do |u|\n u.add_string \"name\"\n u.add_string \"email\"\n u.add_integer \"age\"\n u.add_boolean \"active\"\n end\nend\n```\n\n### #families\n\n def families() -\u003e Array\u003cBigtableSource::ColumnFamily\u003e\n\nList of column families to expose in the table schema along with\ntheir types. This list restricts the column families that can be\nreferenced in queries and specifies their value types. You can use\nthis list to do type conversions - see\n[ColumnFamily#type](/ruby/docs/reference/google-cloud-bigquery/latest/Google-Cloud-Bigquery-External-BigtableSource-ColumnFamily#Google__Cloud__Bigquery__External__BigtableSource__ColumnFamily_type_instance_ \"Google::Cloud::Bigquery::External::BigtableSource::ColumnFamily#type (method)\") for more details. If you leave\nthis list empty, all column families are present in the table schema\nand their values are read as `BYTES`. During a query only the column\nfamilies referenced in that query are read from Bigtable. \n**Returns**\n\n- (Array\\\u003c[BigtableSource::ColumnFamily](./Google-Cloud-Bigquery-External-BigtableSource-ColumnFamily)\\\u003e)\n**Example** \n\n```ruby\nrequire \"google/cloud/bigquery\"\n\nbigquery = Google::Cloud::Bigquery.new\n\nbigtable_url = \"https://googleapis.com/bigtable/projects/...\"\nbigtable_table = bigquery.external bigtable_url do |bt|\n bt.rowkey_as_string = true\n bt.add_family \"user\" do |u|\n u.add_string \"name\"\n u.add_string \"email\"\n u.add_integer \"age\"\n u.add_boolean \"active\"\n end\nend\n\nbigtable_table.families.count #=\u003e 1\n```\n\n### #rowkey_as_string\n\n def rowkey_as_string() -\u003e Boolean\n\nWhether the rowkey column families will be read and converted to\nstring. Otherwise they are read with `BYTES` type values and users\nneed to manually cast them with `CAST` if necessary. The default\nvalue is `false`. \n**Returns**\n\n- (Boolean)\n**Example** \n\n```ruby\nrequire \"google/cloud/bigquery\"\n\nbigquery = Google::Cloud::Bigquery.new\n\nbigtable_url = \"https://googleapis.com/bigtable/projects/...\"\nbigtable_table = bigquery.external bigtable_url do |bt|\n bt.rowkey_as_string = true\nend\n\nbigtable_table.rowkey_as_string #=\u003e true\n```\n\n### #rowkey_as_string=\n\n def rowkey_as_string=(row_rowkey)\n\nSet the number of rows at the top of a sheet that BigQuery will skip\nwhen reading the data. \n**Parameter**\n\n- **row_rowkey** (Boolean) --- New rowkey_as_string value\n**Example** \n\n```ruby\nrequire \"google/cloud/bigquery\"\n\nbigquery = Google::Cloud::Bigquery.new\n\nbigtable_url = \"https://googleapis.com/bigtable/projects/...\"\nbigtable_table = bigquery.external bigtable_url do |bt|\n bt.rowkey_as_string = true\nend\n\nbigtable_table.rowkey_as_string #=\u003e true\n```"]]