Search in sources :

Example 6 with ColumnFamily

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

the class ColumnDescriptorAdapter method adapt.

/**
 * Convert a Bigtable {@link com.google.cloud.bigtable.admin.v2.models.ColumnFamily} to an HBase
 * {@link HColumnDescriptor}. See {@link #convertGarbageCollectionRule(GcRule, HColumnDescriptor)}
 * for more info.
 *
 * @param columnFamily a {@link com.google.cloud.bigtable.admin.v2.models.ColumnFamily} object.
 * @return a {@link org.apache.hadoop.hbase.HColumnDescriptor} object.
 */
public HColumnDescriptor adapt(com.google.cloud.bigtable.admin.v2.models.ColumnFamily columnFamily) {
    HColumnDescriptor hColumnDescriptor = new HColumnDescriptor(columnFamily.getId());
    GCRule gcRule = columnFamily.getGCRule();
    if (gcRule != null) {
        convertGarbageCollectionRule(gcRule.toProto(), hColumnDescriptor);
    }
    return hColumnDescriptor;
}
Also used : HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) GCRule(com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule)

Example 7 with ColumnFamily

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

the class TableAdapter method adapt.

/**
 * adapt. This method adapts ColumnFamily to CreateTableRequest.
 *
 * @param desc a {@link HTableDescriptor} object.
 * @param request a {@link CreateTableRequest}
 */
protected static void adapt(HTableDescriptor desc, CreateTableRequest request) {
    if (request != null) {
        for (HColumnDescriptor column : desc.getColumnFamilies()) {
            String columnName = column.getNameAsString();
            GCRule gcRule = buildGarbageCollectionRule(column);
            if (gcRule == null) {
                request.addFamily(columnName);
            } else {
                request.addFamily(columnName, gcRule);
            }
        }
    }
}
Also used : HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) GCRule(com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule) ByteString(com.google.protobuf.ByteString)

Example 8 with ColumnFamily

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

the class TestColumnDescriptorAdapter method maxVersionsIsPreservedInColumnFamily.

@Test
public void maxVersionsIsPreservedInColumnFamily() {
    GCRules.GCRule expected = GCRULES.maxVersions(10);
    HColumnDescriptor descriptor = adapter.adapt(columnFamily(expected));
    Assert.assertEquals(10, descriptor.getMaxVersions());
}
Also used : GCRule(com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule) GCRules(com.google.cloud.bigtable.admin.v2.models.GCRules) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) Test(org.junit.Test)

Example 9 with ColumnFamily

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

the class TestColumnDescriptorAdapter method testGCruleMaxVersion.

@Test
public void testGCruleMaxVersion() {
    int ttl = 100;
    descriptor.setTimeToLive(ttl);
    descriptor.setMaxVersions(Integer.MAX_VALUE);
    ColumnFamily result = adapter.adapt(descriptor);
    GCRule expected = GCRULES.maxAge(Duration.ofSeconds(ttl));
    Assert.assertEquals(expected.toProto(), result.getGcRule());
}
Also used : GCRule(com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule) ColumnFamily(com.google.bigtable.admin.v2.ColumnFamily) Test(org.junit.Test)

Example 10 with ColumnFamily

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

the class TestColumnDescriptorAdapter method testAdaptWithColumnFamilyForMaxAge.

@Test
public void testAdaptWithColumnFamilyForMaxAge() {
    int ttl = 86400;
    GCRule maxAgeGCRule = GCRULES.maxAge(Duration.ofSeconds(ttl));
    HColumnDescriptor actual = adapter.adapt(columnFamily(maxAgeGCRule));
    Assert.assertEquals(ttl, actual.getTimeToLive());
}
Also used : HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) GCRule(com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule) 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