本文整理匯總了Java中org.apache.hadoop.hbase.client.HBaseAdmin.tableExists方法的典型用法代碼示例。如果您正苦於以下問題:Java HBaseAdmin.tableExists方法的具體用法?Java HBaseAdmin.tableExists怎麽用?Java HBaseAdmin.tableExists使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.hadoop.hbase.client.HBaseAdmin
的用法示例。
在下文中一共展示了HBaseAdmin.tableExists方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: creatTable
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入方法依賴的package包/類
/**
* Create a hbaseBtable in case the table is not there Else prints table already exist conf is the
* configuration file object which needs to be passed, hbase-site.xml
* @method creatTable
* @inputParameters: tablename as String, ColumnFamalies as String Array[]
* @return NA as is a voild method
**/
public static void creatTable(String myHbaseBtableName, String[] cfamlies) throws Exception {
HBaseAdmin hbaseBadmin = new HBaseAdmin(hbaseBconf);
if (hbaseBadmin.tableExists(myHbaseBtableName)) {
System.out.println("Ohh.. this table is already there");
} else {
@SuppressWarnings("deprecation")
HTableDescriptor hbaseBtableDesc = new HTableDescriptor(myHbaseBtableName);
for (int i = 0; i < cfamlies.length; i++) {
hbaseBtableDesc.addFamily(new HColumnDescriptor(cfamlies[i]));
}
hbaseBadmin.createTable(hbaseBtableDesc);// creating a table
System.out.println("create table " + myHbaseBtableName + " Done.");
// Table is created and printed with the name.
}
}
示例2: prepareData
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入方法依賴的package包/類
private Store prepareData() throws IOException {
HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
if (admin.tableExists(tableName)) {
admin.disableTable(tableName);
admin.deleteTable(tableName);
}
HTable table = TEST_UTIL.createTable(tableName, family);
Random rand = new Random();
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
byte[] value = new byte[128 * 1024];
rand.nextBytes(value);
table.put(new Put(Bytes.toBytes(i * 10 + j)).add(family, qualifier, value));
}
admin.flush(tableName);
}
return getStoreWithName(tableName);
}
示例3: create
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入方法依賴的package包/類
public static void create() throws Exception {
HBaseAdmin admin = new HBaseAdmin(cfg);
if (admin.tableExists(tableName)) {
System.out.println("[info]table has created!");
} else {
try {
TableName table = TableName.valueOf(tableName);
HTableDescriptor tableDescriptor = new HTableDescriptor(table);
tableDescriptor.addFamily(new HColumnDescriptor(familyName));
admin.createTable(tableDescriptor);
} catch (TableExistsException e) {
System.out.println("[warning] table exists!");
}
}
System.out.println("[info]create table success!");
}
示例4: create
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入方法依賴的package包/類
public static void create() throws Exception
{
HBaseAdmin admin = new HBaseAdmin(cfg);
if (admin.tableExists(tableName)) {
System.out.println("[info]table has created!");
} else {
TableName table = TableName.valueOf(tableName);
HTableDescriptor tableDescriptor = new HTableDescriptor(table);
tableDescriptor.addFamily(new HColumnDescriptor(familyName));
try{
admin.createTable(tableDescriptor);
}catch(TableExistsException e)
{
System.out.println("[warning] table exists!");
}
}
System.out.println("[info]create table success!");
}
示例5: delete
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入方法依賴的package包/類
public static boolean delete(String tablename) throws IOException{
HBaseAdmin admin=new HBaseAdmin(cfg);
if(admin.tableExists(tablename)){
try
{
admin.disableTable(tablename);
admin.deleteTable(tablename);
}catch(Exception ex){
ex.printStackTrace();
return false;
}
}
return true;
}
示例6: setUp
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入方法依賴的package包/類
@BeforeMethod
public void setUp() throws Exception {
HBaseAdmin admin = testutil.getHBaseAdmin();
if (!admin.tableExists(DEFAULT_TIMESTAMP_STORAGE_TABLE_NAME)) {
HTableDescriptor desc = new HTableDescriptor(TABLE_NAME);
HColumnDescriptor datafam = new HColumnDescriptor(DEFAULT_TIMESTAMP_STORAGE_CF_NAME);
datafam.setMaxVersions(Integer.MAX_VALUE);
desc.addFamily(datafam);
admin.createTable(desc);
}
if (admin.isTableDisabled(DEFAULT_TIMESTAMP_STORAGE_TABLE_NAME)) {
admin.enableTable(DEFAULT_TIMESTAMP_STORAGE_TABLE_NAME);
}
HTableDescriptor[] tables = admin.listTables();
for (HTableDescriptor t : tables) {
LOG.info(t.getNameAsString());
}
}
示例7: createTable
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入方法依賴的package包/類
private static void createTable(HBaseAdmin admin, String tableName, byte[][] families, byte[][] splitKeys,
int maxVersions)
throws IOException {
LOG.info("About to create Table named {} with {} splits", tableName, splitKeys.length);
if (admin.tableExists(tableName)) {
LOG.error("Table {} already exists. Table creation cancelled", tableName);
return;
}
HTableDescriptor tableDescriptor = new HTableDescriptor(TableName.valueOf(tableName));
for (byte[] family : families) {
HColumnDescriptor colDescriptor = new HColumnDescriptor(family);
colDescriptor.setMaxVersions(maxVersions);
HBaseShims.addFamilyToHTableDescriptor(tableDescriptor, colDescriptor);
LOG.info("\tAdding Family {}", colDescriptor);
}
admin.createTable(tableDescriptor, splitKeys);
LOG.info("Table {} created. Regions: {}", tableName, admin.getTableRegions(Bytes.toBytes(tableName)).size());
}
示例8: deleteTable
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入方法依賴的package包/類
/**
* @param tableName
* @return
*/
public boolean deleteTable(String tableName) throws IOException {
HBaseAdmin admin = new HBaseAdmin(getConnPool().getConn());
if (admin.tableExists(tableName)) {
try {
if (admin.isTableEnabled(tableName)) {
admin.disableTable(tableName);
}
admin.deleteTable(tableName);
LOGGER.info(">>>> Table {} delete success!", tableName);
} catch (Exception ex) {
LOGGER.error("delete table error:", ex);
return false;
}
} else {
LOGGER.warn(">>>> Table {} delete but not exist.", tableName);
}
admin.close();
return true;
}
示例9: setUpBeforeClass
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入方法依賴的package包/類
@BeforeClass
public static void setUpBeforeClass() throws Exception {
conf = TEST_UTIL.getConfiguration();
TEST_UTIL.startMiniCluster(3);
REST_TEST_UTIL.startServletContainer(conf);
context = JAXBContext.newInstance(
CellModel.class,
CellSetModel.class,
RowModel.class);
marshaller = context.createMarshaller();
unmarshaller = context.createUnmarshaller();
client = new Client(new Cluster().add("localhost",
REST_TEST_UTIL.getServletPort()));
HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
if (admin.tableExists(TABLE)) {
return;
}
HTableDescriptor htd = new HTableDescriptor(TABLE);
htd.addFamily(new HColumnDescriptor(CFA));
htd.addFamily(new HColumnDescriptor(CFB));
admin.createTable(htd);
}
示例10: deleteTable
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入方法依賴的package包/類
@Override
public void deleteTable(String tableName) {
Util.checkEmptyString(tableName);
try {
HBaseAdmin hbaseAdmin = hbaseDataSource.getHBaseAdmin();
// delete table if table exist.
if (hbaseAdmin.tableExists(tableName)) {
// disable table before delete it.
if (!hbaseAdmin.isTableDisabled(tableName)) {
hbaseAdmin.disableTable(tableName);
}
hbaseAdmin.deleteTable(tableName);
}
} catch (Exception e) {
log.error(e);
throw new SimpleHBaseException(e);
}
}
示例11: deleteTable
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入方法依賴的package包/類
@Override
public void deleteTable(String tableName) {
Util.checkEmptyString(tableName);
try {
HBaseAdmin hbaseAdmin = hbaseDataSource.getHBaseAdmin();
// delete table if table exist.
if (hbaseAdmin.tableExists(tableName)) {
// disable table before delete it.
if (!hbaseAdmin.isTableDisabled(tableName)) {
hbaseAdmin.disableTable(tableName);
}
hbaseAdmin.deleteTable(tableName);
}
} catch (Exception e) {
log.error(e);
throw new SimpleHBaseException(e);
}
}
示例12: init
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入方法依賴的package包/類
public void init(String resourcePath) throws IOException {
System.out.println("start init");
Configuration conf = HBaseConfiguration.create();
if (resourcePath != null) {
conf.addResource(resourcePath);
}
HBaseAdmin admin = new HBaseAdmin(conf);
if (admin.tableExists(tableName)) {
admin.disableTable(tableName);
admin.deleteTable(tableName);
System.out.println("finish deleting existing table and index tables");
}
// for each kind
initIRIndex(admin);
}
示例13: createTableAndColumn
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入方法依賴的package包/類
public static void createTableAndColumn(Configuration conf,
String table,
byte[] columnFamily)
throws IOException {
HBaseAdmin hbase = new HBaseAdmin(conf);
HTableDescriptor desc = new HTableDescriptor(table);
HColumnDescriptor meta = new HColumnDescriptor(columnFamily);
desc.addFamily(meta);
if (hbase.tableExists(table)) {
if(hbase.isTableEnabled(table)) {
hbase.disableTable(table);
}
hbase.deleteTable(table);
}
hbase.createTable(desc);
}
示例14: generateHBaseDatasetCompositeKeyDate
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入方法依賴的package包/類
public static void generateHBaseDatasetCompositeKeyDate(HBaseAdmin admin, String tableName, int numberRegions) throws Exception {
if (admin.tableExists(tableName)) {
admin.disableTable(tableName);
admin.deleteTable(tableName);
}
HTableDescriptor desc = new HTableDescriptor(tableName);
desc.addFamily(new HColumnDescriptor(FAMILY_F));
if (numberRegions > 1) {
admin.createTable(desc, Arrays.copyOfRange(SPLIT_KEYS, 0, numberRegions-1));
} else {
admin.createTable(desc);
}
HTable table = new HTable(admin.getConfiguration(), tableName);
Date startDate = new Date(1408924800000L);
long startTime = startDate.getTime();
long MILLISECONDS_IN_A_DAY = (long)1000 * 60 * 60 * 24;
long MILLISECONDS_IN_A_YEAR = MILLISECONDS_IN_A_DAY * 365;
long endTime = startTime + MILLISECONDS_IN_A_YEAR;
long interval = MILLISECONDS_IN_A_DAY / 3;
for (long ts = startTime, counter = 0; ts < endTime; ts += interval, counter ++) {
byte[] rowKey = ByteBuffer.allocate(16) .putLong(ts).array();
for(int i = 0; i < 8; ++i) {
rowKey[8 + i] = (byte)(counter >> (56 - (i * 8)));
}
Put p = new Put(rowKey);
p.add(FAMILY_F, COLUMN_C, "dummy".getBytes());
table.put(p);
}
table.flushCommits();
table.close();
}
示例15: generateHBaseDatasetCompositeKeyInt
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入方法依賴的package包/類
public static void generateHBaseDatasetCompositeKeyInt(HBaseAdmin admin, String tableName, int numberRegions) throws Exception {
if (admin.tableExists(tableName)) {
admin.disableTable(tableName);
admin.deleteTable(tableName);
}
HTableDescriptor desc = new HTableDescriptor(tableName);
desc.addFamily(new HColumnDescriptor(FAMILY_F));
if (numberRegions > 1) {
admin.createTable(desc, Arrays.copyOfRange(SPLIT_KEYS, 0, numberRegions-1));
} else {
admin.createTable(desc);
}
HTable table = new HTable(admin.getConfiguration(), tableName);
int startVal = 0;
int stopVal = 1000;
int interval = 47;
long counter = 0;
for (int i = startVal; i < stopVal; i += interval, counter ++) {
byte[] rowKey = ByteBuffer.allocate(12).putInt(i).array();
for(int j = 0; j < 8; ++j) {
rowKey[4 + j] = (byte)(counter >> (56 - (j * 8)));
}
Put p = new Put(rowKey);
p.add(FAMILY_F, COLUMN_C, "dummy".getBytes());
table.put(p);
}
table.flushCommits();
table.close();
}