https://github.com/exposebox/node-thrift2-hbase. Original repository only supported thrift 0.9.3 to support 0.98.4. Hence, I forked this new repository to use thrift 0.10.0 and HBase 1.2.x
A simple, performant, connection-pooled, cached and promisified HBase client library for NodeJS. This repository is forked fromAPI
Instantiating the HBase client
const config = hosts: "master" port: "9090"; const HBase = config;
Get
var get = HBase; //row1 is rowKeyget;// get.add('cf'); identical to addFamily get;// get.add('info', 'name'); identical to addColumn get;// get.add('info', 'name', 1414385447707); identical to addTimestamp get; //last ten days as timerangeget; HBase ; HBase;
A shorthand version is the getRow
function:
HBase; HBase ;
Put
var put = HBase; // cf qualifier valueput; put; //string values don't need a wrapper objectput; // timestampput; HBase; HBase ;
A shorthand version is the putRow
function:
HBase; HBase ;
Inc
var inc = hbaseClient; //row1 is rowKey inc; inc; hbaseClient;
Del
var del = hbaseClient; //row1 is rowKey //del.addFamily('ips'); //delete family ips//del.addColumn('info','click2'); //delete family and qualifier info:click2//del.addTimestamp('info','click3',1414136046864); //delete info:click3 and timestamp //or Recommend this function add del; //delete all family infodel; //delete family and qualifier info:namedel; //delete info:tel and timestamp del; //delete other family ecfdel; //delete family and qualifier ecf:namedel; //delete info:tel and timestamp //del.add('ips'); //is error ,because this family ips is not exist hbaseClient;
Scan
var scan = hbaseClient; //get.addFamily('cf'); //add not found column is error //scan.addFamily('info'); //add all family //scan.addStartRow('row1'); //start rowKey //scan.addStopRow('row1p'); //stop rowKey //scan.addColumn('info','name'); //add family and qualifier //scan.addColumn('ecf','name'); //add other family //scan.setMaxVersions(1); //set maxversions //scan.addNumRows(10); //search how much number rows //or Recommend this function add scan; //start rowKey scan; //stop rowKey scan; //scan all family info scan; //scan family and qualifier info:name scan; //scan other family ecf scan; //scan family and qualifier ecf:name scan; //set maxversions scan; //search how much number rows hbaseClient;
Scan Stream
const tableName = 'test:test_table'; const scanObject = hbaseClient; hbaseClient ;
Table Salting
What is "salting"? The term is taken from the encryption nomenclature, but for our purposes it just means adding a predictable string to a key. The way HBase stores rows means that if the keys are not spread across the string spectrum, then the data will physically be kept in a "not spread" manner - for example, having most rows of a table on very few Region Server
s. So if your keys are well-spread, so is your data. This allows for faster and more parallel reads/writes en-masse. The only problem is keeping track of which table has its keys salted, and exactly how were the keys salted. We have a solution for that:
var hbase = hbaseConfig;hbasesaltMap = 'myTable1': hbasesaltFunctionssaltByLastKeyCharCode 'myTable2': hbasesaltFunctionssaltByLastKeyCharCode;
All get
and put
operations for tables specified in the saltMap
will be
salted using the given function. hbase.saltFunctions
contains some ready-made salt functions. If you have a salt function you find useful, don't hesitate to make a PR adding it!