org.apache.hadoop.hbase.filter.Filter.ReturnCode Java Examples

The following examples show how to use org.apache.hadoop.hbase.filter.Filter.ReturnCode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FilteredKeyValueScanner.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
private boolean seekToNextUnfilteredKeyValue() throws IOException {
    while (true) {
        Cell peeked = delegate.peek();
        // no more key values, so we are done
        if (peeked == null) { return false; }

        // filter the peeked value to see if it should be served
        ReturnCode code = filter.filterKeyValue(peeked);
        switch (code) {
        // included, so we are done
        case INCLUDE:
        case INCLUDE_AND_NEXT_COL:
            return true;
            // not included, so we need to go to the next row
        case SKIP:
        case NEXT_COL:
        case NEXT_ROW:
            delegate.next();
            break;
        // use a seek hint to find out where we should go
        case SEEK_NEXT_USING_HINT:
            delegate.seek(KeyValueUtil.ensureKeyValue(filter.getNextCellHint(peeked)));
        }
    }
}
 
Example #2
Source File: TestApplyAndFilterDeletesFilter.java    From phoenix with Apache License 2.0 6 votes vote down vote up
/**
 * Point deletes should only cover the exact entry they are tied to. Earlier puts should always
 * show up.
 */
@Test
public void testCoveringPointDelete() {
  // start with doing a family delete, so we will seek to the next column
  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));
  // we should filter out the exact same put again, which could occur with the kvs all kept in the
  // same memstore
  assertEquals("Didn't filter out put with same timestamp on second call!", ReturnCode.SKIP,
    filter.filterKeyValue(put));

  // ensure then that we don't filter out a put with an earlier timestamp (though everything else
  // matches)
  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));
}
 
Example #3
Source File: TestApplyAndFilterDeletesFilter.java    From phoenix with Apache License 2.0 6 votes vote down vote up
/**
 * DeleteFamily markers should delete everything from that timestamp backwards, but not hide
 * anything forwards
 */
@Test
public void testDeleteFamilyCorrectlyCoversColumns() {
  ApplyAndFilterDeletesFilter filter = new ApplyAndFilterDeletesFilter(EMPTY_SET);
  KeyValue df = createKvForType(Type.DeleteFamily, 11);
  KeyValue put = createKvForType(Type.Put, 12);

  assertEquals("Didn't filter out delete family", ReturnCode.SKIP, filter.filterKeyValue(df));
  assertEquals("Filtered out put with newer TS than delete family", ReturnCode.INCLUDE,
    filter.filterKeyValue(put));

  // older kv shouldn't be visible
  put = createKvForType(Type.Put, 10);
  assertEquals("Didn't filter out older put, covered by DeleteFamily marker",
    ReturnCode.SEEK_NEXT_USING_HINT, filter.filterKeyValue(put));

  // next seek should be past the families
  assertEquals(KeyValue.LOWESTKEY, filter.getNextCellHint(put));
}
 
Example #4
Source File: TestApplyAndFilterDeletesFilter.java    From phoenix with Apache License 2.0 6 votes vote down vote up
/**
 * Test that we don't cover other columns when we have a delete column.
 */
@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));
  // different column put should still be visible
  assertEquals("Filtered out put with different column than the delete", ReturnCode.INCLUDE,
    filter.filterKeyValue(put));

  // set a delete family, but in the past
  d = createKvForType(Type.DeleteFamily, 10);
  assertEquals("Didn't filter out delete column", ReturnCode.SKIP, filter.filterKeyValue(d));
  // add back in the original delete column
  d = createKvForType(Type.DeleteColumn, 11);
  assertEquals("Didn't filter out delete column", ReturnCode.SKIP, filter.filterKeyValue(d));
  // onto a different family, so that must be visible too
  assertEquals("Filtered out put with different column than the delete", ReturnCode.INCLUDE,
    filter.filterKeyValue(put));
}
 
