本文整理匯總了Java中org.apache.hadoop.hbase.client.Admin.addColumn方法的典型用法代碼示例。如果您正苦於以下問題:Java Admin.addColumn方法的具體用法?Java Admin.addColumn怎麽用?Java Admin.addColumn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.hadoop.hbase.client.Admin
的用法示例。
在下文中一共展示了Admin.addColumn方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addColumn
import org.apache.hadoop.hbase.client.Admin; //導入方法依賴的package包/類
/**
* 往表中添加列族
*
* @param tableName 表名
* @param familyName 列族名
*/
public void addColumn(String tableName, String familyName) {
HBaseConfiguration hBaseConfiguration = new HBaseConfiguration();
Admin admin = hBaseConfiguration.admin();
TableName tb = TableName.valueOf(tableName);
try {
if (admin.tableExists(tb)) {
HColumnDescriptor columnDescriptor = new HColumnDescriptor(familyName);
columnDescriptor.setMaxVersions(1);//設置列族保留的最多版本
columnDescriptor.setCompressionType(Compression.Algorithm.GZ);//設置壓縮算法
columnDescriptor.setCompactionCompressionType(Compression.Algorithm.GZ);//合並壓縮算法
admin.addColumn(tb, columnDescriptor);
} else {
log.info("表名【" + tableName + "】不存在");
}
} catch (IOException e) {
log.error(e);
} finally {
hBaseConfiguration.close();
}
}
示例2: testAddColumn
import org.apache.hadoop.hbase.client.Admin; //導入方法依賴的package包/類
@Test
public void testAddColumn() throws IOException {
Admin admin = TEST_UTIL.getHBaseAdmin();
// Create a table with two families
HTableDescriptor baseHtd = new HTableDescriptor(TABLE_NAME);
baseHtd.addFamily(new HColumnDescriptor(FAMILY_0));
admin.createTable(baseHtd);
admin.disableTable(TABLE_NAME);
try {
// Verify the table descriptor
verifyTableDescriptor(TABLE_NAME, FAMILY_0);
// Modify the table removing one family and verify the descriptor
admin.addColumn(TABLE_NAME, new HColumnDescriptor(FAMILY_1));
verifyTableDescriptor(TABLE_NAME, FAMILY_0, FAMILY_1);
} finally {
admin.deleteTable(TABLE_NAME);
}
}
示例3: testAddSameColumnFamilyTwice
import org.apache.hadoop.hbase.client.Admin; //導入方法依賴的package包/類
@Test
public void testAddSameColumnFamilyTwice() throws IOException {
Admin admin = TEST_UTIL.getHBaseAdmin();
// Create a table with one families
HTableDescriptor baseHtd = new HTableDescriptor(TABLE_NAME);
baseHtd.addFamily(new HColumnDescriptor(FAMILY_0));
admin.createTable(baseHtd);
admin.disableTable(TABLE_NAME);
try {
// Verify the table descriptor
verifyTableDescriptor(TABLE_NAME, FAMILY_0);
// Modify the table removing one family and verify the descriptor
admin.addColumn(TABLE_NAME, new HColumnDescriptor(FAMILY_1));
verifyTableDescriptor(TABLE_NAME, FAMILY_0, FAMILY_1);
try {
// Add same column family again - expect failure
admin.addColumn(TABLE_NAME, new HColumnDescriptor(FAMILY_1));
Assert.fail("Delete a non-exist column family should fail");
} catch (InvalidFamilyOperationException e) {
// Expected.
}
} finally {
admin.deleteTable(TABLE_NAME);
}
}