HBASE-10848 Filter SingleColumnValueFilter combined with NullComparator does not work (Fabien)
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1583511 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
bc42dc04ac
commit
0f0d6c1754
|
@ -56,7 +56,7 @@ public class NullComparator extends ByteArrayComparable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(byte[] value, int offset, int length) {
|
public int compareTo(byte[] value, int offset, int length) {
|
||||||
throw new UnsupportedOperationException();
|
return compareTo(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Licensed 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.
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.apache.hadoop.hbase.filter;
|
||||||
|
|
||||||
|
import org.apache.hadoop.hbase.SmallTests;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.experimental.categories.Category;
|
||||||
|
|
||||||
|
@Category(SmallTests.class)
|
||||||
|
public class TestNullComparator {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNullValue()
|
||||||
|
{
|
||||||
|
// given
|
||||||
|
byte[] value = null;
|
||||||
|
NullComparator comparator = new NullComparator();
|
||||||
|
|
||||||
|
// when
|
||||||
|
int comp1 = comparator.compareTo(value);
|
||||||
|
int comp2 = comparator.compareTo(value, 5, 15);
|
||||||
|
|
||||||
|
// then
|
||||||
|
Assert.assertEquals(0, comp1);
|
||||||
|
Assert.assertEquals(0, comp2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNonNullValue() {
|
||||||
|
// given
|
||||||
|
byte[] value = new byte[] { 0, 1, 2, 3, 4, 5 };
|
||||||
|
NullComparator comparator = new NullComparator();
|
||||||
|
|
||||||
|
// when
|
||||||
|
int comp1 = comparator.compareTo(value);
|
||||||
|
int comp2 = comparator.compareTo(value, 1, 3);
|
||||||
|
|
||||||
|
// then
|
||||||
|
Assert.assertEquals(1, comp1);
|
||||||
|
Assert.assertEquals(1, comp2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEmptyValue() {
|
||||||
|
// given
|
||||||
|
byte[] value = new byte[] { 0 };
|
||||||
|
NullComparator comparator = new NullComparator();
|
||||||
|
|
||||||
|
// when
|
||||||
|
int comp1 = comparator.compareTo(value);
|
||||||
|
int comp2 = comparator.compareTo(value, 1, 3);
|
||||||
|
|
||||||
|
// then
|
||||||
|
Assert.assertEquals(1, comp1);
|
||||||
|
Assert.assertEquals(1, comp2);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -18,23 +18,19 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.hadoop.hbase.filter;
|
package org.apache.hadoop.hbase.filter;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import static org.junit.Assert.assertFalse;
|
||||||
import java.io.ByteArrayOutputStream;
|
import static org.junit.Assert.assertTrue;
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.apache.hadoop.hbase.KeyValue;
|
import org.apache.hadoop.hbase.KeyValue;
|
||||||
import org.apache.hadoop.hbase.SmallTests;
|
import org.apache.hadoop.hbase.SmallTests;
|
||||||
import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
|
import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
|
||||||
import org.apache.hadoop.hbase.util.Bytes;
|
import org.apache.hadoop.hbase.util.Bytes;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.experimental.categories.Category;
|
import org.junit.experimental.categories.Category;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the value filter
|
* Tests the value filter
|
||||||
*/
|
*/
|
||||||
|
@ -56,6 +52,7 @@ public class TestSingleColumnValueFilter {
|
||||||
private static final Pattern QUICK_PATTERN = Pattern.compile("QuIcK", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
|
private static final Pattern QUICK_PATTERN = Pattern.compile("QuIcK", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
|
||||||
|
|
||||||
Filter basicFilter;
|
Filter basicFilter;
|
||||||
|
Filter nullFilter;
|
||||||
Filter substrFilter;
|
Filter substrFilter;
|
||||||
Filter regexFilter;
|
Filter regexFilter;
|
||||||
Filter regexPatternFilter;
|
Filter regexPatternFilter;
|
||||||
|
@ -63,6 +60,7 @@ public class TestSingleColumnValueFilter {
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
basicFilter = basicFilterNew();
|
basicFilter = basicFilterNew();
|
||||||
|
nullFilter = nullFilterNew();
|
||||||
substrFilter = substrFilterNew();
|
substrFilter = substrFilterNew();
|
||||||
regexFilter = regexFilterNew();
|
regexFilter = regexFilterNew();
|
||||||
regexPatternFilter = regexFilterNew(QUICK_PATTERN);
|
regexPatternFilter = regexFilterNew(QUICK_PATTERN);
|
||||||
|
@ -73,6 +71,11 @@ public class TestSingleColumnValueFilter {
|
||||||
CompareOp.GREATER_OR_EQUAL, VAL_2);
|
CompareOp.GREATER_OR_EQUAL, VAL_2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Filter nullFilterNew() {
|
||||||
|
return new SingleColumnValueFilter(COLUMN_FAMILY, COLUMN_QUALIFIER, CompareOp.NOT_EQUAL,
|
||||||
|
new NullComparator());
|
||||||
|
}
|
||||||
|
|
||||||
private Filter substrFilterNew() {
|
private Filter substrFilterNew() {
|
||||||
return new SingleColumnValueFilter(COLUMN_FAMILY, COLUMN_QUALIFIER,
|
return new SingleColumnValueFilter(COLUMN_FAMILY, COLUMN_QUALIFIER,
|
||||||
CompareOp.EQUAL,
|
CompareOp.EQUAL,
|
||||||
|
@ -116,6 +119,17 @@ public class TestSingleColumnValueFilter {
|
||||||
assertFalse("basicFilterNotNull", filter.filterRow());
|
assertFalse("basicFilterNotNull", filter.filterRow());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void nullFilterTests(Filter filter) throws Exception {
|
||||||
|
((SingleColumnValueFilter) filter).setFilterIfMissing(true);
|
||||||
|
KeyValue kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER, FULLSTRING_1);
|
||||||
|
assertTrue("null1", filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE);
|
||||||
|
assertFalse("null1FilterRow", filter.filterRow());
|
||||||
|
filter.reset();
|
||||||
|
kv = new KeyValue(ROW, COLUMN_FAMILY, Bytes.toBytes("qual2"), FULLSTRING_2);
|
||||||
|
assertTrue("null2", filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE);
|
||||||
|
assertTrue("null2FilterRow", filter.filterRow());
|
||||||
|
}
|
||||||
|
|
||||||
private void substrFilterTests(Filter filter)
|
private void substrFilterTests(Filter filter)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
KeyValue kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER,
|
KeyValue kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER,
|
||||||
|
@ -168,7 +182,8 @@ public class TestSingleColumnValueFilter {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testStop() throws Exception {
|
public void testStop() throws Exception {
|
||||||
basicFilterTests((SingleColumnValueFilter)basicFilter);
|
basicFilterTests((SingleColumnValueFilter) basicFilter);
|
||||||
|
nullFilterTests(nullFilter);
|
||||||
substrFilterTests(substrFilter);
|
substrFilterTests(substrFilter);
|
||||||
regexFilterTests(regexFilter);
|
regexFilterTests(regexFilter);
|
||||||
regexPatternFilterTests(regexPatternFilter);
|
regexPatternFilterTests(regexPatternFilter);
|
||||||
|
@ -182,6 +197,8 @@ public class TestSingleColumnValueFilter {
|
||||||
public void testSerialization() throws Exception {
|
public void testSerialization() throws Exception {
|
||||||
Filter newFilter = serializationTest(basicFilter);
|
Filter newFilter = serializationTest(basicFilter);
|
||||||
basicFilterTests((SingleColumnValueFilter)newFilter);
|
basicFilterTests((SingleColumnValueFilter)newFilter);
|
||||||
|
newFilter = serializationTest(nullFilter);
|
||||||
|
nullFilterTests(newFilter);
|
||||||
newFilter = serializationTest(substrFilter);
|
newFilter = serializationTest(substrFilter);
|
||||||
substrFilterTests(newFilter);
|
substrFilterTests(newFilter);
|
||||||
newFilter = serializationTest(regexFilter);
|
newFilter = serializationTest(regexFilter);
|
||||||
|
|
Loading…
Reference in New Issue