Example #5
Source File: FilteredKeyValueScanner.java    From phoenix with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private boolean seekToNextUnfilteredKeyValue() throws IOException {
    while (true) {
        KeyValue peeked = delegate.peek();
        // no more key values, so we are done
        if (peeked == null) { return false; }

        // filter the peeked value to see if it should be served
        ReturnCode code = filter.filterKeyValue(peeked);
        switch (code) {
        // included, so we are done
        case INCLUDE:
        case INCLUDE_AND_NEXT_COL:
            return true;
            // not included, so we need to go to the next row
        case SKIP:
        case NEXT_COL:
        case NEXT_ROW:
            delegate.next();
            break;
        // use a seek hint to find out where we should go
        case SEEK_NEXT_USING_HINT:
            delegate.seek(filter.getNextKeyHint(peeked));
        }
    }
}
 
Example #6
Source File: TestFilterList.java    From hbase with Apache License 2.0 6 votes vote down vote up
@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.SEEK_NEXT_USING_HINT, filterList.filterCell(kv2));
  assertEquals(ReturnCode.INCLUDE_AND_NEXT_COL, filterList.filterCell(kv3));
  assertEquals(ReturnCode.NEXT_COL, filterList.filterCell(kv4));
}
 
Example #7
Source File: TestFilterList.java    From hbase with Apache License 2.0 6 votes vote down vote up
@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.NEXT_COL, filterList01.filterCell(kv2));
  assertEquals(ReturnCode.NEXT_COL, filterList01.filterCell(kv3));

  FilterList filterList11 =
      new FilterList(Operator.MUST_PASS_ONE, new ColumnPaginationFilter(1, 1));

  assertEquals(ReturnCode.NEXT_COL, filterList11.filterCell(kv1));
  assertEquals(ReturnCode.NEXT_COL, filterList11.filterCell(kv2));
  assertEquals(ReturnCode.NEXT_COL, filterList11.filterCell(kv3));
}
 
Example #8
Source File: TestFilterList.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * 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)));
}
 
Example #9
Source File: TestApplyAndFilterDeletesFilter.java    From phoenix with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Point deletes should only cover the exact entry they are tied to. Earlier puts should always
 * show up.
 */
@Test
public void testCoveringPointDelete() {
  // start with doing a family delete, so we will seek to the next column
  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));
  // we should filter out the exact same put again, which could occur with the kvs all kept in the
  // same memstore
  assertEquals("Didn't filter out put with same timestamp on second call!", ReturnCode.SKIP,
    filter.filterKeyValue(put));

  // ensure then that we don't filter out a put with an earlier timestamp (though everything else
  // matches)
  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));
}
 
Example #10
Source File: TestApplyAndFilterDeletesFilter.java    From phoenix with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Test that we don't cover other columns when we have a delete column.
 */
@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, 0, qual2.length, 11, Type.Put, value, 0,
          value.length);

  assertEquals("Didn't filter out delete column", ReturnCode.SKIP, filter.filterKeyValue(d));
  // different column put should still be visible
  assertEquals("Filtered out put with different column than the delete", ReturnCode.INCLUDE,
    filter.filterKeyValue(put));

  // set a delete family, but in the past
  d = createKvForType(Type.DeleteFamily, 10);
  assertEquals("Didn't filter out delete column", ReturnCode.SKIP, filter.filterKeyValue(d));
  // add back in the original delete column
  d = createKvForType(Type.DeleteColumn, 11);
  assertEquals("Didn't filter out delete column", ReturnCode.SKIP, filter.filterKeyValue(d));
  // onto a different family, so that must be visible too
  assertEquals("Filtered out put with different column than the delete", ReturnCode.INCLUDE,
    filter.filterKeyValue(put));
}
 
Example #11
Source File: TestApplyAndFilterDeletesFilter.java    From phoenix with Apache License 2.0 6 votes vote down vote up
/**
 * Test that we don't cover other columns when we have a delete column.
 */
@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));
  // different column put should still be visible
  assertEquals("Filtered out put with different column than the delete", ReturnCode.INCLUDE,
    filter.filterKeyValue(put));

  // set a delete family, but in the past
  d = createKvForType(Type.DeleteFamily, 10);
  assertEquals("Didn't filter out delete column", ReturnCode.SKIP, filter.filterKeyValue(d));
  // add back in the original delete column
  d = createKvForType(Type.DeleteColumn, 11);
  assertEquals("Didn't filter out delete column", ReturnCode.SKIP, filter.filterKeyValue(d));
  // onto a different family, so that must be visible too
  assertEquals("Filtered out put with different column than the delete", ReturnCode.INCLUDE,
    filter.filterKeyValue(put));
}
 
