Cloud Bigtable API - Module Google::Cloud::Bigtable::ReadOperations (v2.9.1)

Reference documentation and code samples for the Cloud Bigtable API module Google::Cloud::Bigtable::ReadOperations.

ReadOperations

Collection of read-rows APIs.

  • Sample row key
  • Read row
  • Read rows

Methods

#filter

def filter() -> Google::Cloud::Bigtable::RowRange

Gets a row filter.

Example
require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table "my-instance", "my-table"

filter = table.filter.key "user-*"

#new_column_range

def new_column_range(family) -> Google::Cloud::Bigtable::ColumnRange

Gets a new instance of ColumnRange.

Parameter
  • family (String) — Column family name.
Examples
require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table "my-instance", "my-table"

range = table.new_column_range "test-family"
range.from "abc"
range.to "xyz"

# OR
range = table.new_column_range("test-family").from("key-1").to("key-5")

With exclusive from range.

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table "my-instance", "my-table"

range = table.new_column_range("test-family").from("key-1", inclusive: false).to("key-5")

#new_row_range

def new_row_range() -> Google::Cloud::Bigtable::RowRange

Gets a new instance of RowRange.

Examples
require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table "my-instance", "my-table"

range = table.new_row_range
range.from "abc"
range.to "xyz"

# OR
range = table.new_row_range.from("key-1").to("key-5")

With exclusive from range.

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table "my-instance", "my-table"

range = table.new_row_range.from("key-1", inclusive: false).to("key-5")

#new_value_range

def new_value_range() -> Google::Cloud::Bigtable::ValueRange

Creates a new instance of ValueRange.

Examples
require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table "my-instance", "my-table"

range = table.new_value_range
range.from "abc"
range.to "xyz"

# OR
range = table.new_value_range.from("abc").to("xyz")

With exclusive from range.

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table "my-instance", "my-table"

range = table.new_value_range.from("abc", inclusive: false).to("xyz")

#read_row

def read_row(key, filter: nil) -> Google::Cloud::Bigtable::Row

Reads a single row by row key.

Parameters
  • key (String) — Row key. Required.
  • filter (Google::Cloud::Bigtable::RowFilter) (defaults to: nil) — The filter to apply to the contents of the specified row. Optional.
Examples
require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table "my-instance", "my-table"

row = table.read_row "user-1"

Read row with filter.

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table "my-instance", "my-table"

filter = Google::Cloud::Bigtable::RowFilter.cells_per_row 3

row = table.read_row "user-1", filter: filter

#read_rows

def read_rows(keys: nil, ranges: nil, filter: nil, limit: nil, &block) -> Array<Google::Cloud::Bigtable::Row> | :yields: row

Reads rows.

Streams back the contents of all requested rows in key order, optionally applying the same Reader filter to each. read_rows, row_ranges and filter if not specified, reads from all rows.

See RowFilter for filter types.

Parameters
  • keys (Array<String>) (defaults to: nil) — List of row keys to be read. Optional.
  • ranges (Google::Cloud::Bigtable::RowRange | Array<Google::Cloud::Bigtable::RowRange>) (defaults to: nil) — Row ranges array or single range. Optional.
  • filter (SimpleFilter, ChainFilter, InterleaveFilter, ConditionFilter) (defaults to: nil) — The filter to apply to the contents of the specified row(s). If unset, reads the entries of each row. Optional.
  • limit (Integer) (defaults to: nil) — Limit number of read rows count. Optional. The read will terminate after committing to N rows' worth of results. The default (zero) is to return all results.
Returns
Examples

Read with limit.

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table "my-instance", "my-table"

table.read_rows(limit: 10).each do |row|
  puts row
end

Read using row keys.

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table "my-instance", "my-table"

table.read_rows(keys: ["user-1", "user-2"]).each do |row|
  puts row
end

Read using row ranges.

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table "my-instance", "my-table"

range = table.new_row_range.between "user-1", "user-100"

table.read_rows(ranges: range).each do |row|
  puts row
end

Read using filter.

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table "my-instance", "my-table"

filter = table.filter.key "user-*"
# OR
# filter = Google::Cloud::Bigtable::RowFilter.key "user-*"

table.read_rows(filter: filter).each do |row|
  puts row
end

Read using filter with limit.

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table "my-instance", "my-table"

filter = table.filter.key "user-*"
# OR
# filter = Google::Cloud::Bigtable::RowFilter.key "user-*"

table.read_rows(filter: filter, limit: 10).each do |row|
  puts row
end

#sample_row_keys

def sample_row_keys() -> :yields: sample_row_key

Reads sample row keys.

Returns a sample of row keys in the table. The returned row keys will delimit contiguous sections of the table of approximately equal size. The sections can be used to break up the data for distributed tasks like MapReduces.

Returns
  • (:yields: sample_row_key) — Yield block for each processed SampleRowKey.
Example
require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table "my-instance", "my-table"

table.sample_row_keys.each do |sample_row_key|
  p sample_row_key.key # user00116
  p sample_row_key.offset # 805306368
end