本文整理匯總了Java中org.apache.hadoop.hbase.client.HBaseAdmin.addColumn方法的典型用法代碼示例。如果您正苦於以下問題:Java HBaseAdmin.addColumn方法的具體用法?Java HBaseAdmin.addColumn怎麽用?Java HBaseAdmin.addColumn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.hadoop.hbase.client.HBaseAdmin
的用法示例。
在下文中一共展示了HBaseAdmin.addColumn方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testAddColumn
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入方法依賴的package包/類
@Test
public void testAddColumn() throws IOException {
HBaseAdmin 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);
}
}
示例2: createMetaData
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入方法依賴的package包/類
public static void createMetaData(ObjectValue object, HTable table) throws IOException {
final HBaseAdmin admin = new HBaseAdmin(table.getConfiguration());
// create non existing column families
for (Step<String> columnFamily : object.keySet()) {
if(columnFamily.getStep().equals("_id"))
continue;
final String columnFamilyId = columnFamily.getStep();
// check if column family exists
boolean exists = false;
for (HColumnDescriptor familyDescriptor : table.getTableDescriptor().getFamilies()) {
if(Bytes.toString(familyDescriptor.getName()).equals(columnFamilyId)) {
exists = true;
break;
}
}
// if not: add it
if(!exists) {
admin.disableTable(table.getTableName());
admin.addColumn(table.getTableName(), new HColumnDescriptor(columnFamilyId));
admin.enableTable(table.getTableName());
}
}
}
示例3: createFamily
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入方法依賴的package包/類
public static void createFamily(String family, HTable table) {
try {
final HBaseAdmin admin = new HBaseAdmin(table.getConfiguration());
// check if column family exists
boolean exists = false;
for (HColumnDescriptor familyDescriptor : table.getTableDescriptor().getFamilies()) {
if(Bytes.toString(familyDescriptor.getName()).equals(family)) {
exists = true;
break;
}
}
// if not: add it
if(!exists) {
admin.addColumn(table.getTableName(), new HColumnDescriptor(family));
}
} catch (IOException e) {
e.printStackTrace();
}
}
示例4: connect
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入方法依賴的package包/類
@Override
public void connect() throws IOException
{
super.connect();
HTableDescriptor tdesc = table.getTableDescriptor();
if (!tdesc.hasFamily(columnFamilyBytes)) {
HBaseAdmin admin = new HBaseAdmin(table.getConfiguration());
admin.disableTable(table.getTableName());
try {
HColumnDescriptor cdesc = new HColumnDescriptor(columnFamilyBytes);
admin.addColumn(table.getTableName(), cdesc);
} finally {
admin.enableTable(table.getTableName());
admin.close();
}
}
}
示例5: applyColumnFamilyOptions
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入方法依賴的package包/類
/**
* Apply column family options such as Bloom filters, compression, and data
* block encoding.
*/
protected void applyColumnFamilyOptions(byte[] tableName,
byte[][] columnFamilies) throws IOException {
HBaseAdmin admin = new HBaseAdmin(conf);
HTableDescriptor tableDesc = admin.getTableDescriptor(tableName);
LOG.info("Disabling table " + Bytes.toString(tableName));
admin.disableTable(tableName);
for (byte[] cf : columnFamilies) {
HColumnDescriptor columnDesc = tableDesc.getFamily(cf);
boolean isNewCf = columnDesc == null;
if (isNewCf) {
columnDesc = new HColumnDescriptor(cf);
}
if (bloomType != null) {
columnDesc.setBloomFilterType(bloomType);
}
if (compressAlgo != null) {
columnDesc.setCompressionType(compressAlgo);
}
if (dataBlockEncodingAlgo != null) {
columnDesc.setDataBlockEncoding(dataBlockEncodingAlgo);
columnDesc.setEncodeOnDisk(!encodeInCacheOnly);
}
if (inMemoryCF) {
columnDesc.setInMemory(inMemoryCF);
}
if (isNewCf) {
admin.addColumn(tableName, columnDesc);
} else {
admin.modifyColumn(tableName, columnDesc);
}
}
LOG.info("Enabling table " + Bytes.toString(tableName));
admin.enableTable(tableName);
}
示例6: applyColumnFamilyOptions
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入方法依賴的package包/類
/**
* Apply column family options such as Bloom filters, compression, and data
* block encoding.
*/
protected void applyColumnFamilyOptions(TableName tableName,
byte[][] columnFamilies) throws IOException {
HBaseAdmin admin = new HBaseAdmin(conf);
HTableDescriptor tableDesc = admin.getTableDescriptor(tableName);
LOG.info("Disabling table " + tableName);
admin.disableTable(tableName);
for (byte[] cf : columnFamilies) {
HColumnDescriptor columnDesc = tableDesc.getFamily(cf);
boolean isNewCf = columnDesc == null;
if (isNewCf) {
columnDesc = new HColumnDescriptor(cf);
}
if (bloomType != null) {
columnDesc.setBloomFilterType(bloomType);
}
if (compressAlgo != null) {
columnDesc.setCompressionType(compressAlgo);
}
if (dataBlockEncodingAlgo != null) {
columnDesc.setDataBlockEncoding(dataBlockEncodingAlgo);
}
if (inMemoryCF) {
columnDesc.setInMemory(inMemoryCF);
}
if (cipher != null) {
byte[] keyBytes = new byte[cipher.getKeyLength()];
new SecureRandom().nextBytes(keyBytes);
columnDesc.setEncryptionType(cipher.getName());
columnDesc.setEncryptionKey(EncryptionUtil.wrapKey(conf,
User.getCurrent().getShortName(),
new SecretKeySpec(keyBytes, cipher.getName())));
}
if (isNewCf) {
admin.addColumn(tableName, columnDesc);
} else {
admin.modifyColumn(tableName, columnDesc);
}
}
LOG.info("Enabling table " + tableName);
admin.enableTable(tableName);
}
示例7: addColumnFamily
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入方法依賴的package包/類
@Test
public void addColumnFamily() throws Exception {
String TABLE_NAME = "TEST_BENCHMARK";
//
Configuration configuration = createConfiguration();
HBaseAdmin hbaseAdmin = createHBaseAdmin(configuration);
//
// 新增column時,須將table disable
if (hbaseAdmin.isTableEnabled(TABLE_NAME)) {
hbaseAdmin.disableTable(TABLE_NAME);
}
//
String COLUMN_FAMILY = "seq";
HColumnDescriptor hcd = new HColumnDescriptor(COLUMN_FAMILY);
// hcd.setBloomFilterType(BloomType.ROWCOL);
hcd.setBlockCacheEnabled(true);
// hcd.setCompressionType(Algorithm.SNAPPY);
hcd.setInMemory(true);
hcd.setMaxVersions(1);
hcd.setMinVersions(0);
hcd.setTimeToLive(432000);// 秒為單位
hbaseAdmin.addColumn(TABLE_NAME, hcd);// TableNotDisabledException,
System.out.println("add column family [" + COLUMN_FAMILY + "]");
//
COLUMN_FAMILY = "id";
hcd = new HColumnDescriptor(COLUMN_FAMILY);
// hcd.setBloomFilterType(BloomType.ROWCOL);
hcd.setBlockCacheEnabled(true);
// hcd.setCompressionType(Algorithm.SNAPPY);
hcd.setInMemory(true);
hcd.setMaxVersions(1);
hcd.setMinVersions(0);
hcd.setTimeToLive(432000);// 秒為單位,5d
hbaseAdmin.addColumn(TABLE_NAME, hcd);// TableNotDisabledException,
System.out.println("add column family [" + COLUMN_FAMILY + "]");
//
COLUMN_FAMILY = "info";
hcd = new HColumnDescriptor(COLUMN_FAMILY);
// hcd.setBloomFilterType(BloomType.ROWCOL);
hcd.setBlockCacheEnabled(true);
// hcd.setCompressionType(Algorithm.SNAPPY);
hcd.setInMemory(true);
hcd.setMaxVersions(1);
hcd.setMinVersions(0);
hcd.setTimeToLive(432000);// 秒為單位
hbaseAdmin.addColumn(TABLE_NAME, hcd);// TableNotDisabledException
System.out.println("add column family [" + COLUMN_FAMILY + "]");
// 新增column後,再將table enable
if (hbaseAdmin.isTableDisabled(TABLE_NAME)) {
hbaseAdmin.enableTable(TABLE_NAME);
}
}