org.apache.hadoop.hbase.filter.FilterList.Operator Java Examples

The following examples show how to use org.apache.hadoop.hbase.filter.FilterList.Operator. 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: DefaultHBaseSerde.java    From envelope with Apache License 2.0 6 votes vote down vote up
private FilterList getColumnValueFilters(Row row) {
  FilterList filterList = new FilterList(Operator.MUST_PASS_ALL);
  Set<String> filterColumnNames = Sets.newHashSet(row.schema().fieldNames());
  
  for (Map.Entry<String, ColumnDef> column : columns.entrySet()) {
    if (!column.getValue().cf.equals("rowkey")) {
      if (filterColumnNames.contains(column.getKey())) {
        byte[] value = getColumnValueAsBytes(column.getValue().name, column.getValue().type, row);
        if (value != null) {
          SingleColumnValueFilter columnValueFilter = new SingleColumnValueFilter(
              Bytes.toBytes(column.getValue().cf),
              Bytes.toBytes(column.getValue().name),
              CompareFilter.CompareOp.EQUAL,
              value
          );
          filterList.addFilter(columnValueFilter);
        }
      }
    }
  }
  
  return filterList;
}
 
Example #2
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 #3
Source File: TestFilterList.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Test serialization
 * @throws Exception
 */
@Test
public void testSerialization() throws Exception {
  List<Filter> filters = new ArrayList<>();
  filters.add(new PageFilter(MAX_PAGES));
  filters.add(new WhileMatchFilter(new PrefixFilter(Bytes.toBytes("yyy"))));
  Filter filterMPALL =
    new FilterList(FilterList.Operator.MUST_PASS_ALL, filters);

  // Decompose filterMPALL to bytes.
  byte[] buffer = filterMPALL.toByteArray();

  // Recompose filterMPALL.
  FilterList newFilter = FilterList.parseFrom(buffer);

  // Run tests
  mpOneTest(ProtobufUtil.toFilter(ProtobufUtil.toFilter(getFilterMPONE())));
  mpAllTest(ProtobufUtil.toFilter(ProtobufUtil.toFilter(getMPALLFilter())));
  orderingTest(ProtobufUtil.toFilter(ProtobufUtil.toFilter(getOrderingFilter())));
}
 
Example #4
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 #5
Source File: Filters.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
public static void filterLimitValueRange(String projectId, String instanceId, String tableId) {
  // A filter that matches cells whose values are between the given values
  ValueFilter valueGreaterFilter =
      new ValueFilter(
          CompareFilter.CompareOp.GREATER_OR_EQUAL,
          new BinaryComparator(Bytes.toBytes("PQ2A.190405")));
  ValueFilter valueLesserFilter =
      new ValueFilter(
          CompareFilter.CompareOp.LESS_OR_EQUAL,
          new BinaryComparator(Bytes.toBytes("PQ2A.190406")));

  FilterList filter = new FilterList(FilterList.Operator.MUST_PASS_ALL);
  filter.addFilter(valueGreaterFilter);
  filter.addFilter(valueLesserFilter);

  Scan scan = new Scan().setFilter(filter);
  readWithFilter(projectId, instanceId, tableId, scan);
}
 
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 5 votes vote down vote up
public Filter getOrderingFilter() {
  List<Filter> filters = new ArrayList<>();
  filters.add(new PrefixFilter(Bytes.toBytes("yyy")));
  filters.add(new PageFilter(MAX_PAGES));
  Filter filterMPONE =
    new FilterList(FilterList.Operator.MUST_PASS_ONE, filters);
  return filterMPONE;
}
 
Example #8
Source File: TestFilterList.java    From hbase with Apache License 2.0 5 votes vote down vote up
private Filter getMPALLFilter() {
  List<Filter> filters = new ArrayList<>();
  filters.add(new PageFilter(MAX_PAGES));
  filters.add(new WhileMatchFilter(new PrefixFilter(Bytes.toBytes("yyy"))));
  Filter filterMPALL =
    new FilterList(FilterList.Operator.MUST_PASS_ALL, filters);
  return filterMPALL;
}
 
Example #9
Source File: TestFilterList.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * 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)));
}
 
Example #10
Source File: TestFilterList.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * 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));
}
 
