DataCellPredicateFactory implements Function<Cell, Predicate<Cell>> { @Override public Predicate<Cell> apply(Cell deleteMarker) { checkArgument(CellUtil.isDelete(deleteMarker), "expecting delete marker cell."); switch (KeyValue.Type.codeToType(deleteMarker.getTypeByte())) { case Delete: return Predicates.and( new MatchQualifier(deleteMarker), new MatchExactTimestamp(deleteMarker)); case DeleteFamilyVersion: return new MatchExactTimestamp(deleteMarker); case DeleteColumn: return Predicates.and( new MatchQualifier(deleteMarker), new MatchTimestampRangeByUpperBound(deleteMarker)); case DeleteFamily: return new MatchTimestampRangeByUpperBound(deleteMarker); default: throw new IllegalStateException("Unexpected type byte: " + deleteMarker.getTypeByte()); } }  @Override Predicate<Cell> apply(Cell deleteMarker);  }
@Test public void testDeleteMarkerForOneCellWithExactTimestamp() { long timestamp = 10000L; List<Cell> cells = Lists.newArrayList( HBaseCellUtils.createDataCell(ROW_KEY, COLUMN_FAMILY, QUALIFIER, timestamp), HBaseCellUtils.createDataCell(ROW_KEY, COLUMN_FAMILY, QUALIFIER, timestamp - 1), HBaseCellUtils.createDataCell(ROW_KEY, COLUMN_FAMILY, QUALIFIER, timestamp + 1)); Predicate<Cell> predicate = predicateMaker.apply( HBaseCellUtils.deleteMarkerForOneCellWithExactTimestamp( ROW_KEY, COLUMN_FAMILY, QUALIFIER, timestamp)); assertEquals(cells.get(0), Iterables.getOnlyElement(Iterables.filter(cells, predicate))); predicate = predicateMaker.apply( HBaseCellUtils.deleteMarkerForOneCellWithExactTimestamp( ROW_KEY, COLUMN_FAMILY, ANOTHER_QUALIFIER, timestamp)); assertTrue(Iterables.isEmpty(Iterables.filter(cells, predicate))); }
@Test public void testDeleteMarkerForCellsWithLowerOrEqualTimestamp() { long timestamp = 10000L; List<Cell> cells = Lists.newArrayList( HBaseCellUtils.createDataCell(ROW_KEY, COLUMN_FAMILY, QUALIFIER, timestamp), HBaseCellUtils.createDataCell(ROW_KEY, COLUMN_FAMILY, QUALIFIER, timestamp - 1), HBaseCellUtils.createDataCell(ROW_KEY, COLUMN_FAMILY, QUALIFIER, timestamp + 1)); Predicate<Cell> predicate = predicateMaker.apply( HBaseCellUtils.deleteMarkerForCellsWithLowerOrEqualTimestamp( ROW_KEY, COLUMN_FAMILY, QUALIFIER, timestamp)); assertEquals( Sets.newHashSet(cells.get(0), cells.get(1)), Sets.newHashSet(Iterables.filter(cells, predicate))); predicate = predicateMaker.apply( HBaseCellUtils.deleteMarkerForCellsWithLowerOrEqualTimestamp( ROW_KEY, COLUMN_FAMILY, ANOTHER_QUALIFIER, timestamp)); assertTrue(Iterables.isEmpty(Iterables.filter(cells, predicate))); }
@Test public void testDeleteMarkerForAllCellsInFamilyWithExactTimestamp() { long timestamp = 10000L; Predicate<Cell> predicate = predicateMaker.apply( HBaseCellUtils.deleteMarkerForAllCellsInFamilyWithExactTimestamp( ROW_KEY, COLUMN_FAMILY, timestamp)); List<Cell> allCells = Lists.newArrayList( HBaseCellUtils.createDataCell(ROW_KEY, COLUMN_FAMILY, QUALIFIER, timestamp), HBaseCellUtils.createDataCell(ROW_KEY, COLUMN_FAMILY, ANOTHER_QUALIFIER, timestamp), HBaseCellUtils.createDataCell(ROW_KEY, COLUMN_FAMILY, QUALIFIER, timestamp - 1), HBaseCellUtils.createDataCell(ROW_KEY, COLUMN_FAMILY, ANOTHER_QUALIFIER, timestamp - 1), HBaseCellUtils.createDataCell(ROW_KEY, COLUMN_FAMILY, QUALIFIER, timestamp + 1), HBaseCellUtils.createDataCell( ROW_KEY, COLUMN_FAMILY, ANOTHER_QUALIFIER, timestamp + 1)); Set<Cell> expected = Sets.newHashSet(allCells.get(0), allCells.get(1)); assertEquals(expected, Sets.newHashSet(Iterables.filter(allCells, predicate))); }
@Test public void testDeleteMarkerForAllCellsInFamilyWithLowerOrEqualTimestamp() { long timestamp = 10000L; Predicate<Cell> predicate = predicateMaker.apply( HBaseCellUtils.deleteMarkerForAllCellsInFamilyWithLowerOrEqualTimestamp( ROW_KEY, COLUMN_FAMILY, timestamp)); List<Cell> allCells = Lists.newArrayList( HBaseCellUtils.createDataCell(ROW_KEY, COLUMN_FAMILY, QUALIFIER, timestamp), HBaseCellUtils.createDataCell(ROW_KEY, COLUMN_FAMILY, ANOTHER_QUALIFIER, timestamp), HBaseCellUtils.createDataCell(ROW_KEY, COLUMN_FAMILY, QUALIFIER, timestamp - 1), HBaseCellUtils.createDataCell(ROW_KEY, COLUMN_FAMILY, ANOTHER_QUALIFIER, timestamp - 1), HBaseCellUtils.createDataCell(ROW_KEY, COLUMN_FAMILY, QUALIFIER, timestamp + 1), HBaseCellUtils.createDataCell( ROW_KEY, COLUMN_FAMILY, ANOTHER_QUALIFIER, timestamp + 1)); Set<Cell> expected = Sets.newHashSet(allCells.subList(0, 4)); assertEquals(expected, Sets.newHashSet(Iterables.filter(allCells, predicate))); }