Skip to content

Commit

Permalink
修正Scan结果最大返回条数代码
Browse files Browse the repository at this point in the history
  • Loading branch information
AlionSSS committed May 26, 2019
1 parent 6b5b791 commit 01d3146
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 17 deletions.
3 changes: 0 additions & 3 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions src/com/skey/evehbase/client/EveHBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,9 @@ public <T> List<T> scan(@Nonnull EveScan eveScan, @Nonnull Class<T> clazz) throw

// 提交scan请求
scanner = table.getScanner(eveScan.getScan());
int i = 0;
long max = eveScan.getMax();
Result r;
while ((r = scanner.next()) != null && i <= max) {
while ((r = scanner.next()) != null ) {
results.add(r);
i++;
}

if (LOG.isInfoEnabled()) LOG.info("Column value filter successfully.");
Expand Down
8 changes: 1 addition & 7 deletions src/com/skey/evehbase/request/EveScan.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ public class EveScan {

private final Scan scan;

private final long max;

EveScan(TableName tableName, Scan scan, long max) {
EveScan(TableName tableName, Scan scan) {
this.tableName = tableName;
this.scan = scan;
this.max = max;
}

public TableName getTableName() {
Expand All @@ -35,10 +33,6 @@ public Scan getScan() {
return scan;
}

public long getMax() {
return max;
}

public static class Builder {

private String table;
Expand Down
9 changes: 6 additions & 3 deletions src/com/skey/evehbase/request/EveScanDirector.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ static EveScan create(String table, String startRow, String endRow,

TableName tableName = TableName.valueOf(table);

Scan scan = generateScan(columnMap, startRow, endRow, filter);
Scan scan = generateScan(columnMap, startRow, endRow, filter, max);

return new EveScan(tableName, scan, max);
return new EveScan(tableName, scan);
}

/**
Expand All @@ -49,11 +49,14 @@ static EveScan create(String table, String startRow, String endRow,
* @param startRow HBase的startRowKey
* @param endRow HBase的endRowKey
* @param filter HBase的过滤器 {@link Filter}
* @param max 结果最大返回条数
* @return {@link Scan}
*/
private static Scan generateScan(Map<String, Set<String>> columnMap, String startRow, String endRow, Filter filter) {
private static Scan generateScan(Map<String, Set<String>> columnMap, String startRow, String endRow, Filter filter, long max) {
Scan scan = new Scan();

scan.setMaxResultSize(max);

// 添加要查询的列
for (Map.Entry<String, Set<String>> entry : columnMap.entrySet()) {
byte[] bFamily = Bytes.toBytes(entry.getKey());
Expand Down

0 comments on commit 01d3146

Please sign in to comment.