Example #11
Source File: TestFilterList.java    From hbase with 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 #12
Source File: TestFilterList.java    From hbase with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example #13
Source File: TestFilterList.java    From hbase with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example #14
Source File: TestFilterList.java    From hbase with Apache License 2.0 5 votes vote down vote up
@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)));
}
 
Example #15
Source File: TestFilterList.java    From hbase with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #16
Source File: TestFilterList.java    From hbase with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example #17
Source File: TestFilterList.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testRowCountFilter() throws IOException {
  KeyValue kv1 = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("fam1"), Bytes.toBytes("a"), 1,
      Bytes.toBytes("value"));
  KeyValue kv2 = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("fam2"), Bytes.toBytes("a"), 2,
      Bytes.toBytes("value"));
  MockNextRowFilter mockNextRowFilter = new MockNextRowFilter();
  FilterList filter = new FilterList(Operator.MUST_PASS_ONE, mockNextRowFilter);
  filter.filterCell(kv1);
  filter.filterCell(kv2);
  assertEquals(2, mockNextRowFilter.getHitCount());
}
 
Example #18
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 #19
Source File: WhereOptimizerTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Test
public void testForceSkipScanOnSaltedTable() throws SQLException {
    Connection conn = DriverManager.getConnection(getUrl());
    conn.createStatement().execute("CREATE TABLE IF NOT EXISTS user_messages (\n" + 
            "        SENDER_ID UNSIGNED_LONG NOT NULL,\n" + 
            "        RECIPIENT_ID UNSIGNED_LONG NOT NULL,\n" + 
            "        SENDER_IP VARCHAR,\n" + 
            "        IS_READ VARCHAR,\n" + 
            "        IS_DELETED VARCHAR,\n" + 
            "        M_TEXT VARCHAR,\n" + 
            "        M_TIMESTAMP timestamp  NOT NULL,\n" + 
            "        ROW_ID UNSIGNED_LONG NOT NULL\n" + 
            "        constraint rowkey primary key (SENDER_ID,RECIPIENT_ID,M_TIMESTAMP DESC,ROW_ID))\n" + 
            "SALT_BUCKETS=12\n");
    String query = "select /*+ SKIP_SCAN */ count(*) from user_messages where is_read='N' and recipient_id=5399179882";
    StatementContext context = compileStatement(query);
    Scan scan = context.getScan();
    Filter filter = scan.getFilter();
    
    assertNotNull(filter);
    assertTrue(filter instanceof FilterList);
    FilterList filterList = (FilterList)filter;
    assertEquals(FilterList.Operator.MUST_PASS_ALL, filterList.getOperator());
    assertEquals(2, filterList.getFilters().size());
    assertTrue(filterList.getFilters().get(0) instanceof SkipScanFilter);
    assertTrue(filterList.getFilters().get(1) instanceof SingleKeyValueComparisonFilter);
    
    ScanRanges scanRanges = context.getScanRanges();
    assertNotNull(scanRanges);
    assertEquals(3,scanRanges.getRanges().size());
    assertEquals(1,scanRanges.getRanges().get(1).size());
    assertEquals(KeyRange.EVERYTHING_RANGE,scanRanges.getRanges().get(1).get(0));
    assertEquals(1,scanRanges.getRanges().get(2).size());
    assertTrue(scanRanges.getRanges().get(2).get(0).isSingleKey());
    assertEquals(Long.valueOf(5399179882L), PUnsignedLong.INSTANCE.toObject(scanRanges.getRanges().get(2).get(0).getLowerRange()));
}
 
Example #20
Source File: TestFilterList.java    From hbase with Apache License 2.0 5 votes vote down vote up
private Filter getFilterMPONE() {
  List<Filter> filters = new ArrayList<>();
  filters.add(new PageFilter(MAX_PAGES));
  filters.add(new WhileMatchFilter(new PrefixFilter(Bytes.toBytes("yyy"))));
  Filter filterMPONE =
    new FilterList(FilterList.Operator.MUST_PASS_ONE, filters);
  return filterMPONE;
}
 
