Skip to content

CoffeeScript HBase client implementation with protobuf support

License

Notifications You must be signed in to change notification settings

falsecz/hbase-rpc-client

Repository files navigation

hbase-rpc-client

Build Status Dependency Status License

CoffeeScript HBase Implementation with protobuf support based on https://github.com/alibaba/node-hbase-client/

Installation

npm install -S hbase-rpc-client

Supported HBase versions

  • 0.98.x
  • 1.0.x
  • 1.2.x

Features

  • get
  • put
  • delete
  • mget
  • mput
  • mdelete
  • checkAndPut
  • checkAndDelete
  • scan:
    • [√] filter
    • [√] filterList
    • [√] reverse scan
  • increment
  • incrementColumnValue
  • getRowOrBefore
  • mutateRow
  • append

Create a hbase client through zookeeper

hbase = require "hbase-rpc-client"

client = hbase
	zookeeperHosts: ["localhost"] # required
	zookeeperRoot: "/hbase"
	zookeeperReconnectTimeout: 20000
	rootRegionZKPath: "/meta-region-server"
	rpcTimeout: 30000
	callTimeout: 5000
	tcpNoDelay: no
	tcpKeepAlive: yes
	realUser: "someRealUser"
	effectiveUser: "someEffectiveUser"

client.on "error", (err) ->
	console.log "hbase client error:", err

In case you experience slow communication with hbase, please see issue #24 and try to set tcpNoDelay: true

Timeouts explained:

  • zookeeperReconnectTimeout - Time after zookeeper watcher creates new zk client upon receiving following events: closing, session_expired or authentication_failed (other events are handled by node-zookeeper-client). Default: 20000ms (set by zookeeper-watcher)
  • rpcTimeout - Time after hbase-rpc-client emits an error if it doesn't manage to ensure zookeeper connection or doesn't manage to get region server connection. Default: 30000ms
  • callTimeout - Time after each operation call on hbase timeouts. Default: 5000ms

put

Values can be only strings or buffers.

put table, put, callback
put = new hbase.Put rowKey
put.add cf, qualifier, value

client.put table, put, (err, res) ->
	console.log arguments

get

get table, get, callback
get = new hbase.Get rowKey

client.get table, get, (err, res) ->
	console.log arguments

delete

delete table, delete, callback
del = new hbase.Delete rowKey

client.delete table, del, (err, res) ->
	console.log arguments

mput

Values can be only strings or buffers.

mput table, arrayOfPutObjects, callback
mput table, arrayOfObjects, callback
put1 = new hbase.Put rowKey1
put1.add cf1, qualifier1, value1

put2 = new hbase.Put rowKey2
put2.add cf2, qualifier2, value2

client.mput table, [put1, put2], (err, res) ->
	console.log arguments
put1 =
	row: rowKey1
put1["#{cf1}:#{qualifier1}"] = value1

put2 =
	row: rowKey2
put2["#{cf2}:#{qualifier2}"] = value2

client.mput table, [put1, put2], (err, res) ->
	console.log arguments

mget

mget table, arrayOfGetObjects, callback
mget table, arrayOfObjects, callback
get1 = new hbase.Get rowKey1
get2 = new hbase.Get rowKey2

client.mget table, [get1, get2], (err, res) ->
	console.log arguments
client.mget table, [rowKey1, rowKey2], (err, res) ->
	console.log arguments

mdelete

mdelete table, arrayOfDeleteObjects, callback
mdelete table, arrayOfObjects, callback
delete1 = new hbase.Delete rowKey1
delete2 = new hbase.Delete rowKey2

client.mdelete table, [delete1, delete2], (err, res) ->
	console.log arguments
client.mdelete table, [rowKey1, rowKey2], (err, res) ->
	console.log arguments

scan

scanner = getScanner table, startRow, stopRow
scanner.setFilter filter
scanner.setReversed()
scanner.next callback
scanner.each function, callback
scanner.toArray callback
scanner.close()
scan = client.getScanner table

scan.next (err, row) ->
	console.log arguments
scan = client.getScanner table, startRow, stopRow

scan.next (err, row) ->
	console.log arguments
scan = client.getScanner table
scan.setFilter columnPrefixFilter: prefix: columnPrefix

scan.next (err, row) ->
	console.log arguments
scan = client.getScanner table

filter1 =
	singleColumnValueFilter:
		columnFamily: cf1
		columnQualifier: qualifier1
		compareOp: "EQUAL"
		comparator:
			substringComparator:
				substr: value1
		filterIfMissing: yes
		latestVersionOnly: yes

filter2 =
	singleColumnValueFilter:
		columnFamily: cf2
		columnQualifier: qualifier2
		compareOp: "EQUAL"
		comparator:
			substringComparator:
				substr: value2
		filterIfMissing: yes
		latestVersionOnly: yes

filterList1 = new hbase.FilterList
filterList2 = new hbase.FilterList
filterList3 = new hbase.FilterList "MUST_PASS_ONE"

filterList1.addFilter f1
filterList2.addFilter f2

filterList3.addFilter filterList1
filterList3.addFilter filterList2

scan.setFilter filterList3
scan.toArray (err, res) ->
	console.log arguments
scan = client.getScanner table

scan.toArray (err, res) ->
	console.log arguments
scan = client.getScanner table

scan.each (err, row) ->
	return unless row # no more rows
	# do something with row synchronously
scan = client.getScanner table

scan.each (err, row, done) ->
	return unless row # no more rows
	# do something with row asynchronously
	done()
scan = client.getScanner table

scan.each (err, row, done) ->
	# do something with row asynchronously
	done()
, (err) ->
	# error or no more rows
	console.log err if err

checkAndPut

Values can be only strings or buffers.

checkAndPut table, rowKey, cf, qualifier, value, putObject, callback
put = new hbase.Put rowKey1
put.add cf1, qualifier1, value1

client.checkAndPut table, rowKey2, cf2, qualifier2, value2, put, (err, res) ->
	console.log arguments

checkAndDelete

checkAndDelete table, rowKey, cf, qualifier, value, deleteObject, callback
del = new hbase.Put rowKey1

client.checkAndDelete table, rowKey2, cf2, qualifier2, value2, del, (err, res) ->
	console.log arguments

increment

increment table, incrementObject, callback
increment = new hbase.Increment rowKey
increment.add cf1, qualifier1, incrementValue1
increment.add cf2, qualifier2, incrementValue2

client.increment table, increment, (err, res) ->
	console.log arguments

incrementColumnValue

incrementColumnValue table, rowKey, cf, qualifier, value, callback
client.incrementColumnValue table, rowKey, cf, qualifier, incrementValue, (err, res) ->
	console.log arguments

License

hbase-rpc-client is made available under the Apache License, version 2.0

About

CoffeeScript HBase client implementation with protobuf support

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages