From f4e0ea24e674a8dd68b3a780318abe5e97c135b3 Mon Sep 17 00:00:00 2001 From: Jingcheng Du Date: Tue, 28 Feb 2017 11:38:35 +0800 Subject: [PATCH] HBASE-17688 MultiRowRangeFilter not working correctly if given same start and stop RowKey --- .../hbase/filter/MultiRowRangeFilter.java | 15 +++++---- .../hbase/filter/TestMultiRowRangeFilter.java | 31 +++++++++++++++++++ 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/MultiRowRangeFilter.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/MultiRowRangeFilter.java index 768088be1dd..2cc754ac9d5 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/MultiRowRangeFilter.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/MultiRowRangeFilter.java @@ -116,7 +116,9 @@ public class MultiRowRangeFilter extends FilterBase { } else { if (range.contains(rowArr, offset, length)) { currentReturnCode = ReturnCode.INCLUDE; - } else currentReturnCode = ReturnCode.SEEK_NEXT_USING_HINT; + } else { + currentReturnCode = ReturnCode.SEEK_NEXT_USING_HINT; + } } } else { currentReturnCode = ReturnCode.INCLUDE; @@ -151,7 +153,6 @@ public class MultiRowRangeFilter extends FilterBase { if (range.stopRow != null) rangebuilder.setStopRow(UnsafeByteOperations.unsafeWrap(range.stopRow)); rangebuilder.setStopRowInclusive(range.stopRowInclusive); - range.isScan = Bytes.equals(range.startRow, range.stopRow) ? 1 : 0; builder.addRowRangeList(rangebuilder.build()); } } @@ -418,7 +419,6 @@ public class MultiRowRangeFilter extends FilterBase { private boolean startRowInclusive = true; private byte[] stopRow; private boolean stopRowInclusive = false; - private int isScan = 0; public RowRange() { } @@ -441,7 +441,6 @@ public class MultiRowRangeFilter extends FilterBase { this.startRowInclusive = startRowInclusive; this.stopRow = (stopRow == null) ? HConstants.EMPTY_BYTE_ARRAY :stopRow; this.stopRowInclusive = stopRowInclusive; - isScan = Bytes.equals(startRow, stopRow) ? 1 : 0; } public byte[] getStartRow() { @@ -475,21 +474,21 @@ public class MultiRowRangeFilter extends FilterBase { if(stopRowInclusive) { return Bytes.compareTo(buffer, offset, length, startRow, 0, startRow.length) >= 0 && (Bytes.equals(stopRow, HConstants.EMPTY_BYTE_ARRAY) || - Bytes.compareTo(buffer, offset, length, stopRow, 0, stopRow.length) <= isScan); + Bytes.compareTo(buffer, offset, length, stopRow, 0, stopRow.length) <= 0); } else { return Bytes.compareTo(buffer, offset, length, startRow, 0, startRow.length) >= 0 && (Bytes.equals(stopRow, HConstants.EMPTY_BYTE_ARRAY) || - Bytes.compareTo(buffer, offset, length, stopRow, 0, stopRow.length) < isScan); + Bytes.compareTo(buffer, offset, length, stopRow, 0, stopRow.length) < 0); } } else { if(stopRowInclusive) { return Bytes.compareTo(buffer, offset, length, startRow, 0, startRow.length) > 0 && (Bytes.equals(stopRow, HConstants.EMPTY_BYTE_ARRAY) || - Bytes.compareTo(buffer, offset, length, stopRow, 0, stopRow.length) <= isScan); + Bytes.compareTo(buffer, offset, length, stopRow, 0, stopRow.length) <= 0); } else { return Bytes.compareTo(buffer, offset, length, startRow, 0, startRow.length) > 0 && (Bytes.equals(stopRow, HConstants.EMPTY_BYTE_ARRAY) || - Bytes.compareTo(buffer, offset, length, stopRow, 0, stopRow.length) < isScan); + Bytes.compareTo(buffer, offset, length, stopRow, 0, stopRow.length) < 0); } } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestMultiRowRangeFilter.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestMultiRowRangeFilter.java index b85441b727c..271edaf567b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestMultiRowRangeFilter.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestMultiRowRangeFilter.java @@ -473,6 +473,35 @@ public class TestMultiRowRangeFilter { ht.close(); } + @Test + public void testOneRowRange() throws IOException { + tableName = TableName.valueOf(name.getMethodName()); + Table ht = TEST_UTIL.createTable(tableName, family, Integer.MAX_VALUE); + generateRows(numRows, ht, family, qf, value); + ArrayList rowRangesList = new ArrayList<>(); + rowRangesList + .add(new MultiRowRangeFilter.RowRange(Bytes.toBytes(50), true, Bytes.toBytes(50), true)); + Scan scan = new Scan(); + scan.setFilter(new MultiRowRangeFilter(rowRangesList)); + int resultsSize = getResultsSize(ht, scan); + assertEquals(1, resultsSize); + rowRangesList.clear(); + rowRangesList + .add(new MultiRowRangeFilter.RowRange(Bytes.toBytes(50), true, Bytes.toBytes(51), false)); + scan = new Scan(); + scan.setFilter(new MultiRowRangeFilter(rowRangesList)); + resultsSize = getResultsSize(ht, scan); + assertEquals(1, resultsSize); + rowRangesList.clear(); + rowRangesList + .add(new MultiRowRangeFilter.RowRange(Bytes.toBytes(50), true, Bytes.toBytes(51), true)); + scan = new Scan(); + scan.setFilter(new MultiRowRangeFilter(rowRangesList)); + resultsSize = getResultsSize(ht, scan); + assertEquals(2, resultsSize); + ht.close(); + } + private void generateRows(int numberOfRows, Table ht, byte[] family, byte[] qf, byte[] value) throws IOException { for (int i = 0; i < numberOfRows; i++) { @@ -501,6 +530,7 @@ public class TestMultiRowRangeFilter { kvList.add(kv); } } + scanner.close(); return kvList; } @@ -513,6 +543,7 @@ public class TestMultiRowRangeFilter { results.add(kv); } } + scanner.close(); return results.size(); } }