Search in sources :

Example 16 with ColumnFamily

use of com.google.cloud.bigtable.admin.v2.models.ColumnFamily in project java-bigtable by googleapis.

the class TableAdminExample method listColumnFamilies.

/**
 * Demonstrates how to list a table's column families.
 */
public void listColumnFamilies() {
    System.out.println("\nPrinting ID and GC Rule for all column families");
    // Lists all families in the table with GC rules.
    try {
        Table table = adminClient.getTable(tableId);
        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 list column families from a non-existent table: " + e.getMessage());
    }
// [END bigtable_list_column_families]
}
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 17 with ColumnFamily

use of com.google.cloud.bigtable.admin.v2.models.ColumnFamily in project java-bigtable by googleapis.

the class TableAdminExample method printModifiedColumnFamily.

/**
 * Demonstrates how to print the modified column family.
 */
public void printModifiedColumnFamily() {
    System.out.printf("%nPrint updated GC rule for column family %s%n", COLUMN_FAMILY_1);
    // [START bigtable_family_get_gc_rule]
    try {
        Table table = adminClient.getTable(tableId);
        Collection<ColumnFamily> columnFamilies = table.getColumnFamilies();
        for (ColumnFamily columnFamily : columnFamilies) {
            if (columnFamily.getId().equals(COLUMN_FAMILY_1)) {
                System.out.printf("Column family: %s%nGC Rule: %s%n", columnFamily.getId(), columnFamily.getGCRule().toString());
            }
        }
    } catch (NotFoundException e) {
        System.err.println("Failed to print a non-existent column family: " + e.getMessage());
    }
// [END bigtable_family_get_gc_rule]
}
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 18 with ColumnFamily

use of com.google.cloud.bigtable.admin.v2.models.ColumnFamily in project java-bigtable by googleapis.

the class TableAdminExampleTest method testCreateMaxVersionsRuleAndDeleteColumnFamily.

@Test
public void testCreateMaxVersionsRuleAndDeleteColumnFamily() {
    // Max versions rule
    tableAdmin.addFamilyWithMaxVersionsRule();
    VersionRule maxVersionCondition = GCRULES.maxVersions(2);
    boolean maxVersionRule = ruleCheck(maxVersionCondition);
    assertTrue(maxVersionRule);
    // Deletes cf2.
    tableAdmin.deleteColumnFamily();
    boolean found = true;
    List<ColumnFamily> columnFamilies = adminClient.getTable(tableId).getColumnFamilies();
    for (ColumnFamily columnFamily : columnFamilies) {
        if (columnFamily.equals("cf2")) {
            found = false;
            break;
        }
    }
    assertTrue(found);
}
Also used : VersionRule(com.google.cloud.bigtable.admin.v2.models.GCRules.VersionRule) 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