Search in sources :

Example 11 with ModifyColumnFamiliesRequest

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

the class BigtableTableAdminClientTest 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));
}
Also used : Table(com.google.cloud.bigtable.admin.v2.models.Table) Test(org.junit.Test)

Example 12 with ModifyColumnFamiliesRequest

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

the class TableAdminExample method addFamilyWithMaxAgeRule.

/**
 * Demonstrates how to create a new instance of the DurationRule.
 */
public void addFamilyWithMaxAgeRule() {
    System.out.printf("%nCreating column family %s with max age GC rule%n", COLUMN_FAMILY_1);
    // [START bigtable_create_family_gc_max_age]
    // Creates a column family with GC policy : maximum age
    // where age = current time minus cell timestamp
    // Defines the GC rule to retain data with max age of 5 days.
    DurationRule maxAgeRule = GCRULES.maxAge(5, TimeUnit.DAYS);
    // 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_1, maxAgeRule);
        adminClient.modifyFamilies(columnFamiliesRequest);
        System.out.println("Created column family: " + COLUMN_FAMILY_1);
    } catch (AlreadyExistsException e) {
        System.err.println("Failed to create column family with rule, already exists: " + e.getMessage());
    }
// [END bigtable_create_family_gc_max_age]
}
Also used : AlreadyExistsException(com.google.api.gax.rpc.AlreadyExistsException) DurationRule(com.google.cloud.bigtable.admin.v2.models.GCRules.DurationRule) ModifyColumnFamiliesRequest(com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest)

Example 13 with ModifyColumnFamiliesRequest

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

the class TableAdminExample method addFamilyWithNestedRule.

/**
 * Demonstrates how to create a nested rule using the IntersectionRule and UnionRule.
 */
public void addFamilyWithNestedRule() {
    System.out.printf("%nCreating column family %s with a nested GC rule%n", COLUMN_FAMILY_5);
    // [START bigtable_create_family_gc_nested]
    // Creates a nested GC rule:
    // Drop cells that are either older than the 10 recent versions
    // OR
    // Drop cells that are older than a month AND older than the 2 recent versions
    VersionRule versionRule1 = GCRULES.maxVersions(10);
    VersionRule versionRule2 = GCRULES.maxVersions(2);
    DurationRule maxAgeRule = GCRULES.maxAge(30, TimeUnit.DAYS);
    IntersectionRule intersectionRule = GCRULES.intersection().rule(maxAgeRule).rule(versionRule2);
    UnionRule unionRule = GCRULES.union().rule(intersectionRule).rule(versionRule1);
    // 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_5, unionRule);
        adminClient.modifyFamilies(columnFamiliesRequest);
        System.out.println("Created column family: " + COLUMN_FAMILY_5);
    } catch (AlreadyExistsException e) {
        System.err.println("Failed to create column family with rule, already exists: " + e.getMessage());
    }
// [END bigtable_create_family_gc_nested]
}
Also used : AlreadyExistsException(com.google.api.gax.rpc.AlreadyExistsException) IntersectionRule(com.google.cloud.bigtable.admin.v2.models.GCRules.IntersectionRule) UnionRule(com.google.cloud.bigtable.admin.v2.models.GCRules.UnionRule) DurationRule(com.google.cloud.bigtable.admin.v2.models.GCRules.DurationRule) VersionRule(com.google.cloud.bigtable.admin.v2.models.GCRules.VersionRule) ModifyColumnFamiliesRequest(com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest)

Example 14 with ModifyColumnFamiliesRequest

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

the class TableAdminExample method addFamilyWithIntersectionRule.

/**
 * Demonstrates how to create a new instance of the IntersectionRule.
 */
public void addFamilyWithIntersectionRule() {
    System.out.printf("%nCreating column family %s with intersection GC rule%n", COLUMN_FAMILY_4);
    // [START bigtable_create_family_gc_intersection]
    // Creates a column family with GC policy to drop data that matches all conditions.
    // Defines a GC rule to drop cells older than 5 days AND older than the most recent 2 versions.
    DurationRule maxAgeRule = GCRULES.maxAge(5, TimeUnit.DAYS);
    VersionRule versionRule = GCRULES.maxVersions(2);
    IntersectionRule intersectionRule = GCRULES.intersection().rule(maxAgeRule).rule(versionRule);
    // 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_4, intersectionRule);
        adminClient.modifyFamilies(columnFamiliesRequest);
        System.out.println("Created column family: " + COLUMN_FAMILY_4);
    } catch (AlreadyExistsException e) {
        System.err.println("Failed to create column family with rule, already exists: " + e.getMessage());
    }
// [END bigtable_create_family_gc_intersection]
}
Also used : AlreadyExistsException(com.google.api.gax.rpc.AlreadyExistsException) IntersectionRule(com.google.cloud.bigtable.admin.v2.models.GCRules.IntersectionRule) DurationRule(com.google.cloud.bigtable.admin.v2.models.GCRules.DurationRule) 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