HBASE-1455 Update DemoClient.py for thrift 1.0

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@780334 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2009-05-30 21:44:46 +00:00
parent 981d990af9
commit 9068037058
2 changed files with 39 additions and 49 deletions

View File

@ -289,6 +289,7 @@ Release 0.20.0 - Unreleased
HBASE-1454 HBaseAdmin.getClusterStatus HBASE-1454 HBaseAdmin.getClusterStatus
HBASE-1236 Improve readability of table descriptions in the UI HBASE-1236 Improve readability of table descriptions in the UI
(Lars George and Alex Newman via Stack) (Lars George and Alex Newman via Stack)
HBASE-1455 Update DemoClient.py for thrift 1.0 (Tim Sell via Stack)
OPTIMIZATIONS OPTIMIZATIONS
HBASE-1412 Change values for delete column and column family in KeyValue HBASE-1412 Change values for delete column and column family in KeyValue

View File

@ -106,20 +106,21 @@ invalid = "foo-\xfc\xa1\xa1\xa1\xa1\xa1"
valid = "foo-\xE7\x94\x9F\xE3\x83\x93\xE3\x83\xBC\xE3\x83\xAB"; 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)
client.mutateRow(t, "foo", mutations) client.mutateRow(t, "foo", mutations)
# try empty strings # try empty strings
mutations = [Mutation({"column":"entry:", "value":""})] mutations = [Mutation(column="entry:", value="")]
client.mutateRow(t, "", mutations) client.mutateRow(t, "", mutations)
# 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)
# 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)
except ttypes.IOError, e: except ttypes.IOError, e:
print 'expected exception: %s' %(e.message) print 'expected exception: %s' %(e.message)
@ -127,10 +128,11 @@ except ttypes.IOError, e:
# 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:"])
try:
while 1: r = client.scannerGet(scanner)
printRow(client.scannerGet(scanner)) while r:
except ttypes.NotFound, e: printRow(r[0])
r = client.scannerGet(scanner)
print "Scanner finished" print "Scanner finished"
# #
@ -140,46 +142,32 @@ for e in range(100, 0, -1):
# format row keys as "00000" to "00100" # format row keys as "00000" to "00100"
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)
printRow(client.getRow(t, row)) printRow(client.getRow(t, row)[0])
client.deleteAllRow(t, row) client.deleteAllRow(t, row)
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)
printRow(client.getRow(t, row)); printRow(client.getRow(t, row)[0]);
mutations = [] mutations = [Mutation(column="entry:foo",isDelete=True),
m = Mutation() Mutation(column="entry:num",value="-1")]
m.column = "entry:foo"
m.isDelete = 1
mutations.append(m)
m = Mutation()
m.column = "entry:num"
m.value = "-1"
mutations.append(m)
client.mutateRow(t, row, mutations) client.mutateRow(t, row, mutations)
printRow(client.getRow(t, row)) printRow(client.getRow(t, row)[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)
printRow(client.getRow(t, row)); printRow(client.getRow(t, row)[0])
time.sleep(0.05) time.sleep(0.05)
mutations = [] mutations = [Mutation(column="entry:num",value="-999"),
m = Mutation() Mutation(column="entry:sqr",isDelete=True)]
m.column = "entry:num"
m.value = "-999"
mutations.append(m)
m = Mutation()
m.column = "entry:sqr"
m.isDelete = 1
mutations.append(m)
client.mutateRowTs(t, row, mutations, 1) # shouldn't override latest client.mutateRowTs(t, row, mutations, 1) # shouldn't override latest
printRow(client.getRow(t, row)) printRow(client.getRow(t, row)[0])
versions = client.getVer(t, row, "entry:num", 10) versions = client.getVer(t, row, "entry:num", 10)
printVersions(row, versions) printVersions(row, versions)
@ -187,13 +175,12 @@ for e in range(100, 0, -1):
print("FATAL: wrong # of versions") print("FATAL: wrong # of versions")
sys.exit(-1) sys.exit(-1)
try: r = client.get(t, row, "entry:foo")
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!" raise "shouldn't get here!"
except ttypes.NotFound, e:
pass
print
columnNames = [] columnNames = []
for (col, desc) in client.getColumnDescriptors(t).items(): for (col, desc) in client.getColumnDescriptors(t).items():
@ -203,10 +190,12 @@ for (col, desc) in client.getColumnDescriptors(t).items():
print "Starting scanner..." print "Starting scanner..."
scanner = client.scannerOpenWithStop(t, "00020", "00040", columnNames) scanner = client.scannerOpenWithStop(t, "00020", "00040", columnNames)
try:
while 1: r = client.scannerGet(scanner)
printRow(client.scannerGet(scanner)) while r:
except ttypes.NotFound: printRow(r[0])
r = client.scannerGet(scanner)
client.scannerClose(scanner) client.scannerClose(scanner)
print "Scanner finished" print "Scanner finished"