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]
}
use of com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest in project java-bigtable by googleapis.
the class BigtableTableAdminClientTests method testModifyFamilies.
@Test
public void testModifyFamilies() {
// Setup
Mockito.when(mockStub.modifyColumnFamiliesCallable()).thenReturn(mockModifyTableCallable);
com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest expectedRequest = com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest.newBuilder().setName(TABLE_NAME).addModifications(Modification.newBuilder().setId("cf").setCreate(ColumnFamily.newBuilder().setGcRule(GcRule.getDefaultInstance()))).build();
com.google.bigtable.admin.v2.Table fakeResponse = com.google.bigtable.admin.v2.Table.newBuilder().setName(TABLE_NAME).putColumnFamilies("cf", ColumnFamily.newBuilder().setGcRule(GcRule.getDefaultInstance()).build()).build();
Mockito.when(mockModifyTableCallable.futureCall(expectedRequest)).thenReturn(ApiFutures.immediateFuture(fakeResponse));
// Execute
Table actualResult = adminClient.modifyFamilies(ModifyColumnFamiliesRequest.of(TABLE_ID).addFamily("cf"));
// Verify
assertThat(actualResult).isEqualTo(Table.fromProto(fakeResponse));
}
use of com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest in project java-bigtable by googleapis.
the class BigtableTableAdminClientIT method modifyFamilies.
@Test
public void modifyFamilies() {
tableAdmin.createTable(CreateTableRequest.of(tableId));
ModifyColumnFamiliesRequest modifyFamiliesReq = ModifyColumnFamiliesRequest.of(tableId).addFamily("mf1").addFamily("mf2", GCRULES.maxAge(Duration.ofSeconds(1000, 20000))).updateFamily("mf1", GCRULES.union().rule(GCRULES.maxAge(Duration.ofSeconds(100))).rule(GCRULES.maxVersions(1))).addFamily("mf3", GCRULES.intersection().rule(GCRULES.maxAge(Duration.ofSeconds(2000))).rule(GCRULES.maxVersions(10))).addFamily("mf4", GCRULES.intersection().rule(GCRULES.maxAge(Duration.ofSeconds(360)))).addFamily("mf5").addFamily("mf6").dropFamily("mf5").dropFamily("mf6").addFamily("mf7");
Table tableResponse = tableAdmin.modifyFamilies(modifyFamiliesReq);
Map<String, ColumnFamily> columnFamilyById = Maps.newHashMap();
for (ColumnFamily columnFamily : tableResponse.getColumnFamilies()) {
columnFamilyById.put(columnFamily.getId(), columnFamily);
}
assertEquals(5, columnFamilyById.size());
assertNotNull(columnFamilyById.get("mf1"));
assertNotNull(columnFamilyById.get("mf2"));
assertEquals(2, ((UnionRule) columnFamilyById.get("mf1").getGCRule()).getRulesList().size());
assertEquals(1000, ((DurationRule) columnFamilyById.get("mf2").getGCRule()).getMaxAge().getSeconds());
assertEquals(20000, ((DurationRule) columnFamilyById.get("mf2").getGCRule()).getMaxAge().getNano());
assertEquals(2, ((IntersectionRule) columnFamilyById.get("mf3").getGCRule()).getRulesList().size());
assertEquals(360, ((DurationRule) columnFamilyById.get("mf4").getGCRule()).getMaxAge().getSeconds());
assertNotNull(columnFamilyById.get("mf7"));
}
use of com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest in project java-bigtable-hbase by googleapis.
the class TestModifyTableBuilder method testBuildModificationForUpdateFamily.
@Test
public void testBuildModificationForUpdateFamily() {
HTableDescriptor tableDescriptor = new HTableDescriptor(TableName.valueOf(TABLE_ID));
HColumnDescriptor addColumn = new HColumnDescriptor(COLUMN_FAMILY);
tableDescriptor.addFamily(addColumn);
ModifyTableBuilder actualRequest = ModifyTableBuilder.buildModifications(tableDescriptor, new HTableDescriptor(tableDescriptor));
ModifyColumnFamiliesRequest expectedRequest = ModifyColumnFamiliesRequest.of(TABLE_ID).updateFamily(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 TestAdminClientVeneerApi method testModifyFamilyAsync.
@Test
public void testModifyFamilyAsync() throws Exception {
ModifyColumnFamiliesRequest request = ModifyColumnFamiliesRequest.of(TABLE_ID_1).addFamily("first-family").addFamily("another-family");
Future<Table> response = adminClientWrapper.modifyFamiliesAsync(request);
assertEquals(TABLE_ID_1, response.get().getId());
}
Aggregations