Example #21
Source File: Filters.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
public static void filterComposingChain(String projectId, String instanceId, String tableId) {
  // A filter that selects one cell per row AND within the column family cell_plan
  Filter familyFilter =
      new FamilyFilter(CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes("cell_plan")));
  Filter columnCountGetFilter = new ColumnCountGetFilter(3);

  FilterList filter = new FilterList(FilterList.Operator.MUST_PASS_ALL);
  filter.addFilter(columnCountGetFilter);
  filter.addFilter(familyFilter);
  Scan scan = new Scan().setFilter(filter);
  readWithFilter(projectId, instanceId, tableId, scan);
}
 
Example #22
Source File: Filters.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
public static void filterComposingInterleave(
    String projectId, String instanceId, String tableId) {
  // A filter that matches cells with the value true OR with the column qualifier os_build
  Filter qualifierFilter =
      new QualifierFilter(CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes("os_build")));
  Filter valueFilter =
      new ValueFilter(CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes("true")));

  FilterList filter = new FilterList(Operator.MUST_PASS_ONE);
  filter.addFilter(qualifierFilter);
  filter.addFilter(valueFilter);

  Scan scan = new Scan().setFilter(filter).setMaxVersions();
  readWithFilter(projectId, instanceId, tableId, scan);
}
 
Example #23
Source File: TestFuzzyRowFilterEndToEnd.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void runScanner(Table hTable, int expectedSize, Filter filter1, Filter filter2)
    throws IOException {
  String cf = "f";
  Scan scan = new Scan();
  scan.addFamily(Bytes.toBytes(cf));
  FilterList filterList = new FilterList(Operator.MUST_PASS_ALL, filter1, filter2);
  scan.setFilter(filterList);

  ResultScanner scanner = hTable.getScanner(scan);
  List<Cell> results = new ArrayList<>();
  Result result;
  long timeBeforeScan = System.currentTimeMillis();
  while ((result = scanner.next()) != null) {
    for (Cell kv : result.listCells()) {
      LOG.info("Got rk: " + Bytes.toStringBinary(CellUtil.cloneRow(kv)) + " cq: "
          + Bytes.toStringBinary(CellUtil.cloneQualifier(kv)));
      results.add(kv);
    }
  }
  long scanTime = System.currentTimeMillis() - timeBeforeScan;
  scanner.close();

  LOG.info("scan time = " + scanTime + "ms");
  LOG.info("found " + results.size() + " results");

  assertEquals(expectedSize, results.size());
}
 
Example #24
Source File: TestFilterListOnMini.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testFiltersWithOR() throws Exception {
  TableName tn = TableName.valueOf(name.getMethodName());
  Table table = TEST_UTIL.createTable(tn, new String[] { "cf1", "cf2" });
  byte[] CF1 = Bytes.toBytes("cf1");
  byte[] CF2 = Bytes.toBytes("cf2");
  Put put1 = new Put(Bytes.toBytes("0"));
  put1.addColumn(CF1, Bytes.toBytes("col_a"), Bytes.toBytes(0));
  table.put(put1);
  Put put2 = new Put(Bytes.toBytes("0"));
  put2.addColumn(CF2, Bytes.toBytes("col_b"), Bytes.toBytes(0));
  table.put(put2);
  FamilyFilter filterCF1 =
      new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(CF1));
  FamilyFilter filterCF2 =
      new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(CF2));
  FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ONE);
  filterList.addFilter(filterCF1);
  filterList.addFilter(filterCF2);
  Scan scan = new Scan();
  scan.setFilter(filterList);
  ResultScanner scanner = table.getScanner(scan);
  LOG.info("Filter list: " + filterList);
  for (Result rr = scanner.next(); rr != null; rr = scanner.next()) {
    Assert.assertEquals(2, rr.size());
  }
}
 
Example #25
Source File: TestFilterList.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddFilter() throws Exception {
  Filter filter1 = new FirstKeyOnlyFilter();
  Filter filter2 = new FirstKeyOnlyFilter();

  FilterList filterList = new FilterList(filter1, filter2);
  filterList.addFilter(new FirstKeyOnlyFilter());

  filterList = new FilterList(Arrays.asList(filter1, filter2));
  filterList.addFilter(new FirstKeyOnlyFilter());

  filterList = new FilterList(Operator.MUST_PASS_ALL, filter1, filter2);
  filterList.addFilter(new FirstKeyOnlyFilter());

  filterList = new FilterList(Operator.MUST_PASS_ALL, Arrays.asList(filter1, filter2));
  filterList.addFilter(new FirstKeyOnlyFilter());

  filterList.setReversed(false);
  FirstKeyOnlyFilter f = new FirstKeyOnlyFilter();
  f.setReversed(true);
  try {
    filterList.addFilter(f);
    fail("The IllegalArgumentException should be thrown because the added filter is reversed");
  } catch (IllegalArgumentException e) {
  }

}
 
