Rebuilding the Enterprise - Software, Hardware and Peopleware Migrations for the Systems Architect


HBase, Thrift, & C# - Batch Reads

5/17/2014 Posted by William Berry No comments
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.

  1 public virtual List<T> BatchSelectWithPrefixScanner<T>(string identifier, int batchSize)
  2     where T : IHBaseEntity, new() 
  3 { 
  4     var col = new List<byte[]>(); 
  5     col.AddRange(Columns.Select(x => x.GetBytes())); 
  7     var tableName = string.Format(TableNameTemplate, RetailerId);
  9     var scanner = HBaseClient.scannerOpenWithPrefix( 
 10         tableName.GetBytes(), 
 11         identifier.GetBytes(), 
 12         col, 
 13         new Dictionary<byte[], byte[]>() 
 14         ); 
 15     return GetBatchRows<T>(batchSize, scanner); 
 16 }

Yet again we have leveraged generics to return a List<T>.


Post a Comment