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:
parent
061fda6ae1
commit
7c9d6f3440
|
@ -88,12 +88,19 @@ main(int argc, char** argv)
|
|||
std::cerr << "Invalid arguments!\n" << "Usage: DemoClient host port" << std::endl;
|
||||
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])));
|
||||
boost::shared_ptr<TTransport> transport(new TBufferedTransport(socket));
|
||||
if (isFramed) {
|
||||
transport.reset(new TFramedTransport(socket));
|
||||
} else {
|
||||
transport.reset(new TBufferedTransport(socket));
|
||||
}
|
||||
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 {
|
||||
transport->open();
|
||||
|
||||
|
@ -152,35 +159,35 @@ main(int argc, char** argv)
|
|||
mutations.push_back(Mutation());
|
||||
mutations.back().column = "entry:foo";
|
||||
mutations.back().value = invalid;
|
||||
client.mutateRow(t, "foo", mutations);
|
||||
client.mutateRow(t, "foo", mutations, dummyAttributes);
|
||||
|
||||
// try empty strings
|
||||
mutations.clear();
|
||||
mutations.push_back(Mutation());
|
||||
mutations.back().column = "entry:";
|
||||
mutations.back().value = "";
|
||||
client.mutateRow(t, "", mutations);
|
||||
client.mutateRow(t, "", mutations, dummyAttributes);
|
||||
|
||||
// this row name is valid utf8
|
||||
mutations.clear();
|
||||
mutations.push_back(Mutation());
|
||||
mutations.back().column = "entry:foo";
|
||||
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
|
||||
mutations.clear();
|
||||
mutations.push_back(Mutation());
|
||||
mutations.back().column = "entry:foo";
|
||||
mutations.back().value = invalid;
|
||||
client.mutateRow(t, invalid, mutations);
|
||||
client.mutateRow(t, invalid, mutations, dummyAttributes);
|
||||
|
||||
// Run a scanner on the rows we just created
|
||||
StrVec columnNames;
|
||||
columnNames.push_back("entry:");
|
||||
|
||||
std::cout << "Starting scanner..." << std::endl;
|
||||
int scanner = client.scannerOpen(t, "", columnNames);
|
||||
int scanner = client.scannerOpen(t, "", columnNames, dummyAttributes);
|
||||
try {
|
||||
while (true) {
|
||||
std::vector<TRowResult> value;
|
||||
|
@ -210,10 +217,10 @@ main(int argc, char** argv)
|
|||
mutations.push_back(Mutation());
|
||||
mutations.back().column = "unused:";
|
||||
mutations.back().value = "DELETE_ME";
|
||||
client.mutateRow(t, row, mutations);
|
||||
client.getRow(rowResult, t, row);
|
||||
client.mutateRow(t, row, mutations, dummyAttributes);
|
||||
client.getRow(rowResult, t, row, dummyAttributes);
|
||||
printRow(rowResult);
|
||||
client.deleteAllRow(t, row);
|
||||
client.deleteAllRow(t, row, dummyAttributes);
|
||||
|
||||
mutations.clear();
|
||||
mutations.push_back(Mutation());
|
||||
|
@ -222,8 +229,8 @@ main(int argc, char** argv)
|
|||
mutations.push_back(Mutation());
|
||||
mutations.back().column = "entry:foo";
|
||||
mutations.back().value = "FOO";
|
||||
client.mutateRow(t, row, mutations);
|
||||
client.getRow(rowResult, t, row);
|
||||
client.mutateRow(t, row, mutations, dummyAttributes);
|
||||
client.getRow(rowResult, t, row, dummyAttributes);
|
||||
printRow(rowResult);
|
||||
|
||||
// sleep to force later timestamp
|
||||
|
@ -236,8 +243,8 @@ main(int argc, char** argv)
|
|||
mutations.push_back(Mutation());
|
||||
mutations.back().column = "entry:num";
|
||||
mutations.back().value = "-1";
|
||||
client.mutateRow(t, row, mutations);
|
||||
client.getRow(rowResult, t, row);
|
||||
client.mutateRow(t, row, mutations, dummyAttributes);
|
||||
client.getRow(rowResult, t, row, dummyAttributes);
|
||||
printRow(rowResult);
|
||||
|
||||
mutations.clear();
|
||||
|
@ -247,8 +254,8 @@ main(int argc, char** argv)
|
|||
mutations.push_back(Mutation());
|
||||
mutations.back().column = "entry:sqr";
|
||||
mutations.back().value = boost::lexical_cast<std::string>(i*i);
|
||||
client.mutateRow(t, row, mutations);
|
||||
client.getRow(rowResult, t, row);
|
||||
client.mutateRow(t, row, mutations, dummyAttributes);
|
||||
client.getRow(rowResult, t, row, dummyAttributes);
|
||||
printRow(rowResult);
|
||||
|
||||
mutations.clear();
|
||||
|
@ -258,19 +265,19 @@ main(int argc, char** argv)
|
|||
mutations.push_back(Mutation());
|
||||
mutations.back().column = "entry:sqr";
|
||||
mutations.back().isDelete = true;
|
||||
client.mutateRowTs(t, row, mutations, 1); // shouldn't override latest
|
||||
client.getRow(rowResult, t, row);
|
||||
client.mutateRowTs(t, row, mutations, 1, dummyAttributes); // shouldn't override latest
|
||||
client.getRow(rowResult, t, row, dummyAttributes);
|
||||
printRow(rowResult);
|
||||
|
||||
CellVec versions;
|
||||
client.getVer(versions, t, row, "entry:num", 10);
|
||||
client.getVer(versions, t, row, "entry:num", 10, dummyAttributes);
|
||||
printVersions(row, versions);
|
||||
assert(versions.size());
|
||||
std::cout << std::endl;
|
||||
|
||||
try {
|
||||
std::vector<TCell> value;
|
||||
client.get(value, t, row, "entry:foo");
|
||||
client.get(value, t, row, "entry:foo", dummyAttributes);
|
||||
if (value.size()) {
|
||||
std::cerr << "FATAL: shouldn't get here!" << std::endl;
|
||||
return -1;
|
||||
|
@ -292,7 +299,7 @@ main(int argc, char** argv)
|
|||
std::cout << std::endl;
|
||||
|
||||
std::cout << "Starting scanner..." << std::endl;
|
||||
scanner = client.scannerOpenWithStop(t, "00020", "00040", columnNames);
|
||||
scanner = client.scannerOpenWithStop(t, "00020", "00040", columnNames, dummyAttributes);
|
||||
try {
|
||||
while (true) {
|
||||
std::vector<TRowResult> value;
|
||||
|
|
|
@ -163,6 +163,9 @@ public class DemoClient {
|
|||
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
|
||||
//
|
||||
|
@ -172,25 +175,25 @@ public class DemoClient {
|
|||
ArrayList<Mutation> mutations;
|
||||
// non-utf8 is fine for data
|
||||
mutations = new ArrayList<Mutation>();
|
||||
mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:foo")), ByteBuffer.wrap(invalid)));
|
||||
client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(bytes("foo")), mutations);
|
||||
mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:foo")), ByteBuffer.wrap(invalid), writeToWal));
|
||||
client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(bytes("foo")), mutations, dummyAttributes);
|
||||
|
||||
// try empty strings
|
||||
mutations = new ArrayList<Mutation>();
|
||||
mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:")), ByteBuffer.wrap(bytes(""))));
|
||||
client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(bytes("")), mutations);
|
||||
mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:")), ByteBuffer.wrap(bytes("")), writeToWal));
|
||||
client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(bytes("")), mutations, dummyAttributes);
|
||||
|
||||
// this row name is valid utf8
|
||||
mutations = new ArrayList<Mutation>();
|
||||
mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:foo")), ByteBuffer.wrap(valid)));
|
||||
client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(valid), mutations);
|
||||
mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:foo")), ByteBuffer.wrap(valid), writeToWal));
|
||||
client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(valid), mutations, dummyAttributes);
|
||||
|
||||
// non-utf8 is now allowed in row names because HBase stores values as binary
|
||||
ByteBuffer bf = ByteBuffer.wrap(invalid);
|
||||
|
||||
mutations = new ArrayList<Mutation>();
|
||||
mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:foo")), ByteBuffer.wrap(invalid)));
|
||||
client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(invalid), mutations);
|
||||
mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:foo")), ByteBuffer.wrap(invalid), writeToWal));
|
||||
client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(invalid), mutations, dummyAttributes);
|
||||
|
||||
|
||||
// Run a scanner on the rows we just created
|
||||
|
@ -198,7 +201,7 @@ public class DemoClient {
|
|||
columnNames.add(ByteBuffer.wrap(bytes("entry:")));
|
||||
|
||||
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) {
|
||||
List<TRowResult> entry = client.scannerGet(scanner);
|
||||
|
@ -219,16 +222,16 @@ public class DemoClient {
|
|||
byte[] row = bytes(nf.format(i));
|
||||
|
||||
mutations = new ArrayList<Mutation>();
|
||||
mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("unused:")), ByteBuffer.wrap(bytes("DELETE_ME"))));
|
||||
client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), mutations);
|
||||
printRow(client.getRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row)));
|
||||
client.deleteAllRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row));
|
||||
mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("unused:")), ByteBuffer.wrap(bytes("DELETE_ME")), writeToWal));
|
||||
client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), mutations, dummyAttributes);
|
||||
printRow(client.getRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), dummyAttributes));
|
||||
client.deleteAllRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), dummyAttributes);
|
||||
|
||||
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:foo")), ByteBuffer.wrap(bytes("FOO"))));
|
||||
client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), mutations);
|
||||
printRow(client.getRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row)));
|
||||
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")), writeToWal));
|
||||
client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), mutations, dummyAttributes);
|
||||
printRow(client.getRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), dummyAttributes));
|
||||
|
||||
Mutation m = null;
|
||||
mutations = new ArrayList<Mutation>();
|
||||
|
@ -240,14 +243,14 @@ public class DemoClient {
|
|||
m.column = ByteBuffer.wrap(bytes("entry:num"));
|
||||
m.value = ByteBuffer.wrap(bytes("-1"));
|
||||
mutations.add(m);
|
||||
client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), mutations);
|
||||
printRow(client.getRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row)));
|
||||
client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), mutations, dummyAttributes);
|
||||
printRow(client.getRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), dummyAttributes));
|
||||
|
||||
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:sqr")), ByteBuffer.wrap(bytes(Integer.toString(i * i)))));
|
||||
client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), mutations);
|
||||
printRow(client.getRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row)));
|
||||
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))), writeToWal));
|
||||
client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), mutations, dummyAttributes);
|
||||
printRow(client.getRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), dummyAttributes));
|
||||
|
||||
// sleep to force later timestamp
|
||||
try {
|
||||
|
@ -264,10 +267,10 @@ public class DemoClient {
|
|||
m = new Mutation();
|
||||
m.column = ByteBuffer.wrap(bytes("entry:sqr"));
|
||||
m.isDelete = true;
|
||||
client.mutateRowTs(ByteBuffer.wrap(t), ByteBuffer.wrap(row), mutations, 1); // shouldn't override latest
|
||||
printRow(client.getRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row)));
|
||||
client.mutateRowTs(ByteBuffer.wrap(t), ByteBuffer.wrap(row), mutations, 1, dummyAttributes); // shouldn't override latest
|
||||
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);
|
||||
if (versions.isEmpty()) {
|
||||
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) {
|
||||
System.out.println("FATAL: shouldn't get here");
|
||||
System.exit(-1);
|
||||
|
@ -295,8 +298,7 @@ public class DemoClient {
|
|||
}
|
||||
|
||||
System.out.println("Starting scanner...");
|
||||
scanner = client.scannerOpenWithStop(ByteBuffer.wrap(t), ByteBuffer.wrap(bytes("00020")), ByteBuffer.wrap(bytes("00040")),
|
||||
columnNames);
|
||||
scanner = client.scannerOpenWithStop(ByteBuffer.wrap(t), ByteBuffer.wrap(bytes("00020")), ByteBuffer.wrap(bytes("00040")), columnNames, dummyAttributes);
|
||||
|
||||
while (true) {
|
||||
List<TRowResult> entry = client.scannerGet(scanner);
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
# Instructions:
|
||||
# 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.
|
||||
# 3. Execute {php DemoClient.php}. Note that you must use php5 or higher.
|
||||
# 4. See {$THRIFT_HOME}/lib/php/README for additional help.
|
||||
|
@ -112,7 +112,7 @@ asort( $descriptors );
|
|||
foreach ( $descriptors as $col ) {
|
||||
echo( " column: {$col->name}, maxVer: {$col->maxVersions}\n" );
|
||||
}
|
||||
|
||||
$dummy_attributes = array();
|
||||
#
|
||||
# Test UTF-8 handling
|
||||
#
|
||||
|
@ -126,7 +126,7 @@ $mutations = array(
|
|||
'value' => $invalid
|
||||
) ),
|
||||
);
|
||||
$client->mutateRow( $t, "foo", $mutations );
|
||||
$client->mutateRow( $t, "foo", $mutations, $dummy_attributes );
|
||||
|
||||
# try empty strings
|
||||
$mutations = array(
|
||||
|
@ -135,7 +135,7 @@ $mutations = array(
|
|||
'value' => ""
|
||||
) ),
|
||||
);
|
||||
$client->mutateRow( $t, "", $mutations );
|
||||
$client->mutateRow( $t, "", $mutations, $dummy_attributes );
|
||||
|
||||
# this row name is valid utf8
|
||||
$mutations = array(
|
||||
|
@ -144,7 +144,7 @@ $mutations = array(
|
|||
'value' => $valid
|
||||
) ),
|
||||
);
|
||||
$client->mutateRow( $t, $valid, $mutations );
|
||||
$client->mutateRow( $t, $valid, $mutations, $dummy_attributes );
|
||||
|
||||
# non-utf8 is not allowed in row names
|
||||
try {
|
||||
|
@ -154,7 +154,7 @@ try {
|
|||
'value' => $invalid
|
||||
) ),
|
||||
);
|
||||
$client->mutateRow( $t, $invalid, $mutations );
|
||||
$client->mutateRow( $t, $invalid, $mutations, $dummy_attributes );
|
||||
throw new Exception( "shouldn't get here!" );
|
||||
} catch ( IOError $e ) {
|
||||
echo( "expected error: {$e->message}\n" );
|
||||
|
@ -162,7 +162,7 @@ try {
|
|||
|
||||
# Run a scanner on the rows we just created
|
||||
echo( "Starting scanner...\n" );
|
||||
$scanner = $client->scannerOpen( $t, "", array( "entry:" ) );
|
||||
$scanner = $client->scannerOpen( $t, "", array( "entry:" ), $dummy_attributes );
|
||||
try {
|
||||
while (true) printRow( $client->scannerGet( $scanner ) );
|
||||
} catch ( NotFound $nf ) {
|
||||
|
@ -184,9 +184,9 @@ for ($e=100; $e>=0; $e--) {
|
|||
'value' => "DELETE_ME"
|
||||
) ),
|
||||
);
|
||||
$client->mutateRow( $t, $row, $mutations);
|
||||
printRow( $client->getRow( $t, $row ));
|
||||
$client->deleteAllRow( $t, $row );
|
||||
$client->mutateRow( $t, $row, $mutations, $dummy_attributes );
|
||||
printRow( $client->getRow( $t, $row, $dummy_attributes ));
|
||||
$client->deleteAllRow( $t, $row, $dummy_attributes );
|
||||
|
||||
$mutations = array(
|
||||
new Mutation( array(
|
||||
|
@ -198,8 +198,8 @@ for ($e=100; $e>=0; $e--) {
|
|||
'value' => "FOO"
|
||||
) ),
|
||||
);
|
||||
$client->mutateRow( $t, $row, $mutations );
|
||||
printRow( $client->getRow( $t, $row ));
|
||||
$client->mutateRow( $t, $row, $mutations, $dummy_attributes );
|
||||
printRow( $client->getRow( $t, $row, $dummy_attributes ));
|
||||
|
||||
$mutations = array(
|
||||
new Mutation( array(
|
||||
|
@ -211,8 +211,8 @@ for ($e=100; $e>=0; $e--) {
|
|||
'value' => '-1'
|
||||
) ),
|
||||
);
|
||||
$client->mutateRow( $t, $row, $mutations );
|
||||
printRow( $client->getRow( $t, $row ) );
|
||||
$client->mutateRow( $t, $row, $mutations, $dummy_attributes );
|
||||
printRow( $client->getRow( $t, $row, $dummy_attributes ) );
|
||||
|
||||
$mutations = array(
|
||||
new Mutation( array(
|
||||
|
@ -224,8 +224,8 @@ for ($e=100; $e>=0; $e--) {
|
|||
'value' => $e * $e
|
||||
) ),
|
||||
);
|
||||
$client->mutateRow( $t, $row, $mutations );
|
||||
printRow( $client->getRow( $t, $row ));
|
||||
$client->mutateRow( $t, $row, $mutations, $dummy_attributes );
|
||||
printRow( $client->getRow( $t, $row, $dummy_attributes ));
|
||||
|
||||
$mutations = array(
|
||||
new Mutation( array(
|
||||
|
@ -237,15 +237,15 @@ for ($e=100; $e>=0; $e--) {
|
|||
'isDelete' => 1
|
||||
) ),
|
||||
);
|
||||
$client->mutateRowTs( $t, $row, $mutations, 1 ); # shouldn't override latest
|
||||
printRow( $client->getRow( $t, $row ) );
|
||||
$client->mutateRowTs( $t, $row, $mutations, 1, $dummy_attributes ); # shouldn't override latest
|
||||
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" );
|
||||
foreach ( $versions as $v ) echo( " {$v->value};\n" );
|
||||
|
||||
try {
|
||||
$client->get( $t, $row, "entry:foo");
|
||||
$client->get( $t, $row, "entry:foo", $dummy_attributes );
|
||||
throw new Exception ( "shouldn't get here! " );
|
||||
} catch ( NotFound $nf ) {
|
||||
# blank
|
||||
|
@ -260,7 +260,7 @@ foreach ( $client->getColumnDescriptors($t) as $col=>$desc ) {
|
|||
}
|
||||
|
||||
echo( "Starting scanner...\n" );
|
||||
$scanner = $client->scannerOpenWithStop( $t, "00020", "00040", $columns );
|
||||
$scanner = $client->scannerOpenWithStop( $t, "00020", "00040", $columns, $dummy_attributes );
|
||||
try {
|
||||
while (true) printRow( $client->scannerGet( $scanner ) );
|
||||
} catch ( NotFound $nf ) {
|
||||
|
|
|
@ -123,6 +123,8 @@ foreach my $col (sort keys %{$descriptors})
|
|||
printf (" column: {%s}, maxVer: {%s}\n", $descriptors->{$col}->{name}, $descriptors->{$col}->{maxVersions} );
|
||||
}
|
||||
|
||||
my %dummy_attributes = ();
|
||||
|
||||
#
|
||||
# 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
|
||||
my $key = "foo";
|
||||
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
|
||||
$key = "";
|
||||
$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
|
||||
$key = "foo";
|
||||
|
@ -146,13 +148,13 @@ my $mutation = Hbase::Mutation->new ();
|
|||
$mutation->{column} = "entry:$key";
|
||||
$mutation->{value} = $valid;
|
||||
$mutations = [ $mutation ];
|
||||
$client->mutateRow ( $demo_table, $key, $mutations );
|
||||
$client->mutateRow ( $demo_table, $key, $mutations, %dummy_attributes );
|
||||
|
||||
# non-utf8 is not allowed in row names
|
||||
eval {
|
||||
$mutations = [ Hbase::Mutation->new ( { column => "entry:$key", value => $invalid } ) ];
|
||||
# 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!");
|
||||
};
|
||||
if ($@)
|
||||
|
@ -168,7 +170,7 @@ $key = "";
|
|||
# scannerOpen expects ( table, key, <column descriptors> )
|
||||
# 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
|
||||
my $scanner = $client->scannerOpen ( $demo_table, $key, [ "entry:" ] );
|
||||
my $scanner = $client->scannerOpen ( $demo_table, $key, [ "entry:" ], %dummy_attributes );
|
||||
eval {
|
||||
|
||||
# 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);
|
||||
|
||||
$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 ) );
|
||||
$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:foo", value => "FOO" } ),
|
||||
];
|
||||
$client->mutateRow ( $demo_table, $row, $mutations );
|
||||
printRow ( $client->getRow ( $demo_table, $row ) );
|
||||
$client->mutateRow ( $demo_table, $row, $mutations, %dummy_attributes );
|
||||
printRow ( $client->getRow ( $demo_table, $row, %dummy_attributes ) );
|
||||
|
||||
$mutations = [
|
||||
Hbase::Mutation->new ( { column => "entry:foo", isDelete => 1 } ),
|
||||
Hbase::Mutation->new ( { column => "entry:num", value => -1 } ),
|
||||
];
|
||||
$client->mutateRow ( $demo_table, $row, $mutations );
|
||||
printRow ( $client->getRow ( $demo_table, $row ) );
|
||||
$client->mutateRow ( $demo_table, $row, $mutations, %dummy_attributes );
|
||||
printRow ( $client->getRow ( $demo_table, $row, %dummy_attributes ) );
|
||||
|
||||
$mutations = [
|
||||
Hbase::Mutation->new ( { column => "entry:num", value => $e } ),
|
||||
Hbase::Mutation->new ( { column => "entry:sqr", value => $e * $e } ),
|
||||
];
|
||||
$client->mutateRow ( $demo_table, $row, $mutations );
|
||||
printRow ( $client->getRow ( $demo_table, $row ) );
|
||||
$client->mutateRow ( $demo_table, $row, $mutations, %dummy_attributes );
|
||||
printRow ( $client->getRow ( $demo_table, $row, %dummy_attributes ) );
|
||||
|
||||
$mutations = [
|
||||
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)
|
||||
$client->mutateRowTs ( $demo_table, $row, $mutations, 1 ); # shouldn't override latest
|
||||
printRow ( $client->getRow ( $demo_table, $row ) );
|
||||
$client->mutateRowTs ( $demo_table, $row, $mutations, 1, %dummy_attributes ); # shouldn't override latest
|
||||
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 );
|
||||
foreach my $v ( @{$versions} )
|
||||
{
|
||||
|
@ -240,7 +242,7 @@ for (my $e = 100; $e > 0; $e--)
|
|||
|
||||
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
|
||||
# to signify a "not found", which makes it slightly inconvenient.
|
||||
|
@ -267,7 +269,7 @@ foreach my $col ( keys %{$column_descriptor} )
|
|||
}
|
||||
|
||||
print "Starting scanner...\n";
|
||||
$scanner = $client->scannerOpenWithStop ( $demo_table, "00020", "00040", $columns );
|
||||
$scanner = $client->scannerOpenWithStop ( $demo_table, "00020", "00040", $columns, %dummy_attributes );
|
||||
eval {
|
||||
|
||||
# scannerGet returns an empty arrayref (instead of an undef) to indicate no results
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
'''
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
|
@ -48,11 +48,17 @@ def printRow(entry):
|
|||
print k + " => " + entry.columns[k].value,
|
||||
print
|
||||
|
||||
# Make socket
|
||||
transport = TSocket.TSocket('localhost', 9090)
|
||||
|
||||
# Buffering is critical. Raw sockets are very slow
|
||||
transport = TTransport.TBufferedTransport(transport)
|
||||
def demo_client(host, port, is_framed_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
|
||||
protocol = TBinaryProtocol.TBinaryProtocol(transport)
|
||||
|
@ -98,6 +104,8 @@ print "column families in %s" %(t)
|
|||
for col_name in cols.keys():
|
||||
col = cols[col_name]
|
||||
print " column: %s, maxVer: %d" % (col.name, col.maxVersions)
|
||||
|
||||
dummy_attributes = {}
|
||||
#
|
||||
# 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
|
||||
mutations = [Mutation(column="entry:foo",value=invalid)]
|
||||
print str(mutations)
|
||||
client.mutateRow(t, "foo", mutations)
|
||||
client.mutateRow(t, "foo", mutations, dummy_attributes)
|
||||
|
||||
# try empty strings
|
||||
mutations = [Mutation(column="entry:", value="")]
|
||||
client.mutateRow(t, "", mutations)
|
||||
client.mutateRow(t, "", mutations, dummy_attributes)
|
||||
|
||||
# this row name is valid utf8
|
||||
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
|
||||
try:
|
||||
mutations = [Mutation(column="entry:foo", value=invalid)]
|
||||
client.mutateRow(t, invalid, mutations)
|
||||
client.mutateRow(t, invalid, mutations, dummy_attributes)
|
||||
except ttypes.IOError, e:
|
||||
print 'expected exception: %s' %(e.message)
|
||||
|
||||
# Run a scanner on the rows we just created
|
||||
print "Starting scanner..."
|
||||
scanner = client.scannerOpen(t, "", ["entry:"])
|
||||
scanner = client.scannerOpen(t, "", ["entry:"], dummy_attributes)
|
||||
|
||||
r = client.scannerGet(scanner)
|
||||
while r:
|
||||
|
@ -142,41 +150,39 @@ for e in range(100, 0, -1):
|
|||
row = "%0.5d" % (e)
|
||||
|
||||
mutations = [Mutation(column="unused:", value="DELETE_ME")]
|
||||
client.mutateRow(t, row, mutations)
|
||||
printRow(client.getRow(t, row)[0])
|
||||
client.deleteAllRow(t, row)
|
||||
client.mutateRow(t, row, mutations, dummy_attributes)
|
||||
printRow(client.getRow(t, row, dummy_attributes)[0])
|
||||
client.deleteAllRow(t, row, dummy_attributes)
|
||||
|
||||
mutations = [Mutation(column="entry:num", value="0"),
|
||||
Mutation(column="entry:foo", value="FOO")]
|
||||
client.mutateRow(t, row, mutations)
|
||||
printRow(client.getRow(t, row)[0]);
|
||||
client.mutateRow(t, row, mutations, dummy_attributes)
|
||||
printRow(client.getRow(t, row, dummy_attributes)[0]);
|
||||
|
||||
mutations = [Mutation(column="entry:foo",isDelete=True),
|
||||
Mutation(column="entry:num",value="-1")]
|
||||
client.mutateRow(t, row, mutations)
|
||||
printRow(client.getRow(t, row)[0])
|
||||
client.mutateRow(t, row, mutations, dummy_attributes)
|
||||
printRow(client.getRow(t, row, dummy_attributes)[0])
|
||||
|
||||
mutations = [Mutation(column="entry:num", value=str(e)),
|
||||
Mutation(column="entry:sqr", value=str(e*e))]
|
||||
client.mutateRow(t, row, mutations)
|
||||
printRow(client.getRow(t, row)[0])
|
||||
client.mutateRow(t, row, mutations, dummy_attributes)
|
||||
printRow(client.getRow(t, row, dummy_attributes)[0])
|
||||
|
||||
time.sleep(0.05)
|
||||
|
||||
mutations = [Mutation(column="entry:num",value="-999"),
|
||||
Mutation(column="entry:sqr",isDelete=True)]
|
||||
client.mutateRowTs(t, row, mutations, 1) # shouldn't override latest
|
||||
printRow(client.getRow(t, row)[0])
|
||||
client.mutateRowTs(t, row, mutations, 1, dummy_attributes) # shouldn't override latest
|
||||
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)
|
||||
if len(versions) != 4:
|
||||
if len(versions) != 3:
|
||||
print("FATAL: wrong # of versions")
|
||||
sys.exit(-1)
|
||||
|
||||
r = client.get(t, row, "entry:foo")
|
||||
if not r:
|
||||
print "yup, we didn't find entry:foo"
|
||||
r = client.get(t, row, "entry:foo", dummy_attributes)
|
||||
# just to be explicit, we get lists back, if it's empty there was no matching row.
|
||||
if len(r) > 0:
|
||||
raise "shouldn't get here!"
|
||||
|
@ -188,7 +194,7 @@ for (col, desc) in client.getColumnDescriptors(t).items():
|
|||
columnNames.append(desc.name+":")
|
||||
|
||||
print "Starting scanner..."
|
||||
scanner = client.scannerOpenWithStop(t, "00020", "00040", columnNames)
|
||||
scanner = client.scannerOpenWithStop(t, "00020", "00040", columnNames, dummy_attributes)
|
||||
|
||||
r = client.scannerGet(scanner)
|
||||
while r:
|
||||
|
@ -199,3 +205,17 @@ client.scannerClose(scanner)
|
|||
print "Scanner finished"
|
||||
|
||||
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)
|
||||
|
||||
|
|
|
@ -88,6 +88,8 @@ client.getColumnDescriptors(t).sort.each do |key, col|
|
|||
puts " column: #{col.name}, maxVer: #{col.maxVersions}"
|
||||
end
|
||||
|
||||
dummy_attributes = {}
|
||||
|
||||
#
|
||||
# Test UTF-8 handling
|
||||
#
|
||||
|
@ -100,7 +102,7 @@ m = Apache::Hadoop::Hbase::Thrift::Mutation.new
|
|||
m.column = "entry:foo"
|
||||
m.value = invalid
|
||||
mutations << m
|
||||
client.mutateRow(t, "foo", mutations)
|
||||
client.mutateRow(t, "foo", mutations, dummy_attributes)
|
||||
|
||||
# try empty strings
|
||||
mutations = []
|
||||
|
@ -108,7 +110,7 @@ m = Apache::Hadoop::Hbase::Thrift::Mutation.new
|
|||
m.column = "entry:"
|
||||
m.value = ""
|
||||
mutations << m
|
||||
client.mutateRow(t, "", mutations)
|
||||
client.mutateRow(t, "", mutations, dummy_attributes)
|
||||
|
||||
# this row name is valid utf8
|
||||
mutations = []
|
||||
|
@ -116,7 +118,7 @@ m = Apache::Hadoop::Hbase::Thrift::Mutation.new
|
|||
m.column = "entry:foo"
|
||||
m.value = valid
|
||||
mutations << m
|
||||
client.mutateRow(t, valid, mutations)
|
||||
client.mutateRow(t, valid, mutations, dummy_attributes)
|
||||
|
||||
# non-utf8 is not allowed in row names
|
||||
begin
|
||||
|
@ -125,7 +127,7 @@ begin
|
|||
m.column = "entry:foo"
|
||||
m.value = invalid
|
||||
mutations << m
|
||||
client.mutateRow(t, invalid, mutations)
|
||||
client.mutateRow(t, invalid, mutations, dummy_attributes)
|
||||
raise "shouldn't get here!"
|
||||
rescue Apache::Hadoop::Hbase::Thrift::IOError => e
|
||||
puts "expected error: #{e.message}"
|
||||
|
@ -133,7 +135,7 @@ end
|
|||
|
||||
# Run a scanner on the rows we just created
|
||||
puts "Starting scanner..."
|
||||
scanner = client.scannerOpen(t, "", ["entry:"])
|
||||
scanner = client.scannerOpen(t, "", ["entry:"], dummy_attributes)
|
||||
begin
|
||||
while (true)
|
||||
printRow(client.scannerGet(scanner))
|
||||
|
@ -155,9 +157,9 @@ end
|
|||
m.column = "unused:"
|
||||
m.value = "DELETE_ME"
|
||||
mutations << m
|
||||
client.mutateRow(t, row, mutations)
|
||||
printRow(client.getRow(t, row))
|
||||
client.deleteAllRow(t, row)
|
||||
client.mutateRow(t, row, mutations, dummy_attributes)
|
||||
printRow(client.getRow(t, row, dummy_attributes))
|
||||
client.deleteAllRow(t, row, dummy_attributes)
|
||||
|
||||
mutations = []
|
||||
m = Apache::Hadoop::Hbase::Thrift::Mutation.new
|
||||
|
@ -168,8 +170,8 @@ end
|
|||
m.column = "entry:foo"
|
||||
m.value = "FOO"
|
||||
mutations << m
|
||||
client.mutateRow(t, row, mutations)
|
||||
printRow(client.getRow(t, row))
|
||||
client.mutateRow(t, row, mutations, dummy_attributes)
|
||||
printRow(client.getRow(t, row, dummy_attributes))
|
||||
|
||||
mutations = []
|
||||
m = Apache::Hadoop::Hbase::Thrift::Mutation.new
|
||||
|
@ -180,8 +182,8 @@ end
|
|||
m.column = "entry:num"
|
||||
m.value = "-1"
|
||||
mutations << m
|
||||
client.mutateRow(t, row, mutations)
|
||||
printRow(client.getRow(t, row));
|
||||
client.mutateRow(t, row, mutations, dummy_attributes)
|
||||
printRow(client.getRow(t, row, dummy_attributes));
|
||||
|
||||
mutations = []
|
||||
m = Apache::Hadoop::Hbase::Thrift::Mutation.new
|
||||
|
@ -192,8 +194,8 @@ end
|
|||
m.column = "entry:sqr"
|
||||
m.value = (e*e).to_s
|
||||
mutations << m
|
||||
client.mutateRow(t, row, mutations)
|
||||
printRow(client.getRow(t, row))
|
||||
client.mutateRow(t, row, mutations, dummy_attributes, dummy_attributes)
|
||||
printRow(client.getRow(t, row, dummy_attributes))
|
||||
|
||||
mutations = []
|
||||
m = Apache::Hadoop::Hbase::Thrift::Mutation.new
|
||||
|
@ -204,10 +206,10 @@ end
|
|||
m.column = "entry:sqr"
|
||||
m.isDelete = 1
|
||||
mutations << m
|
||||
client.mutateRowTs(t, row, mutations, 1) # shouldn't override latest
|
||||
printRow(client.getRow(t, row));
|
||||
client.mutateRowTs(t, row, mutations, 1, dummy_attributes) # shouldn't override latest
|
||||
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: "
|
||||
versions.each do |v|
|
||||
print "#{v.value}; "
|
||||
|
@ -215,7 +217,7 @@ end
|
|||
puts ""
|
||||
|
||||
begin
|
||||
client.get(t, row, "entry:foo")
|
||||
client.get(t, row, "entry:foo", dummy_attributes)
|
||||
raise "shouldn't get here!"
|
||||
rescue Apache::Hadoop::Hbase::Thrift::NotFound => nf
|
||||
# blank
|
||||
|
@ -231,10 +233,10 @@ client.getColumnDescriptors(t).each do |col, desc|
|
|||
end
|
||||
|
||||
puts "Starting scanner..."
|
||||
scanner = client.scannerOpenWithStop(t, "00020", "00040", columns)
|
||||
scanner = client.scannerOpenWithStop(t, "00020", "00040", columns, dummy_attributes)
|
||||
begin
|
||||
while (true)
|
||||
printRow(client.scannerGet(scanner))
|
||||
printRow(client.scannerGet(scanner, dummy_attributes))
|
||||
end
|
||||
rescue Apache::Hadoop::Hbase::Thrift::NotFound => nf
|
||||
client.scannerClose(scanner)
|
||||
|
|
|
@ -29,7 +29,7 @@ GEN_SRC = ./gen-cpp/Hbase.cpp \
|
|||
default: DemoClient
|
||||
|
||||
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:
|
||||
rm -rf DemoClient
|
||||
|
|
Loading…
Reference in New Issue