HBASE-6806 HBASE-4658 breaks backward compatibility / example scripts

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1388318 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2012-09-21 04:06:17 +00:00
parent 061fda6ae1
commit 7c9d6f3440
7 changed files with 266 additions and 233 deletions

View File

@ -88,12 +88,19 @@ main(int argc, char** argv)
std::cerr << "Invalid arguments!\n" << "Usage: DemoClient host port" << std::endl; std::cerr << "Invalid arguments!\n" << "Usage: DemoClient host port" << std::endl;
return -1; return -1;
} }
bool isFramed = false;
boost::shared_ptr<TTransport> socket(new TSocket(argv[1], boost::lexical_cast<int>(argv[2])));
boost::shared_ptr<TTransport> transport;
boost::shared_ptr<TTransport> socket(new TSocket("localhost", boost::lexical_cast<int>(argv[2]))); if (isFramed) {
boost::shared_ptr<TTransport> transport(new TBufferedTransport(socket)); transport.reset(new TFramedTransport(socket));
} else {
transport.reset(new TBufferedTransport(socket));
}
boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport)); boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
HbaseClient client(protocol);
const std::map<Text, Text> dummyAttributes; // see HBASE-6806 HBASE-4658
HbaseClient client(protocol);
try { try {
transport->open(); transport->open();
@ -152,35 +159,35 @@ main(int argc, char** argv)
mutations.push_back(Mutation()); mutations.push_back(Mutation());
mutations.back().column = "entry:foo"; mutations.back().column = "entry:foo";
mutations.back().value = invalid; mutations.back().value = invalid;
client.mutateRow(t, "foo", mutations); client.mutateRow(t, "foo", mutations, dummyAttributes);
// try empty strings // try empty strings
mutations.clear(); mutations.clear();
mutations.push_back(Mutation()); mutations.push_back(Mutation());
mutations.back().column = "entry:"; mutations.back().column = "entry:";
mutations.back().value = ""; mutations.back().value = "";
client.mutateRow(t, "", mutations); client.mutateRow(t, "", mutations, dummyAttributes);
// this row name is valid utf8 // this row name is valid utf8
mutations.clear(); mutations.clear();
mutations.push_back(Mutation()); mutations.push_back(Mutation());
mutations.back().column = "entry:foo"; mutations.back().column = "entry:foo";
mutations.back().value = valid; mutations.back().value = valid;
client.mutateRow(t, valid, mutations); client.mutateRow(t, valid, mutations, dummyAttributes);
// non-utf8 is now allowed in row names because HBase stores values as binary // non-utf8 is now allowed in row names because HBase stores values as binary
mutations.clear(); mutations.clear();
mutations.push_back(Mutation()); mutations.push_back(Mutation());
mutations.back().column = "entry:foo"; mutations.back().column = "entry:foo";
mutations.back().value = invalid; mutations.back().value = invalid;
client.mutateRow(t, invalid, mutations); client.mutateRow(t, invalid, mutations, dummyAttributes);
// Run a scanner on the rows we just created // Run a scanner on the rows we just created
StrVec columnNames; StrVec columnNames;
columnNames.push_back("entry:"); columnNames.push_back("entry:");
std::cout << "Starting scanner..." << std::endl; std::cout << "Starting scanner..." << std::endl;
int scanner = client.scannerOpen(t, "", columnNames); int scanner = client.scannerOpen(t, "", columnNames, dummyAttributes);
try { try {
while (true) { while (true) {
std::vector<TRowResult> value; std::vector<TRowResult> value;
@ -210,10 +217,10 @@ main(int argc, char** argv)
mutations.push_back(Mutation()); mutations.push_back(Mutation());
mutations.back().column = "unused:"; mutations.back().column = "unused:";
mutations.back().value = "DELETE_ME"; mutations.back().value = "DELETE_ME";
client.mutateRow(t, row, mutations); client.mutateRow(t, row, mutations, dummyAttributes);
client.getRow(rowResult, t, row); client.getRow(rowResult, t, row, dummyAttributes);
printRow(rowResult); printRow(rowResult);
client.deleteAllRow(t, row); client.deleteAllRow(t, row, dummyAttributes);
mutations.clear(); mutations.clear();
mutations.push_back(Mutation()); mutations.push_back(Mutation());
@ -222,8 +229,8 @@ main(int argc, char** argv)
mutations.push_back(Mutation()); mutations.push_back(Mutation());
mutations.back().column = "entry:foo"; mutations.back().column = "entry:foo";
mutations.back().value = "FOO"; mutations.back().value = "FOO";
client.mutateRow(t, row, mutations); client.mutateRow(t, row, mutations, dummyAttributes);
client.getRow(rowResult, t, row); client.getRow(rowResult, t, row, dummyAttributes);
printRow(rowResult); printRow(rowResult);
// sleep to force later timestamp // sleep to force later timestamp
@ -236,8 +243,8 @@ main(int argc, char** argv)
mutations.push_back(Mutation()); mutations.push_back(Mutation());
mutations.back().column = "entry:num"; mutations.back().column = "entry:num";
mutations.back().value = "-1"; mutations.back().value = "-1";
client.mutateRow(t, row, mutations); client.mutateRow(t, row, mutations, dummyAttributes);
client.getRow(rowResult, t, row); client.getRow(rowResult, t, row, dummyAttributes);
printRow(rowResult); printRow(rowResult);
mutations.clear(); mutations.clear();
@ -247,8 +254,8 @@ main(int argc, char** argv)
mutations.push_back(Mutation()); mutations.push_back(Mutation());
mutations.back().column = "entry:sqr"; mutations.back().column = "entry:sqr";
mutations.back().value = boost::lexical_cast<std::string>(i*i); mutations.back().value = boost::lexical_cast<std::string>(i*i);
client.mutateRow(t, row, mutations); client.mutateRow(t, row, mutations, dummyAttributes);
client.getRow(rowResult, t, row); client.getRow(rowResult, t, row, dummyAttributes);
printRow(rowResult); printRow(rowResult);
mutations.clear(); mutations.clear();
@ -258,19 +265,19 @@ main(int argc, char** argv)
mutations.push_back(Mutation()); mutations.push_back(Mutation());
mutations.back().column = "entry:sqr"; mutations.back().column = "entry:sqr";
mutations.back().isDelete = true; mutations.back().isDelete = true;
client.mutateRowTs(t, row, mutations, 1); // shouldn't override latest client.mutateRowTs(t, row, mutations, 1, dummyAttributes); // shouldn't override latest
client.getRow(rowResult, t, row); client.getRow(rowResult, t, row, dummyAttributes);
printRow(rowResult); printRow(rowResult);
CellVec versions; CellVec versions;
client.getVer(versions, t, row, "entry:num", 10); client.getVer(versions, t, row, "entry:num", 10, dummyAttributes);
printVersions(row, versions); printVersions(row, versions);
assert(versions.size()); assert(versions.size());
std::cout << std::endl; std::cout << std::endl;
try { try {
std::vector<TCell> value; std::vector<TCell> value;
client.get(value, t, row, "entry:foo"); client.get(value, t, row, "entry:foo", dummyAttributes);
if (value.size()) { if (value.size()) {
std::cerr << "FATAL: shouldn't get here!" << std::endl; std::cerr << "FATAL: shouldn't get here!" << std::endl;
return -1; return -1;
@ -292,7 +299,7 @@ main(int argc, char** argv)
std::cout << std::endl; std::cout << std::endl;
std::cout << "Starting scanner..." << std::endl; std::cout << "Starting scanner..." << std::endl;
scanner = client.scannerOpenWithStop(t, "00020", "00040", columnNames); scanner = client.scannerOpenWithStop(t, "00020", "00040", columnNames, dummyAttributes);
try { try {
while (true) { while (true) {
std::vector<TRowResult> value; std::vector<TRowResult> value;

View File

@ -163,6 +163,9 @@ public class DemoClient {
System.out.println(" column: " + utf8(col2.name.array()) + ", maxVer: " + Integer.toString(col2.maxVersions)); System.out.println(" column: " + utf8(col2.name.array()) + ", maxVer: " + Integer.toString(col2.maxVersions));
} }
Map<ByteBuffer, ByteBuffer> dummyAttributes = null;
boolean writeToWal = false;
// //
// Test UTF-8 handling // Test UTF-8 handling
// //
@ -172,25 +175,25 @@ public class DemoClient {
ArrayList<Mutation> mutations; ArrayList<Mutation> mutations;
// non-utf8 is fine for data // non-utf8 is fine for data
mutations = new ArrayList<Mutation>(); mutations = new ArrayList<Mutation>();
mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:foo")), ByteBuffer.wrap(invalid))); mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:foo")), ByteBuffer.wrap(invalid), writeToWal));
client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(bytes("foo")), mutations); client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(bytes("foo")), mutations, dummyAttributes);
// try empty strings // try empty strings
mutations = new ArrayList<Mutation>(); mutations = new ArrayList<Mutation>();
mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:")), ByteBuffer.wrap(bytes("")))); mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:")), ByteBuffer.wrap(bytes("")), writeToWal));
client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(bytes("")), mutations); client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(bytes("")), mutations, dummyAttributes);
// this row name is valid utf8 // this row name is valid utf8
mutations = new ArrayList<Mutation>(); mutations = new ArrayList<Mutation>();
mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:foo")), ByteBuffer.wrap(valid))); mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:foo")), ByteBuffer.wrap(valid), writeToWal));
client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(valid), mutations); client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(valid), mutations, dummyAttributes);
// non-utf8 is now allowed in row names because HBase stores values as binary // non-utf8 is now allowed in row names because HBase stores values as binary
ByteBuffer bf = ByteBuffer.wrap(invalid); ByteBuffer bf = ByteBuffer.wrap(invalid);
mutations = new ArrayList<Mutation>(); mutations = new ArrayList<Mutation>();
mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:foo")), ByteBuffer.wrap(invalid))); mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:foo")), ByteBuffer.wrap(invalid), writeToWal));
client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(invalid), mutations); client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(invalid), mutations, dummyAttributes);
// Run a scanner on the rows we just created // Run a scanner on the rows we just created
@ -198,7 +201,7 @@ public class DemoClient {
columnNames.add(ByteBuffer.wrap(bytes("entry:"))); columnNames.add(ByteBuffer.wrap(bytes("entry:")));
System.out.println("Starting scanner..."); System.out.println("Starting scanner...");
int scanner = client.scannerOpen(ByteBuffer.wrap(t), ByteBuffer.wrap(bytes("")), columnNames); int scanner = client.scannerOpen(ByteBuffer.wrap(t), ByteBuffer.wrap(bytes("")), columnNames, dummyAttributes);
while (true) { while (true) {
List<TRowResult> entry = client.scannerGet(scanner); List<TRowResult> entry = client.scannerGet(scanner);
@ -219,16 +222,16 @@ public class DemoClient {
byte[] row = bytes(nf.format(i)); byte[] row = bytes(nf.format(i));
mutations = new ArrayList<Mutation>(); mutations = new ArrayList<Mutation>();
mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("unused:")), ByteBuffer.wrap(bytes("DELETE_ME")))); mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("unused:")), ByteBuffer.wrap(bytes("DELETE_ME")), writeToWal));
client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), mutations); client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), mutations, dummyAttributes);
printRow(client.getRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row))); printRow(client.getRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), dummyAttributes));
client.deleteAllRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row)); client.deleteAllRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), dummyAttributes);
mutations = new ArrayList<Mutation>(); mutations = new ArrayList<Mutation>();
mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:num")), ByteBuffer.wrap(bytes("0")))); mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:num")), ByteBuffer.wrap(bytes("0")), writeToWal));
mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:foo")), ByteBuffer.wrap(bytes("FOO")))); mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:foo")), ByteBuffer.wrap(bytes("FOO")), writeToWal));
client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), mutations); client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), mutations, dummyAttributes);
printRow(client.getRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row))); printRow(client.getRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), dummyAttributes));
Mutation m = null; Mutation m = null;
mutations = new ArrayList<Mutation>(); mutations = new ArrayList<Mutation>();
@ -240,14 +243,14 @@ public class DemoClient {
m.column = ByteBuffer.wrap(bytes("entry:num")); m.column = ByteBuffer.wrap(bytes("entry:num"));
m.value = ByteBuffer.wrap(bytes("-1")); m.value = ByteBuffer.wrap(bytes("-1"));
mutations.add(m); mutations.add(m);
client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), mutations); client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), mutations, dummyAttributes);
printRow(client.getRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row))); printRow(client.getRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), dummyAttributes));
mutations = new ArrayList<Mutation>(); mutations = new ArrayList<Mutation>();
mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:num")), ByteBuffer.wrap(bytes(Integer.toString(i))))); mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:num")), ByteBuffer.wrap(bytes(Integer.toString(i))), writeToWal));
mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:sqr")), ByteBuffer.wrap(bytes(Integer.toString(i * i))))); mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:sqr")), ByteBuffer.wrap(bytes(Integer.toString(i * i))), writeToWal));
client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), mutations); client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), mutations, dummyAttributes);
printRow(client.getRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row))); printRow(client.getRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), dummyAttributes));
// sleep to force later timestamp // sleep to force later timestamp
try { try {
@ -264,10 +267,10 @@ public class DemoClient {
m = new Mutation(); m = new Mutation();
m.column = ByteBuffer.wrap(bytes("entry:sqr")); m.column = ByteBuffer.wrap(bytes("entry:sqr"));
m.isDelete = true; m.isDelete = true;
client.mutateRowTs(ByteBuffer.wrap(t), ByteBuffer.wrap(row), mutations, 1); // shouldn't override latest client.mutateRowTs(ByteBuffer.wrap(t), ByteBuffer.wrap(row), mutations, 1, dummyAttributes); // shouldn't override latest
printRow(client.getRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row))); printRow(client.getRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), dummyAttributes));
List<TCell> versions = client.getVer(ByteBuffer.wrap(t), ByteBuffer.wrap(row), ByteBuffer.wrap(bytes("entry:num")), 10); List<TCell> versions = client.getVer(ByteBuffer.wrap(t), ByteBuffer.wrap(row), ByteBuffer.wrap(bytes("entry:num")), 10, dummyAttributes);
printVersions(ByteBuffer.wrap(row), versions); printVersions(ByteBuffer.wrap(row), versions);
if (versions.isEmpty()) { if (versions.isEmpty()) {
System.out.println("FATAL: wrong # of versions"); System.out.println("FATAL: wrong # of versions");
@ -275,7 +278,7 @@ public class DemoClient {
} }
List<TCell> result = client.get(ByteBuffer.wrap(t), ByteBuffer.wrap(row), ByteBuffer.wrap(bytes("entry:foo"))); List<TCell> result = client.get(ByteBuffer.wrap(t), ByteBuffer.wrap(row), ByteBuffer.wrap(bytes("entry:foo")), dummyAttributes);
if (result.isEmpty() == false) { if (result.isEmpty() == false) {
System.out.println("FATAL: shouldn't get here"); System.out.println("FATAL: shouldn't get here");
System.exit(-1); System.exit(-1);
@ -295,8 +298,7 @@ public class DemoClient {
} }
System.out.println("Starting scanner..."); System.out.println("Starting scanner...");
scanner = client.scannerOpenWithStop(ByteBuffer.wrap(t), ByteBuffer.wrap(bytes("00020")), ByteBuffer.wrap(bytes("00040")), scanner = client.scannerOpenWithStop(ByteBuffer.wrap(t), ByteBuffer.wrap(bytes("00020")), ByteBuffer.wrap(bytes("00040")), columnNames, dummyAttributes);
columnNames);
while (true) { while (true) {
List<TRowResult> entry = client.scannerGet(scanner); List<TRowResult> entry = client.scannerGet(scanner);

View File

@ -21,7 +21,7 @@
# Instructions: # Instructions:
# 1. Run Thrift to generate the php module HBase # 1. Run Thrift to generate the php module HBase
# thrift -php ../../../src/main/resources/org/apache/hadoop/hbase/thrift/Hbase.thrift # thrift --gen php ../../../src/main/resources/org/apache/hadoop/hbase/thrift/Hbase.thrift
# 2. Modify the import string below to point to {$THRIFT_HOME}/lib/php/src. # 2. Modify the import string below to point to {$THRIFT_HOME}/lib/php/src.
# 3. Execute {php DemoClient.php}. Note that you must use php5 or higher. # 3. Execute {php DemoClient.php}. Note that you must use php5 or higher.
# 4. See {$THRIFT_HOME}/lib/php/README for additional help. # 4. See {$THRIFT_HOME}/lib/php/README for additional help.
@ -112,7 +112,7 @@ asort( $descriptors );
foreach ( $descriptors as $col ) { foreach ( $descriptors as $col ) {
echo( " column: {$col->name}, maxVer: {$col->maxVersions}\n" ); echo( " column: {$col->name}, maxVer: {$col->maxVersions}\n" );
} }
$dummy_attributes = array();
# #
# Test UTF-8 handling # Test UTF-8 handling
# #
@ -126,7 +126,7 @@ $mutations = array(
'value' => $invalid 'value' => $invalid
) ), ) ),
); );
$client->mutateRow( $t, "foo", $mutations ); $client->mutateRow( $t, "foo", $mutations, $dummy_attributes );
# try empty strings # try empty strings
$mutations = array( $mutations = array(
@ -135,7 +135,7 @@ $mutations = array(
'value' => "" 'value' => ""
) ), ) ),
); );
$client->mutateRow( $t, "", $mutations ); $client->mutateRow( $t, "", $mutations, $dummy_attributes );
# this row name is valid utf8 # this row name is valid utf8
$mutations = array( $mutations = array(
@ -144,7 +144,7 @@ $mutations = array(
'value' => $valid 'value' => $valid
) ), ) ),
); );
$client->mutateRow( $t, $valid, $mutations ); $client->mutateRow( $t, $valid, $mutations, $dummy_attributes );
# non-utf8 is not allowed in row names # non-utf8 is not allowed in row names
try { try {
@ -154,7 +154,7 @@ try {
'value' => $invalid 'value' => $invalid
) ), ) ),
); );
$client->mutateRow( $t, $invalid, $mutations ); $client->mutateRow( $t, $invalid, $mutations, $dummy_attributes );
throw new Exception( "shouldn't get here!" ); throw new Exception( "shouldn't get here!" );
} catch ( IOError $e ) { } catch ( IOError $e ) {
echo( "expected error: {$e->message}\n" ); echo( "expected error: {$e->message}\n" );
@ -162,7 +162,7 @@ try {
# Run a scanner on the rows we just created # Run a scanner on the rows we just created
echo( "Starting scanner...\n" ); echo( "Starting scanner...\n" );
$scanner = $client->scannerOpen( $t, "", array( "entry:" ) ); $scanner = $client->scannerOpen( $t, "", array( "entry:" ), $dummy_attributes );
try { try {
while (true) printRow( $client->scannerGet( $scanner ) ); while (true) printRow( $client->scannerGet( $scanner ) );
} catch ( NotFound $nf ) { } catch ( NotFound $nf ) {
@ -184,9 +184,9 @@ for ($e=100; $e>=0; $e--) {
'value' => "DELETE_ME" 'value' => "DELETE_ME"
) ), ) ),
); );
$client->mutateRow( $t, $row, $mutations); $client->mutateRow( $t, $row, $mutations, $dummy_attributes );
printRow( $client->getRow( $t, $row )); printRow( $client->getRow( $t, $row, $dummy_attributes ));
$client->deleteAllRow( $t, $row ); $client->deleteAllRow( $t, $row, $dummy_attributes );
$mutations = array( $mutations = array(
new Mutation( array( new Mutation( array(
@ -198,8 +198,8 @@ for ($e=100; $e>=0; $e--) {
'value' => "FOO" 'value' => "FOO"
) ), ) ),
); );
$client->mutateRow( $t, $row, $mutations ); $client->mutateRow( $t, $row, $mutations, $dummy_attributes );
printRow( $client->getRow( $t, $row )); printRow( $client->getRow( $t, $row, $dummy_attributes ));
$mutations = array( $mutations = array(
new Mutation( array( new Mutation( array(
@ -211,8 +211,8 @@ for ($e=100; $e>=0; $e--) {
'value' => '-1' 'value' => '-1'
) ), ) ),
); );
$client->mutateRow( $t, $row, $mutations ); $client->mutateRow( $t, $row, $mutations, $dummy_attributes );
printRow( $client->getRow( $t, $row ) ); printRow( $client->getRow( $t, $row, $dummy_attributes ) );
$mutations = array( $mutations = array(
new Mutation( array( new Mutation( array(
@ -224,8 +224,8 @@ for ($e=100; $e>=0; $e--) {
'value' => $e * $e 'value' => $e * $e
) ), ) ),
); );
$client->mutateRow( $t, $row, $mutations ); $client->mutateRow( $t, $row, $mutations, $dummy_attributes );
printRow( $client->getRow( $t, $row )); printRow( $client->getRow( $t, $row, $dummy_attributes ));
$mutations = array( $mutations = array(
new Mutation( array( new Mutation( array(
@ -237,15 +237,15 @@ for ($e=100; $e>=0; $e--) {
'isDelete' => 1 'isDelete' => 1
) ), ) ),
); );
$client->mutateRowTs( $t, $row, $mutations, 1 ); # shouldn't override latest $client->mutateRowTs( $t, $row, $mutations, 1, $dummy_attributes ); # shouldn't override latest
printRow( $client->getRow( $t, $row ) ); printRow( $client->getRow( $t, $row, $dummy_attributes ) );
$versions = $client->getVer( $t, $row, "entry:num", 10 ); $versions = $client->getVer( $t, $row, "entry:num", 10, $dummy_attributes );
echo( "row: {$row}, values: \n" ); echo( "row: {$row}, values: \n" );
foreach ( $versions as $v ) echo( " {$v->value};\n" ); foreach ( $versions as $v ) echo( " {$v->value};\n" );
try { try {
$client->get( $t, $row, "entry:foo"); $client->get( $t, $row, "entry:foo", $dummy_attributes );
throw new Exception ( "shouldn't get here! " ); throw new Exception ( "shouldn't get here! " );
} catch ( NotFound $nf ) { } catch ( NotFound $nf ) {
# blank # blank
@ -260,7 +260,7 @@ foreach ( $client->getColumnDescriptors($t) as $col=>$desc ) {
} }
echo( "Starting scanner...\n" ); echo( "Starting scanner...\n" );
$scanner = $client->scannerOpenWithStop( $t, "00020", "00040", $columns ); $scanner = $client->scannerOpenWithStop( $t, "00020", "00040", $columns, $dummy_attributes );
try { try {
while (true) printRow( $client->scannerGet( $scanner ) ); while (true) printRow( $client->scannerGet( $scanner ) );
} catch ( NotFound $nf ) { } catch ( NotFound $nf ) {

View File

@ -123,6 +123,8 @@ foreach my $col (sort keys %{$descriptors})
printf (" column: {%s}, maxVer: {%s}\n", $descriptors->{$col}->{name}, $descriptors->{$col}->{maxVersions} ); printf (" column: {%s}, maxVer: {%s}\n", $descriptors->{$col}->{name}, $descriptors->{$col}->{maxVersions} );
} }
my %dummy_attributes = ();
# #
# Test UTF-8 handling # Test UTF-8 handling
# #
@ -132,12 +134,12 @@ my $valid = "foo-\xE7\x94\x9F\xE3\x83\x93\xE3\x83\xBC\xE3\x83\xAB";
# non-utf8 is fine for data # non-utf8 is fine for data
my $key = "foo"; my $key = "foo";
my $mutations = [ Hbase::Mutation->new ( { column => "entry:$key", value => $invalid } ) ]; my $mutations = [ Hbase::Mutation->new ( { column => "entry:$key", value => $invalid } ) ];
$client->mutateRow ( $demo_table, $key, $mutations ); $client->mutateRow ( $demo_table, $key, $mutations, %dummy_attributes );
# try emptry strings # try emptry strings
$key = ""; $key = "";
$mutations = [ Hbase::Mutation->new ( { column => "entry:$key", value => "" } ) ]; $mutations = [ Hbase::Mutation->new ( { column => "entry:$key", value => "" } ) ];
$client->mutateRow ( $demo_table, $key, $mutations ); $client->mutateRow ( $demo_table, $key, $mutations, %dummy_attributes );
# this row name is valid utf8 # this row name is valid utf8
$key = "foo"; $key = "foo";
@ -146,13 +148,13 @@ my $mutation = Hbase::Mutation->new ();
$mutation->{column} = "entry:$key"; $mutation->{column} = "entry:$key";
$mutation->{value} = $valid; $mutation->{value} = $valid;
$mutations = [ $mutation ]; $mutations = [ $mutation ];
$client->mutateRow ( $demo_table, $key, $mutations ); $client->mutateRow ( $demo_table, $key, $mutations, %dummy_attributes );
# non-utf8 is not allowed in row names # non-utf8 is not allowed in row names
eval { eval {
$mutations = [ Hbase::Mutation->new ( { column => "entry:$key", value => $invalid } ) ]; $mutations = [ Hbase::Mutation->new ( { column => "entry:$key", value => $invalid } ) ];
# this can throw a TApplicationException (HASH) error # this can throw a TApplicationException (HASH) error
$client->mutateRow ($demo_table, $key, $mutations); $client->mutateRow ($demo_table, $key, $mutations, %dummy_attributes);
die ("shouldn't get here!"); die ("shouldn't get here!");
}; };
if ($@) if ($@)
@ -168,7 +170,7 @@ $key = "";
# scannerOpen expects ( table, key, <column descriptors> ) # scannerOpen expects ( table, key, <column descriptors> )
# if key is empty, it searches for all entries in the table # if key is empty, it searches for all entries in the table
# if column descriptors is empty, it searches for all column descriptors within the table # if column descriptors is empty, it searches for all column descriptors within the table
my $scanner = $client->scannerOpen ( $demo_table, $key, [ "entry:" ] ); my $scanner = $client->scannerOpen ( $demo_table, $key, [ "entry:" ], %dummy_attributes );
eval { eval {
# scannerGet returns an empty arrayref (instead of an undef) to indicate no results # scannerGet returns an empty arrayref (instead of an undef) to indicate no results
@ -197,7 +199,7 @@ for (my $e = 100; $e > 0; $e--)
my $row = sprintf ("%05d", $e); my $row = sprintf ("%05d", $e);
$mutations = [ Hbase::Mutation->new ( { column => "unused:", value => "DELETE_ME" } ) ]; $mutations = [ Hbase::Mutation->new ( { column => "unused:", value => "DELETE_ME" } ) ];
$client->mutateRow ( $demo_table, $row, $mutations ); $client->mutateRow ( $demo_table, $row, $mutations, %dummy_attributes );
printRow ( $client->getRow ( $demo_table, $row ) ); printRow ( $client->getRow ( $demo_table, $row ) );
$client->deleteAllRow ( $demo_table, $row ); $client->deleteAllRow ( $demo_table, $row );
@ -205,22 +207,22 @@ for (my $e = 100; $e > 0; $e--)
Hbase::Mutation->new ( { column => "entry:num", value => "0" } ), Hbase::Mutation->new ( { column => "entry:num", value => "0" } ),
Hbase::Mutation->new ( { column => "entry:foo", value => "FOO" } ), Hbase::Mutation->new ( { column => "entry:foo", value => "FOO" } ),
]; ];
$client->mutateRow ( $demo_table, $row, $mutations ); $client->mutateRow ( $demo_table, $row, $mutations, %dummy_attributes );
printRow ( $client->getRow ( $demo_table, $row ) ); printRow ( $client->getRow ( $demo_table, $row, %dummy_attributes ) );
$mutations = [ $mutations = [
Hbase::Mutation->new ( { column => "entry:foo", isDelete => 1 } ), Hbase::Mutation->new ( { column => "entry:foo", isDelete => 1 } ),
Hbase::Mutation->new ( { column => "entry:num", value => -1 } ), Hbase::Mutation->new ( { column => "entry:num", value => -1 } ),
]; ];
$client->mutateRow ( $demo_table, $row, $mutations ); $client->mutateRow ( $demo_table, $row, $mutations, %dummy_attributes );
printRow ( $client->getRow ( $demo_table, $row ) ); printRow ( $client->getRow ( $demo_table, $row, %dummy_attributes ) );
$mutations = [ $mutations = [
Hbase::Mutation->new ( { column => "entry:num", value => $e } ), Hbase::Mutation->new ( { column => "entry:num", value => $e } ),
Hbase::Mutation->new ( { column => "entry:sqr", value => $e * $e } ), Hbase::Mutation->new ( { column => "entry:sqr", value => $e * $e } ),
]; ];
$client->mutateRow ( $demo_table, $row, $mutations ); $client->mutateRow ( $demo_table, $row, $mutations, %dummy_attributes );
printRow ( $client->getRow ( $demo_table, $row ) ); printRow ( $client->getRow ( $demo_table, $row, %dummy_attributes ) );
$mutations = [ $mutations = [
Hbase::Mutation->new ( { column => "entry:num", value => -999 } ), Hbase::Mutation->new ( { column => "entry:num", value => -999 } ),
@ -228,10 +230,10 @@ for (my $e = 100; $e > 0; $e--)
]; ];
# mutateRowTs => modify the row entry at the specified timestamp (ts) # mutateRowTs => modify the row entry at the specified timestamp (ts)
$client->mutateRowTs ( $demo_table, $row, $mutations, 1 ); # shouldn't override latest $client->mutateRowTs ( $demo_table, $row, $mutations, 1, %dummy_attributes ); # shouldn't override latest
printRow ( $client->getRow ( $demo_table, $row ) ); printRow ( $client->getRow ( $demo_table, $row, %dummy_attributes ) );
my $versions = $client->getVer ( $demo_table, $row, "entry:num", 10 ); my $versions = $client->getVer ( $demo_table, $row, "entry:num", 10, %dummy_attributes );
printf ( "row: {%s}, values: \n", $row ); printf ( "row: {%s}, values: \n", $row );
foreach my $v ( @{$versions} ) foreach my $v ( @{$versions} )
{ {
@ -240,7 +242,7 @@ for (my $e = 100; $e > 0; $e--)
eval { eval {
my $result = $client->get ( $demo_table, $row, "entry:foo" ); my $result = $client->get ( $demo_table, $row, "entry:foo", %dummy_attributes );
# Unfortunately, the API returns an empty arrayref instead of undef # Unfortunately, the API returns an empty arrayref instead of undef
# to signify a "not found", which makes it slightly inconvenient. # to signify a "not found", which makes it slightly inconvenient.
@ -267,7 +269,7 @@ foreach my $col ( keys %{$column_descriptor} )
} }
print "Starting scanner...\n"; print "Starting scanner...\n";
$scanner = $client->scannerOpenWithStop ( $demo_table, "00020", "00040", $columns ); $scanner = $client->scannerOpenWithStop ( $demo_table, "00020", "00040", $columns, %dummy_attributes );
eval { eval {
# scannerGet returns an empty arrayref (instead of an undef) to indicate no results # scannerGet returns an empty arrayref (instead of an undef) to indicate no results

View File

@ -1,5 +1,5 @@
#!/usr/bin/python #!/usr/bin/python
'''
Licensed to the Apache Software Foundation (ASF) under one Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file or more contributor license agreements. See the NOTICE file
distributed with this work for additional information distributed with this work for additional information
@ -48,11 +48,17 @@ def printRow(entry):
print k + " => " + entry.columns[k].value, print k + " => " + entry.columns[k].value,
print print
# Make socket
transport = TSocket.TSocket('localhost', 9090)
# Buffering is critical. Raw sockets are very slow def demo_client(host, port, is_framed_transport):
transport = TTransport.TBufferedTransport(transport)
# Make socket
socket = TSocket.TSocket(host, port)
# Make transport
if is_framed_transport:
transport = TTransport.TFramedTransport(socket)
else:
transport = TTransport.TBufferedTransport(socket)
# Wrap in a protocol # Wrap in a protocol
protocol = TBinaryProtocol.TBinaryProtocol(transport) protocol = TBinaryProtocol.TBinaryProtocol(transport)
@ -98,6 +104,8 @@ print "column families in %s" %(t)
for col_name in cols.keys(): for col_name in cols.keys():
col = cols[col_name] col = cols[col_name]
print " column: %s, maxVer: %d" % (col.name, col.maxVersions) print " column: %s, maxVer: %d" % (col.name, col.maxVersions)
dummy_attributes = {}
# #
# Test UTF-8 handling # Test UTF-8 handling
# #
@ -107,26 +115,26 @@ valid = "foo-\xE7\x94\x9F\xE3\x83\x93\xE3\x83\xBC\xE3\x83\xAB";
# non-utf8 is fine for data # non-utf8 is fine for data
mutations = [Mutation(column="entry:foo",value=invalid)] mutations = [Mutation(column="entry:foo",value=invalid)]
print str(mutations) print str(mutations)
client.mutateRow(t, "foo", mutations) client.mutateRow(t, "foo", mutations, dummy_attributes)
# try empty strings # try empty strings
mutations = [Mutation(column="entry:", value="")] mutations = [Mutation(column="entry:", value="")]
client.mutateRow(t, "", mutations) client.mutateRow(t, "", mutations, dummy_attributes)
# this row name is valid utf8 # this row name is valid utf8
mutations = [Mutation(column="entry:foo", value=valid)] mutations = [Mutation(column="entry:foo", value=valid)]
client.mutateRow(t, valid, mutations) client.mutateRow(t, valid, mutations, dummy_attributes)
# non-utf8 is not allowed in row names # non-utf8 is not allowed in row names
try: try:
mutations = [Mutation(column="entry:foo", value=invalid)] mutations = [Mutation(column="entry:foo", value=invalid)]
client.mutateRow(t, invalid, mutations) client.mutateRow(t, invalid, mutations, dummy_attributes)
except ttypes.IOError, e: except ttypes.IOError, e:
print 'expected exception: %s' %(e.message) print 'expected exception: %s' %(e.message)
# Run a scanner on the rows we just created # Run a scanner on the rows we just created
print "Starting scanner..." print "Starting scanner..."
scanner = client.scannerOpen(t, "", ["entry:"]) scanner = client.scannerOpen(t, "", ["entry:"], dummy_attributes)
r = client.scannerGet(scanner) r = client.scannerGet(scanner)
while r: while r:
@ -142,41 +150,39 @@ for e in range(100, 0, -1):
row = "%0.5d" % (e) row = "%0.5d" % (e)
mutations = [Mutation(column="unused:", value="DELETE_ME")] mutations = [Mutation(column="unused:", value="DELETE_ME")]
client.mutateRow(t, row, mutations) client.mutateRow(t, row, mutations, dummy_attributes)
printRow(client.getRow(t, row)[0]) printRow(client.getRow(t, row, dummy_attributes)[0])
client.deleteAllRow(t, row) client.deleteAllRow(t, row, dummy_attributes)
mutations = [Mutation(column="entry:num", value="0"), mutations = [Mutation(column="entry:num", value="0"),
Mutation(column="entry:foo", value="FOO")] Mutation(column="entry:foo", value="FOO")]
client.mutateRow(t, row, mutations) client.mutateRow(t, row, mutations, dummy_attributes)
printRow(client.getRow(t, row)[0]); printRow(client.getRow(t, row, dummy_attributes)[0]);
mutations = [Mutation(column="entry:foo",isDelete=True), mutations = [Mutation(column="entry:foo",isDelete=True),
Mutation(column="entry:num",value="-1")] Mutation(column="entry:num",value="-1")]
client.mutateRow(t, row, mutations) client.mutateRow(t, row, mutations, dummy_attributes)
printRow(client.getRow(t, row)[0]) printRow(client.getRow(t, row, dummy_attributes)[0])
mutations = [Mutation(column="entry:num", value=str(e)), mutations = [Mutation(column="entry:num", value=str(e)),
Mutation(column="entry:sqr", value=str(e*e))] Mutation(column="entry:sqr", value=str(e*e))]
client.mutateRow(t, row, mutations) client.mutateRow(t, row, mutations, dummy_attributes)
printRow(client.getRow(t, row)[0]) printRow(client.getRow(t, row, dummy_attributes)[0])
time.sleep(0.05) time.sleep(0.05)
mutations = [Mutation(column="entry:num",value="-999"), mutations = [Mutation(column="entry:num",value="-999"),
Mutation(column="entry:sqr",isDelete=True)] Mutation(column="entry:sqr",isDelete=True)]
client.mutateRowTs(t, row, mutations, 1) # shouldn't override latest client.mutateRowTs(t, row, mutations, 1, dummy_attributes) # shouldn't override latest
printRow(client.getRow(t, row)[0]) printRow(client.getRow(t, row, dummy_attributes)[0])
versions = client.getVer(t, row, "entry:num", 10) versions = client.getVer(t, row, "entry:num", 10, dummy_attributes)
printVersions(row, versions) printVersions(row, versions)
if len(versions) != 4: if len(versions) != 3:
print("FATAL: wrong # of versions") print("FATAL: wrong # of versions")
sys.exit(-1) sys.exit(-1)
r = client.get(t, row, "entry:foo") r = client.get(t, row, "entry:foo", dummy_attributes)
if not r:
print "yup, we didn't find entry:foo"
# just to be explicit, we get lists back, if it's empty there was no matching row. # just to be explicit, we get lists back, if it's empty there was no matching row.
if len(r) > 0: if len(r) > 0:
raise "shouldn't get here!" raise "shouldn't get here!"
@ -188,7 +194,7 @@ for (col, desc) in client.getColumnDescriptors(t).items():
columnNames.append(desc.name+":") columnNames.append(desc.name+":")
print "Starting scanner..." print "Starting scanner..."
scanner = client.scannerOpenWithStop(t, "00020", "00040", columnNames) scanner = client.scannerOpenWithStop(t, "00020", "00040", columnNames, dummy_attributes)
r = client.scannerGet(scanner) r = client.scannerGet(scanner)
while r: while r:
@ -199,3 +205,17 @@ client.scannerClose(scanner)
print "Scanner finished" print "Scanner finished"
transport.close() transport.close()
if __name__ == '__main__':
import sys
if len(sys.argv) < 3:
print 'usage: %s <host> <port>' % __file__
sys.exit(1)
host = sys.argv[1]
port = sys.argv[2]
is_framed_transport = False
demo_client(host, port, is_framed_transport)

View File

@ -88,6 +88,8 @@ client.getColumnDescriptors(t).sort.each do |key, col|
puts " column: #{col.name}, maxVer: #{col.maxVersions}" puts " column: #{col.name}, maxVer: #{col.maxVersions}"
end end
dummy_attributes = {}
# #
# Test UTF-8 handling # Test UTF-8 handling
# #
@ -100,7 +102,7 @@ m = Apache::Hadoop::Hbase::Thrift::Mutation.new
m.column = "entry:foo" m.column = "entry:foo"
m.value = invalid m.value = invalid
mutations << m mutations << m
client.mutateRow(t, "foo", mutations) client.mutateRow(t, "foo", mutations, dummy_attributes)
# try empty strings # try empty strings
mutations = [] mutations = []
@ -108,7 +110,7 @@ m = Apache::Hadoop::Hbase::Thrift::Mutation.new
m.column = "entry:" m.column = "entry:"
m.value = "" m.value = ""
mutations << m mutations << m
client.mutateRow(t, "", mutations) client.mutateRow(t, "", mutations, dummy_attributes)
# this row name is valid utf8 # this row name is valid utf8
mutations = [] mutations = []
@ -116,7 +118,7 @@ m = Apache::Hadoop::Hbase::Thrift::Mutation.new
m.column = "entry:foo" m.column = "entry:foo"
m.value = valid m.value = valid
mutations << m mutations << m
client.mutateRow(t, valid, mutations) client.mutateRow(t, valid, mutations, dummy_attributes)
# non-utf8 is not allowed in row names # non-utf8 is not allowed in row names
begin begin
@ -125,7 +127,7 @@ begin
m.column = "entry:foo" m.column = "entry:foo"
m.value = invalid m.value = invalid
mutations << m mutations << m
client.mutateRow(t, invalid, mutations) client.mutateRow(t, invalid, mutations, dummy_attributes)
raise "shouldn't get here!" raise "shouldn't get here!"
rescue Apache::Hadoop::Hbase::Thrift::IOError => e rescue Apache::Hadoop::Hbase::Thrift::IOError => e
puts "expected error: #{e.message}" puts "expected error: #{e.message}"
@ -133,7 +135,7 @@ end
# Run a scanner on the rows we just created # Run a scanner on the rows we just created
puts "Starting scanner..." puts "Starting scanner..."
scanner = client.scannerOpen(t, "", ["entry:"]) scanner = client.scannerOpen(t, "", ["entry:"], dummy_attributes)
begin begin
while (true) while (true)
printRow(client.scannerGet(scanner)) printRow(client.scannerGet(scanner))
@ -155,9 +157,9 @@ end
m.column = "unused:" m.column = "unused:"
m.value = "DELETE_ME" m.value = "DELETE_ME"
mutations << m mutations << m
client.mutateRow(t, row, mutations) client.mutateRow(t, row, mutations, dummy_attributes)
printRow(client.getRow(t, row)) printRow(client.getRow(t, row, dummy_attributes))
client.deleteAllRow(t, row) client.deleteAllRow(t, row, dummy_attributes)
mutations = [] mutations = []
m = Apache::Hadoop::Hbase::Thrift::Mutation.new m = Apache::Hadoop::Hbase::Thrift::Mutation.new
@ -168,8 +170,8 @@ end
m.column = "entry:foo" m.column = "entry:foo"
m.value = "FOO" m.value = "FOO"
mutations << m mutations << m
client.mutateRow(t, row, mutations) client.mutateRow(t, row, mutations, dummy_attributes)
printRow(client.getRow(t, row)) printRow(client.getRow(t, row, dummy_attributes))
mutations = [] mutations = []
m = Apache::Hadoop::Hbase::Thrift::Mutation.new m = Apache::Hadoop::Hbase::Thrift::Mutation.new
@ -180,8 +182,8 @@ end
m.column = "entry:num" m.column = "entry:num"
m.value = "-1" m.value = "-1"
mutations << m mutations << m
client.mutateRow(t, row, mutations) client.mutateRow(t, row, mutations, dummy_attributes)
printRow(client.getRow(t, row)); printRow(client.getRow(t, row, dummy_attributes));
mutations = [] mutations = []
m = Apache::Hadoop::Hbase::Thrift::Mutation.new m = Apache::Hadoop::Hbase::Thrift::Mutation.new
@ -192,8 +194,8 @@ end
m.column = "entry:sqr" m.column = "entry:sqr"
m.value = (e*e).to_s m.value = (e*e).to_s
mutations << m mutations << m
client.mutateRow(t, row, mutations) client.mutateRow(t, row, mutations, dummy_attributes, dummy_attributes)
printRow(client.getRow(t, row)) printRow(client.getRow(t, row, dummy_attributes))
mutations = [] mutations = []
m = Apache::Hadoop::Hbase::Thrift::Mutation.new m = Apache::Hadoop::Hbase::Thrift::Mutation.new
@ -204,10 +206,10 @@ end
m.column = "entry:sqr" m.column = "entry:sqr"
m.isDelete = 1 m.isDelete = 1
mutations << m mutations << m
client.mutateRowTs(t, row, mutations, 1) # shouldn't override latest client.mutateRowTs(t, row, mutations, 1, dummy_attributes) # shouldn't override latest
printRow(client.getRow(t, row)); printRow(client.getRow(t, row, dummy_attributes, dummy_attributes));
versions = client.getVer(t, row, "entry:num", 10) versions = client.getVer(t, row, "entry:num", 10, dummy_attributes)
print "row: #{row}, values: " print "row: #{row}, values: "
versions.each do |v| versions.each do |v|
print "#{v.value}; " print "#{v.value}; "
@ -215,7 +217,7 @@ end
puts "" puts ""
begin begin
client.get(t, row, "entry:foo") client.get(t, row, "entry:foo", dummy_attributes)
raise "shouldn't get here!" raise "shouldn't get here!"
rescue Apache::Hadoop::Hbase::Thrift::NotFound => nf rescue Apache::Hadoop::Hbase::Thrift::NotFound => nf
# blank # blank
@ -231,10 +233,10 @@ client.getColumnDescriptors(t).each do |col, desc|
end end
puts "Starting scanner..." puts "Starting scanner..."
scanner = client.scannerOpenWithStop(t, "00020", "00040", columns) scanner = client.scannerOpenWithStop(t, "00020", "00040", columns, dummy_attributes)
begin begin
while (true) while (true)
printRow(client.scannerGet(scanner)) printRow(client.scannerGet(scanner, dummy_attributes))
end end
rescue Apache::Hadoop::Hbase::Thrift::NotFound => nf rescue Apache::Hadoop::Hbase::Thrift::NotFound => nf
client.scannerClose(scanner) client.scannerClose(scanner)

View File

@ -29,7 +29,7 @@ GEN_SRC = ./gen-cpp/Hbase.cpp \
default: DemoClient default: DemoClient
DemoClient: DemoClient.cpp DemoClient: DemoClient.cpp
g++ -o DemoClient -I${THRIFT_DIR} -I./gen-cpp -L${LIB_DIR} -lthrift DemoClient.cpp ${GEN_SRC} g++ -o DemoClient -I${THRIFT_DIR} -I./gen-cpp -L${LIB_DIR} -Wl,-rpath,${LIB_DIR} -lthrift DemoClient.cpp ${GEN_SRC}
clean: clean:
rm -rf DemoClient rm -rf DemoClient