Database Reference
In-Depth Information
All the preceding methods return an instance of the ResultScanner class. This
class provides a behavior similar to an iterator to the Scan class instance. The Scan
instance does not obtain the complete results in a single call, as this could be a very
heavy call to make. The following methods of the ResultScanner class help to
achieve iterative behavior:
Method
Description
close()
Closes the scanner and releases any resources it
has allocated
next()
Grabs the next row's worth of values
next(int nbRows)
Grabs the zero and nbRows results
The next() method returns the Results class to represent the row's contents. By
default, the result is contained only for a single row and a fresh RPC call is made
for each next call. To avoid too many calls, the ResultScanner class also provides
the provision for row caching. Within the hbase-site.xml coniguration ile, we
can set the following code:
<property>
<name>hbase.client.scanner.caching</name>
<value>5</value>
</property>
This property sets the row caching to 5 from the default value of 1 for all the
scan calls. We can also set the caching limit for individual scan calls using the
setScannerCaching(int scannerCaching) method on an HTable instance.
This caching works at the row level and might not be a good option for the rows
containing hundreds of columns. For limiting the columns returned on each next()
call, we can use the following code:
void setBatch(int batch)
Using scanner caching and batch together provides control over the number of RPC
calls required to scan the row key range selected.
Let's take a look at a complete example of the Scan usage:
public class ScanExample {
public static void main(String[] args) throws IOException {
// Get instance of Default Configuration
Configuration conf = HBaseConfiguration.create();
// Get table instance
HTable table = new HTable(conf, "tab1");
Search WWH ::




Custom Search