use of com.google.cloud.bigtable.admin.v2.models.ColumnFamily in project java-bigtable-hbase by googleapis.
the class ColumnDescriptorAdapter method adapt.
/**
* Adapt a single instance of an HBase {@link org.apache.hadoop.hbase.HColumnDescriptor} to an
* instance of {@link com.google.bigtable.admin.v2.ColumnFamily.Builder}.
*
* <p>NOTE: This method does not set the name of the ColumnFamily.Builder. The assumption is that
* the CreateTableRequest or CreateColumnFamilyRequest takes care of the naming. As of now
* (3/11/2015), the server insists on having a blank name.
*
* @param columnDescriptor a {@link org.apache.hadoop.hbase.HColumnDescriptor} object.
* @return a {@link com.google.bigtable.admin.v2.ColumnFamily.Builder} object.
*/
public ColumnFamily adapt(HColumnDescriptor columnDescriptor) {
throwIfRequestingUnknownFeatures(columnDescriptor);
throwIfRequestingUnsupportedFeatures(columnDescriptor);
ColumnFamily.Builder resultBuilder = ColumnFamily.newBuilder();
GCRule gcRule = buildGarbageCollectionRule(columnDescriptor);
if (gcRule != null) {
resultBuilder.setGcRule(gcRule.toProto());
}
return resultBuilder.build();
}
use of com.google.cloud.bigtable.admin.v2.models.ColumnFamily in project java-bigtable-hbase by googleapis.
the class TestColumnDescriptorAdapter method ttlIsPreservedInGcRule.
@Test
public void ttlIsPreservedInGcRule() {
// TTL of 1 day (in seconds):
int ttl = 86400;
descriptor.setTimeToLive(ttl);
ColumnFamily result = adapter.adapt(descriptor);
GCRules.GCRule expected = GCRULES.union().rule(GCRULES.maxAge(Duration.ofSeconds(ttl))).rule(GCRULES.maxVersions(1));
Assert.assertEquals(expected.toProto(), result.getGcRule());
}
use of com.google.cloud.bigtable.admin.v2.models.ColumnFamily in project java-bigtable by googleapis.
the class TableAdminExample method getTableMeta.
/**
* Demonstrates how to get a table's metadata.
*/
public void getTableMeta() {
System.out.println("\nPrinting table metadata");
// Gets table metadata, and applies a view to the table fields.
try {
Table table = adminClient.getTable(tableId);
System.out.println("Table: " + table.getId());
Collection<ColumnFamily> columnFamilies = table.getColumnFamilies();
for (ColumnFamily columnFamily : columnFamilies) {
System.out.printf("Column family: %s%nGC Rule: %s%n", columnFamily.getId(), columnFamily.getGCRule().toString());
}
} catch (NotFoundException e) {
System.err.println("Failed to retrieve table metadata for a non-existent table: " + e.getMessage());
}
// [END bigtable_get_table_metadata]
}
use of com.google.cloud.bigtable.admin.v2.models.ColumnFamily 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.ColumnFamily 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"));
}
Aggregations