Filter whileMatchFilter = new WhileMatchFilter(wrappedFilter); operatorStack.pop(); return whileMatchFilter;
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; }
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; }
@Test public void testPrefixOnRowInsideWhileMatchRow() throws Exception { prefixRowTests(new WhileMatchFilter(this.mainFilter), true); }
private Scan createScanWithRowFilter(final byte [] key, final byte [] startRow, CompareOperator op) { // Make sure key is of some substance... non-null and > than first key. assertTrue(key != null && key.length > 0 && Bytes.BYTES_COMPARATOR.compare(key, new byte [] {'a', 'a', 'a'}) >= 0); LOG.info("Key=" + Bytes.toString(key)); Scan s = startRow == null? new Scan(): new Scan(startRow); Filter f = new RowFilter(op, new BinaryComparator(key)); f = new WhileMatchFilter(f); s.setFilter(f); return s; }
/** * @param pbBytes A pb serialized {@link WhileMatchFilter} instance * @return An instance of {@link WhileMatchFilter} made from <code>bytes</code> * @throws org.apache.hadoop.hbase.exceptions.DeserializationException * @see #toByteArray */ public static WhileMatchFilter parseFrom(final byte [] pbBytes) throws DeserializationException { FilterProtos.WhileMatchFilter proto; try { proto = FilterProtos.WhileMatchFilter.parseFrom(pbBytes); } catch (InvalidProtocolBufferException e) { throw new DeserializationException(e); } try { return new WhileMatchFilter(ProtobufUtil.toFilter(proto.getFilter())); } catch (IOException ioe) { throw new DeserializationException(ioe); } }
break; case WhileMatchFilter: filter = new WhileMatchFilter(filters.get(0).build()); break; default:
Scan scan = new Scan(getBytes(startAndPrefix)); addAttributes(scan, attributes); Filter f = new WhileMatchFilter( new PrefixFilter(getBytes(startAndPrefix))); scan.setFilter(f);
@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 void testRow(final int i) throws IOException { Scan scan = new Scan(getRandomRow(this.rand, this.totalRows)); scan.addColumn(FAMILY_NAME, QUALIFIER_NAME); scan.setFilter(new WhileMatchFilter(new PageFilter(120))); ResultScanner s = this.table.getScanner(scan); s.close(); }
@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(); }
/** * 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 testFilters() throws IOException { try { this.region = TEST_UTIL.createLocalHRegion(TESTTABLEDESC, null, null); HBaseTestCase.addContent(this.region, HConstants.CATALOG_FAMILY); byte [] prefix = Bytes.toBytes("ab"); Filter newFilter = new PrefixFilter(prefix); Scan scan = new Scan(); scan.setFilter(newFilter); rowPrefixFilter(scan); byte[] stopRow = Bytes.toBytes("bbc"); newFilter = new WhileMatchFilter(new InclusiveStopFilter(stopRow)); scan = new Scan(); scan.setFilter(newFilter); rowInclusiveStopFilter(scan, stopRow); } finally { HBaseTestingUtility.closeRegionAndWAL(this.region); } }
/** * 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 testWhileMatchFilterWithFilterRowWithReverseScan() throws Exception { final int pageSize = 4; Scan s = new Scan(); s.setReversed(true); 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) { Assert.assertTrue( "The WhileMatchFilter should now filter all remaining", filter.filterAllRemaining()); } if (!isMoreResults) { break; } } scanner.close(); Assert.assertEquals("The page filter returned more rows than expected", pageSize, scannerCounter); }
/** * Test serialization * @throws Exception */ @Test public void testSerialization() throws Exception { 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); // Decompose filterMPALL to bytes. byte[] buffer = filterMPALL.toByteArray(); // Recompose filterMPALL. FilterList newFilter = FilterList.parseFrom(buffer); // Run tests mpOneTest(ProtobufUtil.toFilter(ProtobufUtil.toFilter(getFilterMPONE()))); mpAllTest(ProtobufUtil.toFilter(ProtobufUtil.toFilter(getMPALLFilter()))); orderingTest(ProtobufUtil.toFilter(ProtobufUtil.toFilter(getOrderingFilter()))); }
list.addFilter(new FilterAllFilter()); list.addFilter(new WhileMatchFilter(new PageFilter(120))); scan.setFilter(list); ResultScanner s = this.table.getScanner(scan);
/** * @param pbBytes A pb serialized {@link WhileMatchFilter} instance * @return An instance of {@link WhileMatchFilter} made from <code>bytes</code> * @throws org.apache.hadoop.hbase.exceptions.DeserializationException * @see #toByteArray */ public static WhileMatchFilter parseFrom(final byte [] pbBytes) throws DeserializationException { FilterProtos.WhileMatchFilter proto; try { proto = FilterProtos.WhileMatchFilter.parseFrom(pbBytes); } catch (InvalidProtocolBufferException e) { throw new DeserializationException(e); } try { return new WhileMatchFilter(ProtobufUtil.toFilter(proto.getFilter())); } catch (IOException ioe) { throw new DeserializationException(ioe); } }
Filter filter2 = new /*[*/WhileMatchFilter(filter1);/*]*/