use of com.google.cloud.bigtable.admin.v2.models.GCRules.VersionRule in project java-bigtable by googleapis.
the class TableAdminExample method modifyColumnFamilyRule.
/**
* Demonstrates how to modify a column family's rule.
*/
public void modifyColumnFamilyRule() {
System.out.printf("%nUpdating column family %s GC rule%n", COLUMN_FAMILY_1);
// [START bigtable_update_gc_rule]
// Updates the column family metadata to update the GC rule.
// Updates a column family GC rule.
VersionRule versionRule = GCRULES.maxVersions(1);
try {
// ModifyColumnFamiliesRequest can be used both for adding and modifying families, here it is
// being used to modify a family
// Updates column family with given GC rule.
ModifyColumnFamiliesRequest updateRequest = ModifyColumnFamiliesRequest.of(tableId).updateFamily(COLUMN_FAMILY_1, versionRule);
adminClient.modifyFamilies(updateRequest);
System.out.printf("Column family %s GC rule updated%n", COLUMN_FAMILY_1);
} catch (NotFoundException e) {
System.err.println("Failed to modify a non-existent column family: " + e.getMessage());
}
// [END bigtable_update_gc_rule]
}
use of com.google.cloud.bigtable.admin.v2.models.GCRules.VersionRule in project java-bigtable by googleapis.
the class TableAdminExample method addFamilyWithMaxVersionsRule.
/**
* Demonstrates how to create a new instance of the VersionRule.
*/
public void addFamilyWithMaxVersionsRule() {
System.out.printf("%nCreating column family %s with max versions GC rule%n", COLUMN_FAMILY_2);
// [START bigtable_create_family_gc_max_versions]
// Creates a column family with GC policy : most recent N versions
// where 1 = most recent version
// Defines the GC policy to retain only the most recent 2 versions.
VersionRule versionRule = GCRULES.maxVersions(2);
// 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_2, versionRule);
adminClient.modifyFamilies(columnFamiliesRequest);
System.out.println("Created column family: " + COLUMN_FAMILY_2);
} catch (AlreadyExistsException e) {
System.err.println("Failed to create column family with rule, already exists: " + e.getMessage());
}
// [END bigtable_create_family_gc_max_versions]
}
use of com.google.cloud.bigtable.admin.v2.models.GCRules.VersionRule in project java-bigtable by googleapis.
the class TableAdminExampleTest method testCreateIntersectionRule.
@Test
public void testCreateIntersectionRule() {
// Intersection rule
tableAdmin.addFamilyWithIntersectionRule();
DurationRule maxAgeRule = GCRULES.maxAge(5, TimeUnit.DAYS);
VersionRule versionRule = GCRULES.maxVersions(2);
IntersectionRule intersectionCondition = GCRULES.intersection().rule(maxAgeRule).rule(versionRule);
boolean intersectionRule = ruleCheck(intersectionCondition);
assertTrue(intersectionRule);
}
use of com.google.cloud.bigtable.admin.v2.models.GCRules.VersionRule in project java-bigtable by googleapis.
the class BigtableTableAdminClientIT method createTable.
@Test
public void createTable() {
assume().withMessage("Emulator doesn't return proper responses for CreateTable").that(testEnvRule.env()).isNotInstanceOf(EmulatorEnv.class);
CreateTableRequest createTableReq = CreateTableRequest.of(tableId).addFamily("cf1").addFamily("cf2", GCRULES.maxVersions(10)).addSplit(ByteString.copyFromUtf8("b")).addSplit(ByteString.copyFromUtf8("q"));
Table tableResponse = tableAdmin.createTable(createTableReq);
assertEquals(tableId, tableResponse.getId());
Map<String, ColumnFamily> columnFamilyById = Maps.newHashMap();
for (ColumnFamily columnFamily : tableResponse.getColumnFamilies()) {
columnFamilyById.put(columnFamily.getId(), columnFamily);
}
assertEquals(2, tableResponse.getColumnFamilies().size());
assertFalse(columnFamilyById.get("cf1").hasGCRule());
assertTrue(columnFamilyById.get("cf2").hasGCRule());
assertEquals(10, ((VersionRule) columnFamilyById.get("cf2").getGCRule()).getMaxVersions());
}
use of com.google.cloud.bigtable.admin.v2.models.GCRules.VersionRule in project java-bigtable by googleapis.
the class GCRulesTest method versions.
@Test
public void versions() {
VersionRule actual = GCRULES.maxVersions(10);
GcRule expected = buildVersionsRule(10);
assertNotNull(actual.getMaxVersions());
assertThat(actual.toProto()).isEqualTo(expected);
}
Aggregations