Example #12
Source File: TestApplyAndFilterDeletesFilter.java    From phoenix with Apache License 2.0 6 votes vote down vote up
/**
 * DeleteFamily markers should delete everything from that timestamp backwards, but not hide
 * anything forwards
 */
@Test
public void testDeleteFamilyCorrectlyCoversColumns() {
  ApplyAndFilterDeletesFilter filter = new ApplyAndFilterDeletesFilter(EMPTY_SET);
  KeyValue df = createKvForType(Type.DeleteFamily, 11);
  KeyValue put = createKvForType(Type.Put, 12);

  assertEquals("Didn't filter out delete family", ReturnCode.SKIP, filter.filterKeyValue(df));
  assertEquals("Filtered out put with newer TS than delete family", ReturnCode.INCLUDE,
    filter.filterKeyValue(put));

  // older kv shouldn't be visible
  put = createKvForType(Type.Put, 10);
  assertEquals("Didn't filter out older put, covered by DeleteFamily marker",
    ReturnCode.SEEK_NEXT_USING_HINT, filter.filterKeyValue(put));

  // next seek should be past the families
  assertEquals(KeyValue.LOWESTKEY, filter.getNextCellHint(put));
}
 
Example #13
Source File: TestApplyAndFilterDeletesFilter.java    From phoenix with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * DeleteFamily markers should delete everything from that timestamp backwards, but not hide
 * anything forwards
 */
@Test
public void testDeleteFamilyCorrectlyCoversColumns() {
  ApplyAndFilterDeletesFilter filter = new ApplyAndFilterDeletesFilter(EMPTY_SET);
  KeyValue df = createKvForType(Type.DeleteFamily, 11);
  KeyValue put = createKvForType(Type.Put, 12);

  assertEquals("Didn't filter out delete family", ReturnCode.SKIP, filter.filterKeyValue(df));
  assertEquals("Filtered out put with newer TS than delete family", ReturnCode.INCLUDE,
    filter.filterKeyValue(put));

  // older kv shouldn't be visible
  put = createKvForType(Type.Put, 10);
  assertEquals("Didn't filter out older put, covered by DeleteFamily marker",
    ReturnCode.SEEK_NEXT_USING_HINT, filter.filterKeyValue(put));

  // next seek should be past the families
  assertEquals(KeyValue.LOWESTKEY, filter.getNextKeyHint(put));
}
 
Example #14
Source File: TestApplyAndFilterDeletesFilter.java    From phoenix with Apache License 2.0 6 votes vote down vote up
/**
 * Point deletes should only cover the exact entry they are tied to. Earlier puts should always
 * show up.
 */
@Test
public void testCoveringPointDelete() {
  // start with doing a family delete, so we will seek to the next column
  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));
  // we should filter out the exact same put again, which could occur with the kvs all kept in the
  // same memstore
  assertEquals("Didn't filter out put with same timestamp on second call!", ReturnCode.SKIP,
    filter.filterKeyValue(put));

  // ensure then that we don't filter out a put with an earlier timestamp (though everything else
  // matches)
  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));
}
 
Example #15
Source File: SkipScanFilterTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override public void examine(SkipScanFilter skipper) throws IOException {
    KeyValue kv = KeyValueUtil.createFirstOnRow(rowkey);
    skipper.reset();
    assertEquals(ReturnCode.NEXT_ROW,skipper.filterKeyValue(kv));
    skipper.reset();
    assertTrue(skipper.filterAllRemaining());
}
 
Example #16
Source File: TestFilterList.java    From hbase with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #17
Source File: FilteredKeyValueScanner.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private boolean seekToNextUnfilteredKeyValue() throws IOException {
    while (true) {
        Cell peeked = delegate.peek();
        // no more key values, so we are done
        if (peeked == null) { return false; }

        // filter the peeked value to see if it should be served
        ReturnCode code = filter.filterKeyValue(peeked);
        switch (code) {
        // included, so we are done
        case INCLUDE:
        case INCLUDE_AND_NEXT_COL:
            return true;
            // not included, so we need to go to the next row
        case SKIP:
        case NEXT_COL:
        case NEXT_ROW:
            delegate.next();
            break;
        // use a seek hint to find out where we should go
        case SEEK_NEXT_USING_HINT:
            Cell nextCellHint = filter.getNextCellHint(peeked);
            if(nextCellHint == KeyValue.LOWESTKEY) {
                delegate.next();
            } else {
                delegate.seek(PhoenixKeyValueUtil.maybeCopyCell(nextCellHint));
            }
        }
    }
}
 
