diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/FilterList.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/FilterList.java index 7433cca..2f6857c 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/FilterList.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/FilterList.java @@ -344,7 +344,7 @@ final public class FilterList extends FilterBase { return !CellUtil.matchingRowColumn(prevCell, currentCell); case NEXT_ROW: case INCLUDE_AND_SEEK_NEXT_ROW: - return !CellUtil.matchingRows(prevCell, currentCell); + return !CellUtil.matchingRows(prevCell, currentCell) || !CellUtil.matchingFamily(prevCell, currentCell); default: throw new IllegalStateException("Received code is not valid."); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestFilterList.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestFilterList.java index cf8a0a0..1d375a3 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestFilterList.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestFilterList.java @@ -710,5 +710,19 @@ public class TestFilterList { filter.filterKeyValue(kv4); assertTrue(mockFilter.didCellPassToTheFilter); } + + @Test + public void testFamilyFilterWithMustPassOne() throws IOException{ + byte[] CF1 = Bytes.toBytes("cf1"); + byte[] CF2 = Bytes.toBytes("cf2"); + FamilyFilter filterCF1 = new FamilyFilter(CompareFilter.CompareOp.EQUAL, new BinaryComparator(CF1)); + FamilyFilter filterCF2 = new FamilyFilter(CompareFilter.CompareOp.EQUAL, new BinaryComparator(CF2)); + + FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ONE); + filterList.addFilter(filterCF1); + filterList.addFilter(filterCF2); + assertEquals(filterList.filterKeyValue(new KeyValue(CF1,CF1,CF1)), ReturnCode.INCLUDE); + assertEquals(filterList.filterKeyValue(new KeyValue(CF1,CF2,CF2)), ReturnCode.INCLUDE); + } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestFiltersWithOr.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestFiltersWithOr.java new file mode 100644 index 0000000..a249317 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestFiltersWithOr.java @@ -0,0 +1,88 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.filter; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.client.*; +import org.apache.hadoop.hbase.testclassification.FilterTests; +import org.apache.hadoop.hbase.testclassification.MediumTests; +import org.apache.hadoop.hbase.util.Bytes; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +@Category({FilterTests.class, MediumTests.class}) +public class TestFiltersWithOr { + + final Log LOG = LogFactory.getLog(getClass()); + private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + TEST_UTIL.startMiniCluster(1); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + TEST_UTIL.shutdownMiniCluster(); + } + + @Test + public void testFiltersWithOr() throws Exception { + TableName tn = TableName.valueOf("MyTest"); + 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(CompareFilter.CompareOp.EQUAL, new BinaryComparator(CF1)); + FamilyFilter filterCF2 = new FamilyFilter(CompareFilter.CompareOp.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.error("Filter list: " + filterList); + + for (Result rr = scanner.next(); rr != null; rr = scanner.next()) { + Assert.assertTrue(rr.size() == 2); + } + } + + +}