use of com.google.cloud.bigtable.admin.v2.models.GCRules.DurationRule in project java-bigtable by googleapis.
the class TableAdminExample method addFamilyWithNestedRule.
/**
* Demonstrates how to create a nested rule using the IntersectionRule and UnionRule.
*/
public void addFamilyWithNestedRule() {
System.out.printf("%nCreating column family %s with a nested GC rule%n", COLUMN_FAMILY_5);
// [START bigtable_create_family_gc_nested]
// Creates a nested GC rule:
// Drop cells that are either older than the 10 recent versions
// OR
// Drop cells that are older than a month AND older than the 2 recent versions
VersionRule versionRule1 = GCRULES.maxVersions(10);
VersionRule versionRule2 = GCRULES.maxVersions(2);
DurationRule maxAgeRule = GCRULES.maxAge(30, TimeUnit.DAYS);
IntersectionRule intersectionRule = GCRULES.intersection().rule(maxAgeRule).rule(versionRule2);
UnionRule unionRule = GCRULES.union().rule(intersectionRule).rule(versionRule1);
// Creates column family with given GC rule.
try {
// ModifyColumnFamiliesRequest can be used both for adding and modifying families, here it is
// being used to add a family
ModifyColumnFamiliesRequest columnFamiliesRequest = ModifyColumnFamiliesRequest.of(tableId).addFamily(COLUMN_FAMILY_5, unionRule);
adminClient.modifyFamilies(columnFamiliesRequest);
System.out.println("Created column family: " + COLUMN_FAMILY_5);
} catch (AlreadyExistsException e) {
System.err.println("Failed to create column family with rule, already exists: " + e.getMessage());
}
// [END bigtable_create_family_gc_nested]
}
use of com.google.cloud.bigtable.admin.v2.models.GCRules.DurationRule in project java-bigtable by googleapis.
the class TableAdminExampleTest method testCreateNestedRule.
@Test
public void testCreateNestedRule() {
// Nested rule
tableAdmin.addFamilyWithNestedRule();
VersionRule versionRule = GCRULES.maxVersions(10);
DurationRule maxAgeRule = GCRULES.maxAge(30, TimeUnit.DAYS);
VersionRule versionRule2 = GCRULES.maxVersions(2);
IntersectionRule intersectionRule = GCRULES.intersection().rule(maxAgeRule).rule(versionRule2);
UnionRule nestedCondition = GCRULES.union().rule(intersectionRule).rule(versionRule);
boolean nestedRule = ruleCheck(nestedCondition);
assertTrue(nestedRule);
}
use of com.google.cloud.bigtable.admin.v2.models.GCRules.DurationRule in project java-bigtable by googleapis.
the class TableAdminExampleTest method testCreateMaxAgeRuleAndModifyAndPrintColumnFamily.
@Test
public void testCreateMaxAgeRuleAndModifyAndPrintColumnFamily() {
// Max age rule
tableAdmin.addFamilyWithMaxAgeRule();
DurationRule maxAgeCondition = GCRULES.maxAge(5, TimeUnit.DAYS);
boolean maxAgeRule = ruleCheck(maxAgeCondition);
assertTrue(maxAgeRule);
// Modifies cf1.
tableAdmin.modifyColumnFamilyRule();
GCRule modifiedRule = GCRULES.maxVersions(1);
boolean maxVersionRule = ruleCheck(modifiedRule);
assertTrue(maxVersionRule);
}
use of com.google.cloud.bigtable.admin.v2.models.GCRules.DurationRule in project java-bigtable by googleapis.
the class TableAdminExampleTest method testCreateUnionRule.
@Test
public void testCreateUnionRule() {
// Union rule
tableAdmin.addFamilyWithUnionRule();
DurationRule maxAgeRule = GCRULES.maxAge(5, TimeUnit.DAYS);
VersionRule versionRule = GCRULES.maxVersions(1);
UnionRule unionCondition = GCRULES.union().rule(maxAgeRule).rule(versionRule);
boolean unionRule = ruleCheck(unionCondition);
assertTrue(unionRule);
}
Aggregations