Search in sources :

Example 1 with DurationRule

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

the class TableAdminExampleTest method testCreateIntersectionRule.

@Test
public void testCreateIntersectionRule() {
    // Intersection rule
    tableAdmin.addFamilyWithIntersectionRule();
    DurationRule maxAgeRule = GCRULES.maxAge(5, TimeUnit.DAYS);
    VersionRule versionRule = GCRULES.maxVersions(2);
    IntersectionRule intersectionCondition = GCRULES.intersection().rule(maxAgeRule).rule(versionRule);
    boolean intersectionRule = ruleCheck(intersectionCondition);
    assertTrue(intersectionRule);
}
Also used : 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) Test(org.junit.Test)

Example 2 with DurationRule

use of com.google.cloud.bigtable.admin.v2.models.GCRules.DurationRule 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)

Example 3 with DurationRule

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

the class GCRulesTest method duration.

@Test
public void duration() {
    DurationRule actual = GCRULES.maxAge(Duration.ofSeconds(61, 9));
    GcRule expected = buildAgeRule(61, 9);
    assertNotNull(actual.getMaxAge());
    assertThat(actual.toProto()).isEqualTo(expected);
}
Also used : GcRule(com.google.bigtable.admin.v2.GcRule) DurationRule(com.google.cloud.bigtable.admin.v2.models.GCRules.DurationRule) Test(org.junit.Test)

Example 4 with DurationRule

use of com.google.cloud.bigtable.admin.v2.models.GCRules.DurationRule 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 5 with DurationRule

use of com.google.cloud.bigtable.admin.v2.models.GCRules.DurationRule 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)

Aggregations

DurationRule (com.google.cloud.bigtable.admin.v2.models.GCRules.DurationRule)9 Test (org.junit.Test)6 IntersectionRule (com.google.cloud.bigtable.admin.v2.models.GCRules.IntersectionRule)5 VersionRule (com.google.cloud.bigtable.admin.v2.models.GCRules.VersionRule)5 UnionRule (com.google.cloud.bigtable.admin.v2.models.GCRules.UnionRule)4 ModifyColumnFamiliesRequest (com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest)4 AlreadyExistsException (com.google.api.gax.rpc.AlreadyExistsException)3 GcRule (com.google.bigtable.admin.v2.GcRule)1 ColumnFamily (com.google.cloud.bigtable.admin.v2.models.ColumnFamily)1 GCRule (com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule)1 Table (com.google.cloud.bigtable.admin.v2.models.Table)1 ByteString (com.google.protobuf.ByteString)1