Search in sources :

Example 1 with TColumn

use of org.apache.hadoop.hbase.thrift.generated.TColumn in project hbase by apache.

the class ThriftUtilities method rowResultFromHBase.

/**
   * This utility method creates a list of Thrift TRowResult "struct" based on
   * an Hbase RowResult object. The empty list is returned if the input is
   * null.
   *
   * @param in
   *          Hbase RowResult object
   * @param sortColumns
   *          This boolean dictates if row data is returned in a sorted order
   *          sortColumns = True will set TRowResult's sortedColumns member
   *                        which is an ArrayList of TColumn struct
   *          sortColumns = False will set TRowResult's columns member which is
   *                        a map of columnName and TCell struct
   * @return Thrift TRowResult array
   */
public static List<TRowResult> rowResultFromHBase(Result[] in, boolean sortColumns) {
    List<TRowResult> results = new ArrayList<>(in.length);
    for (Result result_ : in) {
        if (result_ == null || result_.isEmpty()) {
            continue;
        }
        TRowResult result = new TRowResult();
        result.row = ByteBuffer.wrap(result_.getRow());
        if (sortColumns) {
            result.sortedColumns = new ArrayList<>();
            for (Cell kv : result_.rawCells()) {
                result.sortedColumns.add(new TColumn(ByteBuffer.wrap(KeyValue.makeColumn(CellUtil.cloneFamily(kv), CellUtil.cloneQualifier(kv))), new TCell(ByteBuffer.wrap(CellUtil.cloneValue(kv)), kv.getTimestamp())));
            }
        } else {
            result.columns = new TreeMap<>();
            for (Cell kv : result_.rawCells()) {
                result.columns.put(ByteBuffer.wrap(KeyValue.makeColumn(CellUtil.cloneFamily(kv), CellUtil.cloneQualifier(kv))), new TCell(ByteBuffer.wrap(CellUtil.cloneValue(kv)), kv.getTimestamp()));
            }
        }
        results.add(result);
    }
    return results;
}
Also used : TColumn(org.apache.hadoop.hbase.thrift.generated.TColumn) ArrayList(java.util.ArrayList) TCell(org.apache.hadoop.hbase.thrift.generated.TCell) TRowResult(org.apache.hadoop.hbase.thrift.generated.TRowResult) TCell(org.apache.hadoop.hbase.thrift.generated.TCell) Cell(org.apache.hadoop.hbase.Cell) Result(org.apache.hadoop.hbase.client.Result) TRowResult(org.apache.hadoop.hbase.thrift.generated.TRowResult)

Aggregations

ArrayList (java.util.ArrayList)1 Cell (org.apache.hadoop.hbase.Cell)1 Result (org.apache.hadoop.hbase.client.Result)1 TCell (org.apache.hadoop.hbase.thrift.generated.TCell)1 TColumn (org.apache.hadoop.hbase.thrift.generated.TColumn)1 TRowResult (org.apache.hadoop.hbase.thrift.generated.TRowResult)1