Column Families¶
When creating a Table,
it is possible to set garbage collection rules for expired data.
By setting a rule, cells in the table matching the rule will be deleted during periodic garbage collection (which executes opportunistically in the background).
The types
GarbageCollectionRule,
GarbageCollectionRuleUnion and
GarbageCollectionRuleIntersection
can all be used as the optional gc_rule argument in the
ColumnFamily
constructor. This value is then used in the
create() and
update() methods.
These rules can be nested arbitrarily, with
GarbageCollectionRule
at the lowest level of the nesting:
import datetime
max_age = datetime.timedelta(days=3)
rule1 = GarbageCollectionRule(max_age=max_age)
rule2 = GarbageCollectionRule(max_num_versions=1)
# Make a composite that matches anything older than 3 days **AND**
# with more than 1 version.
rule3 = GarbageCollectionIntersection(rules=[rule1, rule2])
# Make another composite that matches our previous intersection
# **OR** anything that has more than 3 versions.
rule4 = GarbageCollectionRule(max_num_versions=3)
rule5 = GarbageCollectionUnion(rules=[rule3, rule4])
User friendly container for Google Cloud Bigtable Column Family.
-
class
gcloud_bigtable.column_family.ColumnFamily(column_family_id, table, gc_rule=None)[source]¶ Bases:
objectRepresentation of a Google Cloud Bigtable Column Family.
We can use a
ColumnFamilyto:Parameters: - column_family_id (str) – The ID of the column family. Must be of the
form
[_a-zA-Z0-9][-_.a-zA-Z0-9]*. - table (
table.Table) – The table that owns the column family. - gc_rule (
GarbageCollectionRule,GarbageCollectionRuleUnionorGarbageCollectionRuleIntersection) – (Optional) The garbage collection settings for this column family.
-
client¶ Getter for column family’s client.
Return type: client.ClientReturns: The client that owns this column family.
-
create(timeout_seconds=None)[source]¶ Create this column family.
Parameters: timeout_seconds (int) – Number of seconds for request time-out. If not passed, defaults to value set on column family.
-
delete(timeout_seconds=None)[source]¶ Delete this column family.
Parameters: timeout_seconds (int) – Number of seconds for request time-out. If not passed, defaults to value set on column family.
-
name¶ Column family name used in requests.
Note
This property will not change if
column_family_iddoes not, but the return value is not cached.The table name is of the form
"projects/../zones/../clusters/../tables/../columnFamilies/.."Return type: str Returns: The column family name.
-
table¶ Getter for column family’s table.
Return type: table.TableReturns: The table stored on the column family.
-
timeout_seconds¶ Getter for column family’s default timeout seconds.
Return type: int Returns: The timeout seconds default.
-
update(timeout_seconds=None)[source]¶ Update this column family.
Note
The Bigtable Table Admin API currently returns
BigtableTableService.UpdateColumnFamily is not yet implementedwhen this method is used. It’s unclear when this method will actually be supported by the API.
Parameters: timeout_seconds (int) – Number of seconds for request time-out. If not passed, defaults to value set on column family.
- column_family_id (str) – The ID of the column family. Must be of the
form
-
class
gcloud_bigtable.column_family.GarbageCollectionRule(max_num_versions=None, max_age=None)[source]¶ Bases:
objectTable garbage collection rule.
Cells in the table fitting the rule will be deleted during garbage collection.
These values can be combined via
GarbageCollectionRuleUnionandGarbageCollectionRuleIntersection.Note
At most one of
max_num_versionsandmax_agecan be specified at once.Note
A string
gc_expressioncan also be used with API requests, but that value would be superceded by agc_rule. As a result, we don’t support that feature and instead support via this native object.Parameters: - max_num_versions (int) – The maximum number of versions
- max_age (
datetime.timedelta) – The maximum age allowed for a cell in the table.
Raises: TypeErrorif bothmax_num_versionsandmax_ageare set.-
to_pb()[source]¶ Converts the
GarbageCollectionRuleto a protobuf.Return type: data_pb2.GcRuleReturns: The converted current object.
-
class
gcloud_bigtable.column_family.GarbageCollectionRuleIntersection(rules=None)[source]¶ Bases:
objectIntersection of garbage collection rules.
Parameters: rules (list) – List of GarbageCollectionRule,GarbageCollectionRuleUnionand/orGarbageCollectionRuleIntersection
-
class
gcloud_bigtable.column_family.GarbageCollectionRuleUnion(rules=None)[source]¶ Bases:
objectUnion of garbage collection rules.
Parameters: rules (list) – List of GarbageCollectionRule,GarbageCollectionRuleUnionand/orGarbageCollectionRuleIntersection