Search in sources :

Example 1 with ColumnFamily

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();
}
Also used : GCRule(com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule) ColumnFamily(com.google.bigtable.admin.v2.ColumnFamily)

Example 2 with ColumnFamily

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());
}
Also used : GCRule(com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule) GCRules(com.google.cloud.bigtable.admin.v2.models.GCRules) ColumnFamily(com.google.bigtable.admin.v2.ColumnFamily) Test(org.junit.Test)

Example 3 with ColumnFamily

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]
}
Also used : Table(com.google.cloud.bigtable.admin.v2.models.Table) NotFoundException(com.google.api.gax.rpc.NotFoundException) ColumnFamily(com.google.cloud.bigtable.admin.v2.models.ColumnFamily)

Example 4 with ColumnFamily

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());
}
Also used : Table(com.google.cloud.bigtable.admin.v2.models.Table) ByteString(com.google.protobuf.ByteString) CreateTableRequest(com.google.cloud.bigtable.admin.v2.models.CreateTableRequest) ColumnFamily(com.google.cloud.bigtable.admin.v2.models.ColumnFamily) Test(org.junit.Test)

Example 5 with ColumnFamily

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"));
}
Also used : Table(com.google.cloud.bigtable.admin.v2.models.Table) IntersectionRule(com.google.cloud.bigtable.admin.v2.models.GCRules.IntersectionRule) ByteString(com.google.protobuf.ByteString) UnionRule(com.google.cloud.bigtable.admin.v2.models.GCRules.UnionRule) DurationRule(com.google.cloud.bigtable.admin.v2.models.GCRules.DurationRule) ModifyColumnFamiliesRequest(com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest) ColumnFamily(com.google.cloud.bigtable.admin.v2.models.ColumnFamily) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)11 GCRule (com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule)10 ColumnFamily (com.google.cloud.bigtable.admin.v2.models.ColumnFamily)7 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)7 ColumnFamily (com.google.bigtable.admin.v2.ColumnFamily)6 GCRules (com.google.cloud.bigtable.admin.v2.models.GCRules)5 Table (com.google.cloud.bigtable.admin.v2.models.Table)5 NotFoundException (com.google.api.gax.rpc.NotFoundException)3 ByteString (com.google.protobuf.ByteString)3 Table (com.google.bigtable.admin.v2.Table)2 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)2 CreateTableRequest (com.google.cloud.bigtable.admin.v2.models.CreateTableRequest)1 DurationRule (com.google.cloud.bigtable.admin.v2.models.GCRules.DurationRule)1 IntersectionRule (com.google.cloud.bigtable.admin.v2.models.GCRules.IntersectionRule)1 UnionRule (com.google.cloud.bigtable.admin.v2.models.GCRules.UnionRule)1 VersionRule (com.google.cloud.bigtable.admin.v2.models.GCRules.VersionRule)1 ModifyColumnFamiliesRequest (com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest)1 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)1