Example #26
Source File: TestFilterListOnMini.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * Test case for HBASE-21620
 */
@Test
public void testColumnPrefixFilterConcatWithOR() throws Exception {
  TableName tn = TableName.valueOf(name.getMethodName());
  byte[] cf1 = Bytes.toBytes("f1");
  byte[] row = Bytes.toBytes("row");
  byte[] value = Bytes.toBytes("value");
  String[] columns = new String[]{
    "1544768273917010001_lt",
    "1544768273917010001_w_1",
    "1544768723910010001_ca_1",
    "1544768723910010001_lt",
    "1544768723910010001_ut_1",
    "1544768723910010001_w_5",
    "1544769779710010001_lt",
    "1544769779710010001_w_5",
    "1544769883529010001_lt",
    "1544769883529010001_w_5",
    "1544769915805010001_lt",
    "1544769915805010001_w_5",
    "1544779883529010001_lt",
    "1544770422942010001_lt",
    "1544770422942010001_w_5"
  };
  Table table = TEST_UTIL.createTable(tn, cf1);
  for (int i = 0; i < columns.length; i++) {
    Put put = new Put(row).addColumn(cf1, Bytes.toBytes(columns[i]), value);
    table.put(put);
  }
  Scan scan = new Scan();
  scan.withStartRow(row).withStopRow(row, true)
      .setFilter(new FilterList(Operator.MUST_PASS_ONE,
          new ColumnPrefixFilter(Bytes.toBytes("1544770422942010001_")),
          new ColumnPrefixFilter(Bytes.toBytes("1544769883529010001_"))));
  ResultScanner scanner = table.getScanner(scan);
  Result result;
  int resultCount = 0;
  int cellCount = 0;
  while ((result = scanner.next()) != null) {
    cellCount += result.listCells().size();
    resultCount++;
  }
  Assert.assertEquals(resultCount, 1);
  Assert.assertEquals(cellCount, 4);
}
 
Example #27
Source File: TestFilter.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testFilterListWithPrefixFilter() throws IOException {
  byte[] family = Bytes.toBytes("f1");
  byte[] qualifier = Bytes.toBytes("q1");
  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(
      TableName.valueOf(name.getMethodName()));

  tableDescriptor.setColumnFamily(
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(family));
  RegionInfo info = RegionInfoBuilder.newBuilder(tableDescriptor.getTableName()).build();
  HRegion testRegion = HBaseTestingUtility.createRegionAndWAL(info, TEST_UTIL.getDataTestDir(),
    TEST_UTIL.getConfiguration(), tableDescriptor);

  for(int i=0; i<5; i++) {
    Put p = new Put(Bytes.toBytes((char)('a'+i) + "row"));
    p.setDurability(Durability.SKIP_WAL);
    p.addColumn(family, qualifier, Bytes.toBytes(String.valueOf(111 + i)));
    testRegion.put(p);
  }
  testRegion.flush(true);

  // rows starting with "b"
  PrefixFilter pf = new PrefixFilter(new byte[] {'b'}) ;
  // rows with value of column 'q1' set to '113'
  SingleColumnValueFilter scvf = new SingleColumnValueFilter(
      family, qualifier, CompareOperator.EQUAL, Bytes.toBytes("113"));
  // combine these two with OR in a FilterList
  FilterList filterList = new FilterList(Operator.MUST_PASS_ONE, pf, scvf);

  Scan s1 = new Scan();
  s1.setFilter(filterList);
  InternalScanner scanner = testRegion.getScanner(s1);
  List<Cell> results = new ArrayList<>();
  int resultCount = 0;
  while (scanner.next(results)) {
    resultCount++;
    byte[] row =  CellUtil.cloneRow(results.get(0));
    LOG.debug("Found row: " + Bytes.toStringBinary(row));
    assertTrue(Bytes.equals(row, Bytes.toBytes("brow"))
        || Bytes.equals(row, Bytes.toBytes("crow")));
    results.clear();
  }
  assertEquals(2, resultCount);
  scanner.close();

  WAL wal = ((HRegion)testRegion).getWAL();
  ((HRegion)testRegion).close();
  wal.close();
}
 