Example #18
Source File: TestApplyAndFilterDeletesFilter.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeletesAreNotReturned() {
  KeyValue kv = createKvForType(Type.Delete);
  ApplyAndFilterDeletesFilter filter = new ApplyAndFilterDeletesFilter(EMPTY_SET);
  assertEquals("Didn't skip point delete!", ReturnCode.SKIP, filter.filterKeyValue(kv));

  filter.reset();
  kv = createKvForType(Type.DeleteColumn);
  assertEquals("Didn't skip from column delete!", ReturnCode.SKIP, filter.filterKeyValue(kv));

  filter.reset();
  kv = createKvForType(Type.DeleteFamily);
  assertEquals("Didn't skip from family delete!", ReturnCode.SKIP, filter.filterKeyValue(kv));
}
 
Example #19
Source File: TestApplyAndFilterDeletesFilter.java    From phoenix with Apache License 2.0 5 votes vote down vote up
/**
 * Hinting with this filter is a little convoluted as we binary search the list of families to
 * attempt to find the right one to seek.
 */
@Test
public void testHintCorrectlyToNextFamily() {
  // start with doing a family delete, so we will seek to the next column
  KeyValue kv = createKvForType(Type.DeleteFamily);
  ApplyAndFilterDeletesFilter filter = new ApplyAndFilterDeletesFilter(EMPTY_SET);
  assertEquals(ReturnCode.SKIP, filter.filterKeyValue(kv));
  KeyValue next = createKvForType(Type.Put);
  // make sure the hint is our attempt at the end key, because we have no more families to seek
  assertEquals("Didn't get a hint from a family delete", ReturnCode.SEEK_NEXT_USING_HINT,
    filter.filterKeyValue(next));
  assertEquals("Didn't get END_KEY with no families to match", KeyValue.LOWESTKEY,
    filter.getNextCellHint(next));

  // check for a family that comes before our family, so we always seek to the end as well
  filter = new ApplyAndFilterDeletesFilter(asSet(Bytes.toBytes("afamily")));
  assertEquals(ReturnCode.SKIP, filter.filterKeyValue(kv));
  // make sure the hint is our attempt at the end key, because we have no more families to seek
  assertEquals("Didn't get a hint from a family delete", ReturnCode.SEEK_NEXT_USING_HINT,
    filter.filterKeyValue(next));
  assertEquals("Didn't get END_KEY with no families to match", KeyValue.LOWESTKEY,
    filter.getNextCellHint(next));

  // check that we seek to the correct family that comes after our family
  byte[] laterFamily = Bytes.toBytes("zfamily");
  filter = new ApplyAndFilterDeletesFilter(asSet(laterFamily));
  assertEquals(ReturnCode.SKIP, filter.filterKeyValue(kv));
  KeyValue expected = KeyValueUtil.createFirstOnRow(CellUtil.cloneRow(kv), laterFamily, new byte[0]);
  assertEquals("Didn't get a hint from a family delete", ReturnCode.SEEK_NEXT_USING_HINT,
    filter.filterKeyValue(next));
  assertEquals("Didn't get correct next key with a next family", expected,
    filter.getNextCellHint(next));
}
 
Example #20
Source File: TestApplyAndFilterDeletesFilter.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeletesAreNotReturned() {
  KeyValue kv = createKvForType(Type.Delete);
  ApplyAndFilterDeletesFilter filter = new ApplyAndFilterDeletesFilter(EMPTY_SET);
  assertEquals("Didn't skip point delete!", ReturnCode.SKIP, filter.filterKeyValue(kv));

  filter.reset();
  kv = createKvForType(Type.DeleteColumn);
  assertEquals("Didn't skip from column delete!", ReturnCode.SKIP, filter.filterKeyValue(kv));

  filter.reset();
  kv = createKvForType(Type.DeleteFamily);
  assertEquals("Didn't skip from family delete!", ReturnCode.SKIP, filter.filterKeyValue(kv));
}
 
Example #21
Source File: TestApplyAndFilterDeletesFilter.java    From phoenix with Apache License 2.0 5 votes vote down vote up
/**
 * Test that when we do a column delete at a given timestamp that we delete the entire column.
 * @throws Exception
 */
