Search in sources :

Example 1 with ModifyColumnFamiliesRequest

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));
}
Also used : HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) ModifyColumnFamiliesRequest(com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest) Test(org.junit.Test)

Example 2 with ModifyColumnFamiliesRequest

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));
}
Also used : HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) ModifyColumnFamiliesRequest(com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest) Test(org.junit.Test)

Example 3 with ModifyColumnFamiliesRequest

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]
}
Also used : AlreadyExistsException(com.google.api.gax.rpc.AlreadyExistsException) UnionRule(com.google.cloud.bigtable.admin.v2.models.GCRules.UnionRule) ModifyColumnFamiliesRequest(com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest)

Example 4 with ModifyColumnFamiliesRequest

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

Example 5 with ModifyColumnFamiliesRequest

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

Aggregations

ModifyColumnFamiliesRequest (com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest)13 Test (org.junit.Test)6 AlreadyExistsException (com.google.api.gax.rpc.AlreadyExistsException)5 DurationRule (com.google.cloud.bigtable.admin.v2.models.GCRules.DurationRule)4 VersionRule (com.google.cloud.bigtable.admin.v2.models.GCRules.VersionRule)4 IntersectionRule (com.google.cloud.bigtable.admin.v2.models.GCRules.IntersectionRule)3 UnionRule (com.google.cloud.bigtable.admin.v2.models.GCRules.UnionRule)3 Table (com.google.cloud.bigtable.admin.v2.models.Table)3 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)3 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)3 NotFoundException (com.google.api.gax.rpc.NotFoundException)2 ColumnFamily (com.google.cloud.bigtable.admin.v2.models.ColumnFamily)1 ByteString (com.google.protobuf.ByteString)1 IOException (java.io.IOException)1 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)1 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)1