NAME
HBase::JSONRest - Simple REST client for HBase
SYNOPSIS
A simple get request:
my $hbase = HBase::JSONRest->new(host => $hostname);
my $records = $hbase->get({
table => 'table_name',
where => {
key_begins_with => "key_prefix"
},
});
A simple put request:
# array of hashes, where each hash is one row
my $rows = [
...
{
row_key => "$row_key",
# cells: array of hashes where eash hash is one cell
row_cells => [
{ column => "$family_name:$colum_name", value => "$value" },
],
},
...
];
my $res = $hbase->put({
table => $table_name,
changes => $rows
});
DESCRIPTION
A simple rest client for HBase.
METHODS
new
Constructor. Cretes an hbase client object that is used to talk to HBase.
my $hostname = "hbase-restserver.mydomain.com";
my $hbase = HBase::JSONRest->new(host => $hostname);
get
Scans a table by key prefix or exact key match depending on options passed:
# scan by key prefix:
my $records = $hbase->get({
table => $table_name,
where => {
key_begins_with => "$key_prefix"
},
});
# exact key match: get the whole row
my $record = $hbase->get({
table => $table_name,
where => {
key_equals => "$key"
},
});
# exact key match: get only specific columns
my $record = $hbase->get({
table => $table_name,
where => {
key_equals => $key
},
columns => [
'd:some_column_name',
'd:some_other_column_name'
],
});
# exact key match: get last $N cell versions
my $records = $hbase->get({
table => $table_name,
where => {
key_equals => $key
},
columns => [
'd:some_column_name',
'd:some_other_column_name'
],
versions => $N,
});
# exact key match: get cell versions created within a timestamp range
my $records = $hbase->get({
table => $table_name,
where => {
key_equals => $key
},
columns => [
'd:some_column_name',
'd:some_other_column_name'
],
timestamp_range => {
from => $timestamp_from,
until => $timestamp_until,
}
});
multiget
Does a multiget request to HBase, so that multiple keys can be matched in one http request. It also makes sure that the request url is not longer than 2000 chars, so if the number of keys passed is large enough and would result in url longer than 2000 chars, the request is split into multiple smaller request so each is shorter than 2000 chars.
# multiget: get only last cell version from matched rows
my @keys = ($key1,...,$keyN);
my $records = $hbase->multiget({
table => $table_name,
where => {
key_in => \@keys
},
});
# multiget: get last $N cell versions from matched rows
my @keys = ($key1,...,$keyN);
my $records = $hbase->multiget({
table => $table_name,
where => {
key_in => \@keys
},
versions => $N,
});
put
Inserts one or multiple rows. If a key allready exists then depending on if HBase versioning is ON for that specific table, the record will be updated (versioning is off) or new version will be inserted (versioning is on)
# multiple rows
my $rows = [
...
{
row_key => "$row_key",
# cells: array of hashes where eash hash is one cell
row_cells => [
{
column => "$family_name1:$colum_name1",
value => "$value1",
timestamp => "$timestamp1", # <- optional (override HBase timestamp)
},
...,
{
column => "$family_nameN:$colum_nameN",
value => "$valueN",
timestamp => "$timestampN", # <- optional (override HBase timestamp)
},
],
},
...
];
my $res = $hbase->put({
table => $table_name,
changes => $rows
});
# single row - basically the same as multiple rows, but
# the rows array has just one elements
my $rows = [
{
row_key => "$row_key",
# cells: array of hashes where eash hash is one cell
row_cells => [
{ column => "$family_name:$colum_name", value => "$value" },
],
},
];
my $res = $hbase->put({
table => $table_name,
changes => $rows
});
delete
Deletes an entire record or selected columns of it
my $success = $hbase->delete({
table => 'table',
key => 'key',
family => 'family', # optional, unless column is given
column => 'column', # optional
});
version
Returns a hashref with server version info
my $version_info = $hbase->version;
print Dumper($version_info);
output example:
---------------
version => $VAR1 = {
'Server' => 'jetty/6.1.26.cloudera.2',
'Jersey' => '1.8',
'REST' => '0.0.2',
'OS' => 'Linux 2.6.32-358.23.2.el6.x86_64 amd64',
'JVM' => 'Oracle Corporation 1.7.0_51-24.51-b03'
};
list
Returns a list of tables available in HBase
print "tables => " . Dumper($hbase->list);
tables => $VAR1 = [
{
'name' => 'very_big_table'
},
...,
{
'name' => 'super_big_table'
}
];
ERROR HANDLING
Information on error is stored in hbase object under key last error:
my $records = $hbase->get({
table => $table_name,
where => {
key_begins_with => "$key_prefix"
},
});
if ($hbase->{last_error}) {
# handle error
}
else {
# process records
}
VERSION
Current version: 0.044
AUTHOR
bdevetak - Bosko Devetak (cpan:BDEVETAK) <bosko.devetak@gmail.com>
CONTRIBUTORS
theMage, <cpan:NEVES>
, <mailto:themage@magick-source.net>
Sawyer X, <xsawyerx at cpan.org>
Eric Herman, <eherman at cpan.org>
Robert Nilsson, <rn@orbstation.com>
tsheasha - T Sheasha, <tarek.sheasha@gmail.com>
dtcyganov - Dmitrii Tcyganov, <dtcyganov at github.com>
COPYRIGHT
Copyright (c) 2014 the HBase::JSONRest "AUTHOR" and "CONTRIBUTORS" as listed above.
LICENSE
This library is free software and may be distributed under the same terms as perl itself. See http://dev.perl.org/licenses/.
DISCLAIMER OF WARRANTY
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.