@Test
public void testCoverForDeleteColumn() throws Exception {
  ApplyAndFilterDeletesFilter filter = new ApplyAndFilterDeletesFilter(EMPTY_SET);
  KeyValue dc = createKvForType(Type.DeleteColumn, 11);
  KeyValue put = createKvForType(Type.Put, 10);
  assertEquals("Didn't filter out delete column.", ReturnCode.SKIP, filter.filterKeyValue(dc));
  assertEquals("Didn't get a seek hint for the deleted column", ReturnCode.SEEK_NEXT_USING_HINT,
    filter.filterKeyValue(put));
  // seek past the given put
  Cell seek = filter.getNextCellHint(put);
  assertTrue("Seeked key wasn't past the expected put - didn't skip the column",
    KeyValue.COMPARATOR.compare(seek, put) > 0);
}
 
Example #22
Source File: SkipScanFilterTest.java    From phoenix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override public void examine(SkipScanFilter skipper) {
    KeyValue kv = KeyValue.createFirstOnRow(rowkey);
    skipper.reset();
    assertEquals(ReturnCode.NEXT_ROW,skipper.filterKeyValue(kv));
    skipper.reset();
    assertTrue(skipper.filterAllRemaining());
}
 
Example #23
Source File: SkipScanFilterTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override public void examine(SkipScanFilter skipper) throws IOException {
    KeyValue kv = KeyValueUtil.createFirstOnRow(rowkey);
    skipper.reset();
    assertFalse(skipper.filterAllRemaining());
    assertFalse(skipper.filterRowKey(kv.getBuffer(), kv.getRowOffset(), kv.getRowLength()));

    assertEquals(ReturnCode.SEEK_NEXT_USING_HINT, skipper.filterKeyValue(kv));
    assertEquals(KeyValueUtil.createFirstOnRow(hint), skipper.getNextCellHint(kv));
}
 
Example #24
Source File: SkipScanFilterTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override public void examine(SkipScanFilter skipper) throws IOException {
    KeyValue kv = KeyValueUtil.createFirstOnRow(rowkey);
    skipper.reset();
    assertFalse(skipper.filterAllRemaining());
    assertFalse(skipper.filterRowKey(kv.getBuffer(), kv.getRowOffset(), kv.getRowLength()));
    assertEquals(kv.toString(), ReturnCode.INCLUDE_AND_NEXT_COL, skipper.filterKeyValue(kv));
}
 
Example #25
Source File: DistinctPrefixFilterTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private void assertSeekAndHint(byte[] next, Filter f, byte[] rowHint, boolean filterAll) throws IOException {
    Cell c = new KeyValue(next, ByteUtil.EMPTY_BYTE_ARRAY, ByteUtil.EMPTY_BYTE_ARRAY, 0, ByteUtil.EMPTY_BYTE_ARRAY);
    assertTrue(f.filterKeyValue(c) == ReturnCode.SEEK_NEXT_USING_HINT);
    Cell h = f.getNextCellHint(c);
    byte[] hintBytes = rowHint;
    assertTrue(Bytes.equals(hintBytes, 0, hintBytes.length, h.getRowArray(), h.getRowOffset(), h.getRowLength()));
    assertEquals(filterAll, f.filterAllRemaining());
}
 
Example #26
Source File: SkipScanFilterTest.java    From phoenix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override public void examine(SkipScanFilter skipper) {
    KeyValue kv = KeyValue.createFirstOnRow(rowkey);
    skipper.reset();
    assertFalse(skipper.filterAllRemaining());
    assertFalse(skipper.filterRowKey(kv.getBuffer(), kv.getRowOffset(), kv.getRowLength()));
    assertEquals(kv.toString(), ReturnCode.INCLUDE, skipper.filterKeyValue(kv));
}
 
Example #27
Source File: TestApplyAndFilterDeletesFilter.java    From phoenix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testDeletesAreNotReturned() {
  KeyValue kv = createKvForType(Type.Delete);
  ApplyAndFilterDeletesFilter filter = new ApplyAndFilterDeletesFilter(EMPTY_SET);
  assertEquals("Didn't skip point delete!", ReturnCode.SKIP, filter.filterKeyValue(kv));

  filter.reset();
  kv = createKvForType(Type.DeleteColumn);
  assertEquals("Didn't skip from column delete!", ReturnCode.SKIP, filter.filterKeyValue(kv));

  filter.reset();
  kv = createKvForType(Type.DeleteFamily);
  assertEquals("Didn't skip from family delete!", ReturnCode.SKIP, filter.filterKeyValue(kv));
}
 
