Method: Google::Cloud::Bigtable::ReadOperations#read_rows

Defined in:
lib/google/cloud/bigtable/read_operations.rb

#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 Google::Cloud::Bigtable::RowFilter for filter types.

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.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 rowow
end

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:



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/google/cloud/bigtable/read_operations.rb', line 151

def read_rows \
    keys: nil,
    ranges: nil,
    filter: nil,
    limit: nil,
    &block
  unless block_given?
    return enum_for(
      :read_rows,
      keys: keys,
      ranges: ranges,
      filter: filter,
      limit: limit
    )
  end
  row_set = build_row_set(keys, ranges)
  rows_limit = limit
  rows_filter = filter.to_grpc if filter
  rows_reader = RowsReader.new(self)

  begin
    rows_reader.read(
      rows: row_set,
      filter: rows_filter,
      rows_limit: rows_limit,
      &block
    )
  rescue *RowsReader::RETRYABLE_ERRORS => e
    rows_reader.retry_count += 1
    unless rows_reader.retryable?
      raise Google::Cloud::Error.from_error(e)
    end
    rows_limit, row_set = rows_reader.retry_options(limit, row_set)
    retry
  end
end