public static Filter createFilterFromArguments (ArrayList<byte []> filterArguments) { Preconditions.checkArgument(filterArguments.size() == 1, "Expected 1 but got: %s", filterArguments.size()); byte [] stopRowKey = ParseFilter.removeQuotesFromByteArray(filterArguments.get(0)); return new InclusiveStopFilter(stopRowKey); }
@Before public void setUp() throws Exception { mainFilter = new InclusiveStopFilter(STOP_ROW); }
/** * @param pbBytes A pb serialized {@link InclusiveStopFilter} instance * @return An instance of {@link InclusiveStopFilter} made from <code>bytes</code> * @throws DeserializationException * @see #toByteArray */ public static InclusiveStopFilter parseFrom(final byte [] pbBytes) throws DeserializationException { FilterProtos.InclusiveStopFilter proto; try { proto = FilterProtos.InclusiveStopFilter.parseFrom(pbBytes); } catch (InvalidProtocolBufferException e) { throw new DeserializationException(e); } return new InclusiveStopFilter(proto.hasStopRowKey()?proto.getStopRowKey().toByteArray():null); }
@Test public void testInclusiveStopFilter() throws Exception { // Grab rows from group one // If we just use start/stop row, we get total/2 - 1 rows long expectedRows = (numRows / 2) - 1; long expectedKeys = colsPerRow; Scan s = new Scan(Bytes.toBytes("testRowOne-0"), Bytes.toBytes("testRowOne-3")); verifyScan(s, expectedRows, expectedKeys); // Now use start row with inclusive stop filter expectedRows = numRows / 2; s = new Scan(Bytes.toBytes("testRowOne-0")); s.setFilter(new InclusiveStopFilter(Bytes.toBytes("testRowOne-3"))); verifyScan(s, expectedRows, expectedKeys); // Grab rows from group two // If we just use start/stop row, we get total/2 - 1 rows expectedRows = (numRows / 2) - 1; expectedKeys = colsPerRow; s = new Scan(Bytes.toBytes("testRowTwo-0"), Bytes.toBytes("testRowTwo-3")); verifyScan(s, expectedRows, expectedKeys); // Now use start row with inclusive stop filter expectedRows = numRows / 2; s = new Scan(Bytes.toBytes("testRowTwo-0")); s.setFilter(new InclusiveStopFilter(Bytes.toBytes("testRowTwo-3"))); verifyScan(s, expectedRows, expectedKeys); }
@Test public void testInclusiveStopFilter() throws IOException { // Grab rows from group one // If we just use start/stop row, we get total/2 - 1 rows long expectedRows = (this.numRows / 2) - 1; long expectedKeys = this.colsPerRow; Scan s = new Scan(Bytes.toBytes("testRowOne-0"), Bytes.toBytes("testRowOne-3")); verifyScan(s, expectedRows, expectedKeys); // Now use start row with inclusive stop filter expectedRows = this.numRows / 2; s = new Scan(Bytes.toBytes("testRowOne-0")); s.setFilter(new InclusiveStopFilter(Bytes.toBytes("testRowOne-3"))); verifyScan(s, expectedRows, expectedKeys); // Grab rows from group two // If we just use start/stop row, we get total/2 - 1 rows expectedRows = (this.numRows / 2) - 1; expectedKeys = this.colsPerRow; s = new Scan(Bytes.toBytes("testRowTwo-0"), Bytes.toBytes("testRowTwo-3")); verifyScan(s, expectedRows, expectedKeys); // Now use start row with inclusive stop filter expectedRows = this.numRows / 2; s = new Scan(Bytes.toBytes("testRowTwo-0")); s.setFilter(new InclusiveStopFilter(Bytes.toBytes("testRowTwo-3"))); verifyScan(s, expectedRows, expectedKeys); }
break; case InclusiveStopFilter: filter = new InclusiveStopFilter(Base64.getDecoder().decode(value)); break; case KeyOnlyFilter:
@Test public void testInclusiveStopFilterWithReverseScan() throws IOException { // Grab rows from group one // If we just use start/stop row, we get total/2 - 1 rows long expectedRows = (this.numRows / 2) - 1; long expectedKeys = this.colsPerRow; Scan s = new Scan(Bytes.toBytes("testRowOne-3"), Bytes.toBytes("testRowOne-0")); s.setReversed(true); verifyScan(s, expectedRows, expectedKeys); // Now use start row with inclusive stop filter expectedRows = this.numRows / 2; s = new Scan(Bytes.toBytes("testRowOne-3")); s.setReversed(true); s.setFilter(new InclusiveStopFilter(Bytes.toBytes("testRowOne-0"))); verifyScan(s, expectedRows, expectedKeys); // Grab rows from group two // If we just use start/stop row, we get total/2 - 1 rows expectedRows = (this.numRows / 2) - 1; expectedKeys = this.colsPerRow; s = new Scan(Bytes.toBytes("testRowTwo-3"), Bytes.toBytes("testRowTwo-0")); s.setReversed(true); verifyScan(s, expectedRows, expectedKeys); // Now use start row with inclusive stop filter expectedRows = this.numRows / 2; s = new Scan(Bytes.toBytes("testRowTwo-3")); s.setReversed(true); s.setFilter(new InclusiveStopFilter(Bytes.toBytes("testRowTwo-0"))); verifyScan(s, expectedRows, expectedKeys); }
@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); } }
@Test public void testInclusiveStopFilter() throws Exception { // InclusveStopFilter with null stopRowKey InclusiveStopFilter inclusiveStopFilter = new InclusiveStopFilter(null); assertTrue(inclusiveStopFilter.areSerializedFieldsEqual( ProtobufUtil.toFilter(ProtobufUtil.toFilter(inclusiveStopFilter)))); // InclusveStopFilter with non-null stopRowKey inclusiveStopFilter = new InclusiveStopFilter(Bytes.toBytes("inclusiveStopFilter")); assertTrue(inclusiveStopFilter.areSerializedFieldsEqual( ProtobufUtil.toFilter(ProtobufUtil.toFilter(inclusiveStopFilter)))); }
@Test public void testFilterAllRecords() throws IOException { Scan scan = new Scan(); scan.setBatch(1); scan.setCaching(1); // Filter out any records scan.setFilter(new FilterList(new FirstKeyOnlyFilter(), new InclusiveStopFilter(new byte[0]))); try (Table table = TEST_UTIL.getConnection().getTable(TableName.META_TABLE_NAME)) { try (ResultScanner s = table.getScanner(scan)) { assertNull(s.next()); } } }
/** * When we do a "MUST_PASS_ONE" (a logical 'OR') of the two filters * we expect to get the same result as the inclusive stop result. * @throws Exception */ @Test public void testFilterListWithInclusiveStopFilterMustPassOne() throws Exception { byte[] r1 = Bytes.toBytes("Row1"); byte[] r11 = Bytes.toBytes("Row11"); byte[] r2 = Bytes.toBytes("Row2"); FilterList flist = new FilterList(FilterList.Operator.MUST_PASS_ONE); flist.addFilter(new AlwaysNextColFilter()); flist.addFilter(new InclusiveStopFilter(r1)); flist.filterRowKey(KeyValueUtil.createFirstOnRow(r1)); assertEquals(ReturnCode.INCLUDE, flist.filterCell(new KeyValue(r1, r1, r1))); assertEquals(ReturnCode.INCLUDE, flist.filterCell(new KeyValue(r11, r11, r11))); flist.reset(); flist.filterRowKey(KeyValueUtil.createFirstOnRow(r2)); assertEquals(ReturnCode.NEXT_COL, flist.filterCell(new KeyValue(r2, r2, r2))); }
public static Filter createFilterFromArguments (ArrayList<byte []> filterArguments) { Preconditions.checkArgument(filterArguments.size() == 1, "Expected 1 but got: %s", filterArguments.size()); byte [] stopRowKey = ParseFilter.removeQuotesFromByteArray(filterArguments.get(0)); return new InclusiveStopFilter(stopRowKey); }
public static void main(String[] args) throws IOException { Configuration conf = HBaseConfiguration.create(); HBaseHelper helper = HBaseHelper.getHelper(conf); helper.dropTable("testtable"); helper.createTable("testtable", "colfam1"); System.out.println("Adding rows to table..."); helper.fillTable("testtable", 1, 100, 1, "colfam1"); Connection connection = ConnectionFactory.createConnection(conf); Table table = connection.getTable(TableName.valueOf("testtable")); // vv InclusiveStopFilterExample Filter filter = new InclusiveStopFilter(Bytes.toBytes("row-5")); Scan scan = new Scan(); scan.setStartRow(Bytes.toBytes("row-3")); scan.setFilter(filter); ResultScanner scanner = table.getScanner(scan); // ^^ InclusiveStopFilterExample System.out.println("Results of scan:"); // vv InclusiveStopFilterExample for (Result result : scanner) { System.out.println(result); } scanner.close(); // ^^ InclusiveStopFilterExample } }
/** * @param pbBytes A pb serialized {@link InclusiveStopFilter} instance * @return An instance of {@link InclusiveStopFilter} made from <code>bytes</code> * @throws DeserializationException * @see #toByteArray */ public static InclusiveStopFilter parseFrom(final byte [] pbBytes) throws DeserializationException { FilterProtos.InclusiveStopFilter proto; try { proto = FilterProtos.InclusiveStopFilter.parseFrom(pbBytes); } catch (InvalidProtocolBufferException e) { throw new DeserializationException(e); } return new InclusiveStopFilter(proto.hasStopRowKey()?proto.getStopRowKey().toByteArray():null); }
public static Filter createFilterFromArguments (ArrayList<byte []> filterArguments) { Preconditions.checkArgument(filterArguments.size() == 1, "Expected 1 but got: %s", filterArguments.size()); byte [] stopRowKey = ParseFilter.removeQuotesFromByteArray(filterArguments.get(0)); return new InclusiveStopFilter(stopRowKey); }
public static Filter createFilterFromArguments (ArrayList<byte []> filterArguments) { Preconditions.checkArgument(filterArguments.size() == 1, "Expected 1 but got: %s", filterArguments.size()); byte [] stopRowKey = ParseFilter.removeQuotesFromByteArray(filterArguments.get(0)); return new InclusiveStopFilter(stopRowKey); }
public static Filter createFilterFromArguments (ArrayList<byte []> filterArguments) { Preconditions.checkArgument(filterArguments.size() == 1, "Expected 1 but got: %s", filterArguments.size()); byte [] stopRowKey = ParseFilter.removeQuotesFromByteArray(filterArguments.get(0)); return new InclusiveStopFilter(stopRowKey); }
@Before public void setUp() throws Exception { mainFilter = new InclusiveStopFilter(STOP_ROW); }
@Test public void testInclusiveStopFilter() throws Exception { // InclusveStopFilter with null stopRowKey InclusiveStopFilter inclusiveStopFilter = new InclusiveStopFilter(null); assertTrue(inclusiveStopFilter.areSerializedFieldsEqual( ProtobufUtil.toFilter(ProtobufUtil.toFilter(inclusiveStopFilter)))); // InclusveStopFilter with non-null stopRowKey inclusiveStopFilter = new InclusiveStopFilter(Bytes.toBytes("inclusiveStopFilter")); assertTrue(inclusiveStopFilter.areSerializedFieldsEqual( ProtobufUtil.toFilter(ProtobufUtil.toFilter(inclusiveStopFilter)))); }
@Test public void testFilterAllRecords() throws IOException { Scan scan = new Scan(); scan.setBatch(1); scan.setCaching(1); // Filter out any records scan.setFilter(new FilterList(new FirstKeyOnlyFilter(), new InclusiveStopFilter(new byte[0]))); try (Table table = TEST_UTIL.getConnection().getTable(TableName.NAMESPACE_TABLE_NAME)) { try (ResultScanner s = table.getScanner(scan)) { assertNull(s.next()); } } }