use of com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule in project java-bigtable-hbase by googleapis.
the class ColumnDescriptorAdapter method adapt.
/**
* Adapt a single instance of an HBase {@link org.apache.hadoop.hbase.HColumnDescriptor} to an
* instance of {@link com.google.bigtable.admin.v2.ColumnFamily.Builder}.
*
* <p>NOTE: This method does not set the name of the ColumnFamily.Builder. The assumption is that
* the CreateTableRequest or CreateColumnFamilyRequest takes care of the naming. As of now
* (3/11/2015), the server insists on having a blank name.
*
* @param columnDescriptor a {@link org.apache.hadoop.hbase.HColumnDescriptor} object.
* @return a {@link com.google.bigtable.admin.v2.ColumnFamily.Builder} object.
*/
public ColumnFamily adapt(HColumnDescriptor columnDescriptor) {
throwIfRequestingUnknownFeatures(columnDescriptor);
throwIfRequestingUnsupportedFeatures(columnDescriptor);
ColumnFamily.Builder resultBuilder = ColumnFamily.newBuilder();
GCRule gcRule = buildGarbageCollectionRule(columnDescriptor);
if (gcRule != null) {
resultBuilder.setGcRule(gcRule.toProto());
}
return resultBuilder.build();
}
use of com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule in project java-bigtable-hbase by googleapis.
the class ColumnDescriptorAdapter method buildGarbageCollectionRule.
/**
* Construct an Bigtable {@link GCRule} from the given column descriptor.
*
* @param columnDescriptor a {@link org.apache.hadoop.hbase.HColumnDescriptor} object.
* @return a {@link GCRule} object.
*/
public static GCRule buildGarbageCollectionRule(HColumnDescriptor columnDescriptor) {
int maxVersions = columnDescriptor.getMaxVersions();
int minVersions = columnDescriptor.getMinVersions();
int ttlSeconds = columnDescriptor.getTimeToLive();
Preconditions.checkState(minVersions < maxVersions, "HColumnDescriptor min versions must be less than max versions.");
if (ttlSeconds == HColumnDescriptor.DEFAULT_TTL) {
if (maxVersions == Integer.MAX_VALUE) {
return null;
} else {
return GCRULES.maxVersions(maxVersions);
}
}
// minVersions only comes into play with a TTL:
GCRule ageRule = GCRULES.maxAge(Duration.ofSeconds(ttlSeconds));
if (minVersions != HColumnDescriptor.DEFAULT_MIN_VERSIONS) {
// The logic here is: only delete a cell if:
// 1) the age is older than :ttlSeconds AND
// 2) the cell's relative version number is greater than :minVersions
//
// Bigtable's nomenclature for this is:
// Intersection (AND)
// - maxAge = :HBase_ttlSeconds
// - maxVersions = :HBase_minVersion
ageRule = GCRULES.intersection().rule(ageRule).rule(GCRULES.maxVersions(minVersions));
}
if (maxVersions == Integer.MAX_VALUE) {
return ageRule;
} else {
return GCRULES.union().rule(ageRule).rule(GCRULES.maxVersions(maxVersions));
}
}
use of com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule in project java-bigtable-hbase by googleapis.
the class TestTableAdapter method testAdaptWithColumnDesc.
@Test
public void testAdaptWithColumnDesc() {
HColumnDescriptor columnDesc = new HColumnDescriptor(COLUMN_FAMILY);
HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(TABLE_ID));
CreateTableRequest request = CreateTableRequest.of(TABLE_ID);
desc.addFamily(columnDesc);
TableAdapter.adapt(desc, request);
GCRule gcRule = ColumnDescriptorAdapter.buildGarbageCollectionRule(columnDesc);
CreateTableRequest expected = CreateTableRequest.of(TABLE_ID).addFamily(COLUMN_FAMILY, gcRule);
Assert.assertEquals(request.toProto(PROJECT_ID, INSTANCE_ID), expected.toProto(PROJECT_ID, INSTANCE_ID));
}
use of com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule 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);
}
use of com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule in project java-bigtable by googleapis.
the class GCRulesTest method intersectionOfUnions.
@Test
public void intersectionOfUnions() {
IntersectionRule actual = GCRULES.intersection().rule(GCRULES.union().rule(GCRULES.maxVersions(1)).rule(GCRULES.maxAge(Duration.ofSeconds(1)))).rule(GCRULES.union().rule(GCRULES.maxVersions(1)).rule(GCRULES.maxAge(Duration.ofSeconds(1))));
GcRule expected = GcRule.newBuilder().setIntersection(Intersection.newBuilder().addRules(GcRule.newBuilder().setUnion(Union.newBuilder().addRules(buildVersionsRule(1)).addRules(buildAgeRule(1, 0)))).addRules(GcRule.newBuilder().setUnion(Union.newBuilder().addRules(buildVersionsRule(1)).addRules(buildAgeRule(1, 0))))).build();
assertEquals(2, actual.getRulesList().size());
assertThat(actual.toProto()).isEqualTo(expected);
}
Aggregations