Column Families#
When creating a
ColumnFamily, 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
MaxAgeGCRule,
MaxVersionsGCRule,
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 a
MaxAgeGCRule or
MaxVersionsGCRule
at the lowest level of the nesting:
import datetime
max_age = datetime.timedelta(days=3)
rule1 = MaxAgeGCRule(max_age)
rule2 = MaxVersionsGCRule(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
google.cloud.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) – The table that owns the column family. - gc_rule (
GarbageCollectionRule) – (Optional) The garbage collection settings for this 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.
- column_family_id (str) – The ID of the column family. Must be of the
form
-
class
google.cloud.bigtable.column_family.GCRuleIntersection(rules)[source]# Bases:
google.cloud.bigtable.column_family.GarbageCollectionRuleIntersection of garbage collection rules.
Parameters: rules (list) – List of GarbageCollectionRule.
-
class
google.cloud.bigtable.column_family.GCRuleUnion(rules)[source]# Bases:
google.cloud.bigtable.column_family.GarbageCollectionRuleUnion of garbage collection rules.
Parameters: rules (list) – List of GarbageCollectionRule.
-
class
google.cloud.bigtable.column_family.GarbageCollectionRule[source]# Bases:
objectGarbage collection rule for column families within a table.
Cells in the column family (within a table) fitting the rule will be deleted during garbage collection.
Note
This class is a do-nothing base class for all GC rules.
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 native classes.
-
class
google.cloud.bigtable.column_family.MaxAgeGCRule(max_age)[source]# Bases:
google.cloud.bigtable.column_family.GarbageCollectionRuleGarbage collection limiting the age of a cell.
Parameters: max_age ( datetime.timedelta) – The maximum age allowed for a cell in the table.
-
class
google.cloud.bigtable.column_family.MaxVersionsGCRule(max_num_versions)[source]# Bases:
google.cloud.bigtable.column_family.GarbageCollectionRuleGarbage collection limiting the number of versions of a cell.
Parameters: max_num_versions (int) – The maximum number of versions