The key was to piece together steps from the following two pages:
- http://stackoverflow.com/questions/5837776/how-to-load-thrift-client-in-erlang
- http://kungfooguru.wordpress.com/2009/08/31/erlang-thrift-and-hbase/
Thrift API and Hbase.thrift file can be found here
http://wiki.apache.org/hadoop/Hbase/ThriftApi
Download the latest thrift*.tar.gz from http://thrift.apache.org/download/
1
2
3
4
5
6
7
|
sudo apt-get install libboost-dev tar -zxvf thrift*. tar .gz cd thrift* . /configure make cd compiler /cpp . /thrift -gen erl Hbase.thrift |
Take all the files in the gen-erl directory and copy them to your application’s /src.
Copy the thrift erlang client files from thrift*/lib/erl to your application or copy/symlink to $ERL_LIB
Can connect using either approach:
1
2
3
4
|
{ok, TFactory } = thrift_socket_transport:new_transport_factory ( "localhost" , 9090, []). {ok, PFactory } = thrift_binary_protocol:new_protocol_factory ( TFactory , []). {ok, Protocol } = PFactory (). {ok, C0 } = thrift_client:new ( Protocol , hbase_thrift). |
Or by using the utility, need to investigate the difference
1
|
{ok, C0 } = thrift_client_util:new ( "localhost" , 9090, hbase_thrift, []). |
Basic CRUD commands
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
% Load records into the shell rr(hbase_types). % Get a list of tables { C1 , Tables } = thrift_client:call ( C0 , get TableNames , []). % Create a table { C2 , _ Result } = thrift_client:call ( C1 , create Table , [ "test" , [#column Descriptor {name= "test_col:" }]]). % Insert a column value % TODO: Investigate the attributes dictionary's purpose { C3 , _ Result } = thrift_client:call ( C2 , mutate Row , [ "test" , "key1" , [#mutation{is Delete =false,column= "test_col:" , value= "wooo" }], dict:new ()]). % Delete { C4 , _ Result } = thrift_client:call ( C3 , mutate Row , [ "test" , "key1" , [#mutation{is Delete =true}], dict:new ()]). % Get data % TODO: Investigate the attributes dictionary's purpose thrift_client:call ( C4 , get Row , [ "test" , "key1" , dict:new ()]).
|