Skip to content

Instantly share code, notes, and snippets.

@gtata
Created January 29, 2014 18:12
Show Gist options
  • Save gtata/8693622 to your computer and use it in GitHub Desktop.
Save gtata/8693622 to your computer and use it in GitHub Desktop.
Looks like the filter functionality is not working. Has that been implemented yet? I was trying to do the following operation but the filter was being ignored based on my results because my result was showing everything in my table and not filtering. Please advice. Thanks.
FilterList list = new FilterList(FilterList.Operator.MUST_PASS_ALL);
SingleColumnValueFilter filter1 = new SingleColumnValueFilter("myColFam".getBytes(), "myCol".getBytes(), CompareOp.EQUAL, Bytes.toBytes("myValue"));
list.addFilter(filter1);
scan.setFilter(list);
ResultScanner scanner = table.getScanner(scan);
List<String> rowKeyList = new ArrayList<String>();
for (Result result : scanner) {
byte[] row = result.getRow();
rowKeyList.add(Bytes.toString(row));
String rowKey = Bytes.toString(row);
Get get = new Get(row);
get.addColumn("myColFam".getBytes(), "myCol".getBytes());
KeyValue keyValue = table.get(get).getColumnLatest("myColFam".getBytes(), "myCol".getBytes());
if (keyValue != null) {
byte[] byteValue = keyValue.getValue();
String stringValue = Bytes.toString(byteValue);
logger.info(String.format("testHBaseData() :: RowKey = %s, Value = %s ", rowKey, stringValue));
}
}
@gtata
Copy link
Author

gtata commented Jan 29, 2014

Looks like the filter functionality is not working. Has that been implemented yet? I was trying to do the following operation but the filter was being ignored based on my results because my result was showing everything in my table and not filtering. Please advice. Thanks.

FilterList list = new FilterList(FilterList.Operator.MUST_PASS_ALL);
SingleColumnValueFilter filter1 = new SingleColumnValueFilter("myColFam".getBytes(), "myCol".getBytes(), CompareOp.EQUAL, Bytes.toBytes("myValue"));
list.addFilter(filter1);
scan.setFilter(list);
ResultScanner scanner = table.getScanner(scan);
List rowKeyList = new ArrayList();
for (Result result : scanner) {
byte[] row = result.getRow();
rowKeyList.add(Bytes.toString(row));
String rowKey = Bytes.toString(row);
Get get = new Get(row);
get.addColumn("myColFam".getBytes(), "myCol".getBytes());
KeyValue keyValue = table.get(get).getColumnLatest("myColFam".getBytes(), "myCol".getBytes());
if (keyValue != null) {
byte[] byteValue = keyValue.getValue();
String stringValue = Bytes.toString(byteValue);
logger.info(String.format("testHBaseData() :: RowKey = %s, Value = %s ", rowKey, stringValue));
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment