Search in sources :

Example 11 with CreateTableRequest

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);
    }
}
Also used : BulkMutation(com.google.cloud.bigtable.data.v2.models.BulkMutation) BigtableTableAdminClient(com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient) BigtableDataClient(com.google.cloud.bigtable.data.v2.BigtableDataClient) CreateTableRequest(com.google.cloud.bigtable.admin.v2.models.CreateTableRequest) IOException(java.io.IOException) BeforeClass(org.junit.BeforeClass)

Example 12 with CreateTableRequest

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;
}
Also used : ArrayList(java.util.ArrayList) CreateTableRequest(com.google.cloud.bigtable.admin.v2.models.CreateTableRequest)

Example 13 with CreateTableRequest

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);
            }
        }
    }
}
Also used : HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) GCRule(com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule) ByteString(com.google.protobuf.ByteString)

Example 14 with CreateTableRequest

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));
}
Also used : CreateTableRequest(com.google.cloud.bigtable.admin.v2.models.CreateTableRequest) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) Test(org.junit.Test)

Example 15 with CreateTableRequest

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());
}
Also used : Table(com.google.cloud.bigtable.admin.v2.models.Table) CreateTableRequest(com.google.cloud.bigtable.admin.v2.models.CreateTableRequest) Test(org.junit.Test)

Aggregations

CreateTableRequest (com.google.cloud.bigtable.admin.v2.models.CreateTableRequest)16 Test (org.junit.Test)7 BigtableTableAdminClient (com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient)6 BigtableDataClient (com.google.cloud.bigtable.data.v2.BigtableDataClient)5 Table (com.google.cloud.bigtable.admin.v2.models.Table)4 BulkMutation (com.google.cloud.bigtable.data.v2.models.BulkMutation)4 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)4 GCRule (com.google.cloud.bigtable.admin.v2.models.GCRules.GCRule)3 IOException (java.io.IOException)3 BeforeClass (org.junit.BeforeClass)3 ByteString (com.google.protobuf.ByteString)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 PrintStream (java.io.PrintStream)2 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)2 Before (org.junit.Before)2 ColumnFamily (com.google.bigtable.admin.v2.ColumnFamily)1 ColumnFamily (com.google.cloud.bigtable.admin.v2.models.ColumnFamily)1 RowMutation (com.google.cloud.bigtable.data.v2.models.RowMutation)1 ArrayList (java.util.ArrayList)1 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)1