Skip to content

Commit

Permalink
Add support for stop row on queries
Browse files Browse the repository at this point in the history
  • Loading branch information
ghelmling committed Feb 21, 2010
1 parent a824def commit b193fe0
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion RELEASE_NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 18 additions & 0 deletions src/java/meetup/beeno/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,24 @@ public Query<T> startTime(Long time) {
return this;
}

/**
* Sets the stop row key to be used in the generated <code>Scan</code>
* instance.
*/
public Query<T> stop(String key) {
this.opts.setStopKey(key);
return this;
}

/**
* Sets the stop row key to be used in the generated <code>Scan</code>
* instance.
*/
public Query<T> stop(byte[] key) {
this.opts.setStopKey(key);
return this;
}

/**
* Defines an expression to be used in filtering query results
* @param expression
Expand Down
11 changes: 11 additions & 0 deletions src/java/meetup/beeno/QueryOpts.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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; }

Expand Down
8 changes: 7 additions & 1 deletion src/java/meetup/beeno/ScanByIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ public ResultScanner createScanner()

long t1 = System.nanoTime();
scanner = getIndexScanner(idx.getTableName(),
startrow,
startrow,
opts.getStopKey(),
baseFilter,
table,
null);
Expand All @@ -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);
Expand All @@ -114,13 +117,16 @@ public ResultScanner createScanner()

protected ResultScanner getIndexScanner(String tablename,
byte[] startrow,
byte[] stoprow,
Filter filter,
HTable baseTable,
byte[][] families)
throws IOException {

Scan idxScan = new Scan();
idxScan.setStartRow(startrow);
if (stoprow != null)
idxScan.setStopRow(stoprow);
if (filter != null)
idxScan.setFilter(filter);

Expand Down
2 changes: 2 additions & 0 deletions src/java/meetup/beeno/ScanNoIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit b193fe0

Please sign in to comment.