use of org.apache.hadoop.hbase.client.HBaseAdmin in project honeycomb by altamiracorp.
the class TableCreator method createTable.
/**
* Creates a table in HBase to store all Honeycomb tables
*
* @param configuration Configuration of the HTable
* @throws IOException
*/
public static void createTable(Configuration configuration) throws IOException {
HTableDescriptor tableDescriptor;
try {
HBaseAdmin.checkHBaseAvailable(configuration);
} catch (MasterNotRunningException e) {
logger.fatal(String.format("HMaster doesn't appear to be running. Zookeeper quorum: %s", configuration.get("hbase.zookeeper.quorum")), e);
throw e;
} catch (ZooKeeperConnectionException e) {
logger.fatal("Failed to connect to zookeeper when checking HBase. Zookeeper quorum: " + configuration.get("hbase.zookeeper.quorum"), e);
throw e;
}
String columnFamily = configuration.get(ConfigConstants.COLUMN_FAMILY);
byte[] tableName = configuration.get(ConfigConstants.TABLE_NAME).getBytes();
HColumnDescriptor columnDescriptor = new HColumnDescriptor(columnFamily);
HBaseAdmin admin = new HBaseAdmin(configuration);
columnDescriptor.setBloomFilterType(StoreFile.BloomType.ROW).setDataBlockEncoding(DataBlockEncoding.PREFIX).setMaxVersions(1);
if (!admin.tableExists(tableName)) {
logger.info("Creating HBase table");
tableDescriptor = new HTableDescriptor(tableName);
tableDescriptor.addFamily(columnDescriptor);
admin.createTable(tableDescriptor);
}
tableDescriptor = admin.getTableDescriptor(tableName);
if (!tableDescriptor.hasFamily(columnFamily.getBytes())) {
logger.info("Adding column family to HBase table");
if (!admin.isTableDisabled(tableName)) {
logger.info("Disabling HBase table");
admin.disableTable(tableName);
}
admin.addColumn(tableName, columnDescriptor);
}
if (admin.isTableDisabled(tableName)) {
logger.info("Enabling HBase table");
admin.enableTable(tableName);
}
try {
admin.flush(tableName);
} catch (InterruptedException e) {
logger.warn("HBaseAdmin flush was interrupted. Retrying.");
try {
admin.flush(tableName);
} catch (InterruptedException e1) {
throw new RuntimeException(e1);
}
}
logger.info("HBase table successfully initialized.");
}
use of org.apache.hadoop.hbase.client.HBaseAdmin in project siena by mandubian.
the class HBaseDdlGenerator method dropTables.
public void dropTables() {
HBaseConfiguration config = new HBaseConfiguration();
try {
HBaseAdmin admin = new HBaseAdmin(config);
HTableDescriptor[] descriptors = admin.listTables();
for (HTableDescriptor hTableDescriptor : descriptors) {
String name = hTableDescriptor.getNameAsString();
admin.disableTable(name);
admin.deleteTable(name);
}
} catch (IOException e) {
throw new SienaException(e);
}
}
use of org.apache.hadoop.hbase.client.HBaseAdmin in project gora by apache.
the class HBaseClusterSingleton method ensureTable.
/**
* Creates a table with the specified column families.
* @param tableName the table name
* @param cfs the column families
* @throws IOException
*/
public void ensureTable(byte[] tableName, byte[][] cfs) throws IOException {
HBaseAdmin admin = htu.getHBaseAdmin();
if (!admin.tableExists(tableName)) {
HTable hTable = htu.createTable(tableName, cfs);
hTable.close();
}
}
use of org.apache.hadoop.hbase.client.HBaseAdmin in project gora by apache.
the class HBaseClusterSingleton method truncateAllTables.
/**
* Truncates all tables
* @throws Exception
*/
public void truncateAllTables() throws Exception {
HBaseAdmin admin = htu.getHBaseAdmin();
for (HTableDescriptor table : admin.listTables()) {
HTable hTable = htu.deleteTableData(table.getName());
hTable.close();
}
}
use of org.apache.hadoop.hbase.client.HBaseAdmin in project phoenix by apache.
the class AlterTableIT method testAddNewColumnFamilyProperties.
@Test
public void testAddNewColumnFamilyProperties() throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
conn.setAutoCommit(false);
try {
conn.createStatement().execute("CREATE TABLE " + dataTableFullName + " (a_string varchar not null, col1 integer, cf1.col2 integer, col3 integer , cf2.col4 integer " + " CONSTRAINT pk PRIMARY KEY (a_string)) " + generateDDLOptions("immutable_rows=true , SALT_BUCKETS=3 " + (!columnEncoded ? ",IMMUTABLE_STORAGE_SCHEME=" + PTable.ImmutableStorageScheme.ONE_CELL_PER_COLUMN : "")));
String ddl = "Alter table " + dataTableFullName + " add cf3.col5 integer, cf4.col6 integer in_memory=true";
conn.createStatement().execute(ddl);
try (HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName));
assertTrue(tableDesc.isCompactionEnabled());
HColumnDescriptor[] columnFamilies = tableDesc.getColumnFamilies();
assertEquals(5, columnFamilies.length);
assertEquals("0", columnFamilies[0].getNameAsString());
assertFalse(columnFamilies[0].isInMemory());
assertEquals("CF1", columnFamilies[1].getNameAsString());
assertFalse(columnFamilies[1].isInMemory());
assertEquals("CF2", columnFamilies[2].getNameAsString());
assertFalse(columnFamilies[2].isInMemory());
assertEquals("CF3", columnFamilies[3].getNameAsString());
assertTrue(columnFamilies[3].isInMemory());
assertEquals("CF4", columnFamilies[4].getNameAsString());
assertTrue(columnFamilies[4].isInMemory());
}
} finally {
conn.close();
}
}
Aggregations