Search in sources :

Example 1 with Get

use of org.apache.hadoop.hbase.client.Get in project hive by apache.

the class HBaseReadWrite method read.

private byte[] read(String table, byte[] key, byte[] colFam, byte[] colName) throws IOException {
    HTableInterface htab = conn.getHBaseTable(table);
    Get g = new Get(key);
    g.addColumn(colFam, colName);
    Result res = htab.get(g);
    return res.getValue(colFam, colName);
}
Also used : Get(org.apache.hadoop.hbase.client.Get) HTableInterface(org.apache.hadoop.hbase.client.HTableInterface) Result(org.apache.hadoop.hbase.client.Result)

Example 2 with Get

use of org.apache.hadoop.hbase.client.Get in project hive by apache.

the class HBaseReadWrite method read.

private Result read(String table, byte[] key, byte[] colFam, byte[][] colNames) throws IOException {
    HTableInterface htab = conn.getHBaseTable(table);
    Get g = new Get(key);
    for (byte[] colName : colNames) g.addColumn(colFam, colName);
    return htab.get(g);
}
Also used : Get(org.apache.hadoop.hbase.client.Get) HTableInterface(org.apache.hadoop.hbase.client.HTableInterface)

Example 3 with Get

use of org.apache.hadoop.hbase.client.Get in project hive by apache.

the class HBaseReadWrite method multiRead.

private void multiRead(String table, byte[] colFam, byte[] colName, byte[][] keys, ByteBuffer[] resultDest) throws IOException {
    assert keys.length == resultDest.length;
    @SuppressWarnings("deprecation") HTableInterface htab = conn.getHBaseTable(table);
    List<Get> gets = new ArrayList<>(keys.length);
    for (byte[] key : keys) {
        Get g = new Get(key);
        g.addColumn(colFam, colName);
        gets.add(g);
    }
    Result[] results = htab.get(gets);
    for (int i = 0; i < results.length; ++i) {
        Result r = results[i];
        if (r.isEmpty()) {
            resultDest[i] = null;
        } else {
            Cell cell = r.getColumnLatestCell(colFam, colName);
            resultDest[i] = ByteBuffer.wrap(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength());
        }
    }
}
Also used : Get(org.apache.hadoop.hbase.client.Get) ArrayList(java.util.ArrayList) HTableInterface(org.apache.hadoop.hbase.client.HTableInterface) Cell(org.apache.hadoop.hbase.Cell) Result(org.apache.hadoop.hbase.client.Result)

Example 4 with Get

use of org.apache.hadoop.hbase.client.Get in project hbase by apache.

the class MetaTableAccessor method getReplicationPositionForAllPeer.

/**
   * Get replication positions for all peers in a region.
   * @param connection connection we're using
   * @param encodedRegionName region's encoded name
   * @return the map of positions for each peer
   */
public static Map<String, Long> getReplicationPositionForAllPeer(Connection connection, byte[] encodedRegionName) throws IOException {
    Get get = new Get(encodedRegionName);
    get.addFamily(HConstants.REPLICATION_POSITION_FAMILY);
    Result r = get(getMetaHTable(connection), get);
    Map<String, Long> map = new HashMap<>((int) (r.size() / 0.75 + 1));
    for (Cell c : r.listCells()) {
        map.put(Bytes.toString(c.getQualifierArray(), c.getQualifierOffset(), c.getQualifierLength()), Bytes.toLong(c.getValueArray(), c.getValueOffset(), c.getValueLength()));
    }
    return map;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Get(org.apache.hadoop.hbase.client.Get) Result(org.apache.hadoop.hbase.client.Result)

Example 5 with Get

use of org.apache.hadoop.hbase.client.Get in project hbase by apache.

the class MetaTableAccessor method getSerialReplicationDaughterRegion.

/**
   * Get daughter region(s) for a region, only used in serial replication.
   * @param connection connection we're using
   * @param encodedName region's encoded name
   * @throws IOException
   */
public static String getSerialReplicationDaughterRegion(Connection connection, byte[] encodedName) throws IOException {
    Get get = new Get(encodedName);
    get.addColumn(HConstants.REPLICATION_META_FAMILY, daughterNameCq);
    Result result = get(getMetaHTable(connection), get);
    if (!result.isEmpty()) {
        Cell c = result.rawCells()[0];
        return Bytes.toString(c.getValueArray(), c.getValueOffset(), c.getValueLength());
    }
    return null;
}
Also used : Get(org.apache.hadoop.hbase.client.Get) Result(org.apache.hadoop.hbase.client.Result)

Aggregations

Get (org.apache.hadoop.hbase.client.Get)629 Result (org.apache.hadoop.hbase.client.Result)444 Test (org.junit.Test)282 Table (org.apache.hadoop.hbase.client.Table)226 Put (org.apache.hadoop.hbase.client.Put)201 IOException (java.io.IOException)134 Cell (org.apache.hadoop.hbase.Cell)121 TableName (org.apache.hadoop.hbase.TableName)98 Connection (org.apache.hadoop.hbase.client.Connection)91 Delete (org.apache.hadoop.hbase.client.Delete)76 ArrayList (java.util.ArrayList)75 Configuration (org.apache.hadoop.conf.Configuration)72 Scan (org.apache.hadoop.hbase.client.Scan)57 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)52 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)38 CheckAndMutateResult (org.apache.hadoop.hbase.client.CheckAndMutateResult)38 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)36 Map (java.util.Map)34 Path (org.apache.hadoop.fs.Path)34 Admin (org.apache.hadoop.hbase.client.Admin)33