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/
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:
{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
{ok, C0} = thrift_client_util:new("localhost", 9090, hbase_thrift, []).
Basic CRUD commands
% Load records into the shell rr(hbase_types). % Get a list of tables {C1, Tables} = thrift_client:call(C0, getTableNames, []). % Create a table {C2, _Result} = thrift_client:call(C1, createTable, ["test", [#columnDescriptor{name="test_col:"}]]). % Insert a column value % TODO: Investigate the attributes dictionary's purpose {C3, _Result} = thrift_client:call(C2, mutateRow, ["test", "key1", [#mutation{isDelete=false,column="test_col:", value="wooo"}], dict:new()]). % Delete {C4, _Result} = thrift_client:call(C3, mutateRow, ["test", "key1", [#mutation{isDelete=true}], dict:new()]). % Get data % TODO: Investigate the attributes dictionary's purpose thrift_client:call(C4, getRow, ["test", "key1", dict:new()]).
TODO: Research how to use connection pooling with thrift.
TODO: Document connecting to Cassandra using thrift, but all the hard work has already been done by Roberto at https://github.com/ostinelli/erlcassa