diff --git a/examples/thrift/DemoClient.cpp b/examples/thrift/DemoClient.cpp index 06cbc4460d1..cf9dded2368 100644 --- a/examples/thrift/DemoClient.cpp +++ b/examples/thrift/DemoClient.cpp @@ -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 socket(new TSocket(argv[1], boost::lexical_cast(argv[2]))); + boost::shared_ptr transport; - boost::shared_ptr socket(new TSocket("localhost", boost::lexical_cast(argv[2]))); - boost::shared_ptr transport(new TBufferedTransport(socket)); + if (isFramed) { + transport.reset(new TFramedTransport(socket)); + } else { + transport.reset(new TBufferedTransport(socket)); + } boost::shared_ptr protocol(new TBinaryProtocol(transport)); - HbaseClient client(protocol); + const std::map 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 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(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 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 value; diff --git a/examples/thrift/DemoClient.java b/examples/thrift/DemoClient.java index fbb1241b88c..b2941dd8a14 100644 --- a/examples/thrift/DemoClient.java +++ b/examples/thrift/DemoClient.java @@ -163,6 +163,9 @@ public class DemoClient { System.out.println(" column: " + utf8(col2.name.array()) + ", maxVer: " + Integer.toString(col2.maxVersions)); } + Map dummyAttributes = null; + boolean writeToWal = false; + // // Test UTF-8 handling // @@ -172,25 +175,25 @@ public class DemoClient { ArrayList mutations; // non-utf8 is fine for data mutations = new ArrayList(); - 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(); - 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(); - 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(); - 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 entry = client.scannerGet(scanner); @@ -219,16 +222,16 @@ public class DemoClient { byte[] row = bytes(nf.format(i)); mutations = new ArrayList(); - 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(); - 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(); @@ -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(); - 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 versions = client.getVer(ByteBuffer.wrap(t), ByteBuffer.wrap(row), ByteBuffer.wrap(bytes("entry:num")), 10); + List 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 result = client.get(ByteBuffer.wrap(t), ByteBuffer.wrap(row), ByteBuffer.wrap(bytes("entry:foo"))); + List 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 entry = client.scannerGet(scanner); diff --git a/examples/thrift/DemoClient.php b/examples/thrift/DemoClient.php index 669f2b6fc2f..26c75c4e792 100644 --- a/examples/thrift/DemoClient.php +++ b/examples/thrift/DemoClient.php @@ -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 ) { diff --git a/examples/thrift/DemoClient.pl b/examples/thrift/DemoClient.pl index 17d92fad2f0..d9e7587f288 100644 --- a/examples/thrift/DemoClient.pl +++ b/examples/thrift/DemoClient.pl @@ -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, ) # 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 diff --git a/examples/thrift/DemoClient.py b/examples/thrift/DemoClient.py index 54f115e454f..a92d6746c63 100644 --- a/examples/thrift/DemoClient.py +++ b/examples/thrift/DemoClient.py @@ -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 @@ -7,7 +7,7 @@ to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software @@ -15,7 +15,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -''' +''' # Instructions: # 1. Run Thrift to generate the python module HBase # thrift --gen py ../../../src/main/resources/org/apache/hadoop/hbase/thrift/Hbase.thrift @@ -23,7 +23,7 @@ # a. This file (DemoClient.py). # b. The directory gen-py/hbase (generated by instruction step 1). # c. The directory {$THRIFT_HOME}/lib/py/build/lib.{YOUR_SYSTEM}/thrift. -# Or, modify the import statements below such that this file can access the +# Or, modify the import statements below such that this file can access the # directories from steps 3b and 3c. # 3. Execute {python DemoClient.py}. @@ -48,154 +48,174 @@ 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): -# Wrap in a protocol -protocol = TBinaryProtocol.TBinaryProtocol(transport) + # Make socket + socket = TSocket.TSocket(host, port) -# Create a client to use the protocol encoder -client = Client(protocol) + # Make transport + if is_framed_transport: + transport = TTransport.TFramedTransport(socket) + else: + transport = TTransport.TBufferedTransport(socket) -# Connect! -transport.open() + # Wrap in a protocol + protocol = TBinaryProtocol.TBinaryProtocol(transport) -t = "demo_table" + # Create a client to use the protocol encoder + client = Client(protocol) -# -# Scan all tables, look for the demo table and delete it. -# -print "scanning tables..." -for table in client.getTableNames(): - print " found: %s" %(table) - if table == t: - if client.isTableEnabled(table): - print " disabling table: %s" %(t) - client.disableTable(table) - print " deleting table: %s" %(t) - client.deleteTable(table) + # Connect! + transport.open() -columns = [] -col = ColumnDescriptor() -col.name = 'entry:' -col.maxVersions = 10 -columns.append(col) -col = ColumnDescriptor() -col.name = 'unused:' -columns.append(col) + t = "demo_table" -try: - print "creating table: %s" %(t) - client.createTable(t, columns) -except AlreadyExists, ae: - print "WARN: " + ae.message + # + # Scan all tables, look for the demo table and delete it. + # + print "scanning tables..." + for table in client.getTableNames(): + print " found: %s" %(table) + if table == t: + if client.isTableEnabled(table): + print " disabling table: %s" %(t) + client.disableTable(table) + print " deleting table: %s" %(t) + client.deleteTable(table) -cols = client.getColumnDescriptors(t) -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) -# -# Test UTF-8 handling -# -invalid = "foo-\xfc\xa1\xa1\xa1\xa1\xa1" -valid = "foo-\xE7\x94\x9F\xE3\x83\x93\xE3\x83\xBC\xE3\x83\xAB"; + columns = [] + col = ColumnDescriptor() + col.name = 'entry:' + col.maxVersions = 10 + columns.append(col) + col = ColumnDescriptor() + col.name = 'unused:' + columns.append(col) -# non-utf8 is fine for data -mutations = [Mutation(column="entry:foo",value=invalid)] -print str(mutations) -client.mutateRow(t, "foo", mutations) + try: + print "creating table: %s" %(t) + client.createTable(t, columns) + except AlreadyExists, ae: + print "WARN: " + ae.message -# try empty strings -mutations = [Mutation(column="entry:", value="")] -client.mutateRow(t, "", mutations) + cols = client.getColumnDescriptors(t) + 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) -# this row name is valid utf8 -mutations = [Mutation(column="entry:foo", value=valid)] -client.mutateRow(t, valid, mutations) + dummy_attributes = {} + # + # Test UTF-8 handling + # + invalid = "foo-\xfc\xa1\xa1\xa1\xa1\xa1" + valid = "foo-\xE7\x94\x9F\xE3\x83\x93\xE3\x83\xBC\xE3\x83\xAB"; -# non-utf8 is not allowed in row names -try: - mutations = [Mutation(column="entry:foo", value=invalid)] - client.mutateRow(t, invalid, mutations) -except ttypes.IOError, e: - print 'expected exception: %s' %(e.message) + # non-utf8 is fine for data + mutations = [Mutation(column="entry:foo",value=invalid)] + print str(mutations) + client.mutateRow(t, "foo", mutations, dummy_attributes) -# Run a scanner on the rows we just created -print "Starting scanner..." -scanner = client.scannerOpen(t, "", ["entry:"]) + # try empty strings + mutations = [Mutation(column="entry:", value="")] + client.mutateRow(t, "", mutations, dummy_attributes) + + # this row name is valid utf8 + mutations = [Mutation(column="entry:foo", value=valid)] + 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, 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:"], dummy_attributes) -r = client.scannerGet(scanner) -while r: - printRow(r[0]) r = client.scannerGet(scanner) -print "Scanner finished" + while r: + printRow(r[0]) + r = client.scannerGet(scanner) + print "Scanner finished" -# -# Run some operations on a bunch of rows. -# -for e in range(100, 0, -1): + # + # Run some operations on a bunch of rows. + # + for e in range(100, 0, -1): # format row keys as "00000" to "00100" - row = "%0.5d" % (e) + 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) + mutations = [Mutation(column="unused:", value="DELETE_ME")] + 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]); + mutations = [Mutation(column="entry:num", value="0"), + Mutation(column="entry:foo", value="FOO")] + 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]) + mutations = [Mutation(column="entry:foo",isDelete=True), + Mutation(column="entry:num",value="-1")] + 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]) + mutations = [Mutation(column="entry:num", value=str(e)), + Mutation(column="entry:sqr", value=str(e*e))] + client.mutateRow(t, row, mutations, dummy_attributes) + printRow(client.getRow(t, row, dummy_attributes)[0]) - time.sleep(0.05) + 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]) + mutations = [Mutation(column="entry:num",value="-999"), + Mutation(column="entry:sqr",isDelete=True)] + 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) - printVersions(row, versions) - if len(versions) != 4: - print("FATAL: wrong # of versions") - sys.exit(-1) + versions = client.getVer(t, row, "entry:num", 10, dummy_attributes) + printVersions(row, versions) + 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" - # 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!" + 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!" -columnNames = [] -for (col, desc) in client.getColumnDescriptors(t).items(): - print "column with name: "+desc.name - print desc - columnNames.append(desc.name+":") + columnNames = [] + for (col, desc) in client.getColumnDescriptors(t).items(): + print "column with name: "+desc.name + print desc + columnNames.append(desc.name+":") -print "Starting scanner..." -scanner = client.scannerOpenWithStop(t, "00020", "00040", columnNames) + print "Starting scanner..." + scanner = client.scannerOpenWithStop(t, "00020", "00040", columnNames, dummy_attributes) -r = client.scannerGet(scanner) -while r: - printRow(r[0]) r = client.scannerGet(scanner) + while r: + printRow(r[0]) + r = client.scannerGet(scanner) -client.scannerClose(scanner) -print "Scanner finished" + client.scannerClose(scanner) + print "Scanner finished" + + transport.close() + + +if __name__ == '__main__': + + import sys + if len(sys.argv) < 3: + print 'usage: %s ' % __file__ + sys.exit(1) + + host = sys.argv[1] + port = sys.argv[2] + is_framed_transport = False + demo_client(host, port, is_framed_transport) -transport.close() diff --git a/examples/thrift/DemoClient.rb b/examples/thrift/DemoClient.rb index 07411882566..ec6b4cf5b56 100644 --- a/examples/thrift/DemoClient.rb +++ b/examples/thrift/DemoClient.rb @@ -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) diff --git a/examples/thrift/Makefile b/examples/thrift/Makefile index 691a1e981ae..0aa803d5e86 100644 --- a/examples/thrift/Makefile +++ b/examples/thrift/Makefile @@ -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