Hi Mark,
good find. I think that works by accident and the book is wrong.
"row" + new byte[] {0} will use byte[].toString() and actually result in
something like: "row[B@152b6651", which (again accidentally) sorts past rowN.
"row" + new byte[] {255} is not better, though.
You'd have to construct a byte array that is terminated by 255.
An easy way to do that is: byte[] row = new byte[] {'r','o','w',-1}
We need to fix the book.
-- Lars
________________________________
From: Mark <[email protected]>
To: [email protected]
Sent: Wednesday, November 16, 2011 7:59 AM
Subject: Scans and lexical sorting
Section 5.7.3 of the HBase book displays a scan operation:
HTable htable = ... // instantiate HTable
Scan scan = new Scan();
scan.addColumn(Bytes.toBytes("cf"),Bytes.toBytes("attr"));
scan.setStartRow( Bytes.toBytes("row"));
scan.setStopRow( Bytes.toBytes("row" + new byte[] {0})); // note: stop key !=
start key
for(Result result : htable.getScanner(scan)) {
// process Result instance
}
Can someone explain why the stop key is "row" plus an empty byte? The example
says it should return all rows that start with "row" however wouldn't this only
return a row with the exact row key of "row"?
"row" < "row\000" => true
"row\000" < "row1" => false
Shouldn't the example be "row" + new byte[] {255}?
"row1" < "row\255" => true
Can someone please clarify?