Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

offset-limit query fix #256

Merged
merged 1 commit into from
Sep 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public static <T extends Resource> Observable<PipelinedDocumentQueryExecutionCon
if (queryInfo.hasTop()) {
createTopComponentFunction = (continuationToken) -> {
return TopDocumentQueryExecutionContext.createAsync(createSkipComponentFunction,
queryInfo.getTop(), continuationToken);
queryInfo.getTop(), queryInfo.getTop(), continuationToken);
};
} else {
createTopComponentFunction = createSkipComponentFunction;
Expand All @@ -130,8 +130,13 @@ public static <T extends Resource> Observable<PipelinedDocumentQueryExecutionCon
Function<String, Observable<IDocumentQueryExecutionComponent<T>>> createTakeComponentFunction;
if (queryInfo.hasLimit()) {
createTakeComponentFunction = (continuationToken) -> {
int totalLimit = queryInfo.getLimit();
if (queryInfo.hasOffset()){
// This is being done to match the limit from rewritten query
totalLimit = queryInfo.getOffset() + queryInfo.getLimit();
}
return TopDocumentQueryExecutionContext.createAsync(createTopComponentFunction,
queryInfo.getLimit(),
queryInfo.getLimit(), totalLimit,
continuationToken);
};
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,18 @@ public class TopDocumentQueryExecutionContext<T extends Resource> implements IDo

private final IDocumentQueryExecutionComponent<T> component;
private final int top;
// limit from rewritten query
private final int limit;

public TopDocumentQueryExecutionContext(IDocumentQueryExecutionComponent<T> component, int top) {
public TopDocumentQueryExecutionContext(IDocumentQueryExecutionComponent<T> component, int top, int limit) {
this.component = component;
this.top = top;
this.limit = limit;
}

public static <T extends Resource> Observable<IDocumentQueryExecutionComponent<T>> createAsync(
Function<String, Observable<IDocumentQueryExecutionComponent<T>>> createSourceComponentFunction,
int topCount, String topContinuationToken) {
int topCount, int limit, String topContinuationToken) {
TakeContinuationToken takeContinuationToken;

if (topContinuationToken == null) {
Expand All @@ -76,7 +79,7 @@ public static <T extends Resource> Observable<IDocumentQueryExecutionComponent<T
}

return createSourceComponentFunction.apply(takeContinuationToken.getSourceToken()).map(component -> {
return new TopDocumentQueryExecutionContext<T>(component, takeContinuationToken.getTakeCount());
return new TopDocumentQueryExecutionContext<T>(component, takeContinuationToken.getTakeCount(), limit);
});
}

Expand All @@ -94,7 +97,8 @@ public Observable<FeedResponse<T>> drainAsync(int maxPageSize) {
context = (ParallelDocumentQueryExecutionContextBase<T>) this.component;
}

context.setTop(this.top);
// we are setting the new limit from rewritten query
context.setTop(this.limit);

return this.component.drainAsync(maxPageSize).takeUntil(new Func1<FeedResponse<T>, Boolean>() {

Expand Down