/** * 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 */ public void testFilterListWithInclusiveStopFilteMustPassOne() 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(r1, 0, r1.length); assertEquals(flist.filterKeyValue(new KeyValue(r1,r1,r1)), ReturnCode.INCLUDE); assertEquals(flist.filterKeyValue(new KeyValue(r11,r11,r11)), ReturnCode.INCLUDE); flist.reset(); flist.filterRowKey(r2, 0, r2.length); assertEquals(flist.filterKeyValue(new KeyValue(r2,r2,r2)), ReturnCode.SKIP); }
/** * 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))); }
@Test public void testWithMultiVersionsInSameRow() throws Exception { FilterList filterList01 = new FilterList(Operator.MUST_PASS_ONE, new ColumnPaginationFilter(1, 0)); KeyValue kv1 = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("fam"), Bytes.toBytes("qual"), 1, Bytes.toBytes("value")); KeyValue kv2 = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("fam"), Bytes.toBytes("qual"), 2, Bytes.toBytes("value")); KeyValue kv3 = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("fam"), Bytes.toBytes("qual"), 3, Bytes.toBytes("value")); assertEquals(ReturnCode.INCLUDE_AND_NEXT_COL, filterList01.filterCell(kv1)); assertEquals(ReturnCode.SKIP, filterList01.filterCell(kv2)); assertEquals(ReturnCode.SKIP, filterList01.filterCell(kv3)); FilterList filterList11 = new FilterList(Operator.MUST_PASS_ONE, new ColumnPaginationFilter(1, 1)); assertEquals(ReturnCode.NEXT_COL, filterList11.filterCell(kv1)); assertEquals(ReturnCode.SKIP, filterList11.filterCell(kv2)); assertEquals(ReturnCode.SKIP, filterList11.filterCell(kv3)); }
@Test public void testMPONEWithSeekNextUsingHint() throws Exception { byte[] col = Bytes.toBytes("c"); FilterList filterList = new FilterList(Operator.MUST_PASS_ONE, new ColumnPaginationFilter(1, col)); KeyValue kv1 = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("fam"), Bytes.toBytes("a"), 1, Bytes.toBytes("value")); KeyValue kv2 = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("fam"), Bytes.toBytes("b"), 2, Bytes.toBytes("value")); KeyValue kv3 = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("fam"), Bytes.toBytes("c"), 3, Bytes.toBytes("value")); KeyValue kv4 = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("fam"), Bytes.toBytes("c"), 4, Bytes.toBytes("value")); assertEquals(ReturnCode.SEEK_NEXT_USING_HINT, filterList.filterCell(kv1)); assertEquals(ReturnCode.SKIP, filterList.filterCell(kv2)); assertEquals(ReturnCode.INCLUDE_AND_NEXT_COL, filterList.filterCell(kv3)); assertEquals(ReturnCode.SKIP, filterList.filterCell(kv4)); }
/** * When we do a "MUST_PASS_ONE" (a logical 'OR') of the above two filters * we expect to get the same result as the 'prefix' only result. * @throws Exception */ public void testFilterListTwoFiltersMustPassOne() 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 PrefixFilter(r1)); flist.filterRowKey(r1, 0, r1.length); assertEquals(flist.filterKeyValue(new KeyValue(r1,r1,r1)), ReturnCode.INCLUDE); assertEquals(flist.filterKeyValue(new KeyValue(r11,r11,r11)), ReturnCode.INCLUDE); flist.reset(); flist.filterRowKey(r2, 0, r2.length); assertEquals(flist.filterKeyValue(new KeyValue(r2,r2,r2)), ReturnCode.SKIP); flist = new FilterList(FilterList.Operator.MUST_PASS_ONE); flist.addFilter(new AlwaysNextColFilter()); flist.addFilter(new PrefixFilter(r1)); flist.filterRowKey(r1, 0, r1.length); assertEquals(flist.filterKeyValue(new KeyValue(r1,r1,r1)), ReturnCode.INCLUDE); assertEquals(flist.filterKeyValue(new KeyValue(r11,r11,r11)), ReturnCode.INCLUDE); flist.reset(); flist.filterRowKey(r2, 0, r2.length); assertEquals(flist.filterKeyValue(new KeyValue(r2,r2,r2)), ReturnCode.SKIP); }
/** * Tests the behavior of transform() in a hierarchical filter. * * transform() only applies after a filterKeyValue() whose return-code includes the KeyValue. * Lazy evaluation of AND */ @Test public void testTransformMPO() throws Exception { // Apply the following filter: // (family=fam AND qualifier=qual1 AND KeyOnlyFilter) // OR (family=fam AND qualifier=qual2) final FilterList flist = new FilterList(Operator.MUST_PASS_ONE, Lists.<Filter>newArrayList( new FilterList(Operator.MUST_PASS_ALL, Lists.<Filter>newArrayList( new FamilyFilter(CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes("fam"))), new QualifierFilter(CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes("qual1"))), new KeyOnlyFilter())), new FilterList(Operator.MUST_PASS_ALL, Lists.<Filter>newArrayList( new FamilyFilter(CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes("fam"))), new QualifierFilter(CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes("qual2"))))))); final KeyValue kvQual1 = new KeyValue( Bytes.toBytes("row"), Bytes.toBytes("fam"), Bytes.toBytes("qual1"), Bytes.toBytes("value")); final KeyValue kvQual2 = new KeyValue( Bytes.toBytes("row"), Bytes.toBytes("fam"), Bytes.toBytes("qual2"), Bytes.toBytes("value")); final KeyValue kvQual3 = new KeyValue( Bytes.toBytes("row"), Bytes.toBytes("fam"), Bytes.toBytes("qual3"), Bytes.toBytes("value")); // Value for fam:qual1 should be stripped: assertEquals(Filter.ReturnCode.INCLUDE, flist.filterKeyValue(kvQual1)); final KeyValue transformedQual1 = KeyValueUtil.ensureKeyValue(flist.transform(kvQual1)); assertEquals(0, transformedQual1.getValue().length); // Value for fam:qual2 should not be stripped: assertEquals(Filter.ReturnCode.INCLUDE, flist.filterKeyValue(kvQual2)); final KeyValue transformedQual2 = KeyValueUtil.ensureKeyValue(flist.transform(kvQual2)); assertEquals("value", Bytes.toString(transformedQual2.getValue())); // Other keys should be skipped: assertEquals(Filter.ReturnCode.SKIP, flist.filterKeyValue(kvQual3)); }
/** * Tests the behavior of transform() in a hierarchical filter. * * transform() only applies after a filterKeyValue() whose return-code includes the KeyValue. * Lazy evaluation of AND */ public void testTransformMPO() throws Exception { // Apply the following filter: // (family=fam AND qualifier=qual1 AND KeyOnlyFilter) // OR (family=fam AND qualifier=qual2) final FilterList flist = new FilterList(Operator.MUST_PASS_ONE, Lists.<Filter>newArrayList( new FilterList(Operator.MUST_PASS_ALL, Lists.<Filter>newArrayList( new FamilyFilter(CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes("fam"))), new QualifierFilter(CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes("qual1"))), new KeyOnlyFilter())), new FilterList(Operator.MUST_PASS_ALL, Lists.<Filter>newArrayList( new FamilyFilter(CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes("fam"))), new QualifierFilter(CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes("qual2"))))))); final KeyValue kvQual1 = new KeyValue( Bytes.toBytes("row"), Bytes.toBytes("fam"), Bytes.toBytes("qual1"), Bytes.toBytes("value")); final KeyValue kvQual2 = new KeyValue( Bytes.toBytes("row"), Bytes.toBytes("fam"), Bytes.toBytes("qual2"), Bytes.toBytes("value")); final KeyValue kvQual3 = new KeyValue( Bytes.toBytes("row"), Bytes.toBytes("fam"), Bytes.toBytes("qual3"), Bytes.toBytes("value")); // Value for fam:qual1 should be stripped: assertEquals(Filter.ReturnCode.INCLUDE, flist.filterKeyValue(kvQual1)); final KeyValue transformedQual1 = flist.transform(kvQual1); assertEquals(0, transformedQual1.getValue().length); // Value for fam:qual2 should not be stripped: assertEquals(Filter.ReturnCode.INCLUDE, flist.filterKeyValue(kvQual2)); final KeyValue transformedQual2 = flist.transform(kvQual2); assertEquals("value", Bytes.toString(transformedQual2.getValue())); // Other keys should be skipped: assertEquals(Filter.ReturnCode.SKIP, flist.filterKeyValue(kvQual3)); }
/** * When we do a "MUST_PASS_ONE" (a logical 'OR') of the above two filters * we expect to get the same result as the 'prefix' only result. * @throws Exception */ @Test public void testFilterListTwoFiltersMustPassOne() 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 PrefixFilter(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.SKIP, flist.filterCell(new KeyValue(r2, r2, r2))); flist = new FilterList(FilterList.Operator.MUST_PASS_ONE); flist.addFilter(new AlwaysNextColFilter()); flist.addFilter(new PrefixFilter(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))); }
/** * Tests the behavior of transform() in a hierarchical filter. * * transform() only applies after a filterCell() whose return-code includes the KeyValue. * Lazy evaluation of AND */ @Test public void testTransformMPO() throws Exception { // Apply the following filter: // (family=fam AND qualifier=qual1 AND KeyOnlyFilter) // OR (family=fam AND qualifier=qual2) final FilterList flist = new FilterList(Operator.MUST_PASS_ONE, Lists.<Filter>newArrayList( new FilterList(Operator.MUST_PASS_ALL, Lists.<Filter>newArrayList( new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("fam"))), new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("qual1"))), new KeyOnlyFilter())), new FilterList(Operator.MUST_PASS_ALL, Lists.<Filter>newArrayList( new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("fam"))), new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("qual2"))))))); final KeyValue kvQual1 = new KeyValue( Bytes.toBytes("row"), Bytes.toBytes("fam"), Bytes.toBytes("qual1"), Bytes.toBytes("value")); final KeyValue kvQual2 = new KeyValue( Bytes.toBytes("row"), Bytes.toBytes("fam"), Bytes.toBytes("qual2"), Bytes.toBytes("value")); final KeyValue kvQual3 = new KeyValue( Bytes.toBytes("row"), Bytes.toBytes("fam"), Bytes.toBytes("qual3"), Bytes.toBytes("value")); // Value for fam:qual1 should be stripped: assertEquals(Filter.ReturnCode.INCLUDE, flist.filterCell(kvQual1)); final KeyValue transformedQual1 = KeyValueUtil.ensureKeyValue(flist.transformCell(kvQual1)); assertEquals(0, transformedQual1.getValueLength()); // Value for fam:qual2 should not be stripped: assertEquals(Filter.ReturnCode.INCLUDE, flist.filterCell(kvQual2)); final KeyValue transformedQual2 = KeyValueUtil.ensureKeyValue(flist.transformCell(kvQual2)); assertEquals("value", Bytes.toString(transformedQual2.getValueArray(), transformedQual2.getValueOffset(), transformedQual2.getValueLength())); // Other keys should be skipped: assertEquals(Filter.ReturnCode.SKIP, flist.filterCell(kvQual3)); }
@Test public void testTheMaximalRule() throws IOException { KeyValue kv1 = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("fam"), Bytes.toBytes("a"), 1, Bytes.toBytes("value")); MockFilter filter1 = new MockFilter(ReturnCode.INCLUDE); MockFilter filter2 = new MockFilter(ReturnCode.INCLUDE_AND_NEXT_COL); MockFilter filter3 = new MockFilter(ReturnCode.INCLUDE_AND_SEEK_NEXT_ROW); MockFilter filter4 = new MockFilter(ReturnCode.NEXT_COL); MockFilter filter5 = new MockFilter(ReturnCode.SKIP); MockFilter filter6 = new MockFilter(ReturnCode.SEEK_NEXT_USING_HINT); MockFilter filter7 = new MockFilter(ReturnCode.NEXT_ROW); FilterList filterList = new FilterList(Operator.MUST_PASS_ALL, filter1, filter2); assertEquals(ReturnCode.INCLUDE_AND_NEXT_COL, filterList.filterCell(kv1)); filterList = new FilterList(Operator.MUST_PASS_ALL, filter2, filter3); assertEquals(ReturnCode.INCLUDE_AND_SEEK_NEXT_ROW, filterList.filterCell(kv1)); filterList = new FilterList(Operator.MUST_PASS_ALL, filter4, filter5, filter6); assertEquals(ReturnCode.SEEK_NEXT_USING_HINT, filterList.filterCell(kv1)); filterList = new FilterList(Operator.MUST_PASS_ALL, filter4, filter6); assertEquals(ReturnCode.SEEK_NEXT_USING_HINT, filterList.filterCell(kv1)); filterList = new FilterList(Operator.MUST_PASS_ALL, filter3, filter1); assertEquals(ReturnCode.INCLUDE_AND_SEEK_NEXT_ROW, filterList.filterCell(kv1)); filterList = new FilterList(Operator.MUST_PASS_ALL, filter3, filter2, filter1, filter5); assertEquals(ReturnCode.NEXT_ROW, filterList.filterCell(kv1)); filterList = new FilterList(Operator.MUST_PASS_ALL, filter2, new FilterList(Operator.MUST_PASS_ALL, filter3, filter4)); assertEquals(ReturnCode.NEXT_ROW, filterList.filterCell(kv1)); filterList = new FilterList(Operator.MUST_PASS_ALL, filter3, filter7); assertEquals(ReturnCode.NEXT_ROW, filterList.filterCell(kv1)); }
@Test public void testTheMinimalRule() throws IOException { KeyValue kv1 = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("fam"), Bytes.toBytes("a"), 1, Bytes.toBytes("value")); MockFilter filter1 = new MockFilter(ReturnCode.INCLUDE); MockFilter filter2 = new MockFilter(ReturnCode.INCLUDE_AND_NEXT_COL); MockFilter filter3 = new MockFilter(ReturnCode.INCLUDE_AND_SEEK_NEXT_ROW); MockFilter filter4 = new MockFilter(ReturnCode.NEXT_COL); MockFilter filter5 = new MockFilter(ReturnCode.SKIP); MockFilter filter6 = new MockFilter(ReturnCode.SEEK_NEXT_USING_HINT); FilterList filterList = new FilterList(Operator.MUST_PASS_ONE, filter1, filter2); assertEquals(ReturnCode.INCLUDE, filterList.filterCell(kv1)); filterList = new FilterList(Operator.MUST_PASS_ONE, filter2, filter3); assertEquals(ReturnCode.INCLUDE_AND_NEXT_COL, filterList.filterCell(kv1)); filterList = new FilterList(Operator.MUST_PASS_ONE, filter4, filter5, filter6); assertEquals(ReturnCode.SKIP, filterList.filterCell(kv1)); filterList = new FilterList(Operator.MUST_PASS_ONE, filter4, filter6); assertEquals(ReturnCode.SKIP, filterList.filterCell(kv1)); filterList = new FilterList(Operator.MUST_PASS_ONE, filter3, filter1); assertEquals(ReturnCode.INCLUDE, filterList.filterCell(kv1)); filterList = new FilterList(Operator.MUST_PASS_ONE, filter3, filter2, filter1, filter5); assertEquals(ReturnCode.INCLUDE, filterList.filterCell(kv1)); filterList = new FilterList(Operator.MUST_PASS_ONE, filter2, new FilterList(Operator.MUST_PASS_ONE, filter3, filter4)); assertEquals(ReturnCode.INCLUDE_AND_NEXT_COL, filterList.filterCell(kv1)); filterList = new FilterList(Operator.MUST_PASS_ONE, filter2, new FilterList(Operator.MUST_PASS_ONE, filter3, filter4)); assertEquals(ReturnCode.INCLUDE_AND_NEXT_COL, filterList.filterCell(kv1)); filterList = new FilterList(Operator.MUST_PASS_ONE, filter6, filter6); assertEquals(ReturnCode.SEEK_NEXT_USING_HINT, filterList.filterCell(kv1)); }
@Test public void testReversedFilterListWithMockSeekHintFilter() throws IOException { KeyValue kv1 = new KeyValue(Bytes.toBytes("row1"), Bytes.toBytes("fam"), Bytes.toBytes("a"), 1, Bytes.toBytes("value")); KeyValue kv2 = new KeyValue(Bytes.toBytes("row2"), Bytes.toBytes("fam"), Bytes.toBytes("a"), 1, Bytes.toBytes("value")); KeyValue kv3 = new KeyValue(Bytes.toBytes("row3"), Bytes.toBytes("fam"), Bytes.toBytes("a"), 1, Bytes.toBytes("value")); Filter filter1 = new MockSeekHintFilter(kv1); filter1.setReversed(true); Filter filter2 = new MockSeekHintFilter(kv2); filter2.setReversed(true); Filter filter3 = new MockSeekHintFilter(kv3); filter3.setReversed(true); FilterList filterList = new FilterList(Operator.MUST_PASS_ONE); filterList.setReversed(true); filterList.addFilter(filter1); filterList.addFilter(filter2); filterList.addFilter(filter3); Assert.assertEquals(ReturnCode.SEEK_NEXT_USING_HINT, filterList.filterCell(kv1)); Assert.assertEquals(kv3, filterList.getNextCellHint(kv1)); filterList = new FilterList(Operator.MUST_PASS_ALL); filterList.setReversed(true); filterList.addFilter(filter1); filterList.addFilter(filter2); filterList.addFilter(filter3); Assert.assertEquals(ReturnCode.SEEK_NEXT_USING_HINT, filterList.filterCell(kv1)); Assert.assertEquals(kv1, filterList.getNextCellHint(kv1)); }
@Test public void testReversedFilterListWithOR() throws IOException { byte[] r22 = Bytes.toBytes("Row22"); byte[] r2 = Bytes.toBytes("Row2"); byte[] r1 = Bytes.toBytes("Row1"); FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ONE); filterList.setReversed(true); PrefixFilter prefixFilter = new PrefixFilter(r2); prefixFilter.setReversed(true); filterList.addFilter(prefixFilter); filterList.filterRowKey(KeyValueUtil.createFirstOnRow(r22)); assertEquals(ReturnCode.INCLUDE, filterList.filterCell(new KeyValue(r22, r22, r22))); assertEquals(ReturnCode.INCLUDE, filterList.filterCell(new KeyValue(r2, r2, r2))); filterList.reset(); filterList.filterRowKey(KeyValueUtil.createFirstOnRow(r1)); assertEquals(ReturnCode.SKIP, filterList.filterCell(new KeyValue(r1, r1, r1))); filterList = new FilterList(FilterList.Operator.MUST_PASS_ONE); filterList.setReversed(true); AlwaysNextColFilter alwaysNextColFilter = new AlwaysNextColFilter(); alwaysNextColFilter.setReversed(true); prefixFilter = new PrefixFilter(r2); prefixFilter.setReversed(true); filterList.addFilter(alwaysNextColFilter); filterList.addFilter(prefixFilter); filterList.filterRowKey(KeyValueUtil.createFirstOnRow(r22)); assertEquals(ReturnCode.INCLUDE, filterList.filterCell(new KeyValue(r22, r22, r22))); assertEquals(ReturnCode.INCLUDE, filterList.filterCell(new KeyValue(r2, r2, r2))); filterList.reset(); filterList.filterRowKey(KeyValueUtil.createFirstOnRow(r1)); assertEquals(ReturnCode.NEXT_COL, filterList.filterCell(new KeyValue(r1, r1, r1))); }
@Test public void testKeyOnlyFilterTransformCell() throws IOException { Cell c; KeyValue kv1 = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("cf"), Bytes.toBytes("column1"), 1, Bytes.toBytes("value1")); KeyValue kv2 = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("cf"), Bytes.toBytes("column1"), 2, Bytes.toBytes("value2")); Filter filter1 = new SingleColumnValueFilter(Bytes.toBytes("cf"), Bytes.toBytes("column1"), CompareOperator.EQUAL, Bytes.toBytes("value1")); Filter filter2 = new SingleColumnValueFilter(Bytes.toBytes("cf"), Bytes.toBytes("column1"), CompareOperator.EQUAL, Bytes.toBytes("value2")); FilterList internalFilterList = new FilterList(Operator.MUST_PASS_ONE, filter1, filter2); FilterList keyOnlyFilterFirst = new FilterList(Operator.MUST_PASS_ALL, new KeyOnlyFilter(), internalFilterList); assertEquals(ReturnCode.INCLUDE, keyOnlyFilterFirst.filterCell(kv1)); c = keyOnlyFilterFirst.transformCell(kv1); assertEquals(0, c.getValueLength()); assertEquals(ReturnCode.INCLUDE, keyOnlyFilterFirst.filterCell(kv2)); c = keyOnlyFilterFirst.transformCell(kv2); assertEquals(0, c.getValueLength()); internalFilterList.reset(); FilterList keyOnlyFilterLast = new FilterList(Operator.MUST_PASS_ALL, new KeyOnlyFilter(), internalFilterList); assertEquals(ReturnCode.INCLUDE, keyOnlyFilterLast.filterCell(kv1)); c = keyOnlyFilterLast.transformCell(kv1); assertEquals(0, c.getValueLength()); assertEquals(ReturnCode.INCLUDE, keyOnlyFilterLast.filterCell(kv2)); c = keyOnlyFilterLast.transformCell(kv2); assertEquals(0, c.getValueLength()); }
@Test public void testEmptyFilterListTransformCell() throws IOException { KeyValue kv = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("cf"), Bytes.toBytes("column1"), 1, Bytes.toBytes("value")); FilterList filterList = new FilterList(Operator.MUST_PASS_ALL); assertEquals(ReturnCode.INCLUDE, filterList.filterCell(kv)); assertEquals(kv, filterList.transformCell(kv)); filterList = new FilterList(Operator.MUST_PASS_ONE); assertEquals(ReturnCode.INCLUDE, filterList.filterCell(kv)); assertEquals(kv, filterList.transformCell(kv)); }
@Test public void testTransformCell() throws IOException { KeyValue kv = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("cf"), Bytes.toBytes("column1"), 1, Bytes.toBytes("value")); // case MUST_PASS_ONE TransformFilter filter1 = new TransformFilter(ReturnCode.INCLUDE); TransformFilter filter2 = new TransformFilter(ReturnCode.NEXT_ROW); TransformFilter filter3 = new TransformFilter(ReturnCode.SEEK_NEXT_USING_HINT); FilterList filterList = new FilterList(Operator.MUST_PASS_ONE, filter1, filter2, filter3); Assert.assertEquals(ReturnCode.INCLUDE, filterList.filterCell(kv)); Assert.assertEquals(kv, filterList.transformCell(kv)); Assert.assertEquals(true, filter1.getTransformed()); Assert.assertEquals(false, filter2.getTransformed()); Assert.assertEquals(false, filter3.getTransformed()); // case MUST_PASS_ALL filter1 = new TransformFilter(ReturnCode.INCLUDE); filter2 = new TransformFilter(ReturnCode.INCLUDE_AND_SEEK_NEXT_ROW); filter3 = new TransformFilter(ReturnCode.INCLUDE_AND_NEXT_COL); filterList = new FilterList(Operator.MUST_PASS_ALL, filter1, filter2, filter3); Assert.assertEquals(ReturnCode.INCLUDE_AND_SEEK_NEXT_ROW, filterList.filterCell(kv)); Assert.assertEquals(kv, filterList.transformCell(kv)); Assert.assertEquals(true, filter1.getTransformed()); Assert.assertEquals(true, filter2.getTransformed()); Assert.assertEquals(true, filter3.getTransformed()); }
@Override public ReturnCode filterKeyValue(Cell v) { return ReturnCode.NEXT_COL; }
@Override public ReturnCode filterKeyValue(Cell ignored) throws IOException { return ReturnCode.INCLUDE; }
public ReturnCode filterKeyValue(KeyValue keyValue) { if(keyValue.matchingColumn(this.columnFamily, this.columnQualifier)) { if(keyValue.getTimestamp()<this.startTs) { return ReturnCode.NEXT_COL; } else if(keyValue.getTimestamp()>=this.startTs&&keyValue.getTimestamp()<=this.endTs) { this.foundColumn=true; return ReturnCode.INCLUDE; } else { return ReturnCode.SKIP; } }else { return ReturnCode.INCLUDE; } // if (this.timestamps.contains(v.getTimestamp())) { // return ReturnCode.INCLUDE; // } else if (v.getTimestamp() < minTimeStamp) { // // The remaining versions of this column are guaranteed // // to be lesser than all of the other values. // return ReturnCode.NEXT_COL; // } // return ReturnCode.SKIP; // // System.out.println("REMOVE KEY=" + keyValue.toString() + ", value=" + // // Bytes.toString(keyValue.getValue())); // if (this.matchedColumn) { // // We already found and matched the single column, all keys now pass // return ReturnCode.INCLUDE; // } else if (this.latestVersionOnly && this.foundColumn) { // // We found but did not match the single column, skip to next row // return ReturnCode.NEXT_ROW; // } // if (!keyValue.matchingColumn(this.columnFamily, this.columnQualifier)) { // return ReturnCode.INCLUDE; // } // foundColumn = true; // if (keyValue.getTimestamp()>=this.startTs&&keyValue.getTimestamp()<=this.endTs) { // this.matchedColumn = true; // return ReturnCode.INCLUDE; // } // else // { // if(this.latestVersionOnly) // { // return ReturnCode.NEXT_ROW; // } // else // { // return ReturnCode.SKIP; // } // } }
@Override public ReturnCode filterKeyValue(Cell v) { if (done) return ReturnCode.NEXT_ROW; return ReturnCode.INCLUDE; }
@Test public void testFilterKeyValue() { ColumnTimestampFilter filter = new ColumnTimestampFilter(); KeyValue kv = new KeyValue(ROW, FAMILY, QUALIFIER, PREWRITE_TS, Type.Put, VALUE); Assert.assertEquals(ReturnCode.NEXT_ROW, filter.filterKeyValue(kv)); filter = new ColumnTimestampFilter(); filter.addColumnTimestamp(COLUMN, PREWRITE_TS); kv = new KeyValue(ROW, ANOTHER_FAMILY, QUALIFIER, PREWRITE_TS, Type.Put, VALUE); Assert.assertEquals(ReturnCode.SEEK_NEXT_USING_HINT, filter.filterKeyValue(kv)); Assert.assertArrayEquals(filter.getNextKeyHint(kv).getFamily(), FAMILY); Assert.assertArrayEquals(filter.getNextKeyHint(kv).getQualifier(), QUALIFIER); filter = new ColumnTimestampFilter(); filter.addColumnTimestamp(COLUMN, PREWRITE_TS); kv = new KeyValue(ROW, FAMILY, ANOTHER_QUALIFIER, PREWRITE_TS, Type.Put, VALUE); Assert.assertEquals(ReturnCode.SEEK_NEXT_USING_HINT, filter.filterKeyValue(kv)); Assert.assertArrayEquals(filter.getNextKeyHint(kv).getFamily(), FAMILY); Assert.assertArrayEquals(filter.getNextKeyHint(kv).getQualifier(), QUALIFIER); filter = new ColumnTimestampFilter(); filter.addColumnTimestamp(COLUMN, PREWRITE_TS); byte[] laterFamily = Bytes.toBytes(Bytes.toString(FAMILY) + "#"); kv = new KeyValue(ROW, laterFamily, QUALIFIER, PREWRITE_TS, Type.Put, VALUE); Assert.assertEquals(ReturnCode.NEXT_ROW, filter.filterKeyValue(kv)); filter = new ColumnTimestampFilter(); filter.addColumnTimestamp(COLUMN, PREWRITE_TS); kv = new KeyValue(ROW, FAMILY, QUALIFIER, PREWRITE_TS - 1, Type.Put, VALUE); Assert.assertEquals(ReturnCode.NEXT_COL, filter.filterKeyValue(kv)); filter = new ColumnTimestampFilter(); filter.addColumnTimestamp(COLUMN, PREWRITE_TS); kv = new KeyValue(ROW, FAMILY, QUALIFIER, PREWRITE_TS, Type.Put, VALUE); Assert.assertEquals(ReturnCode.INCLUDE_AND_NEXT_COL, filter.filterKeyValue(kv)); filter = new ColumnTimestampFilter(); filter.addColumnTimestamp(COLUMN, PREWRITE_TS); kv = new KeyValue(ROW, FAMILY, QUALIFIER, PREWRITE_TS + 1, Type.Put, VALUE); Assert.assertEquals(ReturnCode.SKIP, filter.filterKeyValue(kv)); filter = new ColumnTimestampFilter(); filter.addColumnTimestamp(COLUMN, PREWRITE_TS); kv = new KeyValue(ROW, FAMILY, ANOTHER_QUALIFIER, PREWRITE_TS, Type.Put, VALUE); Assert.assertEquals(ReturnCode.SEEK_NEXT_USING_HINT, filter.filterKeyValue(kv)); Assert.assertArrayEquals(filter.getNextKeyHint(kv).getFamily(), FAMILY); Assert.assertArrayEquals(filter.getNextKeyHint(kv).getQualifier(), QUALIFIER); kv = new KeyValue(ROW, FAMILY, QUALIFIER, PREWRITE_TS + 1, Type.Put, VALUE); Assert.assertEquals(ReturnCode.SKIP, filter.filterKeyValue(kv)); kv = new KeyValue(ROW, FAMILY, QUALIFIER, PREWRITE_TS, Type.Put, VALUE); Assert.assertEquals(ReturnCode.INCLUDE_AND_NEXT_COL, filter.filterKeyValue(kv)); kv = new KeyValue(ROW, FAMILY, QUALIFIER, PREWRITE_TS - 1, Type.Put, VALUE); Assert.assertEquals(ReturnCode.NEXT_ROW, filter.filterKeyValue(kv)); byte[] laterQualifier = Bytes.toBytes(Bytes.toString(QUALIFIER) + "#"); kv = new KeyValue(ROW, FAMILY, laterQualifier, PREWRITE_TS + 1, Type.Put, VALUE); Assert.assertEquals(ReturnCode.NEXT_ROW, filter.filterKeyValue(kv)); }
@Override public ReturnCode filterCell(final Cell v) { return ReturnCode.NEXT_COL; }
public MockFilter(ReturnCode targetRetCode) { this.targetRetCode = targetRetCode; }
@Override public ReturnCode filterCell(final Cell v) throws IOException { this.didCellPassToTheFilter = true; return targetRetCode; }
@Test public void testShouldPassCurrentCellToFilter() throws IOException { KeyValue kv1 = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("fam"), Bytes.toBytes("a"), 1, Bytes.toBytes("value")); KeyValue kv2 = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("fam"), Bytes.toBytes("a"), 2, Bytes.toBytes("value")); KeyValue kv3 = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("fam"), Bytes.toBytes("b"), 3, Bytes.toBytes("value")); KeyValue kv4 = new KeyValue(Bytes.toBytes("row1"), Bytes.toBytes("fam"), Bytes.toBytes("c"), 4, Bytes.toBytes("value")); MockFilter mockFilter = new MockFilter(ReturnCode.NEXT_COL); FilterList filter = new FilterList(Operator.MUST_PASS_ONE, mockFilter); filter.filterCell(kv1); assertTrue(mockFilter.didCellPassToTheFilter); mockFilter.didCellPassToTheFilter = false; filter.filterCell(kv2); assertFalse(mockFilter.didCellPassToTheFilter); mockFilter.didCellPassToTheFilter = false; filter.filterCell(kv3); assertTrue(mockFilter.didCellPassToTheFilter); mockFilter = new MockFilter(ReturnCode.INCLUDE_AND_NEXT_COL); filter = new FilterList(Operator.MUST_PASS_ONE, mockFilter); filter.filterCell(kv1); assertTrue(mockFilter.didCellPassToTheFilter); mockFilter.didCellPassToTheFilter = false; filter.filterCell(kv2); assertFalse(mockFilter.didCellPassToTheFilter); mockFilter.didCellPassToTheFilter = false; filter.filterCell(kv3); assertTrue(mockFilter.didCellPassToTheFilter); mockFilter = new MockFilter(ReturnCode.NEXT_ROW); filter = new FilterList(Operator.MUST_PASS_ONE, mockFilter); filter.filterCell(kv1); assertTrue(mockFilter.didCellPassToTheFilter); mockFilter.didCellPassToTheFilter = false; filter.filterCell(kv2); assertFalse(mockFilter.didCellPassToTheFilter); mockFilter.didCellPassToTheFilter = false; filter.filterCell(kv3); assertFalse(mockFilter.didCellPassToTheFilter); filter.reset(); mockFilter.didCellPassToTheFilter = false; filter.filterCell(kv4); assertTrue(mockFilter.didCellPassToTheFilter); mockFilter = new MockFilter(ReturnCode.INCLUDE_AND_SEEK_NEXT_ROW); filter = new FilterList(Operator.MUST_PASS_ONE, mockFilter); filter.filterCell(kv1); assertTrue(mockFilter.didCellPassToTheFilter); mockFilter.didCellPassToTheFilter = false; filter.filterCell(kv2); assertFalse(mockFilter.didCellPassToTheFilter); mockFilter.didCellPassToTheFilter = false; filter.filterCell(kv3); assertFalse(mockFilter.didCellPassToTheFilter); filter.reset(); mockFilter.didCellPassToTheFilter = false; filter.filterCell(kv4); assertTrue(mockFilter.didCellPassToTheFilter); }
@Override public ReturnCode filterCell(final Cell v) throws IOException { return ReturnCode.SEEK_NEXT_USING_HINT; }
@Override public ReturnCode filterCell(final Cell v) throws IOException { hitCount++; return ReturnCode.NEXT_ROW; }