ApplyAndFilterDeletesFilter extends FilterBase { @Override public ReturnCode filterKeyValue(Cell next) { if (this.done) { return ReturnCode.SKIP; } KeyValue nextKV = KeyValueUtil.ensureKeyValue(next); switch (KeyValue.Type.codeToType(next.getTypeByte())) { case DeleteFamily: this.coveringDelete.reset(); this.coveringDelete.deleteFamily = nextKV; return ReturnCode.SKIP; case DeleteColumn: this.coveringDelete.pointDelete = null; this.coveringDelete.deleteColumn = nextKV; return ReturnCode.SKIP; case Delete: this.coveringDelete.pointDelete = nextKV; return ReturnCode.SKIP; default: if (coveringDelete.empty()) { return ReturnCode.INCLUDE; } if (coveringDelete.matchesFamily(nextKV)) { this.currentHint = familyHint; return ReturnCode.SEEK_NEXT_USING_HINT; } if (coveringDelete.matchesColumn(nextKV)) { this.currentHint = columnHint; return ReturnCode.SEEK_NEXT_USING_HINT; } if (coveringDelete.matchesPoint(nextKV)) { return ReturnCode.SKIP; } } return ReturnCode.INCLUDE; } ApplyAndFilterDeletesFilter(Set<ImmutableBytesPtr> families); @Override void reset(); @Override Cell getNextCellHint(Cell peeked); @Override ReturnCode filterKeyValue(Cell next);  }
@Test public void testCoveringPointDelete() { KeyValue kv = createKvForType(Type.Delete); ApplyAndFilterDeletesFilter filter = new ApplyAndFilterDeletesFilter(EMPTY_SET); filter.filterKeyValue(kv); KeyValue put = createKvForType(Type.Put); assertEquals("Didn't filter out put with same timestamp!", ReturnCode.SKIP, filter.filterKeyValue(put)); assertEquals("Didn't filter out put with same timestamp on second call!", ReturnCode.SKIP, filter.filterKeyValue(put)); put = createKvForType(Type.Put, ts - 1); assertEquals("Didn't accept put that has an earlier ts than the covering delete!", ReturnCode.INCLUDE, filter.filterKeyValue(put)); }
@Test public void testDeleteColumnCorrectlyCoversColumns() { ApplyAndFilterDeletesFilter filter = new ApplyAndFilterDeletesFilter(EMPTY_SET); KeyValue d = createKvForType(Type.DeleteColumn, 12); byte[] qual2 = Bytes.add(qualifier, Bytes.toBytes("-other")); KeyValue put = new KeyValue(row, family, qual2, 11, Type.Put, value); assertEquals("Didn't filter out delete column", ReturnCode.SKIP, filter.filterKeyValue(d)); assertEquals("Filtered out put with different column than the delete", ReturnCode.INCLUDE, filter.filterKeyValue(put)); d = createKvForType(Type.DeleteFamily, 10); assertEquals("Didn't filter out delete column", ReturnCode.SKIP, filter.filterKeyValue(d)); d = createKvForType(Type.DeleteColumn, 11); assertEquals("Didn't filter out delete column", ReturnCode.SKIP, filter.filterKeyValue(d)); assertEquals("Filtered out put with different column than the delete", ReturnCode.INCLUDE, filter.filterKeyValue(put)); }