Java Code Examples for org.apache.hadoop.hbase.filter.Filter.ReturnCode#NEXT_ROW

The following examples show how to use org.apache.hadoop.hbase.filter.Filter.ReturnCode#NEXT_ROW . These examples are extracted from open source projects. 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 Project: hbase   File: TestFilterList.java    License: Apache License 2.0 5 votes vote down vote up
@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.NEXT_COL, filterList.filterCell(kv1));

  filterList = new FilterList(Operator.MUST_PASS_ALL, filter4, filter6);
  assertEquals(ReturnCode.NEXT_COL, 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));
}
 
Example 2
Source Project: hbase   File: TestFilterList.java    License: 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 3
Source Project: hbase   File: TestFilterList.java    License: Apache License 2.0 4 votes vote down vote up
@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);
}
 
Example 4
Source Project: hbase   File: TestFilterList.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ReturnCode filterCell(final Cell v) throws IOException {
  hitCount++;
  return ReturnCode.NEXT_ROW;
}