/** * Adds a new columnFamily with {@link GCRule} to the configuration. Please note that calling this * method with the same familyId will overwrite the previous family. * * @param familyId * @param gcRule */ public CreateTableRequest addFamily(String familyId, GCRule gcRule) { Preconditions.checkNotNull(familyId); tableRequest.putColumnFamilies( familyId, ColumnFamily.newBuilder().setGcRule(gcRule.toProto()).build()); return this; }
/** * Configures the name and GcRule of the new ColumnFamily to be created * * @param familyId * @param gcRule * @return */ public ModifyColumnFamiliesRequest addFamily(String familyId, GCRule gcRule) { Preconditions.checkNotNull(gcRule); Modification.Builder modification = Modification.newBuilder().setId(familyId); modification.getCreateBuilder().setGcRule(gcRule.toProto()); modFamilyRequest.addModifications(modification.build()); return this; }
/** * Updates the GCRule of existing ColumnFamily * * @param familyId * @param gcRule * @return */ public ModifyColumnFamiliesRequest updateFamily(String familyId, GCRule gcRule) { Preconditions.checkNotNull(gcRule); Modification.Builder modification = Modification.newBuilder().setId(familyId); modification.getUpdateBuilder().setGcRule(gcRule.toProto()); modFamilyRequest.addModifications(modification.build()); return this; }
/** * <p>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> * * <p>NOTE: This method does not set the name of the ColumnFamily.Builder. The assumption is * that the CreateTableRequest or CreateColumFamilyRequest takes care of the naming. As of now * (3/11/2015), the server insists on having a blank name.</p> * * @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(); }
/** * <p>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> * * <p>NOTE: This method does not set the name of the ColumnFamily.Builder. The assumption is * that the CreateTableRequest or CreateColumFamilyRequest takes care of the naming. As of now * (3/11/2015), the server insists on having a blank name.</p> * * @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(); }
/** * Configures the name and GcRule of the new ColumnFamily to be created * * @param familyId * @param gcRule * @return */ public ModifyColumnFamiliesRequest addFamily(String familyId, GCRule gcRule) { Preconditions.checkNotNull(gcRule); Modification.Builder modification = Modification.newBuilder().setId(familyId); modification.getCreateBuilder().setGcRule(gcRule.toProto()); modFamilyRequest.addModifications(modification.build()); return this; }
/** * Updates the GCRule of existing ColumnFamily * * @param familyId * @param gcRule * @return */ public ModifyColumnFamiliesRequest updateFamily(String familyId, GCRule gcRule) { Preconditions.checkNotNull(gcRule); Modification.Builder modification = Modification.newBuilder().setId(familyId); modification.getUpdateBuilder().setGcRule(gcRule.toProto()); modFamilyRequest.addModifications(modification.build()); return this; }
/** * Adds a new columnFamily with {@link GCRule} to the configuration. Please note that calling this * method with the same familyId will overwrite the previous family. * * @param familyId * @param gcRule */ public CreateTableRequest addFamily(String familyId, GCRule gcRule) { Preconditions.checkNotNull(familyId); tableRequest.putColumnFamilies( familyId, ColumnFamily.newBuilder().setGcRule(gcRule.toProto()).build()); return this; }
.setCreate( com.google.bigtable.admin.v2.ColumnFamily.newBuilder() .setGcRule(GcRule.getDefaultInstance()))) .addModifications( com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest.Modification.newBuilder() .setCreate( com.google.bigtable.admin.v2.ColumnFamily.newBuilder() .setGcRule(GCRules.GCRULES.maxVersions(1).toProto()))) .addModifications( com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest.Modification.newBuilder() .setCreate( com.google.bigtable.admin.v2.ColumnFamily.newBuilder() .setGcRule(GcRule.getDefaultInstance()))) .addModifications( com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest.Modification.newBuilder() .setUpdate( com.google.bigtable.admin.v2.ColumnFamily.newBuilder() .setGcRule(GCRules.GCRULES.maxVersions(5).toProto()))) .addModifications( com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest.Modification.newBuilder()
@Test public void testModifyFamilies() { // Setup 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)); }
@Test public void createTable() { com.google.bigtable.admin.v2.CreateTableRequest actual = CreateTableRequest.of("tableId") .addFamily("cf1") .addFamily("cf2", GCRules.GCRULES.maxVersions(1)) .addSplit(ByteString.copyFromUtf8("c")) .toProto(PROJECT_ID, INSTANCE_ID); com.google.bigtable.admin.v2.CreateTableRequest expected = com.google.bigtable.admin.v2.CreateTableRequest.newBuilder() .setTableId("tableId") .setParent(InstanceName.of("project", "instance").toString()) .addInitialSplits(Split.newBuilder().setKey(ByteString.copyFromUtf8("c"))) .setTable( Table.newBuilder() .putColumnFamilies( "cf1", com.google.bigtable.admin.v2.ColumnFamily.newBuilder().build()) .putColumnFamilies( "cf2", com.google.bigtable.admin.v2.ColumnFamily.newBuilder() .setGcRule(GCRules.GCRULES.maxVersions(1).toProto()) .build())) .build(); assertThat(actual).isEqualTo(expected); }