google-cloud-bigtable 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.yardopts +10 -0
- data/LICENSE +201 -0
- data/README.md +65 -0
- data/lib/google/bigtable/admin/v2/bigtable_instance_admin_pb.rb +139 -0
- data/lib/google/bigtable/admin/v2/bigtable_instance_admin_services_pb.rb +85 -0
- data/lib/google/bigtable/admin/v2/bigtable_table_admin_pb.rb +137 -0
- data/lib/google/bigtable/admin/v2/bigtable_table_admin_services_pb.rb +117 -0
- data/lib/google/bigtable/admin/v2/common_pb.rb +24 -0
- data/lib/google/bigtable/admin/v2/instance_pb.rb +72 -0
- data/lib/google/bigtable/admin/v2/table_pb.rb +88 -0
- data/lib/google/bigtable/v2/bigtable_pb.rb +109 -0
- data/lib/google/bigtable/v2/bigtable_services_pb.rb +67 -0
- data/lib/google/bigtable/v2/data_pb.rb +155 -0
- data/lib/google/cloud/bigtable/admin/credentials.rb +26 -0
- data/lib/google/cloud/bigtable/admin/v2/bigtable_instance_admin_client.rb +1417 -0
- data/lib/google/cloud/bigtable/admin/v2/bigtable_instance_admin_client_config.json +123 -0
- data/lib/google/cloud/bigtable/admin/v2/bigtable_table_admin_client.rb +1079 -0
- data/lib/google/cloud/bigtable/admin/v2/bigtable_table_admin_client_config.json +109 -0
- data/lib/google/cloud/bigtable/admin/v2/credentials.rb +50 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/bigtable_instance_admin.rb +279 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/bigtable_table_admin.rb +353 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/instance.rb +194 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/table.rb +209 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/iam/v1/iam_policy.rb +62 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/iam/v1/policy.rb +127 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/longrunning/operations.rb +92 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/any.rb +124 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/duration.rb +90 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/empty.rb +28 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/field_mask.rb +223 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/timestamp.rb +106 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/rpc/status.rb +83 -0
- data/lib/google/cloud/bigtable/admin/v2.rb +200 -0
- data/lib/google/cloud/bigtable/admin.rb +196 -0
- data/lib/google/cloud/bigtable/app_profile/job.rb +102 -0
- data/lib/google/cloud/bigtable/app_profile/list.rb +159 -0
- data/lib/google/cloud/bigtable/app_profile.rb +373 -0
- data/lib/google/cloud/bigtable/chunk_processor.rb +253 -0
- data/lib/google/cloud/bigtable/cluster/job.rb +92 -0
- data/lib/google/cloud/bigtable/cluster/list.rb +169 -0
- data/lib/google/cloud/bigtable/cluster.rb +264 -0
- data/lib/google/cloud/bigtable/column_family.rb +280 -0
- data/lib/google/cloud/bigtable/column_range.rb +186 -0
- data/lib/google/cloud/bigtable/convert.rb +75 -0
- data/lib/google/cloud/bigtable/credentials.rb +24 -0
- data/lib/google/cloud/bigtable/errors.rb +35 -0
- data/lib/google/cloud/bigtable/gc_rule.rb +215 -0
- data/lib/google/cloud/bigtable/instance/cluster_map.rb +70 -0
- data/lib/google/cloud/bigtable/instance/job.rb +97 -0
- data/lib/google/cloud/bigtable/instance/list.rb +159 -0
- data/lib/google/cloud/bigtable/instance.rb +921 -0
- data/lib/google/cloud/bigtable/longrunning_job.rb +105 -0
- data/lib/google/cloud/bigtable/mutation_entry.rb +244 -0
- data/lib/google/cloud/bigtable/mutation_operations.rb +338 -0
- data/lib/google/cloud/bigtable/policy.rb +163 -0
- data/lib/google/cloud/bigtable/project.rb +580 -0
- data/lib/google/cloud/bigtable/read_modify_write_rule.rb +129 -0
- data/lib/google/cloud/bigtable/read_operations.rb +345 -0
- data/lib/google/cloud/bigtable/row.rb +125 -0
- data/lib/google/cloud/bigtable/row_filter/chain_filter.rb +539 -0
- data/lib/google/cloud/bigtable/row_filter/condition_filter.rb +108 -0
- data/lib/google/cloud/bigtable/row_filter/interleave_filter.rb +570 -0
- data/lib/google/cloud/bigtable/row_filter/simple_filter.rb +273 -0
- data/lib/google/cloud/bigtable/row_filter.rb +593 -0
- data/lib/google/cloud/bigtable/row_range.rb +174 -0
- data/lib/google/cloud/bigtable/rows_mutator.rb +120 -0
- data/lib/google/cloud/bigtable/rows_reader.rb +196 -0
- data/lib/google/cloud/bigtable/sample_row_key.rb +82 -0
- data/lib/google/cloud/bigtable/service.rb +817 -0
- data/lib/google/cloud/bigtable/table/cluster_state.rb +93 -0
- data/lib/google/cloud/bigtable/table/column_family_map.rb +68 -0
- data/lib/google/cloud/bigtable/table/list.rb +147 -0
- data/lib/google/cloud/bigtable/table.rb +676 -0
- data/lib/google/cloud/bigtable/v2/bigtable_client.rb +579 -0
- data/lib/google/cloud/bigtable/v2/bigtable_client_config.json +65 -0
- data/lib/google/cloud/bigtable/v2/credentials.rb +45 -0
- data/lib/google/cloud/bigtable/v2/doc/google/bigtable/v2/bigtable.rb +286 -0
- data/lib/google/cloud/bigtable/v2/doc/google/bigtable/v2/data.rb +492 -0
- data/lib/google/cloud/bigtable/v2/doc/google/protobuf/any.rb +124 -0
- data/lib/google/cloud/bigtable/v2/doc/google/protobuf/wrappers.rb +89 -0
- data/lib/google/cloud/bigtable/v2/doc/google/rpc/status.rb +83 -0
- data/lib/google/cloud/bigtable/v2.rb +132 -0
- data/lib/google/cloud/bigtable/value_range.rb +175 -0
- data/lib/google/cloud/bigtable/version.rb +22 -0
- data/lib/google/cloud/bigtable.rb +223 -0
- data/lib/google-cloud-bigtable.rb +167 -0
- metadata +283 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Copyright 2018 Google LLC
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
module Google
|
|
19
|
+
module Cloud
|
|
20
|
+
module Bigtable
|
|
21
|
+
# # ReadModifyWriteRule
|
|
22
|
+
#
|
|
23
|
+
# Specifies an atomic read/modify/write operation on the latest value of the
|
|
24
|
+
# specified column.
|
|
25
|
+
#
|
|
26
|
+
# @example Append value rule
|
|
27
|
+
# rule = Google::Cloud::Bigtable::ReadModifyWriteRule.append(
|
|
28
|
+
# "cf", "field01", "append-xyz"
|
|
29
|
+
# )
|
|
30
|
+
#
|
|
31
|
+
# @example increment value rule
|
|
32
|
+
# rule = Google::Cloud::Bigtable::ReadModifyWriteRule.increment(
|
|
33
|
+
# "cf", "field01", 1
|
|
34
|
+
# )
|
|
35
|
+
#
|
|
36
|
+
class ReadModifyWriteRule
|
|
37
|
+
# @private
|
|
38
|
+
# Create instance of ReadModifyWriteRule
|
|
39
|
+
#
|
|
40
|
+
# @param family [String]
|
|
41
|
+
# The name of the family to which the read/modify/write should be applied.
|
|
42
|
+
# @param qualifier [String]
|
|
43
|
+
# The qualifier of the column to which the read/modify/write should be
|
|
44
|
+
#
|
|
45
|
+
def initialize family, qualifier
|
|
46
|
+
@grpc = Google::Bigtable::V2::ReadModifyWriteRule.new
|
|
47
|
+
@grpc.family_name = family
|
|
48
|
+
@grpc.column_qualifier = qualifier
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Create append value rule instance.
|
|
52
|
+
#
|
|
53
|
+
# @param family [String]
|
|
54
|
+
# The name of the family to which the read/modify/write should be applied.
|
|
55
|
+
# @param qualifier [String]
|
|
56
|
+
# The qualifier of the column to which the read/modify/write should be applied.
|
|
57
|
+
# @param value [String]
|
|
58
|
+
# Rule specifying that `append_value` be appended to the existing value.
|
|
59
|
+
# If the targeted cell is unset, it will be treated as containing the empty string.
|
|
60
|
+
# @return [Google::Cloud::Bigtable::ReadModifyWriteRule]
|
|
61
|
+
#
|
|
62
|
+
# @example Append value rule
|
|
63
|
+
# rule = Google::Cloud::Bigtable::ReadModifyWriteRule.append(
|
|
64
|
+
# "cf", "field01", "append-xyz"
|
|
65
|
+
# )
|
|
66
|
+
#
|
|
67
|
+
def self.append family, qualifier, value
|
|
68
|
+
rule = new(family, qualifier)
|
|
69
|
+
rule.append(value)
|
|
70
|
+
rule
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Create increment amount rule instance.
|
|
74
|
+
#
|
|
75
|
+
# @param family [String]
|
|
76
|
+
# The name of the family to which the read/modify/write should be applied.
|
|
77
|
+
# @param qualifier [String]
|
|
78
|
+
# The qualifier of the column to which the read/modify/write should be applied.
|
|
79
|
+
# @param amount [String]
|
|
80
|
+
# Rule specifying that `increment_amount` be added to the existing value.
|
|
81
|
+
# If the targeted cell is unset, it will be treated as containing a zero.
|
|
82
|
+
# Otherwise, the targeted cell must contain an 8-byte value (interpreted
|
|
83
|
+
# as a 64-bit big-endian signed integer), or the entire request will fail.
|
|
84
|
+
# @return [Google::Cloud::Bigtable::ReadModifyWriteRule]
|
|
85
|
+
#
|
|
86
|
+
# @example increment value rule
|
|
87
|
+
# rule = Google::Cloud::Bigtable::ReadModifyWriteRule.increment(
|
|
88
|
+
# "cf", "field01", 1
|
|
89
|
+
# )
|
|
90
|
+
#
|
|
91
|
+
def self.increment family, qualifier, amount
|
|
92
|
+
rule = new(family, qualifier)
|
|
93
|
+
rule.increment(amount)
|
|
94
|
+
rule
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Set append value.
|
|
98
|
+
#
|
|
99
|
+
# @param value [String]
|
|
100
|
+
# @return [Google::Cloud::Bigtable::ReadModifyWriteRule]
|
|
101
|
+
#
|
|
102
|
+
def append value
|
|
103
|
+
@grpc.append_value = value
|
|
104
|
+
self
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# Set increment amount.
|
|
108
|
+
#
|
|
109
|
+
# @param amount [Integer]
|
|
110
|
+
# @return [Google::Cloud::Bigtable::ReadModifyWriteRule]
|
|
111
|
+
#
|
|
112
|
+
def increment amount
|
|
113
|
+
@grpc.increment_amount = amount
|
|
114
|
+
self
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# @private
|
|
118
|
+
#
|
|
119
|
+
# Get gRPC protobuf instance.
|
|
120
|
+
#
|
|
121
|
+
# @return [Google::Bigtable::V2::ReadModifyWriteRule]
|
|
122
|
+
#
|
|
123
|
+
def to_grpc
|
|
124
|
+
@grpc
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Copyright 2018 Google LLC
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# https:#www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
require "google/cloud/bigtable/row"
|
|
19
|
+
require "google/cloud/bigtable/rows_reader"
|
|
20
|
+
require "google/cloud/bigtable/row_range"
|
|
21
|
+
require "google/cloud/bigtable/row_filter"
|
|
22
|
+
require "google/cloud/bigtable/sample_row_key"
|
|
23
|
+
|
|
24
|
+
module Google
|
|
25
|
+
module Cloud
|
|
26
|
+
module Bigtable
|
|
27
|
+
# # ReadOperations
|
|
28
|
+
#
|
|
29
|
+
# Collection of read rows apis.
|
|
30
|
+
#
|
|
31
|
+
# * Sample row key
|
|
32
|
+
# * Read row
|
|
33
|
+
# * Read rows
|
|
34
|
+
#
|
|
35
|
+
module ReadOperations
|
|
36
|
+
# Read sample row keys.
|
|
37
|
+
#
|
|
38
|
+
# Returns a sample of row keys in the table. The returned row keys will
|
|
39
|
+
# delimit contiguous sections of the table of approximately equal size,
|
|
40
|
+
# which can be used to break up the data for distributed tasks like
|
|
41
|
+
# mapreduces.
|
|
42
|
+
#
|
|
43
|
+
# @yieldreturn [Google::Cloud::Bigtable::SampleRowKey]
|
|
44
|
+
# @return [:yields: sample_row_key]
|
|
45
|
+
# Yield block for each processed SampleRowKey.
|
|
46
|
+
#
|
|
47
|
+
# @example
|
|
48
|
+
# require "google/cloud"
|
|
49
|
+
#
|
|
50
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
51
|
+
# table = bigtable.table("my-instance", "my-table")
|
|
52
|
+
#
|
|
53
|
+
# table.sample_row_keys.each do |sample_row_key|
|
|
54
|
+
# p sample_row_key.key # user00116
|
|
55
|
+
# p sample_row_key.offset # 805306368
|
|
56
|
+
# end
|
|
57
|
+
#
|
|
58
|
+
def sample_row_keys
|
|
59
|
+
return enum_for(:sample_row_keys) unless block_given?
|
|
60
|
+
|
|
61
|
+
response = client.sample_row_keys(
|
|
62
|
+
path,
|
|
63
|
+
app_profile_id: @app_profile_id
|
|
64
|
+
)
|
|
65
|
+
response.each do |grpc|
|
|
66
|
+
yield SampleRowKey.from_grpc(grpc)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Read rows
|
|
71
|
+
#
|
|
72
|
+
# Streams back the contents of all requested rows in key order, optionally
|
|
73
|
+
# applying the same Reader filter to each.
|
|
74
|
+
# `read_rows`, `row_ranges` and `filter` if not specified, reads from all rows.
|
|
75
|
+
#
|
|
76
|
+
# See {Google::Cloud::Bigtable::RowFilter} for filter types.
|
|
77
|
+
#
|
|
78
|
+
# @param keys [Array<String>] List of row keys to be read. Optional.
|
|
79
|
+
# @param ranges [Google::Cloud::Bigtable::RowRange | Array<Google::Cloud::Bigtable::RowRange>]
|
|
80
|
+
# Row ranges array or single range. Optional.
|
|
81
|
+
# @param filter [SimpleFilter, ChainFilter, InterleaveFilter, ConditionFilter]
|
|
82
|
+
# The filter to apply to the contents of the specified row(s). If unset,
|
|
83
|
+
# reads the entries of each row. Optional.
|
|
84
|
+
# @param limit [Integer] Limit number of read rows count. Optional.
|
|
85
|
+
# The read will terminate after committing to N rows' worth of results.
|
|
86
|
+
# The default (zero) is to return all results.
|
|
87
|
+
# @return [Array<Google::Cloud::Bigtable::Row> | :yields: row]
|
|
88
|
+
# Array of row or yield block for each processed row.
|
|
89
|
+
# @example Read with Limit
|
|
90
|
+
# require "google/cloud/bigtable"
|
|
91
|
+
#
|
|
92
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
93
|
+
# table = bigtable.table("my-instance", "my-table")
|
|
94
|
+
#
|
|
95
|
+
# table.read_rows(limit: 10).each do |row|
|
|
96
|
+
# puts row
|
|
97
|
+
# end
|
|
98
|
+
#
|
|
99
|
+
# @example Read using row keys
|
|
100
|
+
# require "google/cloud/bigtable"
|
|
101
|
+
#
|
|
102
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
103
|
+
# table = bigtable.table("my-instance", "my-table")
|
|
104
|
+
#
|
|
105
|
+
# table.read_rows(keys: ["user-1", "user-2"]).each do |row|
|
|
106
|
+
# puts row
|
|
107
|
+
# end
|
|
108
|
+
#
|
|
109
|
+
# @example Read using row ranges
|
|
110
|
+
# require "google/cloud/bigtable"
|
|
111
|
+
#
|
|
112
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
113
|
+
# table = bigtable.table("my-instance", "my-table")
|
|
114
|
+
#
|
|
115
|
+
# range = table.row_range.between("user-1", "user-100")
|
|
116
|
+
#
|
|
117
|
+
# table.read_rows(ranges: range).each do |row|
|
|
118
|
+
# puts row
|
|
119
|
+
# end
|
|
120
|
+
#
|
|
121
|
+
# @example Read using filter
|
|
122
|
+
#
|
|
123
|
+
# require "google/cloud/bigtable"
|
|
124
|
+
#
|
|
125
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
126
|
+
# table = bigtable.table("my-instance", "my-table")
|
|
127
|
+
#
|
|
128
|
+
# filter = table.filter.key("user-*")
|
|
129
|
+
# # OR
|
|
130
|
+
# # filter = Google::Cloud::Bigtable::RowFilter.key("user-*")
|
|
131
|
+
#
|
|
132
|
+
# table.read_rows(filter: filter).each do |row|
|
|
133
|
+
# puts row
|
|
134
|
+
# end
|
|
135
|
+
#
|
|
136
|
+
# @example Read using filter with limit
|
|
137
|
+
#
|
|
138
|
+
# require "google/cloud/bigtable"
|
|
139
|
+
#
|
|
140
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
141
|
+
# table = bigtable.table("my-instance", "my-table")
|
|
142
|
+
#
|
|
143
|
+
# filter = table.filter.key("user-*")
|
|
144
|
+
# # OR
|
|
145
|
+
# # filter = Google::Cloud::Bigtable::RowFilter.key("user-*")
|
|
146
|
+
#
|
|
147
|
+
# table.read_rows(filter: filter, limit: 10).each do |row|
|
|
148
|
+
# puts rowow
|
|
149
|
+
# end
|
|
150
|
+
#
|
|
151
|
+
def read_rows \
|
|
152
|
+
keys: nil,
|
|
153
|
+
ranges: nil,
|
|
154
|
+
filter: nil,
|
|
155
|
+
limit: nil,
|
|
156
|
+
&block
|
|
157
|
+
unless block_given?
|
|
158
|
+
return enum_for(
|
|
159
|
+
:read_rows,
|
|
160
|
+
keys: keys,
|
|
161
|
+
ranges: ranges,
|
|
162
|
+
filter: filter,
|
|
163
|
+
limit: limit
|
|
164
|
+
)
|
|
165
|
+
end
|
|
166
|
+
row_set = build_row_set(keys, ranges)
|
|
167
|
+
rows_limit = limit
|
|
168
|
+
rows_filter = filter.to_grpc if filter
|
|
169
|
+
rows_reader = RowsReader.new(self)
|
|
170
|
+
|
|
171
|
+
begin
|
|
172
|
+
rows_reader.read(
|
|
173
|
+
rows: row_set,
|
|
174
|
+
filter: rows_filter,
|
|
175
|
+
rows_limit: rows_limit,
|
|
176
|
+
&block
|
|
177
|
+
)
|
|
178
|
+
rescue *RowsReader::RETRYABLE_ERRORS => e
|
|
179
|
+
rows_reader.retry_count += 1
|
|
180
|
+
unless rows_reader.retryable?
|
|
181
|
+
raise Google::Cloud::Error.from_error(e)
|
|
182
|
+
end
|
|
183
|
+
rows_limit, row_set = rows_reader.retry_options(limit, row_set)
|
|
184
|
+
retry
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# Read single row by key
|
|
189
|
+
#
|
|
190
|
+
# @param key [String] Row key. Required
|
|
191
|
+
# @param filter [Google::Cloud::Bigtable::RowFilter]
|
|
192
|
+
# The filter to apply to the contents of the specified row. Optional.
|
|
193
|
+
# @return [Google::Cloud::Bigtable::Row]
|
|
194
|
+
#
|
|
195
|
+
# @example Read row
|
|
196
|
+
#
|
|
197
|
+
# require "google/cloud/bigtable"
|
|
198
|
+
#
|
|
199
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
200
|
+
# table = bigtable.table("my-instance", "my-table")
|
|
201
|
+
#
|
|
202
|
+
# row = table.read_row("user-1")
|
|
203
|
+
#
|
|
204
|
+
# @example Read row
|
|
205
|
+
#
|
|
206
|
+
# require "google/cloud/bigtable"
|
|
207
|
+
#
|
|
208
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
209
|
+
# table = bigtable.table("my-instance", "my-table")
|
|
210
|
+
#
|
|
211
|
+
# filter = Google::Cloud::Bigtable::RowFilter.cells_per_row(3)
|
|
212
|
+
#
|
|
213
|
+
# row = table.read_row("user-1", filter: filter)
|
|
214
|
+
#
|
|
215
|
+
def read_row key, filter: nil
|
|
216
|
+
read_rows(keys: [key], filter: filter).first
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
# Create new instance of ValueRange.
|
|
220
|
+
#
|
|
221
|
+
# @return [Google::Cloud::Bigtable::ValueRange]
|
|
222
|
+
#
|
|
223
|
+
# @example
|
|
224
|
+
# require "google/cloud/bigtable"
|
|
225
|
+
#
|
|
226
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
227
|
+
# table = bigtable.table("my-instance", "my-table")
|
|
228
|
+
#
|
|
229
|
+
# range = table.value_range
|
|
230
|
+
# range.from("abc")
|
|
231
|
+
# range.to("xyz")
|
|
232
|
+
#
|
|
233
|
+
# # OR
|
|
234
|
+
# range = table.new_value_range.from("abc").to("xyz")
|
|
235
|
+
#
|
|
236
|
+
# @example With exclusive from range
|
|
237
|
+
# require "google/cloud/bigtable"
|
|
238
|
+
#
|
|
239
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
240
|
+
# table = bigtable.table("my-instance", "my-table")
|
|
241
|
+
#
|
|
242
|
+
# range = table.new_value_range.from("abc", inclusive: false).to("xyz")
|
|
243
|
+
#
|
|
244
|
+
def new_value_range
|
|
245
|
+
Google::Cloud::Bigtable::ValueRange.new
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
# Get new instance of ColumnRange.
|
|
249
|
+
#
|
|
250
|
+
# @param family [String] Column family name
|
|
251
|
+
# @return [Google::Cloud::Bigtable::ColumnRange]
|
|
252
|
+
#
|
|
253
|
+
# @example
|
|
254
|
+
# require "google/cloud/bigtable"
|
|
255
|
+
#
|
|
256
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
257
|
+
# table = bigtable.table("my-instance", "my-table")
|
|
258
|
+
#
|
|
259
|
+
# range = table.column_range("test-family")
|
|
260
|
+
# range.from("abc")
|
|
261
|
+
# range.to("xyz")
|
|
262
|
+
#
|
|
263
|
+
# # OR
|
|
264
|
+
# range = table.new_column_range("test-family").from("key-1").to("key-5")
|
|
265
|
+
#
|
|
266
|
+
# @example With exclusive from range
|
|
267
|
+
# require "google/cloud/bigtable"
|
|
268
|
+
#
|
|
269
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
270
|
+
# table = bigtable.table("my-instance", "my-table")
|
|
271
|
+
#
|
|
272
|
+
# range = table.new_column_range("test-family").from("key-1", inclusive: false).to("key-5")
|
|
273
|
+
#
|
|
274
|
+
def new_column_range family
|
|
275
|
+
Google::Cloud::Bigtable::ColumnRange.new(family)
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
# Get new instance of RowRange.
|
|
279
|
+
#
|
|
280
|
+
# @return [Google::Cloud::Bigtable::RowRange]
|
|
281
|
+
#
|
|
282
|
+
# @example
|
|
283
|
+
# require "google/cloud/bigtable"
|
|
284
|
+
#
|
|
285
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
286
|
+
# table = bigtable.table("my-instance", "my-table")
|
|
287
|
+
#
|
|
288
|
+
# range = table.row_range
|
|
289
|
+
# range.from("abc")
|
|
290
|
+
# range.to("xyz")
|
|
291
|
+
#
|
|
292
|
+
# # OR
|
|
293
|
+
# range = table.new_row_range.from("key-1").to("key-5")
|
|
294
|
+
#
|
|
295
|
+
# @example With exclusive from range
|
|
296
|
+
# require "google/cloud/bigtable"
|
|
297
|
+
#
|
|
298
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
299
|
+
# table = bigtable.table("my-instance", "my-table")
|
|
300
|
+
#
|
|
301
|
+
# range = table.new_row_range.from("key-1", inclusive: false).to("key-5")
|
|
302
|
+
#
|
|
303
|
+
def new_row_range
|
|
304
|
+
Google::Cloud::Bigtable::RowRange.new
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
# Get row filter
|
|
308
|
+
#
|
|
309
|
+
# @return [Google::Cloud::Bigtable::RowRange]
|
|
310
|
+
#
|
|
311
|
+
# @example
|
|
312
|
+
# require "google/cloud/bigtable"
|
|
313
|
+
#
|
|
314
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
315
|
+
# table = bigtable.table("my-instance", "my-table")
|
|
316
|
+
#
|
|
317
|
+
# filter = table.filter.key("user-*")
|
|
318
|
+
#
|
|
319
|
+
def filter
|
|
320
|
+
Google::Cloud::Bigtable::RowFilter
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
private
|
|
324
|
+
|
|
325
|
+
# Build RowSet object from row keys and ranges
|
|
326
|
+
#
|
|
327
|
+
# @param row_keys [Array<String>]
|
|
328
|
+
# @param row_ranges [Google::Cloud::Bigtable::RowRange | Array<Google::Cloud::Bigtable::RowRange>]
|
|
329
|
+
# @return [Google::Bigtable::V2::RowSet]
|
|
330
|
+
#
|
|
331
|
+
def build_row_set row_keys, row_ranges
|
|
332
|
+
row_set = {}
|
|
333
|
+
row_set[:row_keys] = row_keys if row_keys
|
|
334
|
+
|
|
335
|
+
if row_ranges
|
|
336
|
+
row_ranges = [row_ranges] unless row_ranges.instance_of?(Array)
|
|
337
|
+
row_set[:row_ranges] = row_ranges.map(&:to_grpc)
|
|
338
|
+
end
|
|
339
|
+
|
|
340
|
+
Google::Bigtable::V2::RowSet.new(row_set)
|
|
341
|
+
end
|
|
342
|
+
end
|
|
343
|
+
end
|
|
344
|
+
end
|
|
345
|
+
end
|