exposebox/node-thrift2-hbase

rowkey filter help

kuake opened this issue · 5 comments

kuake commented

my key like 20170309204004FAS3KLP3524LIJFAE datetime+id,
hwo to scan by datetime start end and spicle id?
Thanks for your help

Have you tried calling the scan method?
Can you detail the call and parameters to the scan method here?

kuake commented

my code:

var scan = hbaseClient.Scan();
    scan.setStartRow(start);
    scan.setStopRow(end);
    scan.add('p');
    scan.setLimit(maxCount);

    hbaseClient.scan(tbName, scan, function(err,data){
      if(err){
        logger.error('scan error:',err);
      }

      hbasePool.release(hbaseClient);
      callback(err, data);
    });

but didn't know how to set filter to key .
keys like:
20170309204003AAAA 20170309204004BBBB 20170309204005CCCC ... 20170309204006AAAA

how to scan filter 'AAAA'
and start='20170309204003'
end='20170309204006'
Thanks for your help!

First, you are using an internal object within the library (lib/client.js) - if you use the service made available by require('node-thrift2-hbase'), you can simply call the scan method in the required object and save yourself the pool manupuldation.

Second, your question actually deals with key filtering and design. The "highest" character is ~ , so if you use 20170309204006~ as the stop row key. For the start key, you can use just 20170309204003.

kuake commented

Thanks you for your reply!

First, I find scan in lib/service.js:

Service.prototype.scan = function (table, options, callback) {
    var hbasePool = this.clientPool;

    this.clientPool.acquire(function (err, hbaseClient) {
        if (err)
            return callback(err);

        var scan = hbaseClient.Scan();
        hbaseClient.scan(table, scan,
            function releaseAndCallback(err, data) {
                if (err) {
                    //destroy client on error
                    hbasePool.destroy(hbaseClient);
                    return callback(err);
                }
                //release client in the end of use.
                hbasePool.release(hbaseClient);
                return callback(null, data);
            })
    });
};

parameter options is not effect.
Could you show example code,
and Can you explain what is the best practice? Thank you very much!

Second, when use 20170309204006~ as the stop row key. and 20170309204003 is start row key,
How filter key suffix: 'AAAA', not 'BBBB'? Is there is a simple and efficient way to filter ?

I've merged your pull request #3 .
Too bad it doesn't integrate into the main library and just adds the filterString, so scans are still not available to everyone. I'll start working on it though.