本文整理匯總了Java中org.apache.hadoop.hbase.client.Admin.tableExists方法的典型用法代碼示例。如果您正苦於以下問題:Java Admin.tableExists方法的具體用法?Java Admin.tableExists怎麽用?Java Admin.tableExists使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.hadoop.hbase.client.Admin
的用法示例。
在下文中一共展示了Admin.tableExists方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createTable
import org.apache.hadoop.hbase.client.Admin; //導入方法依賴的package包/類
/**
* 創建表
*
* @param tableName 表名稱
* @param columns 列族名稱
*/
public void createTable(String tableName, String... columns) {
HBaseConfiguration hBaseConfiguration = new HBaseConfiguration();
Admin admin = hBaseConfiguration.admin();
try {
TableName tn = TableName.valueOf(tableName);
if (admin.tableExists(tn)) {
log.info("表名【" + tableName + "】已存在");
return;
}
HTableDescriptor hTableDescriptor = new HTableDescriptor(tn);
for (String column : columns) {
HColumnDescriptor hColumnDescriptor = new HColumnDescriptor(column);
hTableDescriptor.addFamily(hColumnDescriptor);
}
admin.createTable(hTableDescriptor);
} catch (IOException e) {
e.printStackTrace();
} finally {
hBaseConfiguration.close();
}
}
示例2: deleteTable
import org.apache.hadoop.hbase.client.Admin; //導入方法依賴的package包/類
/**
* 刪除表
*
* @param tableName
*/
public void deleteTable(String tableName) {
HBaseConfiguration hBaseConfiguration = new HBaseConfiguration();
Admin admin = hBaseConfiguration.admin();
TableName tn = TableName.valueOf(tableName);
try {
if (admin.tableExists(tn)) {
admin.disableTable(tn);//先禁用表 才能刪除
admin.deleteTable(tn);
} else {
log.info("表名【" + tableName + "】不存在");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
hBaseConfiguration.close();
}
}
示例3: setUp
import org.apache.hadoop.hbase.client.Admin; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
LOG.info(String.format("Initializing cluster with %d region servers.",
REGION_SERVER_COUNT));
util.initializeCluster(REGION_SERVER_COUNT);
LOG.info("Cluster initialized");
Admin admin = util.getHBaseAdmin();
if (admin.tableExists(TABLE_NAME)) {
LOG.info(String.format("Deleting existing table %s.", TABLE_NAME));
if (admin.isTableEnabled(TABLE_NAME)) admin.disableTable(TABLE_NAME);
admin.deleteTable(TABLE_NAME);
LOG.info(String.format("Existing table %s deleted.", TABLE_NAME));
}
LOG.info("Cluster ready");
}
示例4: generateHBaseDatasetNullStr
import org.apache.hadoop.hbase.client.Admin; //導入方法依賴的package包/類
public static void generateHBaseDatasetNullStr(Connection conn, Admin admin, TableName tableName, int numberRegions) throws Exception {
if (admin.tableExists(tableName)) {
admin.disableTable(tableName);
admin.deleteTable(tableName);
}
HTableDescriptor desc = new HTableDescriptor(tableName);
desc.addFamily(new HColumnDescriptor("f"));
if (numberRegions > 1) {
admin.createTable(desc, Arrays.copyOfRange(SPLIT_KEYS, 0, numberRegions-1));
} else {
admin.createTable(desc);
}
BufferedMutator table = conn.getBufferedMutator(tableName);
Put p = new Put("a1".getBytes());
p.addColumn("f".getBytes(), "c1".getBytes(), "".getBytes());
p.addColumn("f".getBytes(), "c2".getBytes(), "".getBytes());
p.addColumn("f".getBytes(), "c3".getBytes(), "5".getBytes());
p.addColumn("f".getBytes(), "c4".getBytes(), "".getBytes());
table.mutate(p);
table.close();
}
示例5: setUpBeforeClass
import org.apache.hadoop.hbase.client.Admin; //導入方法依賴的package包/類
@BeforeClass
public static void setUpBeforeClass() throws Exception {
conf = TEST_UTIL.getConfiguration();
TEST_UTIL.startMiniCluster();
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()));
Admin 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);
}
示例6: setUp
import org.apache.hadoop.hbase.client.Admin; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
Admin admin = util.getHBaseAdmin();
if (admin.tableExists(tableName)) {
if (admin.isTableEnabled(tableName)) {
admin.disableTable(tableName);
}
admin.deleteTable(tableName);
}
util.createTable(tableName, new byte[][] {dummy, test});
}
示例7: beforeMethod
import org.apache.hadoop.hbase.client.Admin; //導入方法依賴的package包/類
@Before
public void beforeMethod() throws Exception {
Admin admin = TEST_UTIL.getHBaseAdmin();
if (admin.tableExists(TableName.valueOf(TABLE))) {
TEST_UTIL.deleteTable(Bytes.toBytes(TABLE));
}
HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(TABLE));
htd.addFamily(new HColumnDescriptor(CFA));
htd.addFamily(new HColumnDescriptor(CFB));
admin.createTable(htd);
}
示例8: generateHBaseDatasetDoubleOB
import org.apache.hadoop.hbase.client.Admin; //導入方法依賴的package包/類
public static void generateHBaseDatasetDoubleOB(Connection conn, Admin admin, TableName 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);
}
BufferedMutator table = conn.getBufferedMutator(tableName);
for (double i = 0.5; i <= 100.00; i += 0.75) {
byte[] bytes = new byte[9];
PositionedByteRange br = new SimplePositionedMutableByteRange(bytes, 0, 9);
OrderedBytes.encodeFloat64(br, i, Order.ASCENDING);
Put p = new Put(bytes);
p.addColumn(FAMILY_F, COLUMN_C, String.format("value %03f", i).getBytes());
table.mutate(p);
}
table.close();
admin.flush(tableName);
}
示例9: generateHBaseDatasetFloatOB
import org.apache.hadoop.hbase.client.Admin; //導入方法依賴的package包/類
public static void generateHBaseDatasetFloatOB(Connection conn, Admin admin, TableName 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);
}
BufferedMutator table = conn.getBufferedMutator(tableName);
for (float i = (float)0.5; i <= 100.00; i += 0.75) {
byte[] bytes = new byte[5];
PositionedByteRange br = new SimplePositionedMutableByteRange(bytes, 0, 5);
OrderedBytes.encodeFloat32(br, i,Order.ASCENDING);
Put p = new Put(bytes);
p.addColumn(FAMILY_F, COLUMN_C, String.format("value %03f", i).getBytes());
table.mutate(p);
}
table.close();
admin.flush(tableName);
}
示例10: generateHBaseDatasetBigIntOB
import org.apache.hadoop.hbase.client.Admin; //導入方法依賴的package包/類
public static void generateHBaseDatasetBigIntOB(Connection conn, Admin admin, TableName 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);
}
BufferedMutator table = conn.getBufferedMutator(tableName);
long startTime = (long)1438034423 * 1000;
for (long i = startTime; i <= startTime + 100; i ++) {
byte[] bytes = new byte[9];
PositionedByteRange br = new SimplePositionedMutableByteRange(bytes, 0, 9);
OrderedBytes.encodeInt64(br, i, Order.ASCENDING);
Put p = new Put(bytes);
p.addColumn(FAMILY_F, COLUMN_C, String.format("value %d", i).getBytes());
table.mutate(p);
}
table.close();
admin.flush(tableName);
}
示例11: generateHBaseDatasetDoubleOBDesc
import org.apache.hadoop.hbase.client.Admin; //導入方法依賴的package包/類
public static void generateHBaseDatasetDoubleOBDesc(Connection conn, Admin admin, TableName 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);
}
BufferedMutator table = conn.getBufferedMutator(tableName);
for (double i = 0.5; i <= 100.00; i += 0.75) {
byte[] bytes = new byte[9];
PositionedByteRange br = new SimplePositionedMutableByteRange(bytes, 0, 9);
OrderedBytes.encodeFloat64(br, i, Order.DESCENDING);
Put p = new Put(bytes);
p.addColumn(FAMILY_F, COLUMN_C, String.format("value %03f", i).getBytes());
table.mutate(p);
}
table.close();
admin.flush(tableName);
}
示例12: afterMethod
import org.apache.hadoop.hbase.client.Admin; //導入方法依賴的package包/類
@After
public void afterMethod() throws Exception {
Admin admin = TEST_UTIL.getHBaseAdmin();
if (admin.tableExists(TableName.valueOf(TABLE))) {
TEST_UTIL.deleteTable(Bytes.toBytes(TABLE));
}
}
示例13: generateHBaseDatasetBigIntOBDesc
import org.apache.hadoop.hbase.client.Admin; //導入方法依賴的package包/類
public static void generateHBaseDatasetBigIntOBDesc(Connection conn, Admin admin, TableName 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);
}
BufferedMutator table = conn.getBufferedMutator(tableName);
long startTime = (long)1438034423 * 1000;
for (long i = startTime; i <= startTime + 100; i ++) {
byte[] bytes = new byte[9];
PositionedByteRange br = new SimplePositionedMutableByteRange(bytes, 0, 9);
OrderedBytes.encodeInt64(br, i, Order.DESCENDING);
Put p = new Put(bytes);
p.addColumn(FAMILY_F, COLUMN_C, String.format("value %d", i).getBytes());
table.mutate(p);
}
table.close();
admin.flush(tableName);
}
示例14: generateHBaseDatasetIntOBDesc
import org.apache.hadoop.hbase.client.Admin; //導入方法依賴的package包/類
public static void generateHBaseDatasetIntOBDesc(Connection conn, Admin admin, TableName 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);
}
BufferedMutator table = conn.getBufferedMutator(tableName);
for (int i = -49; i <= 100; i ++) {
byte[] bytes = new byte[5];
PositionedByteRange br = new SimplePositionedMutableByteRange(bytes, 0, 5);
OrderedBytes.encodeInt32(br, i, Order.DESCENDING);
Put p = new Put(bytes);
p.addColumn(FAMILY_F, COLUMN_C, String.format("value %d", i).getBytes());
table.mutate(p);
}
table.close();
admin.flush(tableName);
}
示例15: checkTable
import org.apache.hadoop.hbase.client.Admin; //導入方法依賴的package包/類
static boolean checkTable(Admin admin, TestOptions opts) throws IOException {
TableName tableName = TableName.valueOf(opts.tableName);
boolean needsDelete = false, exists = admin.tableExists(tableName);
boolean isReadCmd = opts.cmdName.toLowerCase().contains("read")
|| opts.cmdName.toLowerCase().contains("scan");
if (!exists && isReadCmd) {
throw new IllegalStateException(
"Must specify an existing table for read commands. Run a write command first.");
}
HTableDescriptor desc =
exists ? admin.getTableDescriptor(TableName.valueOf(opts.tableName)) : null;
byte[][] splits = getSplits(opts);
// recreate the table when user has requested presplit or when existing
// {RegionSplitPolicy,replica count} does not match requested.
if ((exists && opts.presplitRegions != DEFAULT_OPTS.presplitRegions)
|| (!isReadCmd && desc != null && desc.getRegionSplitPolicyClassName() != opts.splitPolicy)
|| (!isReadCmd && desc != null && desc.getRegionReplication() != opts.replicas)) {
needsDelete = true;
// wait, why did it delete my table?!?
LOG.debug(Objects.toStringHelper("needsDelete")
.add("needsDelete", needsDelete)
.add("isReadCmd", isReadCmd)
.add("exists", exists)
.add("desc", desc)
.add("presplit", opts.presplitRegions)
.add("splitPolicy", opts.splitPolicy)
.add("replicas", opts.replicas));
}
// remove an existing table
if (needsDelete) {
if (admin.isTableEnabled(tableName)) {
admin.disableTable(tableName);
}
admin.deleteTable(tableName);
}
// table creation is necessary
if (!exists || needsDelete) {
desc = getTableDescriptor(opts);
if (splits != null) {
if (LOG.isDebugEnabled()) {
for (int i = 0; i < splits.length; i++) {
LOG.debug(" split " + i + ": " + Bytes.toStringBinary(splits[i]));
}
}
}
admin.createTable(desc, splits);
LOG.info("Table " + desc + " created");
}
return admin.tableExists(tableName);
}