You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by te...@apache.org on 2014/04/01 03:53:02 UTC
svn commit: r1583511 - in /hbase/trunk:
hbase-client/src/main/java/org/apache/hadoop/hbase/filter/
hbase-server/src/test/java/org/apache/hadoop/hbase/filter/
Author: tedyu
Date: Tue Apr 1 01:53:01 2014
New Revision: 1583511
URL: http://svn.apache.org/r1583511
Log:
HBASE-10848 Filter SingleColumnValueFilter combined with NullComparator does not work
Added:
hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestNullComparator.java
Modified:
hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/NullComparator.java
hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestSingleColumnValueFilter.java
Modified: hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/NullComparator.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/NullComparator.java?rev=1583511&r1=1583510&r2=1583511&view=diff
==============================================================================
--- hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/NullComparator.java (original)
+++ hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/NullComparator.java Tue Apr 1 01:53:01 2014
@@ -56,7 +56,7 @@ public class NullComparator extends Byte
@Override
public int compareTo(byte[] value, int offset, int length) {
- throw new UnsupportedOperationException();
+ return compareTo(value);
}
/**
Added: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestNullComparator.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestNullComparator.java?rev=1583511&view=auto
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestNullComparator.java (added)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestNullComparator.java Tue Apr 1 01:53:01 2014
@@ -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);
+ }
+
+}
Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestSingleColumnValueFilter.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestSingleColumnValueFilter.java?rev=1583511&r1=1583510&r2=1583511&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestSingleColumnValueFilter.java (original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestSingleColumnValueFilter.java Tue Apr 1 01:53:01 2014
@@ -18,23 +18,19 @@
*/
package org.apache.hadoop.hbase.filter;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import java.util.regex.Pattern;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.SmallTests;
import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
import org.apache.hadoop.hbase.util.Bytes;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
-import static org.junit.Assert.*;
-
/**
* 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);
Filter basicFilter;
+ Filter nullFilter;
Filter substrFilter;
Filter regexFilter;
Filter regexPatternFilter;
@@ -63,6 +60,7 @@ public class TestSingleColumnValueFilter
@Before
public void setUp() throws Exception {
basicFilter = basicFilterNew();
+ nullFilter = nullFilterNew();
substrFilter = substrFilterNew();
regexFilter = regexFilterNew();
regexPatternFilter = regexFilterNew(QUICK_PATTERN);
@@ -73,6 +71,11 @@ public class TestSingleColumnValueFilter
CompareOp.GREATER_OR_EQUAL, VAL_2);
}
+ private Filter nullFilterNew() {
+ return new SingleColumnValueFilter(COLUMN_FAMILY, COLUMN_QUALIFIER, CompareOp.NOT_EQUAL,
+ new NullComparator());
+ }
+
private Filter substrFilterNew() {
return new SingleColumnValueFilter(COLUMN_FAMILY, COLUMN_QUALIFIER,
CompareOp.EQUAL,
@@ -116,6 +119,17 @@ public class TestSingleColumnValueFilter
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)
throws Exception {
KeyValue kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER,
@@ -168,7 +182,8 @@ public class TestSingleColumnValueFilter
*/
@Test
public void testStop() throws Exception {
- basicFilterTests((SingleColumnValueFilter)basicFilter);
+ basicFilterTests((SingleColumnValueFilter) basicFilter);
+ nullFilterTests(nullFilter);
substrFilterTests(substrFilter);
regexFilterTests(regexFilter);
regexPatternFilterTests(regexPatternFilter);
@@ -182,6 +197,8 @@ public class TestSingleColumnValueFilter
public void testSerialization() throws Exception {
Filter newFilter = serializationTest(basicFilter);
basicFilterTests((SingleColumnValueFilter)newFilter);
+ newFilter = serializationTest(nullFilter);
+ nullFilterTests(newFilter);
newFilter = serializationTest(substrFilter);
substrFilterTests(newFilter);
newFilter = serializationTest(regexFilter);