use of com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest in project java-bigtable-hbase by googleapis.
the class TestModifyTableBuilder method testBuildModificationForAddFamily.
@Test
public void testBuildModificationForAddFamily() {
HTableDescriptor tableDescriptor = new HTableDescriptor(TableName.valueOf(TABLE_ID));
HColumnDescriptor addColumn = new HColumnDescriptor(COLUMN_FAMILY);
tableDescriptor.addFamily(addColumn);
ModifyTableBuilder actualRequest = ModifyTableBuilder.buildModifications(tableDescriptor, new HTableDescriptor(TableName.valueOf(TABLE_ID)));
ModifyColumnFamiliesRequest expectedRequest = ModifyColumnFamiliesRequest.of(TABLE_ID).addFamily(COLUMN_FAMILY, buildGarbageCollectionRule(addColumn));
Assert.assertEquals(expectedRequest.toProto(PROJECT_ID, INSTANCE_ID), actualRequest.build().toProto(PROJECT_ID, INSTANCE_ID));
}
use of com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest in project java-bigtable-hbase by googleapis.
the class TestModifyTableBuilder method testBuildModificationForDropFamily.
@Test
public void testBuildModificationForDropFamily() {
final String NEW_COLUMN_FAMILY = "anotherColumnFamily";
HTableDescriptor tableDescriptor = new HTableDescriptor(TableName.valueOf(TABLE_ID));
HColumnDescriptor addColumn = new HColumnDescriptor(COLUMN_FAMILY);
tableDescriptor.addFamily(addColumn);
HTableDescriptor newTableDesc = new HTableDescriptor(TableName.valueOf(TABLE_ID));
HColumnDescriptor newColumnDesc = new HColumnDescriptor(NEW_COLUMN_FAMILY);
newTableDesc.addFamily(newColumnDesc);
ModifyTableBuilder actualRequest = ModifyTableBuilder.buildModifications(tableDescriptor, newTableDesc);
ModifyColumnFamiliesRequest expectedRequest = ModifyColumnFamiliesRequest.of(TABLE_ID).addFamily(COLUMN_FAMILY, buildGarbageCollectionRule(addColumn)).dropFamily(NEW_COLUMN_FAMILY);
Assert.assertEquals(expectedRequest.toProto(PROJECT_ID, INSTANCE_ID), actualRequest.build().toProto(PROJECT_ID, INSTANCE_ID));
}
use of com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest in project java-bigtable by googleapis.
the class TableAdminExample method addFamilyWithUnionRule.
/**
* Demonstrates how to create a new instance of the UnionRule.
*/
public void addFamilyWithUnionRule() {
System.out.printf("%nCreating column family %s with union GC rule%n", COLUMN_FAMILY_3);
// [START bigtable_create_family_gc_union]
// Creates a column family with GC policy to drop data that matches at least one condition.
// Defines a list of GC rules to drop cells older than 5 days OR not the most recent
// version.
UnionRule unionRule = GCRULES.union().rule(GCRULES.maxAge(5, TimeUnit.DAYS)).rule(GCRULES.maxVersions(1));
// 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_3, unionRule);
adminClient.modifyFamilies(columnFamiliesRequest);
System.out.println("Created column family: " + COLUMN_FAMILY_3);
} catch (AlreadyExistsException e) {
System.err.println("Failed to create column family with rule, already exists: " + e.getMessage());
}
// [END bigtable_create_family_gc_union]
}
use of com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest in project java-bigtable by googleapis.
the class TableAdminExample method deleteColumnFamily.
/**
* Demonstrates how to delete a column family.
*/
public void deleteColumnFamily() {
System.out.println("\nDelete column family: " + COLUMN_FAMILY_2);
// Deletes a column family.
try {
ModifyColumnFamiliesRequest deleted = ModifyColumnFamiliesRequest.of(tableId).dropFamily(COLUMN_FAMILY_2);
adminClient.modifyFamilies(deleted);
System.out.printf("Column family %s deleted successfully%n", COLUMN_FAMILY_2);
} catch (NotFoundException e) {
System.err.println("Failed to delete a non-existent column family: " + e.getMessage());
}
// [END bigtable_delete_family]
}
use of com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest 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]
}
Aggregations