@Test public void testSimpleColumnCount() throws IOException { RowFilter adaptedFilter = adapter.adapt(new FilterAdapterContext(new Scan(), null), new ColumnCountGetFilter(2)); Assert.assertEquals( RowFilter.newBuilder() .setChain( Chain.newBuilder() .addFilters(RowFilter.newBuilder().setCellsPerColumnLimitFilter(1)) .addFilters(RowFilter.newBuilder().setCellsPerRowLimitFilter(2))) .build(), adaptedFilter); }
/** Create a filter that will emit all cells in a row if a given qualifier has a given value. */ private RowFilter createEmitRowsWithValueFilter( FilterAdapterContext context, SingleColumnValueFilter filter) throws IOException { return RowFilter.newBuilder() .setCondition( Condition.newBuilder() .setPredicateFilter( RowFilter.newBuilder() .setChain( Chain.newBuilder() .addFilters(createColumnSpecFilter(filter)) .addFilters(createValueMatchFilter(context, filter)))) .setTrueFilter(ALL_VALUES_FILTER)) .build(); }
/** Create a filter that will match a given family, qualifier, and cells per qualifier. */ private RowFilter createColumnSpecFilter(SingleColumnValueFilter filter) throws IOException { return RowFilter.newBuilder() .setChain( Chain.newBuilder() .addFilters( RowFilter.newBuilder() .setFamilyNameRegexFilter( Bytes.toString(quoteRegularExpression(filter.getFamily())))) .addFilters( RowFilter.newBuilder() .setColumnQualifierRegexFilter( ByteStringer.wrap(quoteRegularExpression(filter.getQualifier())))) .addFilters(createVersionLimitFilter(filter))) .build(); }