2.13.2 (latest) 2.13.1 2.12.3 2.11.1 2.10.2 2.9.1 2.8.0 2.7.1 2.6.5 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

## Included In

- [Google::Cloud::Bigtable::Table](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-Table.md.txt)

## Methods

### #filter

```ruby
def filter() -> Google::Cloud::Bigtable::RowRange
```
Gets a row filter.
**Returns**

- ([Google::Cloud::Bigtable::RowRange](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-RowRange.md.txt))
**Example**

```ruby
require "google/cloud/bigtable"

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

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

### #new_column_range

```ruby
def new_column_range(family) -> Google::Cloud::Bigtable::ColumnRange
```
Gets a new instance of ColumnRange.
**Parameter**

- **family** (String) --- Column family name.
**Returns**

- ([Google::Cloud::Bigtable::ColumnRange](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-ColumnRange.md.txt))
**Examples**

```ruby
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.

```ruby
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

```ruby
def new_row_range() -> Google::Cloud::Bigtable::RowRange
```
Gets a new instance of RowRange.
**Returns**

- ([Google::Cloud::Bigtable::RowRange](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-RowRange.md.txt))
**Examples**

```ruby
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.

```ruby
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

```ruby
def new_value_range() -> Google::Cloud::Bigtable::ValueRange
```
Creates a new instance of ValueRange.
**Returns**

- ([Google::Cloud::Bigtable::ValueRange](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-ValueRange.md.txt))
**Examples**

```ruby
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.

```ruby
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

```ruby
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](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-RowFilter.md.txt)) *(defaults to: nil)* --- The filter to apply to the contents of the specified row. Optional.
**Returns**

- ([Google::Cloud::Bigtable::Row](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-Row.md.txt))
**Examples**

```ruby
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.

```ruby
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

```ruby
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.

<br />

See [RowFilter](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-RowFilter.md.txt "Google::Cloud::Bigtable::RowFilter (module)") 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](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-RowRange.md.txt)\>) *(defaults to: nil)* --- Row ranges array or single range. Optional.
- **filter** ([SimpleFilter](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-RowFilter-SimpleFilter.md.txt), [ChainFilter](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-RowFilter-ChainFilter.md.txt), [InterleaveFilter](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-RowFilter-InterleaveFilter.md.txt), [ConditionFilter](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-RowFilter-ConditionFilter.md.txt)) *(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**

- (Array\<[Google::Cloud::Bigtable::Row](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-Row.md.txt)\> \| :yields: row) --- Array of row or yield block for each processed row.
**Examples**

Read with limit.

```ruby
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.

```ruby
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.

```ruby
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.

```ruby
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.

```ruby
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

```ruby
def sample_row_keys() -> :yields: sample_row_key
```
Reads sample row keys.


<br />

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**

```ruby
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
```