google-cloud-bigtable 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +19 -0
- data/AUTHENTICATION.md +177 -0
- data/CHANGELOG.md +223 -0
- data/CODE_OF_CONDUCT.md +40 -0
- data/CONTRIBUTING.md +188 -0
- data/EMULATOR.md +30 -0
- data/LICENSE +201 -0
- data/LOGGING.md +32 -0
- data/OVERVIEW.md +400 -0
- data/TROUBLESHOOTING.md +31 -0
- data/lib/google-cloud-bigtable.rb +171 -0
- data/lib/google/bigtable/admin/v2/bigtable_instance_admin_pb.rb +145 -0
- data/lib/google/bigtable/admin/v2/bigtable_instance_admin_services_pb.rb +90 -0
- data/lib/google/bigtable/admin/v2/bigtable_table_admin_pb.rb +208 -0
- data/lib/google/bigtable/admin/v2/bigtable_table_admin_services_pb.rb +154 -0
- data/lib/google/bigtable/admin/v2/common_pb.rb +30 -0
- data/lib/google/bigtable/admin/v2/instance_pb.rb +74 -0
- data/lib/google/bigtable/admin/v2/table_pb.rb +127 -0
- data/lib/google/bigtable/v2/bigtable_pb.rb +113 -0
- data/lib/google/bigtable/v2/bigtable_services_pb.rb +68 -0
- data/lib/google/bigtable/v2/data_pb.rb +156 -0
- data/lib/google/cloud/bigtable.rb +184 -0
- data/lib/google/cloud/bigtable/admin.rb +202 -0
- data/lib/google/cloud/bigtable/admin/credentials.rb +27 -0
- data/lib/google/cloud/bigtable/admin/v2.rb +223 -0
- data/lib/google/cloud/bigtable/admin/v2/bigtable_instance_admin_client.rb +1451 -0
- data/lib/google/cloud/bigtable/admin/v2/bigtable_instance_admin_client_config.json +139 -0
- data/lib/google/cloud/bigtable/admin/v2/bigtable_table_admin_client.rb +1734 -0
- data/lib/google/cloud/bigtable/admin/v2/bigtable_table_admin_client_config.json +163 -0
- data/lib/google/cloud/bigtable/admin/v2/credentials.rb +51 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/bigtable_instance_admin.rb +297 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/bigtable_table_admin.rb +587 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/instance.rb +193 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/table.rb +303 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/iam/v1/iam_policy.rb +64 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/iam/v1/options.rb +33 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/iam/v1/policy.rb +151 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/longrunning/operations.rb +51 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/any.rb +131 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/duration.rb +91 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/empty.rb +29 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/field_mask.rb +222 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/timestamp.rb +113 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/rpc/status.rb +39 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/type/expr.rb +45 -0
- data/lib/google/cloud/bigtable/app_profile.rb +439 -0
- data/lib/google/cloud/bigtable/app_profile/job.rb +99 -0
- data/lib/google/cloud/bigtable/app_profile/list.rb +165 -0
- data/lib/google/cloud/bigtable/backup.rb +324 -0
- data/lib/google/cloud/bigtable/backup/job.rb +87 -0
- data/lib/google/cloud/bigtable/backup/list.rb +167 -0
- data/lib/google/cloud/bigtable/chunk_processor.rb +241 -0
- data/lib/google/cloud/bigtable/cluster.rb +390 -0
- data/lib/google/cloud/bigtable/cluster/job.rb +88 -0
- data/lib/google/cloud/bigtable/cluster/list.rb +171 -0
- data/lib/google/cloud/bigtable/column_family.rb +73 -0
- data/lib/google/cloud/bigtable/column_family_map.rb +426 -0
- data/lib/google/cloud/bigtable/column_range.rb +194 -0
- data/lib/google/cloud/bigtable/convert.rb +83 -0
- data/lib/google/cloud/bigtable/credentials.rb +25 -0
- data/lib/google/cloud/bigtable/errors.rb +38 -0
- data/lib/google/cloud/bigtable/gc_rule.rb +334 -0
- data/lib/google/cloud/bigtable/instance.rb +935 -0
- data/lib/google/cloud/bigtable/instance/cluster_map.rb +74 -0
- data/lib/google/cloud/bigtable/instance/job.rb +98 -0
- data/lib/google/cloud/bigtable/instance/list.rb +164 -0
- data/lib/google/cloud/bigtable/longrunning_job.rb +122 -0
- data/lib/google/cloud/bigtable/mutation_entry.rb +256 -0
- data/lib/google/cloud/bigtable/mutation_operations.rb +357 -0
- data/lib/google/cloud/bigtable/policy.rb +167 -0
- data/lib/google/cloud/bigtable/project.rb +471 -0
- data/lib/google/cloud/bigtable/read_modify_write_rule.rb +134 -0
- data/lib/google/cloud/bigtable/read_operations.rb +328 -0
- data/lib/google/cloud/bigtable/routing_policy.rb +172 -0
- data/lib/google/cloud/bigtable/row.rb +136 -0
- data/lib/google/cloud/bigtable/row_filter.rb +639 -0
- data/lib/google/cloud/bigtable/row_filter/chain_filter.rb +590 -0
- data/lib/google/cloud/bigtable/row_filter/condition_filter.rb +114 -0
- data/lib/google/cloud/bigtable/row_filter/interleave_filter.rb +621 -0
- data/lib/google/cloud/bigtable/row_filter/simple_filter.rb +287 -0
- data/lib/google/cloud/bigtable/row_range.rb +179 -0
- data/lib/google/cloud/bigtable/rows_mutator.rb +113 -0
- data/lib/google/cloud/bigtable/rows_reader.rb +200 -0
- data/lib/google/cloud/bigtable/sample_row_key.rb +85 -0
- data/lib/google/cloud/bigtable/service.rb +913 -0
- data/lib/google/cloud/bigtable/status.rb +76 -0
- data/lib/google/cloud/bigtable/table.rb +686 -0
- data/lib/google/cloud/bigtable/table/cluster_state.rb +125 -0
- data/lib/google/cloud/bigtable/table/list.rb +154 -0
- data/lib/google/cloud/bigtable/table/restore_job.rb +117 -0
- data/lib/google/cloud/bigtable/v2.rb +146 -0
- data/lib/google/cloud/bigtable/v2/bigtable_client.rb +591 -0
- data/lib/google/cloud/bigtable/v2/bigtable_client_config.json +83 -0
- data/lib/google/cloud/bigtable/v2/credentials.rb +46 -0
- data/lib/google/cloud/bigtable/v2/doc/google/bigtable/v2/bigtable.rb +290 -0
- data/lib/google/cloud/bigtable/v2/doc/google/bigtable/v2/data.rb +493 -0
- data/lib/google/cloud/bigtable/v2/doc/google/protobuf/any.rb +131 -0
- data/lib/google/cloud/bigtable/v2/doc/google/protobuf/wrappers.rb +34 -0
- data/lib/google/cloud/bigtable/v2/doc/google/rpc/status.rb +39 -0
- data/lib/google/cloud/bigtable/value_range.rb +181 -0
- data/lib/google/cloud/bigtable/version.rb +22 -0
- metadata +337 -0
@@ -0,0 +1,194 @@
|
|
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
|
+
##
|
22
|
+
# # ColumnRange
|
23
|
+
#
|
24
|
+
# Specifies a contiguous range of column qualifiers.
|
25
|
+
#
|
26
|
+
# * Start qualifier bound : The qualifier at which to start the range.
|
27
|
+
# If neither field is set, interpreted as the empty string, inclusive.
|
28
|
+
# * End qualifier bound: The qualifier at which to end the range.
|
29
|
+
# If neither field is set, interpreted as the infinite string qualifier, exclusive.
|
30
|
+
#
|
31
|
+
# @example
|
32
|
+
# require "google/cloud/bigtable"
|
33
|
+
#
|
34
|
+
# bigtable = Google::Cloud::Bigtable.new
|
35
|
+
# table = bigtable.table("my-instance", "my-table")
|
36
|
+
#
|
37
|
+
# # Range that includes all qualifiers including "user-001" up until "user-010"
|
38
|
+
# table.new_column_range("cf").from("user-001").to("user-010")
|
39
|
+
#
|
40
|
+
# # Range that includes all qualifiers including "user-001" up to and including "user-005"
|
41
|
+
# table.new_column_range("cf").from("user-001").to("user-005", inclusive: true)
|
42
|
+
#
|
43
|
+
# # Range that includes all qualifiers until end of the row key "user-001".
|
44
|
+
# table.new_column_range("cf").to("user-010") # exclusive
|
45
|
+
#
|
46
|
+
# # Range with unbounded start and the inclusive end "user-100"
|
47
|
+
# table.new_column_range("cf").to("user-100", inclusive: true)
|
48
|
+
#
|
49
|
+
# # Range that includes all qualifiers including "user-001" up to and including "user-100"
|
50
|
+
# table.new_column_range("cf").between("user-001", "user-100")
|
51
|
+
#
|
52
|
+
class ColumnRange
|
53
|
+
##
|
54
|
+
# Create qualifier range instance.
|
55
|
+
#
|
56
|
+
# @param family [String] Column family name.
|
57
|
+
#
|
58
|
+
def initialize family
|
59
|
+
@grpc = Google::Bigtable::V2::ColumnRange.new family_name: family
|
60
|
+
end
|
61
|
+
|
62
|
+
##
|
63
|
+
# Gets the column family name.
|
64
|
+
#
|
65
|
+
# @return [String]
|
66
|
+
#
|
67
|
+
def family
|
68
|
+
@grpc.family_name
|
69
|
+
end
|
70
|
+
|
71
|
+
##
|
72
|
+
# Sets the column family name.
|
73
|
+
#
|
74
|
+
# @param name [String] Column family name
|
75
|
+
#
|
76
|
+
def family= name
|
77
|
+
@grpc.family_name = name
|
78
|
+
end
|
79
|
+
|
80
|
+
##
|
81
|
+
# Sets the column range with the lower bound.
|
82
|
+
#
|
83
|
+
# @param qualifier [String] Column qualifier name. Required
|
84
|
+
# @param inclusive [String] Lower bound flag. Inclusive/Exclusive.
|
85
|
+
# Default is an inclusive lower bound.
|
86
|
+
# @return [Google::Cloud::Bigtable::ColumnRange]
|
87
|
+
#
|
88
|
+
# @example Inclusive lower bound.
|
89
|
+
# require "google/cloud/bigtable"
|
90
|
+
#
|
91
|
+
# bigtable = Google::Cloud::Bigtable.new
|
92
|
+
# table = bigtable.table("my-instance", "my-table")
|
93
|
+
#
|
94
|
+
# table.new_column_range("cf").from("qualifier-1")
|
95
|
+
#
|
96
|
+
# @example Exclusive lower bound.
|
97
|
+
# require "google/cloud/bigtable"
|
98
|
+
#
|
99
|
+
# bigtable = Google::Cloud::Bigtable.new
|
100
|
+
# table = bigtable.table("my-instance", "my-table")
|
101
|
+
#
|
102
|
+
# table.new_column_range("cf").from("qualifier-1", inclusive: false)
|
103
|
+
#
|
104
|
+
def from qualifier, inclusive: true
|
105
|
+
if inclusive
|
106
|
+
@grpc.start_qualifier_closed = qualifier
|
107
|
+
else
|
108
|
+
@grpc.start_qualifier_open = qualifier
|
109
|
+
end
|
110
|
+
self
|
111
|
+
end
|
112
|
+
|
113
|
+
##
|
114
|
+
# Sets the column range with the upper bound.
|
115
|
+
#
|
116
|
+
# @param qualifier [String] Column qualifier name. Required.
|
117
|
+
# @param inclusive [String] Upper bound flag. Inclusive/Exclusive.
|
118
|
+
# Default is an inclusive upper bound.
|
119
|
+
# @return [Google::Cloud::Bigtable::ColumnRange]
|
120
|
+
#
|
121
|
+
# @example Inclusive upper bound.
|
122
|
+
# require "google/cloud/bigtable"
|
123
|
+
#
|
124
|
+
# bigtable = Google::Cloud::Bigtable.new
|
125
|
+
# table = bigtable.table("my-instance", "my-table")
|
126
|
+
#
|
127
|
+
# table.new_column_range("cf").to("qualifier-10", inclusive: true)
|
128
|
+
#
|
129
|
+
# @example Exclusive upper bound.
|
130
|
+
# require "google/cloud/bigtable"
|
131
|
+
#
|
132
|
+
# bigtable = Google::Cloud::Bigtable.new
|
133
|
+
# table = bigtable.table("my-instance", "my-table")
|
134
|
+
#
|
135
|
+
# table.new_column_range("cf").to("qualifier-10")
|
136
|
+
#
|
137
|
+
def to qualifier, inclusive: false
|
138
|
+
if inclusive
|
139
|
+
@grpc.end_qualifier_closed = qualifier
|
140
|
+
else
|
141
|
+
@grpc.end_qualifier_open = qualifier
|
142
|
+
end
|
143
|
+
self
|
144
|
+
end
|
145
|
+
|
146
|
+
##
|
147
|
+
# Sets the column range with the inclusive upper and lower bound.
|
148
|
+
#
|
149
|
+
# @param from_qualifier [String] Inclusive from qualifier. Required.
|
150
|
+
# @param to_qualifier [String] Inclusive to qualifier. Required.
|
151
|
+
# @return [Google::Cloud::Bigtable::ColumnRange]
|
152
|
+
#
|
153
|
+
# @example
|
154
|
+
# require "google/cloud/bigtable"
|
155
|
+
#
|
156
|
+
# bigtable = Google::Cloud::Bigtable.new
|
157
|
+
# table = bigtable.table("my-instance", "my-table")
|
158
|
+
#
|
159
|
+
# table.new_column_range("cf").between("qualifier-1", "qualifier-10")
|
160
|
+
#
|
161
|
+
def between from_qualifier, to_qualifier
|
162
|
+
from(from_qualifier).to(to_qualifier, inclusive: true)
|
163
|
+
end
|
164
|
+
|
165
|
+
##
|
166
|
+
# Sets the column range with the inclusive upper and the exclusive lower bound.
|
167
|
+
#
|
168
|
+
# @param from_qualifier [String] Inclusive from qualifier
|
169
|
+
# @param to_qualifier [String] Exclusive to qualifier
|
170
|
+
# @return [Google::Cloud::Bigtable::ColumnRange]
|
171
|
+
#
|
172
|
+
# @example
|
173
|
+
# require "google/cloud/bigtable"
|
174
|
+
#
|
175
|
+
# bigtable = Google::Cloud::Bigtable.new
|
176
|
+
# table = bigtable.table("my-instance", "my-table")
|
177
|
+
#
|
178
|
+
# table.new_column_range("cf").of("qualifier-1", "qualifier-10")
|
179
|
+
#
|
180
|
+
def of from_qualifier, to_qualifier
|
181
|
+
from(from_qualifier).to(to_qualifier)
|
182
|
+
end
|
183
|
+
|
184
|
+
# @private
|
185
|
+
#
|
186
|
+
# @return [Google::Bigtable::V2::ColumnRange]
|
187
|
+
#
|
188
|
+
def to_grpc
|
189
|
+
@grpc
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
@@ -0,0 +1,83 @@
|
|
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 "time"
|
19
|
+
require "date"
|
20
|
+
|
21
|
+
module Google
|
22
|
+
module Cloud
|
23
|
+
module Bigtable
|
24
|
+
# @private
|
25
|
+
# Helper module for converting Bigtable values.
|
26
|
+
module Convert
|
27
|
+
module_function
|
28
|
+
|
29
|
+
##
|
30
|
+
# Convert number to protobuf duration.
|
31
|
+
#
|
32
|
+
# @param number [Float] Seconds with nano seconds
|
33
|
+
# @return [Google::Protobuf::Duration, nil]
|
34
|
+
#
|
35
|
+
def number_to_duration number
|
36
|
+
return unless number
|
37
|
+
|
38
|
+
Google::Protobuf::Duration.new(
|
39
|
+
seconds: number.to_i,
|
40
|
+
nanos: (number.remainder(1) * 1_000_000_000).round
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# Convert protobuf durations to float.
|
46
|
+
#
|
47
|
+
# @param duration [Google::Protobuf::Duration, nil]
|
48
|
+
# @return [Float, Integer, nil] Seconds with nano seconds
|
49
|
+
#
|
50
|
+
def duration_to_number duration
|
51
|
+
return unless duration
|
52
|
+
return duration.seconds if duration.nanos.zero?
|
53
|
+
|
54
|
+
duration.seconds + (duration.nanos / 1_000_000_000.0)
|
55
|
+
end
|
56
|
+
|
57
|
+
##
|
58
|
+
# Convert protobuf timestamp to Time object.
|
59
|
+
#
|
60
|
+
# @param timestamp [Google::Protobuf::Timestamp]
|
61
|
+
# @return [Time, nil]
|
62
|
+
#
|
63
|
+
def timestamp_to_time timestamp
|
64
|
+
return unless timestamp
|
65
|
+
|
66
|
+
Time.at timestamp.seconds, timestamp.nanos / 1000.0
|
67
|
+
end
|
68
|
+
|
69
|
+
##
|
70
|
+
# Convert time to timestamp protobuf object.
|
71
|
+
#
|
72
|
+
# @param time [Time]
|
73
|
+
# @return [Google::Protobuf::Timestamp, nil]
|
74
|
+
#
|
75
|
+
def time_to_timestamp time
|
76
|
+
return unless time
|
77
|
+
|
78
|
+
Google::Protobuf::Timestamp.new seconds: time.to_i, nanos: time.nsec
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# Copyright 2018 Google LLC
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
|
16
|
+
require "google/cloud/bigtable/v2/credentials"
|
17
|
+
|
18
|
+
module Google
|
19
|
+
module Cloud
|
20
|
+
module Bigtable
|
21
|
+
class Credentials < Google::Cloud::Bigtable::V2::Credentials
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# Copyright 2018 Google LLC
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
|
16
|
+
module Google
|
17
|
+
module Cloud
|
18
|
+
module Bigtable
|
19
|
+
##
|
20
|
+
# Invalid read row state error
|
21
|
+
class InvalidRowStateError < Google::Cloud::Error
|
22
|
+
##
|
23
|
+
# Invalid row chunk data
|
24
|
+
attr_reader :data
|
25
|
+
|
26
|
+
def initialize message, data = nil
|
27
|
+
super message
|
28
|
+
@data = data if data
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
##
|
33
|
+
# Row filter error.
|
34
|
+
class RowFilterError < Google::Cloud::Error
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,334 @@
|
|
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
|
+
##
|
22
|
+
# # GcRule
|
23
|
+
#
|
24
|
+
# A rule or rules for determining which cells to delete during garbage
|
25
|
+
# collection.
|
26
|
+
#
|
27
|
+
# Garbage collection (GC) executes opportunistically in the background,
|
28
|
+
# so it is possible for reads to return a cell even if it matches the
|
29
|
+
# active GC expression for its column family.
|
30
|
+
#
|
31
|
+
# GC Rule types:
|
32
|
+
# * `max_num_versions` - A garbage-collection rule that explicitly
|
33
|
+
# states the maximum number of cells to keep for all columns in a
|
34
|
+
# column family.
|
35
|
+
# * `max_age` - A garbage-collection rule based on the timestamp for
|
36
|
+
# each cell. With this type of garbage-collection rule, you set the
|
37
|
+
# time to live (TTL) for data. Cloud Bigtable looks at each column
|
38
|
+
# family during garbage collection and removes any cells that have
|
39
|
+
# expired.
|
40
|
+
# * `union` - A union garbage-collection policy will remove all data
|
41
|
+
# matching *any* of a set of given rules.
|
42
|
+
# * `intersection` - An intersection garbage-collection policy will
|
43
|
+
# remove all data matching *all* of a set of given rules.
|
44
|
+
#
|
45
|
+
# @example Create a table with column families.
|
46
|
+
# require "google/cloud/bigtable"
|
47
|
+
#
|
48
|
+
# bigtable = Google::Cloud::Bigtable.new
|
49
|
+
#
|
50
|
+
# table = bigtable.create_table("my-instance", "my-table") do |cfm|
|
51
|
+
# cfm.add("cf1", gc_rule: Google::Cloud::Bigtable::GcRule.max_versions(5))
|
52
|
+
# cfm.add("cf2", gc_rule: Google::Cloud::Bigtable::GcRule.max_age(600))
|
53
|
+
#
|
54
|
+
# gc_rule = Google::Cloud::Bigtable::GcRule.union(
|
55
|
+
# Google::Cloud::Bigtable::GcRule.max_age(1800),
|
56
|
+
# Google::Cloud::Bigtable::GcRule.max_versions(3)
|
57
|
+
# )
|
58
|
+
# cfm.add("cf3", gc_rule: gc_rule)
|
59
|
+
# end
|
60
|
+
#
|
61
|
+
# puts table.column_families["cf1"].gc_rule.max_versions
|
62
|
+
# puts table.column_families["cf2"].gc_rule.max_age
|
63
|
+
# puts table.column_families["cf3"].gc_rule.union
|
64
|
+
#
|
65
|
+
class GcRule
|
66
|
+
# @private
|
67
|
+
# Creates a new GC Rule instance.
|
68
|
+
#
|
69
|
+
# @param grpc [Google::Bigtable::Admin::V2::GcRule | nil]
|
70
|
+
#
|
71
|
+
def initialize grpc = nil
|
72
|
+
@grpc = grpc || Google::Bigtable::Admin::V2::GcRule.new
|
73
|
+
end
|
74
|
+
|
75
|
+
##
|
76
|
+
# Sets a garbage-collection rule that explicitly states the maximum
|
77
|
+
# number of cells to keep for all columns in a column family.
|
78
|
+
#
|
79
|
+
# @param versions [Integer]
|
80
|
+
#
|
81
|
+
def max_versions= versions
|
82
|
+
@grpc.max_num_versions = versions
|
83
|
+
end
|
84
|
+
|
85
|
+
##
|
86
|
+
# Gets the garbage-collection rule that explicitly states the maximum
|
87
|
+
# number of cells to keep for all columns in a column family.
|
88
|
+
#
|
89
|
+
# @return [Integer, nil]
|
90
|
+
#
|
91
|
+
# @example
|
92
|
+
# require "google/cloud/bigtable"
|
93
|
+
#
|
94
|
+
# bigtable = Google::Cloud::Bigtable.new
|
95
|
+
#
|
96
|
+
# table = bigtable.create_table("my-instance", "my-table") do |cfm|
|
97
|
+
# cfm.add("cf1", gc_rule: Google::Cloud::Bigtable::GcRule.max_versions(5))
|
98
|
+
# end
|
99
|
+
#
|
100
|
+
# puts table.column_families["cf1"].gc_rule.max_versions
|
101
|
+
#
|
102
|
+
def max_versions
|
103
|
+
@grpc.max_num_versions
|
104
|
+
end
|
105
|
+
|
106
|
+
##
|
107
|
+
# Sets a garbage-collection rule based on the timestamp for each cell.
|
108
|
+
# With this type of garbage-collection rule, you set the time to live
|
109
|
+
# (TTL) for data. Cloud Bigtable looks at each column family during
|
110
|
+
# garbage collection and removes any cells that have expired.
|
111
|
+
#
|
112
|
+
# @param age [Numeric] Max age in seconds. Values must be at least one
|
113
|
+
# millisecond, and will be truncated to microsecond granularity.
|
114
|
+
#
|
115
|
+
def max_age= age
|
116
|
+
@grpc.max_age = Convert.number_to_duration age
|
117
|
+
end
|
118
|
+
|
119
|
+
##
|
120
|
+
# Gets the garbage-collection rule based on the timestamp for each cell.
|
121
|
+
# With this type of garbage-collection rule, you set the time to live
|
122
|
+
# (TTL) for data. Cloud Bigtable looks at each column family during
|
123
|
+
# garbage collection and removes any cells that have expired.
|
124
|
+
#
|
125
|
+
# @return [Numeric, nil] Max age in seconds.
|
126
|
+
#
|
127
|
+
# @example
|
128
|
+
# require "google/cloud/bigtable"
|
129
|
+
#
|
130
|
+
# bigtable = Google::Cloud::Bigtable.new
|
131
|
+
#
|
132
|
+
# table = bigtable.create_table("my-instance", "my-table") do |cfm|
|
133
|
+
# cfm.add("cf1", gc_rule: Google::Cloud::Bigtable::GcRule.max_age(600))
|
134
|
+
# end
|
135
|
+
#
|
136
|
+
# puts table.column_families["cf1"].gc_rule.max_age
|
137
|
+
#
|
138
|
+
def max_age
|
139
|
+
Convert.duration_to_number @grpc.max_age
|
140
|
+
end
|
141
|
+
|
142
|
+
##
|
143
|
+
# Sets the intersection rules collection for this GcRule.
|
144
|
+
#
|
145
|
+
# @param rules [Array<Google::Cloud::Bigtable::GcRule>]
|
146
|
+
# List of GcRule with nested rules.
|
147
|
+
#
|
148
|
+
def intersection= rules
|
149
|
+
@grpc.intersection = Google::Bigtable::Admin::V2::GcRule::Intersection.new rules: rules.map(&:to_grpc)
|
150
|
+
end
|
151
|
+
|
152
|
+
##
|
153
|
+
#
|
154
|
+
# Gets the intersection rules collection for this GcRule.
|
155
|
+
#
|
156
|
+
# @return [Array<Google::Cloud::Bigtable::GcRule>, nil]
|
157
|
+
#
|
158
|
+
# @example
|
159
|
+
# require "google/cloud/bigtable"
|
160
|
+
#
|
161
|
+
# bigtable = Google::Cloud::Bigtable.new
|
162
|
+
#
|
163
|
+
# table = bigtable.create_table("my-instance", "my-table") do |cfm|
|
164
|
+
# gc_rule = Google::Cloud::Bigtable::GcRule.intersection(
|
165
|
+
# Google::Cloud::Bigtable::GcRule.max_age(1800),
|
166
|
+
# Google::Cloud::Bigtable::GcRule.max_versions(3)
|
167
|
+
# )
|
168
|
+
# cfm.add("cf1", gc_rule: gc_rule)
|
169
|
+
# end
|
170
|
+
#
|
171
|
+
# puts table.column_families["cf1"].gc_rule.intersection
|
172
|
+
#
|
173
|
+
def intersection
|
174
|
+
return nil unless @grpc.intersection
|
175
|
+
@grpc.intersection.rules.map do |gc_rule_grpc|
|
176
|
+
self.class.from_grpc gc_rule_grpc
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
##
|
181
|
+
# Sets the union rules collection for this GcRule. A union
|
182
|
+
# garbage-collection policy will remove all data matching *any* of its
|
183
|
+
# set of given rules.
|
184
|
+
#
|
185
|
+
# @param rules [Array<Google::Cloud::Bigtable::GcRule>]
|
186
|
+
# List of GcRule with nested rules.
|
187
|
+
#
|
188
|
+
def union= rules
|
189
|
+
@grpc.union = Google::Bigtable::Admin::V2::GcRule::Union.new rules: rules.map(&:to_grpc)
|
190
|
+
end
|
191
|
+
|
192
|
+
##
|
193
|
+
# Gets the union rules collection for this GcRule. A union
|
194
|
+
# garbage-collection policy will remove all data matching *any* of its
|
195
|
+
# set of given rules.
|
196
|
+
#
|
197
|
+
# @return [Array<Google::Cloud::Bigtable::GcRule>, nil]
|
198
|
+
#
|
199
|
+
# @example
|
200
|
+
# require "google/cloud/bigtable"
|
201
|
+
#
|
202
|
+
# bigtable = Google::Cloud::Bigtable.new
|
203
|
+
#
|
204
|
+
# table = bigtable.create_table("my-instance", "my-table") do |cfm|
|
205
|
+
# gc_rule = Google::Cloud::Bigtable::GcRule.union(
|
206
|
+
# Google::Cloud::Bigtable::GcRule.max_age(1800),
|
207
|
+
# Google::Cloud::Bigtable::GcRule.max_versions(3)
|
208
|
+
# )
|
209
|
+
# cfm.add("cf1", gc_rule: gc_rule)
|
210
|
+
# end
|
211
|
+
#
|
212
|
+
# puts table.column_families["cf1"].gc_rule.union
|
213
|
+
#
|
214
|
+
def union
|
215
|
+
return nil unless @grpc.union
|
216
|
+
@grpc.union.rules.map do |gc_rule_grpc|
|
217
|
+
self.class.from_grpc gc_rule_grpc
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
##
|
222
|
+
# Creates a GcRule instance with max number of versions.
|
223
|
+
#
|
224
|
+
# @param versions [Integer] Max number of versions
|
225
|
+
# @return [Google::Cloud::Bigtable::GcRule]
|
226
|
+
#
|
227
|
+
# @example
|
228
|
+
# require "google/cloud/bigtable"
|
229
|
+
#
|
230
|
+
# bigtable = Google::Cloud::Bigtable.new
|
231
|
+
#
|
232
|
+
# table = bigtable.create_table("my-instance", "my-table") do |cfm|
|
233
|
+
# cfm.add("cf1", gc_rule: Google::Cloud::Bigtable::GcRule.max_versions(5))
|
234
|
+
# end
|
235
|
+
#
|
236
|
+
def self.max_versions versions
|
237
|
+
new.tap do |gc_rule|
|
238
|
+
gc_rule.max_versions = versions
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
##
|
243
|
+
# Creates a GcRule instance with max age.
|
244
|
+
#
|
245
|
+
# @param age [Integer] Max age in seconds.
|
246
|
+
# @return [Google::Cloud::Bigtable::GcRule]
|
247
|
+
#
|
248
|
+
# @example
|
249
|
+
# require "google/cloud/bigtable"
|
250
|
+
#
|
251
|
+
# bigtable = Google::Cloud::Bigtable.new
|
252
|
+
#
|
253
|
+
# table = bigtable.create_table("my-instance", "my-table") do |cfm|
|
254
|
+
# cfm.add("cf1", gc_rule: Google::Cloud::Bigtable::GcRule.max_age(600))
|
255
|
+
# end
|
256
|
+
#
|
257
|
+
def self.max_age age
|
258
|
+
new.tap do |gc_rule|
|
259
|
+
gc_rule.max_age = age
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
##
|
264
|
+
# Creates a union GcRule instance.
|
265
|
+
#
|
266
|
+
# @param rules [Google::Cloud::Bigtable::GcRule, Array<Google::Cloud::Bigtable::GcRule>]
|
267
|
+
# List of GcRule with nested rules.
|
268
|
+
# @return [Google::Cloud::Bigtable::GcRule]
|
269
|
+
#
|
270
|
+
# @example
|
271
|
+
# require "google/cloud/bigtable"
|
272
|
+
#
|
273
|
+
# bigtable = Google::Cloud::Bigtable.new
|
274
|
+
#
|
275
|
+
# table = bigtable.create_table("my-instance", "my-table") do |cfm|
|
276
|
+
# gc_rule = Google::Cloud::Bigtable::GcRule.union(
|
277
|
+
# Google::Cloud::Bigtable::GcRule.max_age(1800),
|
278
|
+
# Google::Cloud::Bigtable::GcRule.max_versions(3)
|
279
|
+
# )
|
280
|
+
# cfm.add("cf1", gc_rule: gc_rule)
|
281
|
+
# end
|
282
|
+
#
|
283
|
+
def self.union *rules
|
284
|
+
new.tap do |gc_rule|
|
285
|
+
gc_rule.union = rules
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
##
|
290
|
+
# Creates a intersection GCRule instance.
|
291
|
+
#
|
292
|
+
# @param rules [Google::Cloud::Bigtable::GcRule, Array<Google::Cloud::Bigtable::GcRule>]
|
293
|
+
# List of GcRule with nested rules.
|
294
|
+
# @return [Google::Cloud::Bigtable::GcRule]
|
295
|
+
#
|
296
|
+
# @example
|
297
|
+
# require "google/cloud/bigtable"
|
298
|
+
#
|
299
|
+
# bigtable = Google::Cloud::Bigtable.new
|
300
|
+
#
|
301
|
+
# table = bigtable.create_table("my-instance", "my-table") do |cfm|
|
302
|
+
# gc_rule = Google::Cloud::Bigtable::GcRule.intersection(
|
303
|
+
# Google::Cloud::Bigtable::GcRule.max_age(1800),
|
304
|
+
# Google::Cloud::Bigtable::GcRule.max_versions(3)
|
305
|
+
# )
|
306
|
+
# cfm.add("cf1", gc_rule: gc_rule)
|
307
|
+
# end
|
308
|
+
#
|
309
|
+
def self.intersection *rules
|
310
|
+
new.tap do |gc_rule|
|
311
|
+
gc_rule.intersection = rules
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
# @private
|
316
|
+
# Get gRPC instance of GC Rule
|
317
|
+
# @return [Google::Bigtable::Admin::V2::GcRule]
|
318
|
+
def to_grpc
|
319
|
+
@grpc
|
320
|
+
end
|
321
|
+
|
322
|
+
# @private
|
323
|
+
#
|
324
|
+
# Creates a new GcRule instance from a
|
325
|
+
# Google::Bigtable::Admin::V2::GcRule.
|
326
|
+
# @param grpc [Google::Bigtable::Admin::V2::GcRule]
|
327
|
+
# @return [Google::Cloud::Bigtable::GcRule]
|
328
|
+
def self.from_grpc grpc
|
329
|
+
new grpc
|
330
|
+
end
|
331
|
+
end
|
332
|
+
end
|
333
|
+
end
|
334
|
+
end
|