diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index e7c8f2f..21074c7 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -12,7 +12,7 @@ Focus on API cleanup and better configurability. q.start( startkey ) .where( Criteria.eq( 'prop', value ) ) .where( Criteria.eq( 'prop2', value2 ) ) - .end( endkey ); + .stop( endkey ); q.execute(); or for an indexed query: diff --git a/src/java/meetup/beeno/Query.java b/src/java/meetup/beeno/Query.java index c04f5d8..d05e394 100644 --- a/src/java/meetup/beeno/Query.java +++ b/src/java/meetup/beeno/Query.java @@ -74,6 +74,24 @@ public Query startTime(Long time) { return this; } + /** + * Sets the stop row key to be used in the generated Scan + * instance. + */ + public Query stop(String key) { + this.opts.setStopKey(key); + return this; + } + + /** + * Sets the stop row key to be used in the generated Scan + * instance. + */ + public Query stop(byte[] key) { + this.opts.setStopKey(key); + return this; + } + /** * Defines an expression to be used in filtering query results * @param expression diff --git a/src/java/meetup/beeno/QueryOpts.java b/src/java/meetup/beeno/QueryOpts.java index 8eff4fa..96717e7 100644 --- a/src/java/meetup/beeno/QueryOpts.java +++ b/src/java/meetup/beeno/QueryOpts.java @@ -16,6 +16,7 @@ public class QueryOpts implements Externalizable { public static final int DEFAULT_PAGE_SIZE = 50; private byte[] startKey = null; + private byte[] stopKey = null; private Long startTime = null; private int pageSize = DEFAULT_PAGE_SIZE; @@ -41,7 +42,17 @@ public void setStartKey(byte[] key) { public Long getStartTime() { return this.startTime; } public void setStartTime(Long time) { this.startTime = time; } + + public byte[] getStopKey() { return this.stopKey; } + public void setStopKey(byte[] key) { this.stopKey = key; } + public void setStopKey(String key) { + if (key != null) + this.stopKey = Bytes.toBytes(key); + else + this.stopKey = null; + } + public int getPageSize() { return this.pageSize; } public void setPageSize(int size) { this.pageSize = size; } diff --git a/src/java/meetup/beeno/ScanByIndex.java b/src/java/meetup/beeno/ScanByIndex.java index 624c225..4812ddb 100644 --- a/src/java/meetup/beeno/ScanByIndex.java +++ b/src/java/meetup/beeno/ScanByIndex.java @@ -73,7 +73,8 @@ public ResultScanner createScanner() long t1 = System.nanoTime(); scanner = getIndexScanner(idx.getTableName(), - startrow, + startrow, + opts.getStopKey(), baseFilter, table, null); @@ -90,6 +91,8 @@ public ResultScanner createScanner() Scan scan = new Scan(); if (startrow != null) scan.setStartRow(startrow); + if (opts.getStopKey() != null) + scan.setStopRow(opts.getStopKey()); if (baseFilter != null) scan.setFilter(baseFilter); scanner = table.getScanner(scan); @@ -114,6 +117,7 @@ public ResultScanner createScanner() protected ResultScanner getIndexScanner(String tablename, byte[] startrow, + byte[] stoprow, Filter filter, HTable baseTable, byte[][] families) @@ -121,6 +125,8 @@ protected ResultScanner getIndexScanner(String tablename, Scan idxScan = new Scan(); idxScan.setStartRow(startrow); + if (stoprow != null) + idxScan.setStopRow(stoprow); if (filter != null) idxScan.setFilter(filter); diff --git a/src/java/meetup/beeno/ScanNoIndex.java b/src/java/meetup/beeno/ScanNoIndex.java index fb7f4c0..4a6b366 100644 --- a/src/java/meetup/beeno/ScanNoIndex.java +++ b/src/java/meetup/beeno/ScanNoIndex.java @@ -38,6 +38,8 @@ public ResultScanner createScanner() throws QueryException { if (opts.getStartKey() != null) scan.setStartRow(opts.getStartKey()); + if (opts.getStopKey() != null) + scan.setStopRow(opts.getStopKey()); long t1 = System.nanoTime();