Skip to content

Instantly share code, notes, and snippets.

@simonmorley
Forked from blmarket/README.mkd
Created December 3, 2017 16:23
Show Gist options
  • Select an option

  • Save simonmorley/01a1146519c5ca6aac74c11120dcfc29 to your computer and use it in GitHub Desktop.

Select an option

Save simonmorley/01a1146519c5ca6aac74c11120dcfc29 to your computer and use it in GitHub Desktop.

Revisions

  1. @blmarket blmarket revised this gist Nov 6, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.mkd
    Original file line number Diff line number Diff line change
    @@ -31,7 +31,7 @@ move to the directory and execute

    thrift --gen js:node Hbase.thrift

    that's it! gen-nodejs will be generated. copy these files into your working directory(where test.coffee in)
    that's it! gen-nodejs will be generated. copy these files into your working directory(where test.coffee is in)

    ### use with node.

  2. @blmarket blmarket revised this gist Nov 6, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.mkd
    Original file line number Diff line number Diff line change
    @@ -31,7 +31,7 @@ move to the directory and execute

    thrift --gen js:node Hbase.thrift

    that's it! gen-nodejs will be generated.
    that's it! gen-nodejs will be generated. copy these files into your working directory(where test.coffee in)

    ### use with node.

  3. @blmarket blmarket created this gist Nov 6, 2013.
    39 changes: 39 additions & 0 deletions README.mkd
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    HBase with thrift using node.js
    -------------------------------

    ## Install (on Mac OS X)

    ### homebrew

    Trivial

    ### hbase

    used https://github.com/seomoz/homebrew-cloudera

    ### thrift

    due to build failure in default formula(my OS X clang doesn't have TR1),

    used https://gist.github.com/duedal/6934417

    brew install https://gist.github.com/duedal/6934417/raw/d802f592d66c5bb9908db8a7c75ae57262dafa06/thrift.rb

    (you may need github api key because it accesses github several times)

    ### generate HBase.js(and more)

    For me, thrift file is on

    /usr/local/Cellar/hbase/0.94.6-cdh4.3.0/libexec/src/main/resources/org/apache/hadoop/hbase/thrift

    move to the directory and execute

    thrift --gen js:node Hbase.thrift

    that's it! gen-nodejs will be generated.

    ### use with node.

    npm install thrift
    coffee test.coffee
    53 changes: 53 additions & 0 deletions test.coffee
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,53 @@
    util = require 'util'
    thrift = require 'thrift'
    hbase = require './Hbase'
    {Mutation} = require './Hbase_types'

    HOST = 'ec2-54-249-207-247.ap-northeast-1.compute.amazonaws.com'
    PORT = 9090

    inspect = (obj) -> util.inspect obj, { colors: true, depth: null }
    debug = (err, res) -> console.log err? && err || inspect(res)

    conn = thrift.createConnection HOST, PORT, {
    transport: thrift.TBufferedTransport
    protocol: thrift.TBinaryProtocol
    }

    conn.on 'connect', ->
    console.log 'connected'
    client = thrift.createClient(hbase, conn)

    # client.getTableNames (err, data) ->
    # console.log err
    # console.log data

    # client.getColumnDescriptors 'item_id_test', (err, data) ->
    # console.log err
    # console.log data

    client.mutateRow 'item_id_test', 'asdf', [
    new Mutation({ column: 'f1:test1', value: 'value1' })
    new Mutation({ column: 'f1:test2', value: 'value2' })
    ], {}, ->
    console.log arguments
    return

    client.getRow 'item_id_test', 'asdf', {}, debug

    # client.getTableRegions 'user_action_log', (err, list) ->
    # for region in list
    # toBuffer = (value) ->
    # ret = new Buffer(8)
    # ret.fill(0)
    # ret.write value, null, null, 'binary'
    # return ret
    # console.log JSON.stringify(region.startKey), toBuffer(region.startKey)
    # console.log JSON.stringify(region.endKey), toBuffer(region.endKey)
    # # console.log toBuffer(region.startKey)
    # # console.log toBuffer(region.endKey)

    conn.on 'error', (err) ->
    console.log 'error', err

    console.log hbase