Written May 18, 2014
HBase, Thrift, & C# - Batch Reads
Continuing the epic series on Hbase, Thrift and C#, this installment is the code for a batch scanner by leveraging inheritance and generics to provide a broad based solution. If you have not done so please check out the other parts of the series:
- Part 1 - NuGet Servers, HBase, Thrift Code Generation and one sweet Jenkins CI Build
- Part 2 - HBase, Thrift & C# - First Connections
- Part 3 - HBase, Thrift, & C# - Managing Sessions
- Part 4 - HBase, Thrift, & C# - First Scanner and Leveraging Generics
Feeling the PAIN of single reads off HBase, I hacked up a little method to allow for batch reads off the HBase Thrift interface. Like the other versions in my last HBase post, this one makes use of the table scanner.
public virtual List<T> BatchSelectWithPrefixScanner<T>(string identifier, int batchSize)
where T : IHBaseEntity, new()
{
var col = new List<byte[]>();
col.AddRange(Columns.Select(x => x.GetBytes()));
var tableName = string.Format(TableNameTemplate, RetailerId);
var scanner = HBaseClient.scannerOpenWithPrefix(
tableName.GetBytes(),
identifier.GetBytes(),
col,
new Dictionary<byte[], byte[]>()
);
return GetBatchRows<T>(batchSize, scanner);
}
Yet again we have leveraged generics to return a List