1
votes

I am writing a Java application that retrieves and presents data from an HBase database.

When writing the Get method for retrieving a row, I would like to get all the data for that row, but exclude the value for a particular column family (the "big" column family). Note: I need to retrieve the column names (qualifiers?) in that family because they contain valuable information.

Is it possible to write a Filter for that?

I have two solutions. The first one does not work and the second one is quite slow.

First solution (using a composite filter):

HTable table = getTable();
Get get = new Get(row);
FilterList filter = new FilterList(FilterList.Operator.MUST_PASS_ONE);

FilterList subFilterList = new FilterList(FilterList.Operator.MUST_PASS_ALL);
subFilterList.addFilter(new KeyOnlyFilter());
subFilterList.addFilter(new FamilyFilter(CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes("big"))));

filter.addFilter(subFilterList);
filter.addFilter(new FamilyFilter(CompareOp.NOT_EQUAL, new BinaryComparator(Bytes.toBytes("big"))));

get.setFilter(filter);
retrieveAndUseResult(table, get);

This solution works neither conceptually nor in practise - but perhaps I am on the right track using a composite FilterList?

Second solution (using two gets):

HTable table = getTable();
Get get = new Get(row);
// exclude the entire "big" column family 
get.setFilter(new FamilyFilter(CompareOp.NOT_EQUAL, new BinaryComparator(Bytes.toBytes("big"))));
retrieveAndUseResult(table, get);

Get get2 = new Get(row);
// include the "big" column family, but only retrieve the key 
FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL);
filterList.addFilter(new KeyOnlyFilter());
filterList.addFilter(new FamilyFilter(CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes("big"))));
get2.setFilter(filterList);
retrieveAndUseResult(table, get2);

This works, but I would favor having to do only one get.

1

1 Answers

0
votes

I ended up using a variant of the second solution - using two gets. But I used a batch get list to speed it up.

The code:

HTable table = getTable();

Get get = new Get(row);
// exclude the entire "big" column family 
get.setFilter(new FamilyFilter(CompareOp.NOT_EQUAL, new BinaryComparator(Bytes.toBytes("big"))));

Get get2 = new Get(row);
// include the "big" column family, but only retrieve the key 
FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL);
filterList.addFilter(new KeyOnlyFilter());
filterList.addFilter(new FamilyFilter(CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes("big"))));
get2.setFilter(filterList);

List<Get> getList = new ArrayList<Get>();
getList.add(get);
getList.add(get2);
retrieveAndUseResults(table, getList);