I am scanning HBase by setting Scanner with only specific column names I want and a range of columns using column filter.
Adding individual rows:
known_fields.forEach(known_field ->scanner.addColumn("x".getBytes(), known_field.getBytes()));
Also I am adding a Column filter:
scanner.setFilter(new ColumnRangeFilter(start, true, stop, true));
All the variables have correct values. And I am scanning as below
scanner.setCacheBlocks(false);
scanner.setBatch(1000);
ResultScanner results = null;
Table table = null;
try {
table = connection.getTable("table_test");
results = table.getScanner(scanner);
boolean hasPerformed;
for (final Result result : results) {
...
The results is always null. But, If I comment out either scanner.setFilter(new ColumnRangeFilter(start, true, stop, true)); or scanner.addColumn(, the result is perfectly fine. It isn't working with combination.
How to achieve the combination of known columns and a range of columns?
If you have small number of columns for scanner.addColumn, you can use FilterList with MUST_PASS_ONE operator and passing to it multiply ColumnRangeFilter. Add column to scan is this case equivalent to add ColumnRangeFilter with coincide start and end columns. E.g.
Filter filter = new FilterList(FilterList.Operator.MUST_PASS_ONE);
known_fields.forEach(known_field ->
filter.addFilter(new ColumnRangeFilter(known_field.getBytes(), true,
known_field.getBytes(), true));
filter.add(new ColumnRangeFilter(start, true, stop, true));
scan.setFilter(filter);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With