hbase-client

Asynchronous HBase client for Node.js, pure javascript implementation.

hbase-client

Asynchronous HBase client for Node.js, pure JavaScript implementation.

  • [√] 0.94.x
    • [√] 0.94.0
    • [√] 0.94.16
  • [ ] 0.96.x
  • [ ] 0.98.x

If you're use HBase >= 0.96.x, please use node-hbase which CoffeeScript HBase Implementation with protobuf.

$ npm install hbase-client --save

Start local hbase server

$ ./start-local-hbase.sh

If everything go fine, run tests

$ make test

Stop hbase server

$ ./stop-local-hbase.sh
  • Create a hbase client through zookeeper:
var HBase = require('hbase-client');
 
var client = HBase.create({
  zookeeperHosts: [
    '127.0.0.1:2181' // only local zookeeper 
  ],
  zookeeperRoot: '/hbase-0.94.16',
});
  • Put a data row to hbase:
client.putRow('someTableName', 'rowkey1', {'f1:name': 'foo name', 'f1:age': '18'}, function (err) {
  console.log(err);
});
  • Get the row we put:
client.getRow('someTableName', 'rowkey1', ['f1:name', 'f1:age'], function (errrow) {
  console.log(row);
});
  • Delete the row we put:
client.deleteRow('someTableName', 'rowkey1', function (err) {
  console.log(err);
});
var HBase = require('hbase-client');
 
var client = HBase.create({
  zookeeperHosts: [
    '127.0.0.1:2181', '127.0.0.1:2182',
  ],
  zookeeperRoot: '/hbase-0.94',
});
 
// Get `f1:name, f2:age` from `user` table. 
var param = new HBase.Get('foo');
param.addColumn('f1', 'name');
param.addColumn('f1', 'age');
 
client.get('user', param, function (errresult) {
  console.log(err);
  var kvs = result.raw();
  for (var i = 0; i < kvs.length; i++) {
    var kv = kvs[i];
    console.log('key: `%s`, value: `%s`', kv.toString(), kv.getValue().toString());
  }
});
client.getRow(table, row, ['f:name', 'f:age'], function (errrow) {
  row.should.have.keys('f:name', 'f:age');
});
 
// return all columns, like `select *` 
client.getRow(table, row, function (errrow) {
  row.should.have.keys('f:name', 'f:age', 'f:gender');
});
 
client.getRow(table, row, '*', function (errrow) {
  row.should.have.keys('f:name', 'f:age', 'f:gender');
});
var put = new HBase.Put('foo');
put.add('f1', 'name', 'foo');
put.add('f1', 'age', '18');
client.put('user', put, function (err) {
  console.log(err);
});
client.putRow(table, row, {'f1:name': 'foo name', 'f1:age': '18'}, function (err) {
  should.not.exists(err);
});
var del = new Delete(rowkey);
del.deleteColumns('f', 'name-t');
client.delete(table, del, function (errresult) {
  //TODO:... 
});
var del = new Delete(rowkey);
del.deleteFamily('f');
client.delete(table, del, function (errresult) {
  //TODO:... 
});
var tableName = 'user_search';
var rowkey = 'rowkeyyyyyy';
client.deleteRow(tableName, rowkey, function (err) {
  //TODO:... 
});
var rows = ['row1', 'row2'];
var columns = ['f:col1', 'f:col2'];
client.mget(tableName, rows, columns, function (errresults){
  //TODO:... 
});
var rows = [{row: 'rowkey1', 'f:col1': 'col_value'}, {row: 'rowkey2', 'f:col1': 'col_value'}];
client.mput(tableName, rows, function (errresults) {
  //TODO:... 
});
var rowKeys = ['rowkey1', 'rowkey2'];
client.mdelete(tableName, rowKeys, function (errresults) {
  //TODO:... 
});
 

Java code:

FilterList filterList = new FilterList({operator: FilterList.Operator.MUST_PASS_ALL});
filterList.addFilter(new FirstKeyOnlyFilter());
filterList.addFilter(new KeyOnlyFilter());
Scan scan = new Scan(Bytes.toBytes("scanner-row0"));
scan.setFilter(filterList);

Nodejs code:

var filters = require('hbase').filters;
 
var filterList = new filters.FilterList({operator: filters.FilterList.Operator.MUST_PASS_ALL});
filterList.addFilter(new filters.FirstKeyOnlyFilter());
filterList.addFilter(new filters.KeyOnlyFilter());
var scan = new Scan('scanner-row0');
scan.setFilter(filterList);
 
client.getScanner('user', scan, function (errscanner) {\
  var index = 0;
  var next = function (numberOfRows) {
    scanner.next(numberOfRows, function (errrows) {
      // console.log(rows) 
      should.not.exists(err);
      if (rows.length === 0) {
        index.should.equal(5);
        return scanner.close(done);
      }
 
      rows.should.length(1);
 
      var closed = false;
      rows.forEach(function (row) {
        var kvs = row.raw();
        var r = {};
        for (var i = 0; i < kvs.length; i++) {
          var kv = kvs[i];
          kv.getRow().toString().should.equal('scanner-row' + index++);
          kv.toString().should.include('/vlen=0/');
          console.log(kv.getRow().toString(), kv.toString())
        }
      });
 
      if (closed) {
        return scanner.close(done);
      }
 
      next(numberOfRows);
    });
  };
 
  next(1);
});

Java code:

byte [] family = Bytes.toBytes("cf1");
byte [] qualifier = Bytes.toBytes("qualifier2");
FilterList filterList = new FilterList({operator: FilterList.Operator.MUST_PASS_ALL});
filterList.addFilter(new SingleColumnValueFilter(family, qualifier, CompareOp.LESS_OR_EQUALBytes.toBytes("scanner-row0 cf1:qualifier2")));
filterList.addFilter(new SingleColumnValueFilter(family, qualifier, CompareOp.GREATER_OR_EQUALnew BinaryPrefixComparator(Bytes.toBytes("scanner-"))));
filterList.addFilter(new SingleColumnValueFilter(family, qualifier, CompareOp.NOT_EQUALnew BitComparator(Bytes.toBytes("0")BitComparator.BitwiseOp.XOR)));
filterList.addFilter(new SingleColumnValueFilter(family, qualifier, CompareOp.NOT_EQUALnew NullComparator()));
filterList.addFilter(new SingleColumnValueFilter(family, qualifier, CompareOp.EQUALnew RegexStringComparator("scanner-*"))));
filterList.addFilter(new SingleColumnValueFilter(family, qualifier, CompareOp.EQUALnew SubstringComparator("cf1:qualifier2"))));
Scan scan = new Scan(Bytes.toBytes("scanner-row0"));
scan.setFilter(filterList);

Nodejs code:

var filterList = new filters.FilterList({operator: filters.FilterList.Operator.MUST_PASS_ALL});
var family = 'cf1';
var qualifier = 'qualifier2';
filterList.addFilter(new filters.SingleColumnValueFilter(family, qualifier, 'LESS_OR_EQUAL', 'scanner-row0 cf1:qualifier2'));
filterList.addFilter(new filters.SingleColumnValueFilter(family, qualifier, 'GREATER_OR_EQUAL', new filters.BinaryPrefixComparator('scanner-')));
filterList.addFilter(new filters.SingleColumnValueFilter(family, qualifier, 'NOT_EQUAL', new filters.BitComparator('0', filters.BitComparator.BitwiseOp.XOR)));
filterList.addFilter(new filters.SingleColumnValueFilter(family, qualifier, 'NOT_EQUAL', new filters.NullComparator()));
filterList.addFilter(new filters.SingleColumnValueFilter(family, qualifier, 'EQUAL', new filters.RegexStringComparator('scanner-*')));
filterList.addFilter(new filters.SingleColumnValueFilter(family, qualifier, 'EQUAL', new filters.SubstringComparator('cf1:qualifier2')));
var scan = new Scan('scanner-row0');
scan.setFilter(filterList);
 
client.getScanner('user', scan, function (errscanner) {\
  //TODO:... 
});
  • [√] support put
  • [√] benchmark
  • [√] more stable
  • [√] support delete
  • [√] multi actions
    • [√] multi get
    • [√] multi put
    • [√] multi delete
  • [√] fail retry
  • [ ] filters
    • [√] FilterList
    • [√] FirstKeyOnlyFilter
    • [√] KeyOnlyFilter
    • [√] SingleColumnValueFilter

@see docs/benchmark.md

Thanks for @haosdent support the test hbase clusters environment and debug helps.

$ git summary
 
 project  : node-hbase-client
 repo age : 1 year, 7 months
 active   : 70 days
 commits  : 195
 files    : 297
 authors  :
   155  fengmk2                 79.5%
    20  tangyao                 10.3%
    15  Martin Cizek            7.7%
     1  coolme200               0.5%
     1  Alsotang                0.5%
     1  不四                  0.5%
     1  Lukas Benes             0.5%
     1  Vaclav Loffelmann       0.5%

(The MIT License)

Copyright (c) 2013 - 2014 Alibaba Group Holding Limited

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.