Database Reference
In-Depth Information
// Create Scan instance
Scan scan = new Scan();
// Add a column with value "Hello", in "cf1:greet",
// to the Scan.
scan.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("greet"));
// Set Start Row
scan.setStartRow(Bytes.toBytes("row-5"));
// Set End Row
scan.setStopRow(Bytes.toBytes("row-10"));
// Get Scanner Results
ResultScanner scanner = table.getScanner(scan);
for (Result res : scanner) {
System.out.println("Row Value: " + res);
}
scanner.close();
table.close();
}
}
This example returns row 5 to row 9 from the column family CF1 and the
greet column.
Implementing ilters
We apply column families, column qualiiers, timestamps, or ranges with the get()
and scan() operations for limiting the data retrieved. Designing a row key to match
the access patterns in every case is not possible, as at times we only need a subset of
the data retrieved. Filters provide such a level of ine-grained access, that is, iltering
the dataset based on some regular expression. The HBase API provides a ilter
interface and an abstract class, FilterBase , under the org.apache.hadoop.hbase.
filter package, which is further extended by many classes such as CompareFilter ,
PageFilter , SkipFilter , TimeStampsFilter , and so on, to provide additional
functionalities. The following method deined in the Scan class is used to set an
instance of the ilter:
setFilter(Filter filter) : Apply the speciied server-side ilter when
performing the query
 
Search WWH ::




Custom Search