HBASE-17688 MultiRowRangeFilter not working correctly if given same start and stop RowKey
This commit is contained in:
parent
5a8f1e8aaa
commit
f4e0ea24e6
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<MultiRowRangeFilter.RowRange> 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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue