use of com.google.cloud.bigtable.admin.v2.models.CreateTableRequest in project java-docs-samples by GoogleCloudPlatform.
the class FiltersTest method beforeClass.
@BeforeClass
public static void beforeClass() throws IOException {
projectId = requireEnv("GOOGLE_CLOUD_PROJECT");
instanceId = requireEnv(INSTANCE_ENV);
try (BigtableTableAdminClient adminClient = BigtableTableAdminClient.create(projectId, instanceId)) {
CreateTableRequest createTableRequest = CreateTableRequest.of(TABLE_ID).addFamily(COLUMN_FAMILY_NAME_STATS).addFamily(COLUMN_FAMILY_NAME_DATA);
adminClient.createTable(createTableRequest);
try (BigtableDataClient dataClient = BigtableDataClient.create(projectId, instanceId)) {
BulkMutation bulkMutation = BulkMutation.create(TABLE_ID).add("phone#4c410523#20190501", Mutation.create().setCell(COLUMN_FAMILY_NAME_STATS, ByteString.copyFrom("connected_cell".getBytes()), TIMESTAMP_NANO, 1).setCell(COLUMN_FAMILY_NAME_STATS, ByteString.copyFrom("connected_wifi".getBytes()), TIMESTAMP_NANO, 1).setCell(COLUMN_FAMILY_NAME_STATS, "os_build", TIMESTAMP_NANO, "PQ2A.190405.003").setCell(COLUMN_FAMILY_NAME_DATA, "data_plan_01gb", TIMESTAMP_MINUS_HR_NANO, "true").setCell(COLUMN_FAMILY_NAME_DATA, "data_plan_01gb", TIMESTAMP_NANO, "false").setCell(COLUMN_FAMILY_NAME_DATA, "data_plan_05gb", TIMESTAMP_NANO, "true")).add("phone#4c410523#20190502", Mutation.create().setCell(COLUMN_FAMILY_NAME_STATS, ByteString.copyFrom("connected_cell".getBytes()), TIMESTAMP_NANO, 1).setCell(COLUMN_FAMILY_NAME_STATS, ByteString.copyFrom("connected_wifi".getBytes()), TIMESTAMP_NANO, 1).setCell(COLUMN_FAMILY_NAME_STATS, "os_build", TIMESTAMP_NANO, "PQ2A.190405.004").setCell(COLUMN_FAMILY_NAME_DATA, "data_plan_05gb", TIMESTAMP_NANO, "true")).add("phone#4c410523#20190505", Mutation.create().setCell(COLUMN_FAMILY_NAME_STATS, ByteString.copyFrom("connected_cell".getBytes()), TIMESTAMP_NANO, 0).setCell(COLUMN_FAMILY_NAME_STATS, ByteString.copyFrom("connected_wifi".getBytes()), TIMESTAMP_NANO, 1).setCell(COLUMN_FAMILY_NAME_STATS, "os_build", TIMESTAMP_NANO, "PQ2A.190406.000").setCell(COLUMN_FAMILY_NAME_DATA, "data_plan_05gb", TIMESTAMP_NANO, "true")).add("phone#5c10102#20190501", Mutation.create().setCell(COLUMN_FAMILY_NAME_STATS, ByteString.copyFrom("connected_cell".getBytes()), TIMESTAMP_NANO, 1).setCell(COLUMN_FAMILY_NAME_STATS, ByteString.copyFrom("connected_wifi".getBytes()), TIMESTAMP_NANO, 1).setCell(COLUMN_FAMILY_NAME_STATS, "os_build", TIMESTAMP_NANO, "PQ2A.190401.002").setCell(COLUMN_FAMILY_NAME_DATA, "data_plan_10gb", TIMESTAMP_NANO, "true")).add("phone#5c10102#20190502", Mutation.create().setCell(COLUMN_FAMILY_NAME_STATS, ByteString.copyFrom("connected_cell".getBytes()), TIMESTAMP_NANO, 1).setCell(COLUMN_FAMILY_NAME_STATS, ByteString.copyFrom("connected_wifi".getBytes()), TIMESTAMP_NANO, 0).setCell(COLUMN_FAMILY_NAME_STATS, "os_build", TIMESTAMP_NANO, "PQ2A.190406.000").setCell(COLUMN_FAMILY_NAME_DATA, "data_plan_10gb", TIMESTAMP_NANO, "true"));
dataClient.bulkMutateRows(bulkMutation);
}
} catch (Exception e) {
System.out.println("Error during beforeClass: \n" + e.toString());
throw (e);
}
}
use of com.google.cloud.bigtable.admin.v2.models.CreateTableRequest in project java-docs-samples by GoogleCloudPlatform.
the class BulkWrite method getNewTableIds.
// Increases or decreases the number of tables in the Bigtable instance based on the expected size
// and returns any newly created table ids.
private static List<String> getNewTableIds(BigtableTableAdminClient adminClient, double expectedSize) {
List<String> tableIds = adminClient.listTables();
List<String> newTableIds = new ArrayList<>();
double currentSize = tableIds.size() * TB_PER_TABLE;
if (currentSize >= expectedSize) {
int numTablesToDelete = (int) ((currentSize - expectedSize) / .5);
for (int i = 0; i < numTablesToDelete; i++) {
adminClient.deleteTable(tableIds.get(i));
}
System.out.printf("Deleted %d tables%n", numTablesToDelete);
} else {
int numTablesToCreate = (int) ((expectedSize - currentSize) / .5);
System.out.printf("Creating %d tables%n", numTablesToCreate);
for (int i = 0; i < numTablesToCreate; i++) {
String tableId = TABLE_PREFIX + UUID.randomUUID().toString().substring(0, 20);
CreateTableRequest createTableRequest = CreateTableRequest.of(tableId).addFamily(COLUMN_FAMILY);
adminClient.createTable(createTableRequest);
newTableIds.add(tableId);
System.out.println(tableId);
}
}
return newTableIds;
}
use of com.google.cloud.bigtable.admin.v2.models.CreateTableRequest 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);
}
}
}
}
use of com.google.cloud.bigtable.admin.v2.models.CreateTableRequest in project java-bigtable-hbase by googleapis.
the class TestTableAdapter method testAdaptWithHTableDescriptorWhenSplitIsEmpty.
@Test
public void testAdaptWithHTableDescriptorWhenSplitIsEmpty() {
byte[][] splits = new byte[0][0];
CreateTableRequest actualRequest = TableAdapter.adapt(new HTableDescriptor(TableName.valueOf(TABLE_ID)), splits);
CreateTableRequest expectedRequest = CreateTableRequest.of(TABLE_ID);
Assert.assertEquals(expectedRequest.toProto(PROJECT_ID, INSTANCE_ID), actualRequest.toProto(PROJECT_ID, INSTANCE_ID));
}
use of com.google.cloud.bigtable.admin.v2.models.CreateTableRequest in project java-bigtable-hbase by googleapis.
the class TestAdminClientVeneerApi method testCreateTableAsync.
@Test
public void testCreateTableAsync() throws Exception {
CreateTableRequest req = CreateTableRequest.of(TABLE_ID_1);
Future<Table> response = adminClientWrapper.createTableAsync(req);
assertEquals(TABLE_ID_1, response.get().getId());
}
Aggregations