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));
}
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));
}
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]
}
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]
}
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());
}
Aggregations