Example #28
Source File: TestFilter.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testFilterListWithSingleColumnValueFilter() throws IOException {
  // Test for HBASE-3191

  // Scan using SingleColumnValueFilter
  SingleColumnValueFilter f1 = new SingleColumnValueFilter(FAMILIES[0], QUALIFIERS_ONE[0],
  CompareOperator.EQUAL, VALUES[0]);
  f1.setFilterIfMissing( true );
  Scan s1 = new Scan();
  s1.addFamily(FAMILIES[0]);
  s1.setFilter(f1);
  KeyValue [] kvs1 = {
      new KeyValue(ROWS_ONE[0], FAMILIES[0], QUALIFIERS_ONE[0], VALUES[0]),
      new KeyValue(ROWS_ONE[0], FAMILIES[0], QUALIFIERS_ONE[2], VALUES[0]),
      new KeyValue(ROWS_ONE[0], FAMILIES[0], QUALIFIERS_ONE[3], VALUES[0]),
      new KeyValue(ROWS_ONE[2], FAMILIES[0], QUALIFIERS_ONE[0], VALUES[0]),
      new KeyValue(ROWS_ONE[2], FAMILIES[0], QUALIFIERS_ONE[2], VALUES[0]),
      new KeyValue(ROWS_ONE[2], FAMILIES[0], QUALIFIERS_ONE[3], VALUES[0]),
      new KeyValue(ROWS_ONE[3], FAMILIES[0], QUALIFIERS_ONE[0], VALUES[0]),
      new KeyValue(ROWS_ONE[3], FAMILIES[0], QUALIFIERS_ONE[2], VALUES[0]),
      new KeyValue(ROWS_ONE[3], FAMILIES[0], QUALIFIERS_ONE[3], VALUES[0]),
  };
  verifyScanNoEarlyOut(s1, 3, 3);
  verifyScanFull(s1, kvs1);

  // Scan using another SingleColumnValueFilter, expect disjoint result
  SingleColumnValueFilter f2 = new SingleColumnValueFilter(FAMILIES[0], QUALIFIERS_TWO[0],
  CompareOperator.EQUAL, VALUES[1]);
  f2.setFilterIfMissing( true );
  Scan s2 = new Scan();
  s2.addFamily(FAMILIES[0]);
  s2.setFilter(f2);
  KeyValue [] kvs2 = {
      new KeyValue(ROWS_TWO[0], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]),
      new KeyValue(ROWS_TWO[0], FAMILIES[0], QUALIFIERS_TWO[2], VALUES[1]),
      new KeyValue(ROWS_TWO[0], FAMILIES[0], QUALIFIERS_TWO[3], VALUES[1]),
      new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]),
      new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[2], VALUES[1]),
      new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[3], VALUES[1]),
      new KeyValue(ROWS_TWO[3], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]),
      new KeyValue(ROWS_TWO[3], FAMILIES[0], QUALIFIERS_TWO[2], VALUES[1]),
      new KeyValue(ROWS_TWO[3], FAMILIES[0], QUALIFIERS_TWO[3], VALUES[1]),
  };
  verifyScanNoEarlyOut(s2, 3, 3);
  verifyScanFull(s2, kvs2);

  // Scan, ORing the two previous filters, expect unified result
  FilterList f = new FilterList(Operator.MUST_PASS_ONE);
  f.addFilter(f1);
  f.addFilter(f2);
  Scan s = new Scan();
  s.addFamily(FAMILIES[0]);
  s.setFilter(f);
  KeyValue [] kvs = {
      new KeyValue(ROWS_ONE[0], FAMILIES[0], QUALIFIERS_ONE[0], VALUES[0]),
      new KeyValue(ROWS_ONE[0], FAMILIES[0], QUALIFIERS_ONE[2], VALUES[0]),
      new KeyValue(ROWS_ONE[0], FAMILIES[0], QUALIFIERS_ONE[3], VALUES[0]),
      new KeyValue(ROWS_ONE[2], FAMILIES[0], QUALIFIERS_ONE[0], VALUES[0]),
      new KeyValue(ROWS_ONE[2], FAMILIES[0], QUALIFIERS_ONE[2], VALUES[0]),
      new KeyValue(ROWS_ONE[2], FAMILIES[0], QUALIFIERS_ONE[3], VALUES[0]),
      new KeyValue(ROWS_ONE[3], FAMILIES[0], QUALIFIERS_ONE[0], VALUES[0]),
      new KeyValue(ROWS_ONE[3], FAMILIES[0], QUALIFIERS_ONE[2], VALUES[0]),
      new KeyValue(ROWS_ONE[3], FAMILIES[0], QUALIFIERS_ONE[3], VALUES[0]),
      new KeyValue(ROWS_TWO[0], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]),
      new KeyValue(ROWS_TWO[0], FAMILIES[0], QUALIFIERS_TWO[2], VALUES[1]),
      new KeyValue(ROWS_TWO[0], FAMILIES[0], QUALIFIERS_TWO[3], VALUES[1]),
      new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]),
      new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[2], VALUES[1]),
      new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[3], VALUES[1]),
      new KeyValue(ROWS_TWO[3], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]),
      new KeyValue(ROWS_TWO[3], FAMILIES[0], QUALIFIERS_TWO[2], VALUES[1]),
      new KeyValue(ROWS_TWO[3], FAMILIES[0], QUALIFIERS_TWO[3], VALUES[1]),
  };
  verifyScanNoEarlyOut(s, 6, 3);
  verifyScanFull(s, kvs);
}
 
