Skip to content

Commit b417258

Browse files
authored
limit bug fix (#131)
1 parent 1baab86 commit b417258

File tree

4 files changed

+55
-40
lines changed

4 files changed

+55
-40
lines changed

src/main/java/com/alipay/oceanbase/hbase/OHTable.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ public ResultScanner call() throws IOException {
972972
clientQueryAsyncStreamResult = (ObTableClientQueryAsyncStreamResult) obTableClient
973973
.execute(request);
974974
return new ClientStreamScanner(clientQueryAsyncStreamResult,
975-
tableNameString, family, true);
975+
tableNameString, scan, true);
976976
} else {
977977
for (Map.Entry<byte[], NavigableSet<byte[]>> entry : scan.getFamilyMap()
978978
.entrySet()) {
@@ -999,7 +999,7 @@ public ResultScanner call() throws IOException {
999999
clientQueryAsyncStreamResult = (ObTableClientQueryAsyncStreamResult) obTableClient
10001000
.execute(request);
10011001
return new ClientStreamScanner(clientQueryAsyncStreamResult,
1002-
tableNameString, family, false);
1002+
tableNameString, scan, false);
10031003
}
10041004
}
10051005
} catch (Exception e) {

src/main/java/com/alipay/oceanbase/hbase/result/ClientStreamScanner.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.hadoop.hbase.KeyValue;
2929
import org.apache.hadoop.hbase.client.AbstractClientScanner;
3030
import org.apache.hadoop.hbase.client.Result;
31+
import org.apache.hadoop.hbase.client.Scan;
3132
import org.apache.hadoop.hbase.util.Bytes;
3233
import org.slf4j.Logger;
3334
import java.io.IOException;
@@ -46,30 +47,38 @@ public class ClientStreamScanner extends AbstractClientScanner {
4647
private final String tableName;
4748

4849
private byte[] family;
50+
protected final Scan scan;
51+
protected int lineCount = 0;
4952

5053
private boolean closed = false;
5154

5255
private boolean isTableGroup = false;
5356

5457
public ClientStreamScanner(ObTableClientQueryStreamResult streamResult, String tableName,
55-
byte[] family, boolean isTableGroup) {
58+
Scan scan, boolean isTableGroup) {
5659
this.streamResult = streamResult;
5760
this.tableName = tableName;
58-
this.family = family;
61+
this.scan = scan;
62+
family = isTableGroup ? null : scan.getFamilyMap().entrySet().iterator().next().getKey();
5963
this.isTableGroup = isTableGroup;
6064
}
6165

6266
public ClientStreamScanner(ObTableClientQueryAsyncStreamResult streamResult, String tableName,
63-
byte[] family, boolean isTableGroup) {
67+
Scan scan, boolean isTableGroup) {
6468
this.streamResult = streamResult;
6569
this.tableName = tableName;
66-
this.family = family;
70+
this.scan = scan;
71+
family = isTableGroup ? null : scan.getFamilyMap().entrySet().iterator().next().getKey();
6772
this.isTableGroup = isTableGroup;
6873
}
6974

7075
@Override
7176
public Result next() throws IOException {
7277
try {
78+
if (scan.getLimit() > 0 && lineCount++ >= scan.getLimit()) {
79+
close();
80+
return null;
81+
}
7382
checkStatus();
7483
List<ObObj> startRow;
7584
if (streamResult.next()) {

src/test/java/com/alipay/oceanbase/hbase/HTableMultiCFTestBase.java

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,35 +1442,36 @@ public void testFamilyFilter() throws Exception {
14421442
Put putKey2Column1Value2 = new Put(toBytes(key2));
14431443
putKey2Column1Value2.addColumn(toBytes(family3), toBytes(column1), toBytes(value2));
14441444

1445-
multiCfHTable.delete(deleteKey1);
1446-
multiCfHTable.delete(deleteKey2);
1447-
multiCfHTable.put(putKey1Column1Value1);
1448-
multiCfHTable.put(putKey1Column1Value2);
1449-
multiCfHTable.put(putKey1Column2Value2);
1450-
multiCfHTable.put(putKey2Column2Value1);
1451-
multiCfHTable.put(putKey2Column1Value1);
1452-
multiCfHTable.put(putKey2Column1Value2);
1445+
multiCfHTable.delete(deleteKey1);
1446+
multiCfHTable.delete(deleteKey2);
1447+
multiCfHTable.put(putKey1Column1Value1);
1448+
multiCfHTable.put(putKey1Column1Value2);
1449+
multiCfHTable.put(putKey1Column2Value2);
1450+
multiCfHTable.put(putKey2Column2Value1);
1451+
multiCfHTable.put(putKey2Column1Value1);
1452+
multiCfHTable.put(putKey2Column1Value2);
14531453

14541454
Scan scan;
14551455
scan = new Scan();
14561456
scan.addFamily(family1.getBytes());
14571457
scan.addFamily(family2.getBytes());
14581458
scan.addFamily(family3.getBytes());
14591459
scan.setMaxVersions(10);
1460-
FamilyFilter f = new FamilyFilter(CompareFilter.CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes(family2)));
1460+
FamilyFilter f = new FamilyFilter(CompareFilter.CompareOp.EQUAL, new BinaryComparator(
1461+
Bytes.toBytes(family2)));
14611462
scan.setFilter(f);
14621463
ResultScanner scanner = multiCfHTable.getScanner(scan);
14631464

14641465
int res_count = 0;
14651466
for (Result result : scanner) {
14661467
for (Cell keyValue : result.rawCells()) {
1467-
System.out.printf("Rowkey: %s, Column Family: %s, Column Qualifier: %s, Timestamp: %d, Value: %s%n",
1468+
System.out
1469+
.printf(
1470+
"Rowkey: %s, Column Family: %s, Column Qualifier: %s, Timestamp: %d, Value: %s%n",
14681471
Bytes.toString(CellUtil.cloneRow(keyValue)),
14691472
Bytes.toString(CellUtil.cloneFamily(keyValue)),
1470-
Bytes.toString(CellUtil.cloneQualifier(keyValue)),
1471-
keyValue.getTimestamp(),
1472-
Bytes.toString(CellUtil.cloneValue(keyValue))
1473-
);
1473+
Bytes.toString(CellUtil.cloneQualifier(keyValue)), keyValue.getTimestamp(),
1474+
Bytes.toString(CellUtil.cloneValue(keyValue)));
14741475
Assert.assertArrayEquals(family2.getBytes(), CellUtil.cloneFamily(keyValue));
14751476
res_count += 1;
14761477
}
@@ -1483,20 +1484,21 @@ public void testFamilyFilter() throws Exception {
14831484
scan.addFamily(family2.getBytes());
14841485
scan.addFamily(family3.getBytes());
14851486
scan.setMaxVersions(10);
1486-
f = new FamilyFilter(CompareFilter.CompareOp.NOT_EQUAL, new BinaryComparator(Bytes.toBytes(family2)));
1487+
f = new FamilyFilter(CompareFilter.CompareOp.NOT_EQUAL, new BinaryComparator(
1488+
Bytes.toBytes(family2)));
14871489
scan.setFilter(f);
14881490
scanner = multiCfHTable.getScanner(scan);
14891491

14901492
res_count = 0;
14911493
for (Result result : scanner) {
14921494
for (Cell keyValue : result.rawCells()) {
1493-
System.out.printf("Rowkey: %s, Column Family: %s, Column Qualifier: %s, Timestamp: %d, Value: %s%n",
1495+
System.out
1496+
.printf(
1497+
"Rowkey: %s, Column Family: %s, Column Qualifier: %s, Timestamp: %d, Value: %s%n",
14941498
Bytes.toString(CellUtil.cloneRow(keyValue)),
14951499
Bytes.toString(CellUtil.cloneFamily(keyValue)),
1496-
Bytes.toString(CellUtil.cloneQualifier(keyValue)),
1497-
keyValue.getTimestamp(),
1498-
Bytes.toString(CellUtil.cloneValue(keyValue))
1499-
);
1500+
Bytes.toString(CellUtil.cloneQualifier(keyValue)), keyValue.getTimestamp(),
1501+
Bytes.toString(CellUtil.cloneValue(keyValue)));
15001502
res_count += 1;
15011503
}
15021504
}
@@ -1508,20 +1510,21 @@ public void testFamilyFilter() throws Exception {
15081510
scan.addFamily(family2.getBytes());
15091511
scan.addFamily(family3.getBytes());
15101512
scan.setMaxVersions(10);
1511-
f = new FamilyFilter(CompareFilter.CompareOp.GREATER, new BinaryComparator(Bytes.toBytes(family2)));
1513+
f = new FamilyFilter(CompareFilter.CompareOp.GREATER, new BinaryComparator(
1514+
Bytes.toBytes(family2)));
15121515
scan.setFilter(f);
15131516
scanner = multiCfHTable.getScanner(scan);
15141517

15151518
res_count = 0;
15161519
for (Result result : scanner) {
15171520
for (Cell keyValue : result.rawCells()) {
1518-
System.out.printf("Rowkey: %s, Column Family: %s, Column Qualifier: %s, Timestamp: %d, Value: %s%n",
1521+
System.out
1522+
.printf(
1523+
"Rowkey: %s, Column Family: %s, Column Qualifier: %s, Timestamp: %d, Value: %s%n",
15191524
Bytes.toString(CellUtil.cloneRow(keyValue)),
15201525
Bytes.toString(CellUtil.cloneFamily(keyValue)),
1521-
Bytes.toString(CellUtil.cloneQualifier(keyValue)),
1522-
keyValue.getTimestamp(),
1523-
Bytes.toString(CellUtil.cloneValue(keyValue))
1524-
);
1526+
Bytes.toString(CellUtil.cloneQualifier(keyValue)), keyValue.getTimestamp(),
1527+
Bytes.toString(CellUtil.cloneValue(keyValue)));
15251528
Assert.assertArrayEquals(family3.getBytes(), CellUtil.cloneFamily(keyValue));
15261529
res_count += 1;
15271530
}
@@ -1534,20 +1537,21 @@ public void testFamilyFilter() throws Exception {
15341537
scan.addFamily(family2.getBytes());
15351538
scan.addFamily(family3.getBytes());
15361539
scan.setMaxVersions(10);
1537-
f = new FamilyFilter(CompareFilter.CompareOp.EQUAL, new BinaryPrefixComparator(Bytes.toBytes("family_with_group")));
1540+
f = new FamilyFilter(CompareFilter.CompareOp.EQUAL, new BinaryPrefixComparator(
1541+
Bytes.toBytes("family_with_group")));
15381542
scan.setFilter(f);
15391543
scanner = multiCfHTable.getScanner(scan);
15401544

15411545
res_count = 0;
15421546
for (Result result : scanner) {
15431547
for (Cell keyValue : result.rawCells()) {
1544-
System.out.printf("Rowkey: %s, Column Family: %s, Column Qualifier: %s, Timestamp: %d, Value: %s%n",
1548+
System.out
1549+
.printf(
1550+
"Rowkey: %s, Column Family: %s, Column Qualifier: %s, Timestamp: %d, Value: %s%n",
15451551
Bytes.toString(CellUtil.cloneRow(keyValue)),
15461552
Bytes.toString(CellUtil.cloneFamily(keyValue)),
1547-
Bytes.toString(CellUtil.cloneQualifier(keyValue)),
1548-
keyValue.getTimestamp(),
1549-
Bytes.toString(CellUtil.cloneValue(keyValue))
1550-
);
1553+
Bytes.toString(CellUtil.cloneQualifier(keyValue)), keyValue.getTimestamp(),
1554+
Bytes.toString(CellUtil.cloneValue(keyValue)));
15511555
res_count += 1;
15521556
}
15531557
}

src/test/java/com/alipay/oceanbase/hbase/filter/HBaseFilterUtilsTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,10 @@ public void testMultipleColumnPrefixFilter() throws IOException {
253253

254254
@Test
255255
public void testFamilyFilter() throws IOException {
256-
FamilyFilter filter = new FamilyFilter(CompareFilter.CompareOp.NOT_EQUAL, new BinaryComparator(Bytes.toBytes("cf")));
257-
Assert.assertArrayEquals("FamilyFilter(!=,'binary:cf')".getBytes(), HBaseFilterUtils.toParseableByteArray(filter));
256+
FamilyFilter filter = new FamilyFilter(CompareFilter.CompareOp.NOT_EQUAL,
257+
new BinaryComparator(Bytes.toBytes("cf")));
258+
Assert.assertArrayEquals("FamilyFilter(!=,'binary:cf')".getBytes(),
259+
HBaseFilterUtils.toParseableByteArray(filter));
258260
}
259261

260262
@Test

0 commit comments

Comments
 (0)