Reference documentation and code samples for the Cloud Bigtable API class Google::Cloud::Bigtable::GcRule.
GcRule
A rule or rules for determining which cells to delete during garbage
collection.
Garbage collection (GC) executes opportunistically in the background,
so it is possible for reads to return a cell even if it matches the
active GC expression for its column family.
GC Rule types:
max_num_versions - A garbage-collection rule that explicitly
states the maximum number of cells to keep for all columns in a
column family.
max_age - A garbage-collection rule based on the timestamp for
each cell. With this type of garbage-collection rule, you set the
time to live (TTL) for data. Cloud Bigtable looks at each column
family during garbage collection and removes any cells that have
expired.
union - A union garbage-collection policy will remove all data
matching any of a set of given rules.
intersection - An intersection garbage-collection policy will
remove all data matching all of a set of given rules.
Gets the garbage-collection rule based on the timestamp for each cell.
With this type of garbage-collection rule, you set the time to live
(TTL) for data. Cloud Bigtable looks at each column family during
garbage collection and removes any cells that have expired.
Sets a garbage-collection rule based on the timestamp for each cell.
With this type of garbage-collection rule, you set the time to live
(TTL) for data. Cloud Bigtable looks at each column family during
garbage collection and removes any cells that have expired.
Parameter
age (Numeric) — Max age in seconds. Values must be at least one
millisecond, and will be truncated to microsecond granularity.
#max_versions
defmax_versions()->Integer,nil
Gets the garbage-collection rule that explicitly states the maximum
number of cells to keep for all columns in a column family.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Cloud Bigtable API - Class Google::Cloud::Bigtable::GcRule (v2.12.1)\n\nVersion latestkeyboard_arrow_down\n\n- [2.12.1 (latest)](/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-GcRule)\n- [2.12.0](/ruby/docs/reference/google-cloud-bigtable/2.12.0/Google-Cloud-Bigtable-GcRule)\n- [2.11.1](/ruby/docs/reference/google-cloud-bigtable/2.11.1/Google-Cloud-Bigtable-GcRule)\n- [2.10.2](/ruby/docs/reference/google-cloud-bigtable/2.10.2/Google-Cloud-Bigtable-GcRule)\n- [2.9.1](/ruby/docs/reference/google-cloud-bigtable/2.9.1/Google-Cloud-Bigtable-GcRule)\n- [2.8.0](/ruby/docs/reference/google-cloud-bigtable/2.8.0/Google-Cloud-Bigtable-GcRule)\n- [2.7.1](/ruby/docs/reference/google-cloud-bigtable/2.7.1/Google-Cloud-Bigtable-GcRule)\n- [2.6.5](/ruby/docs/reference/google-cloud-bigtable/2.6.5/Google-Cloud-Bigtable-GcRule) \nReference documentation and code samples for the Cloud Bigtable API class Google::Cloud::Bigtable::GcRule.\n\nGcRule\n------\n\nA rule or rules for determining which cells to delete during garbage\ncollection.\n\nGarbage collection (GC) executes opportunistically in the background,\nso it is possible for reads to return a cell even if it matches the\nactive GC expression for its column family.\n\nGC Rule types:\n\n- `max_num_versions` - A garbage-collection rule that explicitly states the maximum number of cells to keep for all columns in a column family.\n- `max_age` - A garbage-collection rule based on the timestamp for each cell. With this type of garbage-collection rule, you set the time to live (TTL) for data. Cloud Bigtable looks at each column family during garbage collection and removes any cells that have expired.\n- `union` - A union garbage-collection policy will remove all data matching *any* of a set of given rules.\n- `intersection` - An intersection garbage-collection policy will remove all data matching *all* of a set of given rules. \n\nInherits\n--------\n\n- Object\n\nExample\n-------\n\nCreate a table with column families. \n\n```ruby\nrequire \"google/cloud/bigtable\"\n\nbigtable = Google::Cloud::Bigtable.new\n\ntable = bigtable.create_table \"my-instance\", \"my-table\" do |cfm|\n cfm.add \"cf1\", gc_rule: Google::Cloud::Bigtable::GcRule.max_versions(5)\n cfm.add \"cf2\", gc_rule: Google::Cloud::Bigtable::GcRule.max_age(600)\n\n gc_rule = Google::Cloud::Bigtable::GcRule.union(\n Google::Cloud::Bigtable::GcRule.max_age(1800),\n Google::Cloud::Bigtable::GcRule.max_versions(3)\n )\n cfm.add \"cf3\", gc_rule: gc_rule\nend\n\nputs table.column_families[\"cf1\"].gc_rule.max_versions\nputs table.column_families[\"cf2\"].gc_rule.max_age\nputs table.column_families[\"cf3\"].gc_rule.union\n```\n\nMethods\n-------\n\n### .intersection\n\n def self.intersection(*rules) -\u003e Google::Cloud::Bigtable::GcRule\n\nCreates a intersection GCRule instance. \n**Parameter**\n\n- **rules** ([Google::Cloud::Bigtable::GcRule](./Google-Cloud-Bigtable-GcRule), Array\\\u003c[Google::Cloud::Bigtable::GcRule](./Google-Cloud-Bigtable-GcRule)\\\u003e) --- List of GcRule with nested rules. \n**Returns**\n\n- ([Google::Cloud::Bigtable::GcRule](./Google-Cloud-Bigtable-GcRule))\n**Example** \n\n```ruby\nrequire \"google/cloud/bigtable\"\n\nbigtable = Google::Cloud::Bigtable.new\n\ntable = bigtable.create_table \"my-instance\", \"my-table\" do |cfm|\n gc_rule = Google::Cloud::Bigtable::GcRule.intersection(\n Google::Cloud::Bigtable::GcRule.max_age(1800),\n Google::Cloud::Bigtable::GcRule.max_versions(3)\n )\n cfm.add \"cf1\", gc_rule: gc_rule\nend\n```\n\n### .max_age\n\n def self.max_age(age) -\u003e Google::Cloud::Bigtable::GcRule\n\nCreates a GcRule instance with max age. \n**Parameter**\n\n- **age** (Integer) --- Max age in seconds. \n**Returns**\n\n- ([Google::Cloud::Bigtable::GcRule](./Google-Cloud-Bigtable-GcRule))\n**Example** \n\n```ruby\nrequire \"google/cloud/bigtable\"\n\nbigtable = Google::Cloud::Bigtable.new\n\ntable = bigtable.create_table \"my-instance\", \"my-table\" do |cfm|\n cfm.add \"cf1\", gc_rule: Google::Cloud::Bigtable::GcRule.max_age(600)\nend\n```\n\n### .max_versions\n\n def self.max_versions(versions) -\u003e Google::Cloud::Bigtable::GcRule\n\nCreates a GcRule instance with max number of versions. \n**Parameter**\n\n- **versions** (Integer) --- Max number of versions \n**Returns**\n\n- ([Google::Cloud::Bigtable::GcRule](./Google-Cloud-Bigtable-GcRule))\n**Example** \n\n```ruby\nrequire \"google/cloud/bigtable\"\n\nbigtable = Google::Cloud::Bigtable.new\n\ntable = bigtable.create_table \"my-instance\", \"my-table\" do |cfm|\n cfm.add \"cf1\", gc_rule: Google::Cloud::Bigtable::GcRule.max_versions(5)\nend\n```\n\n### .union\n\n def self.union(*rules) -\u003e Google::Cloud::Bigtable::GcRule\n\nCreates a union GcRule instance. \n**Parameter**\n\n- **rules** ([Google::Cloud::Bigtable::GcRule](./Google-Cloud-Bigtable-GcRule), Array\\\u003c[Google::Cloud::Bigtable::GcRule](./Google-Cloud-Bigtable-GcRule)\\\u003e) --- List of GcRule with nested rules. \n**Returns**\n\n- ([Google::Cloud::Bigtable::GcRule](./Google-Cloud-Bigtable-GcRule))\n**Example** \n\n```ruby\nrequire \"google/cloud/bigtable\"\n\nbigtable = Google::Cloud::Bigtable.new\n\ntable = bigtable.create_table \"my-instance\", \"my-table\" do |cfm|\n gc_rule = Google::Cloud::Bigtable::GcRule.union(\n Google::Cloud::Bigtable::GcRule.max_age(1800),\n Google::Cloud::Bigtable::GcRule.max_versions(3)\n )\n cfm.add \"cf1\", gc_rule: gc_rule\nend\n```\n\n### #intersection\n\n def intersection() -\u003e Array\u003cGoogle::Cloud::Bigtable::GcRule\u003e, nil\n\nGets the intersection rules collection for this GcRule. \n**Returns**\n\n- (Array\\\u003c[Google::Cloud::Bigtable::GcRule](./Google-Cloud-Bigtable-GcRule)\\\u003e, nil)\n**Example** \n\n```ruby\nrequire \"google/cloud/bigtable\"\n\nbigtable = Google::Cloud::Bigtable.new\n\ntable = bigtable.create_table \"my-instance\", \"my-table\" do |cfm|\n gc_rule = Google::Cloud::Bigtable::GcRule.intersection(\n Google::Cloud::Bigtable::GcRule.max_age(1800),\n Google::Cloud::Bigtable::GcRule.max_versions(3)\n )\n cfm.add \"cf1\", gc_rule: gc_rule\nend\n\nputs table.column_families[\"cf1\"].gc_rule.intersection\n```\n\n### #intersection=\n\n def intersection=(rules)\n\nSets the intersection rules collection for this GcRule. \n**Parameter**\n\n- **rules** (Array\\\u003c[Google::Cloud::Bigtable::GcRule](./Google-Cloud-Bigtable-GcRule)\\\u003e) --- List of GcRule with nested rules.\n\n### #max_age\n\n def max_age() -\u003e Numeric, nil\n\nGets the garbage-collection rule based on the timestamp for each cell.\nWith this type of garbage-collection rule, you set the time to live\n(TTL) for data. Cloud Bigtable looks at each column family during\ngarbage collection and removes any cells that have expired. \n**Returns**\n\n- (Numeric, nil) --- Max age in seconds.\n**Example** \n\n```ruby\nrequire \"google/cloud/bigtable\"\n\nbigtable = Google::Cloud::Bigtable.new\n\ntable = bigtable.create_table \"my-instance\", \"my-table\" do |cfm|\n cfm.add \"cf1\", gc_rule: Google::Cloud::Bigtable::GcRule.max_age(600)\nend\n\nputs table.column_families[\"cf1\"].gc_rule.max_age\n```\n\n### #max_age=\n\n def max_age=(age)\n\nSets a garbage-collection rule based on the timestamp for each cell.\nWith this type of garbage-collection rule, you set the time to live\n(TTL) for data. Cloud Bigtable looks at each column family during\ngarbage collection and removes any cells that have expired. \n**Parameter**\n\n- **age** (Numeric) --- Max age in seconds. Values must be at least one millisecond, and will be truncated to microsecond granularity.\n\n### #max_versions\n\n def max_versions() -\u003e Integer, nil\n\nGets the garbage-collection rule that explicitly states the maximum\nnumber of cells to keep for all columns in a column family. \n**Returns**\n\n- (Integer, nil)\n**Example** \n\n```ruby\nrequire \"google/cloud/bigtable\"\n\nbigtable = Google::Cloud::Bigtable.new\n\ntable = bigtable.create_table \"my-instance\", \"my-table\" do |cfm|\n cfm.add \"cf1\", gc_rule: Google::Cloud::Bigtable::GcRule.max_versions(5)\nend\n\nputs table.column_families[\"cf1\"].gc_rule.max_versions\n```\n\n### #max_versions=\n\n def max_versions=(versions)\n\nSets a garbage-collection rule that explicitly states the maximum\nnumber of cells to keep for all columns in a column family. \n**Parameter**\n\n- **versions** (Integer)\n\n### #union\n\n def union() -\u003e Array\u003cGoogle::Cloud::Bigtable::GcRule\u003e, nil\n\nGets the union rules collection for this GcRule. A union\ngarbage-collection policy will remove all data matching *any* of its\nset of given rules. \n**Returns**\n\n- (Array\\\u003c[Google::Cloud::Bigtable::GcRule](./Google-Cloud-Bigtable-GcRule)\\\u003e, nil)\n**Example** \n\n```ruby\nrequire \"google/cloud/bigtable\"\n\nbigtable = Google::Cloud::Bigtable.new\n\ntable = bigtable.create_table \"my-instance\", \"my-table\" do |cfm|\n gc_rule = Google::Cloud::Bigtable::GcRule.union(\n Google::Cloud::Bigtable::GcRule.max_age(1800),\n Google::Cloud::Bigtable::GcRule.max_versions(3)\n )\n cfm.add \"cf1\", gc_rule: gc_rule\nend\n\nputs table.column_families[\"cf1\"].gc_rule.union\n```\n\n### #union=\n\n def union=(rules)\n\nSets the union rules collection for this GcRule. A union\ngarbage-collection policy will remove all data matching *any* of its\nset of given rules. \n**Parameter**\n\n- **rules** (Array\\\u003c[Google::Cloud::Bigtable::GcRule](./Google-Cloud-Bigtable-GcRule)\\\u003e) --- List of GcRule with nested rules."]]