Example #28
Source File: TestApplyAndFilterDeletesFilter.java    From phoenix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Hinting with this filter is a little convoluted as we binary search the list of families to
 * attempt to find the right one to seek.
 */
@Test
public void testHintCorrectlyToNextFamily() {
  // start with doing a family delete, so we will seek to the next column
  KeyValue kv = createKvForType(Type.DeleteFamily);
  ApplyAndFilterDeletesFilter filter = new ApplyAndFilterDeletesFilter(EMPTY_SET);
  assertEquals(ReturnCode.SKIP, filter.filterKeyValue(kv));
  KeyValue next = createKvForType(Type.Put);
  // make sure the hint is our attempt at the end key, because we have no more families to seek
  assertEquals("Didn't get a hint from a family delete", ReturnCode.SEEK_NEXT_USING_HINT,
    filter.filterKeyValue(next));
  assertEquals("Didn't get END_KEY with no families to match", KeyValue.LOWESTKEY,
    filter.getNextKeyHint(next));

  // check for a family that comes before our family, so we always seek to the end as well
  filter = new ApplyAndFilterDeletesFilter(asSet(Bytes.toBytes("afamily")));
  assertEquals(ReturnCode.SKIP, filter.filterKeyValue(kv));
  // make sure the hint is our attempt at the end key, because we have no more families to seek
  assertEquals("Didn't get a hint from a family delete", ReturnCode.SEEK_NEXT_USING_HINT,
    filter.filterKeyValue(next));
  assertEquals("Didn't get END_KEY with no families to match", KeyValue.LOWESTKEY,
    filter.getNextKeyHint(next));

  // check that we seek to the correct family that comes after our family
  byte[] laterFamily = Bytes.toBytes("zfamily");
  filter = new ApplyAndFilterDeletesFilter(asSet(laterFamily));
  assertEquals(ReturnCode.SKIP, filter.filterKeyValue(kv));
  KeyValue expected = KeyValue.createFirstOnRow(kv.getRow(), laterFamily, new byte[0]);
  assertEquals("Didn't get a hint from a family delete", ReturnCode.SEEK_NEXT_USING_HINT,
    filter.filterKeyValue(next));
  assertEquals("Didn't get correct next key with a next family", expected,
    filter.getNextKeyHint(next));
}
 
Example #29
Source File: SkipScanFilterTest.java    From phoenix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override public void examine(SkipScanFilter skipper) {
    KeyValue kv = KeyValue.createFirstOnRow(rowkey);
    skipper.reset();
    assertFalse(skipper.filterAllRemaining());
    assertFalse(skipper.filterRowKey(kv.getBuffer(), kv.getRowOffset(), kv.getRowLength()));

    assertEquals(ReturnCode.SEEK_NEXT_USING_HINT, skipper.filterKeyValue(kv));
    assertEquals(KeyValue.createFirstOnRow(hint), skipper.getNextKeyHint(kv));
}
 
Example #30
Source File: TestApplyAndFilterDeletesFilter.java    From phoenix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Test that when we do a column delete at a given timestamp that we delete the entire column.
 * @throws Exception
 */
@Test
public void testCoverForDeleteColumn() throws Exception {
  ApplyAndFilterDeletesFilter filter = new ApplyAndFilterDeletesFilter(EMPTY_SET);
  KeyValue dc = createKvForType(Type.DeleteColumn, 11);
  KeyValue put = createKvForType(Type.Put, 10);
  assertEquals("Didn't filter out delete column.", ReturnCode.SKIP, filter.filterKeyValue(dc));
  assertEquals("Didn't get a seek hint for the deleted column", ReturnCode.SEEK_NEXT_USING_HINT,
    filter.filterKeyValue(put));
  // seek past the given put
  KeyValue seek = filter.getNextKeyHint(put);
  assertTrue("Seeked key wasn't past the expected put - didn't skip the column",
    KeyValue.COMPARATOR.compare(seek, put) > 0);
}