use of org.apache.hadoop.hbase.client.Table in project hbase by apache.
the class MetaTableAccessor method getAllBarriers.
/**
* Get all barriers in all regions.
* @return a map of barrier lists in all regions
* @throws IOException
*/
public static Map<String, List<Long>> getAllBarriers(Connection connection) throws IOException {
Map<String, List<Long>> map = new HashMap<>();
Scan scan = new Scan();
scan.addFamily(HConstants.REPLICATION_BARRIER_FAMILY);
try (Table t = getMetaHTable(connection);
ResultScanner scanner = t.getScanner(scan)) {
Result result;
while ((result = scanner.next()) != null) {
String key = Bytes.toString(result.getRow());
List<Long> list = new ArrayList<>(result.rawCells().length);
for (Cell cell : result.rawCells()) {
list.add(Bytes.toLong(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength()));
}
map.put(key, list);
}
}
return map;
}
use of org.apache.hadoop.hbase.client.Table in project hbase by apache.
the class HelloHBase method main.
public static void main(final String[] args) throws IOException {
final boolean deleteAllAtEOJ = true;
/**
* ConnectionFactory#createConnection() automatically looks for
* hbase-site.xml (HBase configuration parameters) on the system's
* CLASSPATH, to enable creation of Connection to HBase via ZooKeeper.
*/
try (Connection connection = ConnectionFactory.createConnection();
Admin admin = connection.getAdmin()) {
// assure connection successfully established
admin.getClusterStatus();
System.out.println("\n*** Hello HBase! -- Connection has been " + "established via ZooKeeper!!\n");
createNamespaceAndTable(admin);
System.out.println("Getting a Table object for [" + MY_TABLE_NAME + "] with which to perform CRUD operations in HBase.");
try (Table table = connection.getTable(MY_TABLE_NAME)) {
putRowToTable(table);
getAndPrintRowContents(table);
if (deleteAllAtEOJ) {
deleteRow(table);
}
}
if (deleteAllAtEOJ) {
deleteNamespaceAndTable(admin);
}
}
}
use of org.apache.hadoop.hbase.client.Table in project hbase by apache.
the class TestHelloHBase method testDeleteRow.
@Test
public void testDeleteRow() throws IOException {
Admin admin = TEST_UTIL.getAdmin();
admin.createNamespace(NamespaceDescriptor.create(HelloHBase.MY_NAMESPACE_NAME).build());
Table table = TEST_UTIL.createTable(HelloHBase.MY_TABLE_NAME, HelloHBase.MY_COLUMN_FAMILY_NAME);
table.put(new Put(HelloHBase.MY_ROW_ID).addColumn(HelloHBase.MY_COLUMN_FAMILY_NAME, HelloHBase.MY_FIRST_COLUMN_QUALIFIER, Bytes.toBytes("xyz")));
HelloHBase.deleteRow(table);
Result row = table.get(new Get(HelloHBase.MY_ROW_ID));
assertEquals("#deleteRow failed to delete row.", true, row.isEmpty());
TEST_UTIL.deleteTable(HelloHBase.MY_TABLE_NAME);
admin.deleteNamespace(HelloHBase.MY_NAMESPACE_NAME);
}
use of org.apache.hadoop.hbase.client.Table in project hbase by apache.
the class TestHelloHBase method testDeleteRow.
@Test
public void testDeleteRow() throws IOException {
Admin admin = TEST_UTIL.getAdmin();
admin.createNamespace(NamespaceDescriptor.create(HelloHBase.MY_NAMESPACE_NAME).build());
Table table = TEST_UTIL.createTable(HelloHBase.MY_TABLE_NAME, HelloHBase.MY_COLUMN_FAMILY_NAME);
table.put(new Put(HelloHBase.MY_ROW_ID).addColumn(HelloHBase.MY_COLUMN_FAMILY_NAME, HelloHBase.MY_FIRST_COLUMN_QUALIFIER, Bytes.toBytes("xyz")));
HelloHBase.deleteRow(table);
Result row = table.get(new Get(HelloHBase.MY_ROW_ID));
assertEquals("#deleteRow failed to delete row.", true, row.isEmpty());
TEST_UTIL.deleteTable(HelloHBase.MY_TABLE_NAME);
admin.deleteNamespace(HelloHBase.MY_NAMESPACE_NAME);
}
use of org.apache.hadoop.hbase.client.Table in project hbase by apache.
the class TestHelloHBase method testPutRowToTable.
@Test
public void testPutRowToTable() throws IOException {
Admin admin = TEST_UTIL.getAdmin();
admin.createNamespace(NamespaceDescriptor.create(HelloHBase.MY_NAMESPACE_NAME).build());
Table table = TEST_UTIL.createTable(HelloHBase.MY_TABLE_NAME, HelloHBase.MY_COLUMN_FAMILY_NAME);
HelloHBase.putRowToTable(table);
Result row = table.get(new Get(HelloHBase.MY_ROW_ID));
assertEquals("#putRowToTable failed to store row.", false, row.isEmpty());
TEST_UTIL.deleteTable(HelloHBase.MY_TABLE_NAME);
admin.deleteNamespace(HelloHBase.MY_NAMESPACE_NAME);
}
Aggregations