Filter whileMatchFilter = new WhileMatchFilter(wrappedFilter); operatorStack.pop(); return whileMatchFilter;
/** * @param o the other filter to compare with * @return true if and only if the fields of the filter that are serialized * are equal to the corresponding fields in other. Used for testing. */ @Override boolean areSerializedFieldsEqual(Filter o) { if (o == this) return true; if (!(o instanceof WhileMatchFilter)) return false; WhileMatchFilter other = (WhileMatchFilter)o; return getFilter().areSerializedFieldsEqual(other.getFilter()); }
@Override public boolean filterRowKey(byte[] buffer, int offset, int length) throws IOException { boolean value = filter.filterRowKey(buffer, offset, length); changeFAR(value); return value; }
@Override public boolean filterRowKey(Cell cell) throws IOException { if (filterAllRemaining()) return true; boolean value = filter.filterRowKey(cell); changeFAR(value); return value; }
@Test public void testWhileMatchFilter() throws Exception { WhileMatchFilter whileMatchFilter = new WhileMatchFilter( new ColumnRangeFilter(Bytes.toBytes("c"), false, Bytes.toBytes("d"), true)); assertTrue(whileMatchFilter.areSerializedFieldsEqual( ProtobufUtil.toFilter(ProtobufUtil.toFilter(whileMatchFilter)))); }
/** * Tests the the {@link WhileMatchFilter} works in combination with a * {@link Filter} that uses the * {@link Filter#filterRowKey(Cell)} method. * * See HBASE-2258. * * @throws Exception */ @Test public void testWhileMatchFilterWithFilterRowKey() throws Exception { Scan s = new Scan(); String prefix = "testRowOne"; WhileMatchFilter filter = new WhileMatchFilter(new PrefixFilter(Bytes.toBytes(prefix))); s.setFilter(filter); InternalScanner scanner = this.region.getScanner(s); while (true) { ArrayList<Cell> values = new ArrayList<>(); boolean isMoreResults = scanner.next(values); if (!isMoreResults || !Bytes.toString(CellUtil.cloneRow(values.get(0))).startsWith(prefix)) { assertTrue("The WhileMatchFilter should now filter all remaining", filter.filterAllRemaining()); } if (!isMoreResults) { break; } } }
@Override public boolean equals(Object obj) { return obj instanceof Filter && areSerializedFieldsEqual((Filter) obj); }
/** * Tests the the {@link WhileMatchFilter} works in combination with a * {@link Filter} that uses the {@link Filter#filterCell(Cell)} method. * * See HBASE-2258. * * @throws Exception */ @Test public void testWhileMatchFilterWithFilterCell() throws Exception { Scan s = new Scan(); WhileMatchFilter filter = new WhileMatchFilter( new SingleColumnValueFilter(FAMILIES[0], QUALIFIERS_ONE[0], CompareOperator.EQUAL, Bytes.toBytes("foo")) ); s.setFilter(filter); InternalScanner scanner = this.region.getScanner(s); while (true) { ArrayList<Cell> values = new ArrayList<>(); boolean isMoreResults = scanner.next(values); assertTrue("The WhileMatchFilter should now filter all remaining", filter.filterAllRemaining()); if (!isMoreResults) { break; } } }
@Test public void testWhileMatchFilter() throws Exception { WhileMatchFilter whileMatchFilter = new WhileMatchFilter( new ColumnRangeFilter(Bytes.toBytes("c"), false, Bytes.toBytes("d"), true)); assertTrue(whileMatchFilter.areSerializedFieldsEqual( ProtobufUtil.toFilter(ProtobufUtil.toFilter(whileMatchFilter)))); }
@Override public boolean filterRowKey(Cell cell) throws IOException { if (filterAllRemaining()) return true; boolean value = filter.filterRowKey(cell); changeFAR(value); return value; }
private Filter getMPALLFilter() { List<Filter> filters = new ArrayList<>(); filters.add(new PageFilter(MAX_PAGES)); filters.add(new WhileMatchFilter(new PrefixFilter(Bytes.toBytes("yyy")))); Filter filterMPALL = new FilterList(FilterList.Operator.MUST_PASS_ALL, filters); return filterMPALL; }
@Test public void testWhileMatchFilterWithFilterRowKeyWithReverseScan() throws Exception { Scan s = new Scan(); String prefix = "testRowOne"; WhileMatchFilter filter = new WhileMatchFilter(new PrefixFilter( Bytes.toBytes(prefix))); s.setFilter(filter); s.setReversed(true); InternalScanner scanner = this.region.getScanner(s); while (true) { ArrayList<Cell> values = new ArrayList<>(); boolean isMoreResults = scanner.next(values); if (!isMoreResults || !Bytes.toString(CellUtil.cloneRow(values.get(0))).startsWith(prefix)) { Assert.assertTrue( "The WhileMatchFilter should now filter all remaining", filter.filterAllRemaining()); } if (!isMoreResults) { break; } } scanner.close(); }
this.filters = new ArrayList<>(); this.filters.add( new FilterModel(((WhileMatchFilter)filter).getFilter())); break; default:
@Override public ReturnCode filterCell(final Cell c) throws IOException { ReturnCode code = filter.filterCell(c); changeFAR(code != ReturnCode.INCLUDE); return code; }
@Override public boolean filterRowKey(Cell cell) throws IOException { if (filterAllRemaining()) return true; boolean value = filter.filterRowKey(cell); changeFAR(value); return value; }
private Filter getFilterMPONE() { List<Filter> filters = new ArrayList<>(); filters.add(new PageFilter(MAX_PAGES)); filters.add(new WhileMatchFilter(new PrefixFilter(Bytes.toBytes("yyy")))); Filter filterMPONE = new FilterList(FilterList.Operator.MUST_PASS_ONE, filters); return filterMPONE; }
/** * Tests the the {@link WhileMatchFilter} works in combination with a * {@link Filter} that uses the * {@link Filter#filterRow()} method. * * See HBASE-2258. * * @throws Exception */ @Test public void testWhileMatchFilterWithFilterRow() throws Exception { final int pageSize = 4; Scan s = new Scan(); WhileMatchFilter filter = new WhileMatchFilter(new PageFilter(pageSize)); s.setFilter(filter); InternalScanner scanner = this.region.getScanner(s); int scannerCounter = 0; while (true) { boolean isMoreResults = scanner.next(new ArrayList<>()); scannerCounter++; if (scannerCounter >= pageSize) { assertTrue("The WhileMatchFilter should now filter all remaining", filter.filterAllRemaining()); } if (!isMoreResults) { break; } } assertEquals("The page filter returned more rows than expected", pageSize, scannerCounter); }
@Test public void testWhileFilter() throws IOException { String filterString = " WHILE RowFilter ( !=, 'binary:row1')"; WhileMatchFilter whileMatchFilter = doTestFilter(filterString, WhileMatchFilter.class); assertTrue(whileMatchFilter.getFilter() instanceof RowFilter); RowFilter rowFilter = (RowFilter) whileMatchFilter.getFilter(); assertEquals(CompareOperator.NOT_EQUAL, rowFilter.getCompareOperator()); assertTrue(rowFilter.getComparator() instanceof BinaryComparator); BinaryComparator binaryComparator = (BinaryComparator) rowFilter.getComparator(); assertEquals("row1", new String(binaryComparator.getValue(), StandardCharsets.UTF_8)); }
@Override public boolean filterRow() throws IOException { boolean filterRow = this.filter.filterRow(); changeFAR(filterRow); return filterRow; }
@Test public void testPrefixOnRowInsideWhileMatchRow() throws Exception { prefixRowTests(new WhileMatchFilter(this.mainFilter), true); }