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;
}
Aggregations