Search in sources :

Example 6 with Table

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;
}
Also used : Table(org.apache.hadoop.hbase.client.Table) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Scan(org.apache.hadoop.hbase.client.Scan) Result(org.apache.hadoop.hbase.client.Result)

Example 7 with Table

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);
        }
    }
}
Also used : Table(org.apache.hadoop.hbase.client.Table) Connection(org.apache.hadoop.hbase.client.Connection) Admin(org.apache.hadoop.hbase.client.Admin)

Example 8 with Table

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);
}
Also used : Table(org.apache.hadoop.hbase.client.Table) Get(org.apache.hadoop.hbase.client.Get) Admin(org.apache.hadoop.hbase.client.Admin) Put(org.apache.hadoop.hbase.client.Put) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Example 9 with Table

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);
}
Also used : Table(org.apache.hadoop.hbase.client.Table) Get(org.apache.hadoop.hbase.client.Get) Admin(org.apache.hadoop.hbase.client.Admin) Put(org.apache.hadoop.hbase.client.Put) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Example 10 with Table

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);
}
Also used : Table(org.apache.hadoop.hbase.client.Table) Get(org.apache.hadoop.hbase.client.Get) Admin(org.apache.hadoop.hbase.client.Admin) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Aggregations

Table (org.apache.hadoop.hbase.client.Table)660 Test (org.junit.Test)421 Put (org.apache.hadoop.hbase.client.Put)237 TableName (org.apache.hadoop.hbase.TableName)227 Result (org.apache.hadoop.hbase.client.Result)224 Connection (org.apache.hadoop.hbase.client.Connection)191 Scan (org.apache.hadoop.hbase.client.Scan)174 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)160 IOException (java.io.IOException)157 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)134 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)119 Get (org.apache.hadoop.hbase.client.Get)107 Delete (org.apache.hadoop.hbase.client.Delete)99 Admin (org.apache.hadoop.hbase.client.Admin)95 ArrayList (java.util.ArrayList)85 Cell (org.apache.hadoop.hbase.Cell)83 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)73 Configuration (org.apache.hadoop.conf.Configuration)71 Path (org.apache.hadoop.fs.Path)60 RegionLocator (org.apache.hadoop.hbase.client.RegionLocator)59