Sunday, May 5, 2013

Retrieving Row Keys from HBase

When performing a table scan where only the row keys are needed (no families, qualifiers, values or timestamps), add a FilterList with a MUST_PASS_ALL operator to the scanner using setFilter. The filter list should include both a FirstKeyOnlyFilter and a KeyOnlyFilter. Using this filter combination will result in a worst case scenario of a RegionServer reading a single value from disk and minimal network traffic to the client for a single row.

As example:



List<Filter> filters = new ArrayList<Filter>();
filters.add(new FirstKeyOnlyFilter());
filters.add(new KeyOnlyFilter());
FilterList flist = new FilterList( FilterList.Operator.MUST_PASS_ALL, filters);
Scan scanner = new Scan();
scanner.setCaching(500);  
scanner.setFilter(flist);


try
{
HTableInterface table = environment.getTable("ARTICLES");
rs = table.getScanner(scanner);
for (Result r : rs)
{
                           .......................
                            .......................
}

       } 
rs.close();
}



No comments:

Post a Comment