Example #29
Source File: TestFilterList.java    From hbase with 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 #30
Source File: TestColumnRangeFilter.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void TestColumnRangeFilterWithColumnPaginationFilter() throws Exception {
  String family = "Family";
  String table = "TestColumnRangeFilterWithColumnPaginationFilter";
  try (Table ht =
      TEST_UTIL.createTable(TableName.valueOf(table), Bytes.toBytes(family), Integer.MAX_VALUE)) {
    // one row.
    String row = "row";
    // One version
    long timestamp = 100;
    // 10 columns
    int[] columns = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    String valueString = "ValueString";

    Put p = new Put(Bytes.toBytes(row));
    p.setDurability(Durability.SKIP_WAL);
    for (int column : columns) {
      KeyValue kv =
          KeyValueTestUtil.create(row, family, Integer.toString(column), timestamp, valueString);
      p.add(kv);
    }
    ht.put(p);

    TEST_UTIL.flush();

    // Column range from 1 to 9.
    StringRange stringRange = new StringRange("1", true, "9", false);
    ColumnRangeFilter filter1 = new ColumnRangeFilter(Bytes.toBytes(stringRange.getStart()),
        stringRange.isStartInclusive(), Bytes.toBytes(stringRange.getEnd()),
        stringRange.isEndInclusive());

    ColumnPaginationFilter filter2 = new ColumnPaginationFilter(5, 0);
    ColumnPaginationFilter filter3 = new ColumnPaginationFilter(5, 1);
    ColumnPaginationFilter filter4 = new ColumnPaginationFilter(5, 2);
    ColumnPaginationFilter filter5 = new ColumnPaginationFilter(5, 6);
    ColumnPaginationFilter filter6 = new ColumnPaginationFilter(5, 9);
    assertEquals(5, cellsCount(ht, new FilterList(Operator.MUST_PASS_ALL, filter1, filter2)));
    assertEquals(5, cellsCount(ht, new FilterList(Operator.MUST_PASS_ALL, filter1, filter3)));
    assertEquals(5, cellsCount(ht, new FilterList(Operator.MUST_PASS_ALL, filter1, filter4)));
    assertEquals(2, cellsCount(ht, new FilterList(Operator.MUST_PASS_ALL, filter1, filter5)));
    assertEquals(0, cellsCount(ht, new FilterList(Operator.MUST_PASS_ALL, filter1, filter6)));
  }
}