/** * Adds a new columnFamily to the configuration * * @param familyId */ public CreateTableRequest addFamily(String familyId) { Preconditions.checkNotNull(familyId); tableRequest.putColumnFamilies(familyId, ColumnFamily.getDefaultInstance()); 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; }
.INITIALIZING) .build()) .putColumnFamilies("cf1", ColumnFamily.newBuilder().build()) .putColumnFamilies( "cf2", ColumnFamily.newBuilder() .setGcRule(GcRule.newBuilder().setMaxNumVersions(1)) .build()) .putColumnFamilies( "cf3", ColumnFamily.newBuilder()
/** * 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; }
/** * Adds a new columnFamily to the configuration * * @param familyId */ public CreateTableRequest addFamily(String familyId) { Preconditions.checkNotNull(familyId); tableRequest.putColumnFamilies(familyId, ColumnFamily.getDefaultInstance()); return this; }
/** Helper function to create an empty table. */ private void createEmptyTable(String instanceName, String tableId) { Table.Builder tableBuilder = Table.newBuilder(); tableBuilder.putColumnFamilies(COLUMN_FAMILY_NAME, ColumnFamily.newBuilder().build()); CreateTableRequest.Builder createTableRequestBuilder = CreateTableRequest.newBuilder() .setParent(instanceName) .setTableId(tableId) .setTable(tableBuilder.build()); tableAdminClient.createTable(createTableRequestBuilder.build()); }
@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); }
@Override public void start() throws Exception { emulator = Emulator.createGCloud(); emulator.start(); emulator .getTableAdminClient() .createTable( CreateTableRequest.newBuilder() .setParent(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID)) .setTableId(TABLE_ID) .setTable( Table.newBuilder() .putColumnFamilies(FAMILY_ID, ColumnFamily.getDefaultInstance())) .build()); }