HBASE-697 thrift idl needs update/edit to match new 0.2 API (and to fix bugs)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@686569 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2008-08-16 22:10:13 +00:00
parent e30ed932bb
commit fddd62e6c5
2 changed files with 63 additions and 44 deletions

View File

@ -25,8 +25,9 @@ import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder; import java.nio.charset.CharsetDecoder;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.util.AbstractMap;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.SortedMap; import java.util.SortedMap;
@ -37,7 +38,9 @@ import org.apache.hadoop.hbase.thrift.generated.IOError;
import org.apache.hadoop.hbase.thrift.generated.IllegalArgument; import org.apache.hadoop.hbase.thrift.generated.IllegalArgument;
import org.apache.hadoop.hbase.thrift.generated.Mutation; import org.apache.hadoop.hbase.thrift.generated.Mutation;
import org.apache.hadoop.hbase.thrift.generated.NotFound; import org.apache.hadoop.hbase.thrift.generated.NotFound;
import org.apache.hadoop.hbase.thrift.generated.ScanEntry; import org.apache.hadoop.hbase.thrift.generated.TCell;
import org.apache.hadoop.hbase.thrift.generated.TRowResult;
import com.facebook.thrift.TException; import com.facebook.thrift.TException;
import com.facebook.thrift.protocol.TBinaryProtocol; import com.facebook.thrift.protocol.TBinaryProtocol;
import com.facebook.thrift.protocol.TProtocol; import com.facebook.thrift.protocol.TProtocol;
@ -81,6 +84,7 @@ public class DemoClient {
private void run() throws IOError, TException, NotFound, IllegalArgument, private void run() throws IOError, TException, NotFound, IllegalArgument,
AlreadyExists { AlreadyExists {
TTransport transport = new TSocket("localhost", port); TTransport transport = new TSocket("localhost", port);
TProtocol protocol = new TBinaryProtocol(transport, true, true); TProtocol protocol = new TBinaryProtocol(transport, true, true);
Hbase.Client client = new Hbase.Client(protocol); Hbase.Client client = new Hbase.Client(protocol);
@ -96,6 +100,9 @@ public class DemoClient {
for (byte[] name : client.getTableNames()) { for (byte[] name : client.getTableNames()) {
System.out.println(" found: " + utf8(name)); System.out.println(" found: " + utf8(name));
if (utf8(name).equals(utf8(t))) { if (utf8(name).equals(utf8(t))) {
System.out.println(" disabling table: " + utf8(name));
if (client.isTableEnabled(name))
client.disableTable(name);
System.out.println(" deleting table: " + utf8(name)); System.out.println(" deleting table: " + utf8(name));
client.deleteTable(name); client.deleteTable(name);
} }
@ -122,7 +129,7 @@ public class DemoClient {
} }
System.out.println("column families in " + utf8(t) + ": "); System.out.println("column families in " + utf8(t) + ": ");
AbstractMap<byte[], ColumnDescriptor> columnMap = client.getColumnDescriptors(t); Map<byte[], ColumnDescriptor> columnMap = client.getColumnDescriptors(t);
for (ColumnDescriptor col2 : columnMap.values()) { for (ColumnDescriptor col2 : columnMap.values()) {
System.out.println(" column: " + utf8(col2.name) + ", maxVer: " + Integer.toString(col2.maxVersions)); System.out.println(" column: " + utf8(col2.name) + ", maxVer: " + Integer.toString(col2.maxVersions));
} }
@ -133,18 +140,27 @@ public class DemoClient {
byte[] invalid = { (byte) 'f', (byte) 'o', (byte) 'o', (byte) '-', (byte) 0xfc, (byte) 0xa1, (byte) 0xa1, (byte) 0xa1, (byte) 0xa1 }; byte[] invalid = { (byte) 'f', (byte) 'o', (byte) 'o', (byte) '-', (byte) 0xfc, (byte) 0xa1, (byte) 0xa1, (byte) 0xa1, (byte) 0xa1 };
byte[] valid = { (byte) 'f', (byte) 'o', (byte) 'o', (byte) '-', (byte) 0xE7, (byte) 0x94, (byte) 0x9F, (byte) 0xE3, (byte) 0x83, (byte) 0x93, (byte) 0xE3, (byte) 0x83, (byte) 0xBC, (byte) 0xE3, (byte) 0x83, (byte) 0xAB}; byte[] valid = { (byte) 'f', (byte) 'o', (byte) 'o', (byte) '-', (byte) 0xE7, (byte) 0x94, (byte) 0x9F, (byte) 0xE3, (byte) 0x83, (byte) 0x93, (byte) 0xE3, (byte) 0x83, (byte) 0xBC, (byte) 0xE3, (byte) 0x83, (byte) 0xAB};
ArrayList<Mutation> mutations;
// non-utf8 is fine for data // non-utf8 is fine for data
client.put(t, bytes("foo"), bytes("entry:foo"), invalid); mutations = new ArrayList<Mutation>();
mutations.add(new Mutation(false, bytes("entry:foo"), invalid));
client.mutateRow(t, bytes("foo"), mutations);
// try empty strings // try empty strings
client.put(t, bytes(""), bytes("entry:"), bytes("")); mutations = new ArrayList<Mutation>();
mutations.add(new Mutation(false, bytes("entry:"), bytes("")));
client.mutateRow(t, bytes(""), mutations);
// this row name is valid utf8 // this row name is valid utf8
client.put(t, valid, bytes("entry:foo"), valid); mutations = new ArrayList<Mutation>();
mutations.add(new Mutation(false, bytes("entry:foo"), valid));
client.mutateRow(t, bytes("foo"), mutations);
// non-utf8 is not allowed in row names // non-utf8 is not allowed in row names
try { try {
client.put(t, invalid, bytes("entry:foo"), invalid); mutations = new ArrayList<Mutation>();
mutations.add(new Mutation(false, bytes("entry:foo"), invalid));
client.mutateRow(t, invalid, mutations);
System.out.println("FATAL: shouldn't get here"); System.out.println("FATAL: shouldn't get here");
System.exit(-1); System.exit(-1);
} catch (IOError e) { } catch (IOError e) {
@ -156,12 +172,11 @@ public class DemoClient {
columnNames.add(bytes("entry:")); columnNames.add(bytes("entry:"));
System.out.println("Starting scanner..."); System.out.println("Starting scanner...");
int scanner = client int scanner = client.scannerOpen(t, bytes(""), columnNames);
.scannerOpen(t, bytes(""), columnNames);
try { try {
while (true) { while (true) {
ScanEntry value = client.scannerGet(scanner); TRowResult entry = client.scannerGet(scanner);
printEntry(value); printRow(entry);
} }
} catch (NotFound nf) { } catch (NotFound nf) {
client.scannerClose(scanner); client.scannerClose(scanner);
@ -178,16 +193,20 @@ public class DemoClient {
nf.setGroupingUsed(false); nf.setGroupingUsed(false);
byte[] row = bytes(nf.format(i)); byte[] row = bytes(nf.format(i));
client.put(t, row, bytes("unused:"), bytes("DELETE_ME")); mutations = new ArrayList<Mutation>();
printRow(row, client.getRow(t, row)); mutations.add(new Mutation(false, bytes("unused:"), bytes("DELETE_ME")));
client.mutateRow(t, row, mutations);
printRow(client.getRow(t, row));
client.deleteAllRow(t, row); client.deleteAllRow(t, row);
client.put(t, row, bytes("entry:num"), bytes("0")); mutations = new ArrayList<Mutation>();
client.put(t, row, bytes("entry:foo"), bytes("FOO")); mutations.add(new Mutation(false, bytes("entry:num"), bytes("0")));
printRow(row, client.getRow(t, row)); mutations.add(new Mutation(false, bytes("entry:foo"), bytes("FOO")));
client.mutateRow(t, row, mutations);
printRow(client.getRow(t, row));
Mutation m = null; Mutation m = null;
ArrayList<Mutation> mutations = new ArrayList<Mutation>(); mutations = new ArrayList<Mutation>();
m = new Mutation(); m = new Mutation();
m.column = bytes("entry:foo"); m.column = bytes("entry:foo");
m.isDelete = true; m.isDelete = true;
@ -197,11 +216,13 @@ public class DemoClient {
m.value = bytes("-1"); m.value = bytes("-1");
mutations.add(m); mutations.add(m);
client.mutateRow(t, row, mutations); client.mutateRow(t, row, mutations);
printRow(row, client.getRow(t, row)); printRow(client.getRow(t, row));
client.put(t, row, bytes("entry:num"), bytes(Integer.toString(i))); mutations = new ArrayList<Mutation>();
client.put(t, row, bytes("entry:sqr"), bytes(Integer.toString(i * i))); mutations.add(new Mutation(false, bytes("entry:num"), bytes(Integer.toString(i))));
printRow(row, client.getRow(t, row)); mutations.add(new Mutation(false, bytes("entry:sqr"), bytes(Integer.toString(i * i))));
client.mutateRow(t, row, mutations);
printRow(client.getRow(t, row));
// sleep to force later timestamp // sleep to force later timestamp
try { try {
@ -219,9 +240,9 @@ public class DemoClient {
m.column = bytes("entry:sqr"); m.column = bytes("entry:sqr");
m.isDelete = true; m.isDelete = true;
client.mutateRowTs(t, row, mutations, 1); // shouldn't override latest client.mutateRowTs(t, row, mutations, 1); // shouldn't override latest
printRow(row, client.getRow(t, row)); printRow(client.getRow(t, row));
ArrayList<byte[]> versions = client.getVer(t, row, bytes("entry:num"), 10); List<TCell> versions = client.getVer(t, row, bytes("entry:num"), 10);
printVersions(row, versions); printVersions(row, versions);
if (versions.size() != 4) { if (versions.size() != 4) {
System.out.println("FATAL: wrong # of versions"); System.out.println("FATAL: wrong # of versions");
@ -243,7 +264,9 @@ public class DemoClient {
columnNames.clear(); columnNames.clear();
for (ColumnDescriptor col2 : client.getColumnDescriptors(t).values()) { for (ColumnDescriptor col2 : client.getColumnDescriptors(t).values()) {
columnNames.add(col2.name); System.out.println("column name is " + new String(col2.name));
System.out.println(col2.toString());
columnNames.add((utf8(col2.name) + ":").getBytes());
} }
System.out.println("Starting scanner..."); System.out.println("Starting scanner...");
@ -251,8 +274,8 @@ public class DemoClient {
columnNames); columnNames);
try { try {
while (true) { while (true) {
ScanEntry value = client.scannerGet(scanner); TRowResult entry = client.scannerGet(scanner);
printEntry(value); printRow(entry);
} }
} catch (NotFound nf) { } catch (NotFound nf) {
client.scannerClose(scanner); client.scannerClose(scanner);
@ -262,34 +285,30 @@ public class DemoClient {
transport.close(); transport.close();
} }
private final void printVersions(byte[] row, ArrayList<byte[]> values) { private final void printVersions(byte[] row, List<TCell> versions) {
StringBuilder rowStr = new StringBuilder(); StringBuilder rowStr = new StringBuilder();
for (byte[] value : values) { for (TCell cell : versions) {
rowStr.append(utf8(value)); rowStr.append(utf8(cell.value));
rowStr.append("; "); rowStr.append("; ");
} }
System.out.println("row: " + utf8(row) + ", values: " + rowStr); System.out.println("row: " + utf8(row) + ", values: " + rowStr);
} }
private final void printEntry(ScanEntry entry) { private final void printRow(TRowResult rowResult) {
printRow(entry.row, entry.columns);
}
private final void printRow(byte[] row, AbstractMap<byte[], byte[]> values) {
// copy values into a TreeMap to get them in sorted order // copy values into a TreeMap to get them in sorted order
TreeMap<String,byte[]> sorted = new TreeMap<String,byte[]>(); TreeMap<String,TCell> sorted = new TreeMap<String,TCell>();
for (AbstractMap.Entry<byte[], byte[]> entry : values.entrySet()) { for (Map.Entry<byte[], TCell> column : rowResult.columns.entrySet()) {
sorted.put(utf8(entry.getKey()), entry.getValue()); sorted.put(utf8(column.getKey()), column.getValue());
} }
StringBuilder rowStr = new StringBuilder(); StringBuilder rowStr = new StringBuilder();
for (SortedMap.Entry<String, byte[]> entry : sorted.entrySet()) { for (SortedMap.Entry<String, TCell> entry : sorted.entrySet()) {
rowStr.append(entry.getKey()); rowStr.append(entry.getKey());
rowStr.append(" => "); rowStr.append(" => ");
rowStr.append(utf8(entry.getValue())); rowStr.append(utf8(entry.getValue().value));
rowStr.append("; "); rowStr.append("; ");
} }
System.out.println("row: " + utf8(row) + ", cols: " + rowStr); System.out.println("row: " + utf8(rowResult.row) + ", cols: " + rowStr);
} }
} }

View File

@ -9,6 +9,6 @@ To run/compile this clients, you will first need to install the thrift package
(from http://developers.facebook.com/thrift/) and then run thrift to generate (from http://developers.facebook.com/thrift/) and then run thrift to generate
the language files: the language files:
thrift -cpp -java -rb -php \ thrift --gen cpp --gen java --gen rb --gen php \
../../../src/java/org/apache/hadoop/hbase/thrift/Hbase.thrift ../../../src/java/org/apache/hadoop/hbase/thrift/Hbase.thrift