You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by gx...@apache.org on 2018/09/11 06:17:17 UTC
hbase git commit: HBASE-21158 Empty qualifier cell is always returned
when using QualifierFilter
Repository: hbase
Updated Branches:
refs/heads/branch-1.4 89bbc3065 -> b3aa1c199
HBASE-21158 Empty qualifier cell is always returned when using QualifierFilter
Signed-off-by: tedyu <yu...@gmail.com>
Signed-off-by: Andrew Purtell <ap...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/b3aa1c19
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/b3aa1c19
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/b3aa1c19
Branch: refs/heads/branch-1.4
Commit: b3aa1c199093ba79e849446b597a722210458a74
Parents: 89bbc30
Author: Guangxu Cheng <gu...@gmail.com>
Authored: Tue Sep 11 10:56:08 2018 +0800
Committer: Guangxu Cheng <gu...@gmail.com>
Committed: Tue Sep 11 14:14:23 2018 +0800
----------------------------------------------------------------------
.../hadoop/hbase/filter/QualifierFilter.java | 9 +-
.../TestQualifierFilterWithEmptyQualifier.java | 156 +++++++++++++++++++
2 files changed, 159 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/b3aa1c19/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/QualifierFilter.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/QualifierFilter.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/QualifierFilter.java
index bf503c2..1f7e843 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/QualifierFilter.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/QualifierFilter.java
@@ -61,12 +61,9 @@ public class QualifierFilter extends CompareFilter {
@Override
public ReturnCode filterKeyValue(Cell v) {
- int qualifierLength = v.getQualifierLength();
- if (qualifierLength > 0) {
- if (doCompare(this.compareOp, this.comparator, v.getQualifierArray(),
- v.getQualifierOffset(), qualifierLength)) {
- return ReturnCode.SKIP;
- }
+ if (doCompare(this.compareOp, this.comparator, v.getQualifierArray(),
+ v.getQualifierOffset(), v.getQualifierLength())) {
+ return ReturnCode.SKIP;
}
return ReturnCode.INCLUDE;
}
http://git-wip-us.apache.org/repos/asf/hbase/blob/b3aa1c19/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestQualifierFilterWithEmptyQualifier.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestQualifierFilterWithEmptyQualifier.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestQualifierFilterWithEmptyQualifier.java
new file mode 100644
index 0000000..28421e1
--- /dev/null
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestQualifierFilterWithEmptyQualifier.java
@@ -0,0 +1,156 @@
+/**
+ * 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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.HRegionInfo;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.KeyValue;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Durability;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
+import org.apache.hadoop.hbase.regionserver.HRegion;
+import org.apache.hadoop.hbase.regionserver.InternalScanner;
+import org.apache.hadoop.hbase.testclassification.FilterTests;
+import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TestName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Test qualifierFilter with empty qualifier column
+ */
+@Category({FilterTests.class, SmallTests.class})
+public class TestQualifierFilterWithEmptyQualifier {
+ private final static Logger LOG
+ = LoggerFactory.getLogger(TestQualifierFilterWithEmptyQualifier.class);
+ private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
+ private HRegion region;
+
+ @Rule
+ public TestName name = new TestName();
+
+ private static final byte[][] ROWS =
+ { Bytes.toBytes("testRowOne-0"), Bytes.toBytes("testRowOne-1"),
+ Bytes.toBytes("testRowOne-2"), Bytes.toBytes("testRowOne-3") };
+ private static final byte[] FAMILY = Bytes.toBytes("testFamily");
+ private static final byte[][] QUALIFIERS = {HConstants.EMPTY_BYTE_ARRAY,
+ Bytes.toBytes("testQualifier")};
+ private static final byte[] VALUE = Bytes.toBytes("testValueOne");
+ private long numRows = (long) ROWS.length;
+
+ @Before
+ public void setUp() throws Exception {
+ HTableDescriptor htd = new HTableDescriptor(TableName.valueOf("TestQualifierFilter"));
+ htd.addFamily(new HColumnDescriptor(FAMILY));
+ HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false);
+ this.region = HRegion.createHRegion(info, TEST_UTIL.getDataTestDir(),
+ TEST_UTIL.getConfiguration(), htd);
+
+ // Insert data
+ for (byte[] ROW : ROWS) {
+ Put p = new Put(ROW);
+ p.setDurability(Durability.SKIP_WAL);
+ for (byte[] QUALIFIER : QUALIFIERS) {
+ p.addColumn(FAMILY, QUALIFIER, VALUE);
+ }
+ this.region.put(p);
+ }
+
+ // Flush
+ this.region.flush(true);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ HBaseTestingUtility.closeRegionAndWAL(region);
+ }
+
+ @Test
+ public void testQualifierFilterWithEmptyColumn() throws IOException {
+ long colsPerRow = 2;
+ long expectedKeys = colsPerRow / 2;
+ Filter f = new QualifierFilter(CompareOp.EQUAL,
+ new BinaryComparator(QUALIFIERS[0]));
+ Scan s = new Scan();
+ s.setFilter(f);
+ verifyScanNoEarlyOut(s, this.numRows, expectedKeys);
+
+ expectedKeys = colsPerRow / 2;
+ f = new QualifierFilter(CompareOp.EQUAL,
+ new BinaryComparator(QUALIFIERS[1]));
+ s = new Scan();
+ s.setFilter(f);
+ verifyScanNoEarlyOut(s, this.numRows, expectedKeys);
+
+ expectedKeys = colsPerRow / 2;
+ f = new QualifierFilter(CompareOp.GREATER,
+ new BinaryComparator(QUALIFIERS[0]));
+ s = new Scan();
+ s.setFilter(f);
+ verifyScanNoEarlyOut(s, this.numRows, expectedKeys);
+
+ expectedKeys = colsPerRow;
+ f = new QualifierFilter(CompareOp.GREATER_OR_EQUAL,
+ new BinaryComparator(QUALIFIERS[0]));
+ s = new Scan();
+ s.setFilter(f);
+ verifyScanNoEarlyOut(s, this.numRows, expectedKeys);
+ }
+
+ private void verifyScanNoEarlyOut(Scan s, long expectedRows,
+ long expectedKeys)
+ throws IOException {
+ InternalScanner scanner = this.region.getScanner(s);
+ List<Cell> results = new ArrayList<>();
+ int i = 0;
+ for (boolean done = true; done; i++) {
+ done = scanner.next(results);
+ Arrays.sort(results.toArray(new KeyValue[results.size()]),
+ KeyValue.COMPARATOR);
+ LOG.info("counter=" + i + ", " + results);
+ if(results.isEmpty()) {
+ break;
+ }
+ assertTrue("Scanned too many rows! Only expected " + expectedRows +
+ " total but already scanned " + (i+1), expectedRows > i);
+ assertEquals("Expected " + expectedKeys + " keys per row but " +
+ "returned " + results.size(), expectedKeys, results.size());
+ results.clear();
+ }
+ assertEquals("Expected " + expectedRows + " rows but scanned " + i +
+ " rows", expectedRows, i);
+ }
+}