Database Reference
In-Depth Information
The run() method calls getStationObservations() , asking for the 10 most re-
cent observations, which it turns back into descending order by calling descendin-
gMap() . The observations are formatted and printed to the console (remember that the
temperatures are in tenths of a degree). For example:
% hbase HBaseTemperatureQuery 011990-99999
1902-12-31 20:00 -106
1902-12-31 13:00 -83
1902-12-30 20:00 -78
1902-12-30 13:00 -100
1902-12-29 20:00 -128
1902-12-29 13:00 -111
1902-12-29 06:00 -111
1902-12-28 20:00 -117
1902-12-28 13:00 -61
1902-12-27 20:00 -22
The advantage of storing timestamps in reverse chronological order is that it lets us get the
newest observations, which is often what we want in online applications. If the observa-
tions were stored with the actual timestamps, we would be able to get only the oldest ob-
servations for a given offset and limit efficiently. Getting the newest would mean getting
all of the rows and then grabbing the newest off the end. It's much more efficient to get
the first n rows, then exit the scanner (this is sometimes called an “early-out” scenario).
NOTE
HBase 0.98 added the ability to do reverse scans, which means it is now possible to store observations in
chronological order and scan backward from a given starting row. Reverse scans are a few percent
slower than forward scans. To reverse a scan, call setReversed(true) on the Scan object before
starting the scan.
Search WWH ::




Custom Search