From 98640e4b2c895bcb9290c8f9e067e30ebe7cd257 Mon Sep 17 00:00:00 2001 From: Guanghao Zhang Date: Thu, 20 Dec 2018 11:03:54 +0800 Subject: [PATCH] HBASE-21618 Scan with the same startRow(inclusive=true) and stopRow(inclusive=false) returns one result --- .../hadoop/hbase/protobuf/ProtobufUtil.java | 4 +- .../hbase/client/TestFromClientSide3.java | 4 +- .../client/TestScannersFromClientSide.java | 38 +++++++++++++++++++ .../hbase/protobuf/TestProtobufUtil.java | 1 + 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java index e630b98a793..4b516d4bf1b 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java @@ -1086,9 +1086,7 @@ public final class ProtobufUtil { if (!scan.includeStartRow()) { scanBuilder.setIncludeStartRow(false); } - if (scan.includeStopRow()) { - scanBuilder.setIncludeStopRow(true); - } + scanBuilder.setIncludeStopRow(scan.includeStopRow()); if (scan.getReadType() != Scan.ReadType.DEFAULT) { scanBuilder.setReadType(toReadType(scan.getReadType())); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java index 560f5528850..4cfb853d98c 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide3.java @@ -839,7 +839,7 @@ public class TestFromClientSide3 { } Scan scan = new Scan(); - scan.withStartRow(ROW).withStopRow(ROW).addFamily(FAMILY).setBatch(3) + scan.withStartRow(ROW).withStopRow(ROW, true).addFamily(FAMILY).setBatch(3) .setMaxResultSize(4 * 1024 * 1024); Result result; try (ResultScanner scanner = table.getScanner(scan)) { @@ -861,7 +861,7 @@ public class TestFromClientSide3 { } scan = new Scan(); - scan.withStartRow(ROW).withStopRow(ROW).addFamily(FAMILY).setBatch(2) + scan.withStartRow(ROW).withStopRow(ROW, true).addFamily(FAMILY).setBatch(2) .setMaxResultSize(4 * 1024 * 1024); try (ResultScanner scanner = table.getScanner(scan)) { List list = new ArrayList<>(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestScannersFromClientSide.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestScannersFromClientSide.java index 17c8b92ea53..4bac32db555 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestScannersFromClientSide.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestScannersFromClientSide.java @@ -18,6 +18,7 @@ package org.apache.hadoop.hbase.client; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @@ -699,4 +700,41 @@ public class TestScannersFromClientSide { } } } + + @Test + public void testScanWithSameStartRowStopRow() throws IOException { + TableName tableName = TableName.valueOf("testScanWithSameStartRowStopRow"); + try (Table table = TEST_UTIL.createTable(tableName, FAMILY)) { + table.put(new Put(ROW).addColumn(FAMILY, QUALIFIER, VALUE)); + + Scan scan = new Scan().withStartRow(ROW).withStopRow(ROW); + try (ResultScanner scanner = table.getScanner(scan)) { + assertNull(scanner.next()); + } + + scan = new Scan().withStartRow(ROW, true).withStopRow(ROW, true); + try (ResultScanner scanner = table.getScanner(scan)) { + Result result = scanner.next(); + assertNotNull(result); + assertArrayEquals(ROW, result.getRow()); + assertArrayEquals(VALUE, result.getValue(FAMILY, QUALIFIER)); + assertNull(scanner.next()); + } + + scan = new Scan().withStartRow(ROW, true).withStopRow(ROW, false); + try (ResultScanner scanner = table.getScanner(scan)) { + assertNull(scanner.next()); + } + + scan = new Scan().withStartRow(ROW, false).withStopRow(ROW, false); + try (ResultScanner scanner = table.getScanner(scan)) { + assertNull(scanner.next()); + } + + scan = new Scan().withStartRow(ROW, false).withStopRow(ROW, true); + try (ResultScanner scanner = table.getScanner(scan)) { + assertNull(scanner.next()); + } + } + } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/protobuf/TestProtobufUtil.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/protobuf/TestProtobufUtil.java index 7cff7fd46a8..7710cc31f2d 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/protobuf/TestProtobufUtil.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/protobuf/TestProtobufUtil.java @@ -302,6 +302,7 @@ public class TestProtobufUtil { scanBuilder.setMaxVersions(2); scanBuilder.setCacheBlocks(false); scanBuilder.setCaching(1024); + scanBuilder.setIncludeStopRow(false); ClientProtos.Scan expectedProto = scanBuilder.build(); ClientProtos.Scan actualProto = ProtobufUtil.toScan(