use of org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder in project hbase by apache.
the class TestDeleteMobTable method createTableDescriptor.
private TableDescriptor createTableDescriptor(TableName tableName, boolean hasMob) {
ColumnFamilyDescriptorBuilder builder = ColumnFamilyDescriptorBuilder.newBuilder(FAMILY);
if (hasMob) {
builder.setMobEnabled(true);
builder.setMobThreshold(0);
}
return TableDescriptorBuilder.newBuilder(tableName).setColumnFamily(builder.build()).build();
}
use of org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder in project hbase by apache.
the class TestThriftConnection method createTable.
private TableDescriptor createTable(Admin admin, String tableName) throws IOException {
TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(TableName.valueOf(tableName));
ColumnFamilyDescriptorBuilder familyABuilder = ColumnFamilyDescriptorBuilder.newBuilder(FAMILYA);
familyABuilder.setMaxVersions(3);
ColumnFamilyDescriptorBuilder familyBBuilder = ColumnFamilyDescriptorBuilder.newBuilder(FAMILYB);
familyBBuilder.setMaxVersions(3);
ColumnFamilyDescriptorBuilder familyCBuilder = ColumnFamilyDescriptorBuilder.newBuilder(FAMILYC);
familyCBuilder.setMaxVersions(3);
builder.setColumnFamily(familyABuilder.build());
builder.setColumnFamily(familyBBuilder.build());
builder.setColumnFamily(familyCBuilder.build());
TableDescriptor tableDescriptor = builder.build();
admin.createTable(tableDescriptor);
try (Table table = TEST_UTIL.getConnection().getTable(TableName.valueOf(tableName))) {
Put put = new Put(ROW_1);
put.addColumn(FAMILYA, QUALIFIER_1, TS_2, VALUE_1);
table.put(put);
put = new Put(ROW_2);
put.addColumn(FAMILYA, QUALIFIER_1, TS_1, VALUE_1);
put.addColumn(FAMILYA, QUALIFIER_1, TS_2, VALUE_2);
put.addColumn(FAMILYB, QUALIFIER_2, TS_2, VALUE_2);
table.put(put);
}
return tableDescriptor;
}
use of org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder in project hbase by apache.
the class TestThriftConnection method testThriftAdmin.
private void testThriftAdmin(Connection connection, String namespace, String table) throws Exception {
try (Admin admin = connection.getAdmin()) {
// create name space
NamespaceDescriptor namespaceDescriptor = NamespaceDescriptor.create(namespace).build();
namespaceDescriptor.setConfiguration("key1", "value1");
namespaceDescriptor.setConfiguration("key2", "value2");
admin.createNamespace(namespaceDescriptor);
// list namespace
NamespaceDescriptor[] namespaceDescriptors = admin.listNamespaceDescriptors();
boolean found = false;
for (NamespaceDescriptor nd : namespaceDescriptors) {
if (nd.getName().equals(namespace)) {
found = true;
break;
}
}
assertTrue(found);
// modify namesapce
namespaceDescriptor.setConfiguration("kye3", "value3");
admin.modifyNamespace(namespaceDescriptor);
// get namespace
NamespaceDescriptor namespaceDescriptorReturned = admin.getNamespaceDescriptor(namespace);
assertTrue(namespaceDescriptorReturned.getConfiguration().size() == 3);
// create table
TableDescriptor tableDescriptor = createTable(admin, table);
// modify table
TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableDescriptor);
builder.setDurability(Durability.ASYNC_WAL);
admin.modifyTable(builder.build());
// modify column family
ColumnFamilyDescriptor familyA = tableDescriptor.getColumnFamily(FAMILYA);
ColumnFamilyDescriptorBuilder familyABuilder = ColumnFamilyDescriptorBuilder.newBuilder(familyA);
familyABuilder.setInMemory(true);
admin.modifyColumnFamily(tableDescriptor.getTableName(), familyABuilder.build());
// add column family
ColumnFamilyDescriptorBuilder familyDBuilder = ColumnFamilyDescriptorBuilder.newBuilder(FAMILYD);
familyDBuilder.setDataBlockEncoding(DataBlockEncoding.PREFIX);
admin.addColumnFamily(tableDescriptor.getTableName(), familyDBuilder.build());
// get table descriptor
TableDescriptor tableDescriptorReturned = admin.getDescriptor(tableDescriptor.getTableName());
assertTrue(tableDescriptorReturned.getColumnFamilies().length == 4);
assertTrue(tableDescriptorReturned.getDurability() == Durability.ASYNC_WAL);
ColumnFamilyDescriptor columnFamilyADescriptor1Returned = tableDescriptorReturned.getColumnFamily(FAMILYA);
assertTrue(columnFamilyADescriptor1Returned.isInMemory() == true);
// delete column family
admin.deleteColumnFamily(tableDescriptor.getTableName(), FAMILYA);
tableDescriptorReturned = admin.getDescriptor(tableDescriptor.getTableName());
assertTrue(tableDescriptorReturned.getColumnFamilies().length == 3);
// disable table
admin.disableTable(tableDescriptor.getTableName());
assertTrue(admin.isTableDisabled(tableDescriptor.getTableName()));
// enable table
admin.enableTable(tableDescriptor.getTableName());
assertTrue(admin.isTableEnabled(tableDescriptor.getTableName()));
assertTrue(admin.isTableAvailable(tableDescriptor.getTableName()));
// truncate table
admin.disableTable(tableDescriptor.getTableName());
admin.truncateTable(tableDescriptor.getTableName(), true);
assertTrue(admin.isTableAvailable(tableDescriptor.getTableName()));
// delete table
admin.disableTable(tableDescriptor.getTableName());
admin.deleteTable(tableDescriptor.getTableName());
assertFalse(admin.tableExists(tableDescriptor.getTableName()));
// delete namespace
admin.deleteNamespace(namespace);
namespaceDescriptors = admin.listNamespaceDescriptors();
// should have 2 namespace, default and hbase
found = false;
for (NamespaceDescriptor nd : namespaceDescriptors) {
if (nd.getName().equals(namespace)) {
found = true;
break;
}
}
assertTrue(found == false);
}
}
use of org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder in project hbase by apache.
the class HBaseTestingUtil method createTable.
public Table createTable(TableName tableName, byte[][] families, int numVersions, int blockSize, String cpName) throws IOException {
TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
for (byte[] family : families) {
ColumnFamilyDescriptorBuilder cfBuilder = ColumnFamilyDescriptorBuilder.newBuilder(family).setMaxVersions(numVersions).setBlocksize(blockSize);
if (isNewVersionBehaviorEnabled()) {
cfBuilder.setNewVersionBehavior(true);
}
builder.setColumnFamily(cfBuilder.build());
}
if (cpName != null) {
builder.setCoprocessor(cpName);
}
getAdmin().createTable(builder.build());
// HBaseAdmin only waits for regions to appear in hbase:meta we should wait until they are
// assigned
waitUntilAllRegionsAssigned(tableName);
return getConnection().getTable(tableName);
}
use of org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder in project hbase by apache.
the class HBaseTestingUtil method createTable.
/**
* Create a table.
* @return A Table instance for the created table.
*/
public Table createTable(TableName tableName, byte[][] families, int[] numVersions) throws IOException {
TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
int i = 0;
for (byte[] family : families) {
ColumnFamilyDescriptorBuilder cfBuilder = ColumnFamilyDescriptorBuilder.newBuilder(family).setMaxVersions(numVersions[i]);
if (isNewVersionBehaviorEnabled()) {
cfBuilder.setNewVersionBehavior(true);
}
builder.setColumnFamily(cfBuilder.build());
i++;
}
getAdmin().createTable(builder.build());
// HBaseAdmin only waits for regions to appear in hbase:meta we should wait until they are
// assigned
waitUntilAllRegionsAssigned(tableName);
return getConnection().getTable(tableName);
}
Aggregations