1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.filter;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.apache.hadoop.hbase.HBaseTestingUtility;
24 import org.apache.hadoop.hbase.TableName;
25 import org.apache.hadoop.hbase.client.*;
26 import org.apache.hadoop.hbase.testclassification.FilterTests;
27 import org.apache.hadoop.hbase.testclassification.MediumTests;
28 import org.apache.hadoop.hbase.util.Bytes;
29 import org.junit.AfterClass;
30 import org.junit.Assert;
31 import org.junit.BeforeClass;
32 import org.junit.Ignore;
33 import org.junit.Rule;
34 import org.junit.Test;
35 import org.junit.experimental.categories.Category;
36 import org.junit.rules.TestName;
37
38
39
40
41
42 @Category({MediumTests.class, FilterTests.class})
43 public class TestFilterListOnMini {
44
45 private static final Log LOG = LogFactory.getLog(TestFilterListOnMini.class);
46 private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
47
48 @Rule
49 public TestName name = new TestName();
50
51 @BeforeClass
52 public static void setUpBeforeClass() throws Exception {
53 TEST_UTIL.startMiniCluster(1);
54 }
55
56 @AfterClass
57 public static void tearDownAfterClass() throws Exception {
58 TEST_UTIL.shutdownMiniCluster();
59 }
60
61 @Test
62 public void testFiltersWithOR() throws Exception {
63 TableName tn = TableName.valueOf(name.getMethodName());
64 Table table = TEST_UTIL.createTable(tn, new String[] { "cf1", "cf2" });
65 byte[] CF1 = Bytes.toBytes("cf1");
66 byte[] CF2 = Bytes.toBytes("cf2");
67 Put put1 = new Put(Bytes.toBytes("0"));
68 put1.addColumn(CF1, Bytes.toBytes("col_a"), Bytes.toBytes(0));
69 table.put(put1);
70 Put put2 = new Put(Bytes.toBytes("0"));
71 put2.addColumn(CF2, Bytes.toBytes("col_b"), Bytes.toBytes(0));
72 table.put(put2);
73 FamilyFilter filterCF1 =
74 new FamilyFilter(CompareFilter.CompareOp.EQUAL, new BinaryComparator(CF1));
75 FamilyFilter filterCF2 =
76 new FamilyFilter(CompareFilter.CompareOp.EQUAL, new BinaryComparator(CF2));
77 FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ONE);
78 filterList.addFilter(filterCF1);
79 filterList.addFilter(filterCF2);
80 Scan scan = new Scan();
81 scan.setFilter(filterList);
82 ResultScanner scanner = table.getScanner(scan);
83 LOG.info("Filter list: " + filterList);
84 for (Result rr = scanner.next(); rr != null; rr = scanner.next()) {
85 Assert.assertEquals(2, rr.size());
86 }
87 }
88 }