Search in sources :

Example 6 with CreateTableRequest

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

Example 7 with CreateTableRequest

use of com.google.cloud.bigtable.admin.v2.models.CreateTableRequest in project java-bigtable-hbase by googleapis.

the class TestTableAdapter method testAdaptWithHTableDescriptor.

@Test
public void testAdaptWithHTableDescriptor() {
    byte[][] splits = new byte[][] { Bytes.toBytes("AAA"), Bytes.toBytes("BBB"), Bytes.toBytes("CCC") };
    CreateTableRequest actualRequest = TableAdapter.adapt(new HTableDescriptor(TableName.valueOf(TABLE_ID)), splits);
    CreateTableRequest expectedRequest = CreateTableRequest.of(TABLE_ID);
    TableAdapter.addSplitKeys(splits, expectedRequest);
    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 8 with CreateTableRequest

use of com.google.cloud.bigtable.admin.v2.models.CreateTableRequest in project java-bigtable by googleapis.

the class HelloWorld method createTable.

/**
 * Demonstrates how to create a table.
 */
public void createTable() {
    // Checks if table exists, creates table if does not exist.
    if (!adminClient.exists(tableId)) {
        System.out.println("Creating table: " + tableId);
        CreateTableRequest createTableRequest = CreateTableRequest.of(tableId).addFamily(COLUMN_FAMILY);
        adminClient.createTable(createTableRequest);
        System.out.printf("Table %s created successfully%n", tableId);
    }
// [END bigtable_hw_create_table]
}
Also used : CreateTableRequest(com.google.cloud.bigtable.admin.v2.models.CreateTableRequest)

Example 9 with CreateTableRequest

use of com.google.cloud.bigtable.admin.v2.models.CreateTableRequest in project java-bigtable by googleapis.

the class TableAdminExample method createTable.

/**
 * Demonstrates how to create a table with the specified configuration.
 */
public void createTable() {
    // Checks if table exists, creates table if does not exist.
    if (!adminClient.exists(tableId)) {
        System.out.println("Table does not exist, creating table: " + tableId);
        CreateTableRequest createTableRequest = CreateTableRequest.of(tableId).addFamily("cf");
        Table table = adminClient.createTable(createTableRequest);
        System.out.printf("Table: %s created successfully%n", table.getId());
    }
// [END bigtable_create_table]
}
Also used : Table(com.google.cloud.bigtable.admin.v2.models.Table) CreateTableRequest(com.google.cloud.bigtable.admin.v2.models.CreateTableRequest)

Example 10 with CreateTableRequest

use of com.google.cloud.bigtable.admin.v2.models.CreateTableRequest in project java-bigtable by googleapis.

the class BigtableTableAdminClientIT method createTable.

@Test
public void createTable() {
    assume().withMessage("Emulator doesn't return proper responses for CreateTable").that(testEnvRule.env()).isNotInstanceOf(EmulatorEnv.class);
    CreateTableRequest createTableReq = CreateTableRequest.of(tableId).addFamily("cf1").addFamily("cf2", GCRULES.maxVersions(10)).addSplit(ByteString.copyFromUtf8("b")).addSplit(ByteString.copyFromUtf8("q"));
    Table tableResponse = tableAdmin.createTable(createTableReq);
    assertEquals(tableId, tableResponse.getId());
    Map<String, ColumnFamily> columnFamilyById = Maps.newHashMap();
    for (ColumnFamily columnFamily : tableResponse.getColumnFamilies()) {
        columnFamilyById.put(columnFamily.getId(), columnFamily);
    }
    assertEquals(2, tableResponse.getColumnFamilies().size());
    assertFalse(columnFamilyById.get("cf1").hasGCRule());
    assertTrue(columnFamilyById.get("cf2").hasGCRule());
    assertEquals(10, ((VersionRule) columnFamilyById.get("cf2").getGCRule()).getMaxVersions());
}
Also used : Table(com.google.cloud.bigtable.admin.v2.models.Table) ByteString(com.google.protobuf.ByteString) CreateTableRequest(com.google.cloud.bigtable.admin.v2.models.CreateTableRequest) ColumnFamily(com.google.cloud.bigtable.admin.v2.models.ColumnFamily) 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