forked from opensearch-project/sql
-
Notifications
You must be signed in to change notification settings - Fork 0
Support pagination in V2 engine, phase 1 #226
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
Merged
Merged
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
7e2dc80
Fixing integration tests broken during POC
d359751
Comment to clarify an exception.
9c3f7fe
Add support for paginated scroll request, first page.
1ee718b
Progress on paginated scroll request, subsequent page.
f3cade6
Move `ExpressionSerializer` from `opensearch` to `core`.
Yury-Fridlyand db342b8
Rename `Cursor` `asString` to `toString`.
Yury-Fridlyand c8f0935
Disable scroll cleaning.
Yury-Fridlyand fffc36d
Add full cursor serialization and deserialization.
Yury-Fridlyand d844977
Misc fixes.
Yury-Fridlyand 333432e
Further work on pagination.
Yury-Fridlyand 85c8825
Pagination fix for empty indices.
Yury-Fridlyand 484a8fe
Fix error reporting on wrong cursor.
Yury-Fridlyand cccce53
Minor comments and error reporting improvement.
Yury-Fridlyand 2895883
Add an end-to-end integration test.
Yury-Fridlyand dd6fcd6
Add `explain` request handlers.
Yury-Fridlyand 2a19e56
Add IT for explain.
Yury-Fridlyand a3ef2bf
Address issues flagged by checkstyle build step (#229)
2d29549
Pagination, phase 1: Add unit tests for `:core` module with coverage.…
Yury-Fridlyand 70ccfcb
Pagination, phase 1: Add unit tests for SQL module with coverage. (#239)
Yury-Fridlyand 803f50e
Pagination, phase 1: Add unit tests for `:opensearch` module with cov…
Yury-Fridlyand 27e1793
Fix the merges.
Yury-Fridlyand 304616d
Fix explain.
Yury-Fridlyand 1b5ab7e
Fix scroll cleaning.
Yury-Fridlyand f4ea4ad
Store `TotalHits` and use it to report `total` in response.
Yury-Fridlyand 7f0acdd
Add missing UT for `:protocol` module.
Yury-Fridlyand 2ce1626
Fix PPL UTs damaged in f4ea4ad8c.
Yury-Fridlyand b2e6e56
Minor checkstyle fixes.
Yury-Fridlyand c7ad219
Fallback to v1 engine for pagination (#245)
MaxKsyunz 981bc25
Add UT with coverage for `toCursor` serialization.
Yury-Fridlyand 960c039
Fix broken tests in `legacy`.
Yury-Fridlyand 4f0c176
Fix getting `total` from non-paged requests and from queries without …
Yury-Fridlyand bdd52a0
Fix scroll cleaning.
Yury-Fridlyand a16332f
Fix cursor request processing.
Yury-Fridlyand 9f9e873
Update ITs.
Yury-Fridlyand 3340e38
Fix (again) TotalHits feature.
Yury-Fridlyand 524f220
Fix typo in prometheus config.
Yury-Fridlyand 281f3cd
Recover commented logging.
Yury-Fridlyand ca76e1b
Move `test_pagination_blackbox` to a separate class and add logging.
Yury-Fridlyand c8fcd4e
Address some PR feedbacks: rename some classes and revert unnecessary…
Yury-Fridlyand ec5fb40
Minor commenting.
Yury-Fridlyand 4213388
Address PR comments.
Yury-Fridlyand ca20d16
Minor missing changes.
Yury-Fridlyand a58733e
Integration tests for fetch_size, max_result_window, and query.size_l…
75b8140
Remove `PaginatedQueryService`, extend `QueryService` to hold two pla…
Yury-Fridlyand ba81407
Move push down functions from request builders to a new interface.
Yury-Fridlyand cec012b
Some file moves.
Yury-Fridlyand 9032b3b
Minor clean-up according to PR review.
Yury-Fridlyand File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
core/src/main/java/org/opensearch/sql/ast/tree/Paginate.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.ast.tree; | ||
|
|
||
| import java.util.List; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.ToString; | ||
| import org.opensearch.sql.ast.AbstractNodeVisitor; | ||
| import org.opensearch.sql.ast.Node; | ||
|
|
||
| /** | ||
| * AST node to represent pagination operation. | ||
| * Actually a wrapper to the AST. | ||
| */ | ||
| @RequiredArgsConstructor | ||
| @EqualsAndHashCode(callSuper = false) | ||
| @ToString | ||
| public class Paginate extends UnresolvedPlan { | ||
Yury-Fridlyand marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @Getter | ||
| private final int pageSize; | ||
| private UnresolvedPlan child; | ||
|
|
||
| public Paginate(int pageSize, UnresolvedPlan child) { | ||
| this.pageSize = pageSize; | ||
| this.child = child; | ||
| } | ||
|
|
||
| @Override | ||
| public List<? extends Node> getChild() { | ||
| return List.of(child); | ||
| } | ||
|
|
||
| @Override | ||
| public <T, C> T accept(AbstractNodeVisitor<T, C> nodeVisitor, C context) { | ||
| return nodeVisitor.visitPaginate(this, context); | ||
| } | ||
|
|
||
| @Override | ||
| public UnresolvedPlan attach(UnresolvedPlan child) { | ||
| this.child = child; | ||
| return this; | ||
| } | ||
| } | ||
12 changes: 12 additions & 0 deletions
12
core/src/main/java/org/opensearch/sql/exception/UnsupportedCursorRequestException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.exception; | ||
|
|
||
| /** | ||
| * This should be thrown by V2 engine to support fallback scenario. | ||
| */ | ||
| public class UnsupportedCursorRequestException extends RuntimeException { | ||
Yury-Fridlyand marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
core/src/main/java/org/opensearch/sql/executor/execution/ContinuePaginatedPlan.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.executor.execution; | ||
|
|
||
| import org.opensearch.sql.common.response.ResponseListener; | ||
| import org.opensearch.sql.executor.ExecutionEngine; | ||
| import org.opensearch.sql.executor.QueryId; | ||
| import org.opensearch.sql.executor.QueryService; | ||
| import org.opensearch.sql.executor.pagination.PaginatedPlanCache; | ||
| import org.opensearch.sql.planner.physical.PhysicalPlan; | ||
|
|
||
| /** | ||
| * ContinuePaginatedPlan represents cursor a request. | ||
| * It returns subsequent pages to the user (2nd page and all next). | ||
| * {@link PaginatedPlan} | ||
| */ | ||
| public class ContinuePaginatedPlan extends AbstractPlan { | ||
Yury-Fridlyand marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private final String cursor; | ||
| private final QueryService queryService; | ||
| private final PaginatedPlanCache paginatedPlanCache; | ||
|
|
||
| private final ResponseListener<ExecutionEngine.QueryResponse> queryResponseListener; | ||
|
|
||
|
|
||
| /** | ||
| * Create an abstract plan that can continue paginating a given cursor. | ||
| */ | ||
| public ContinuePaginatedPlan(QueryId queryId, String cursor, QueryService queryService, | ||
| PaginatedPlanCache planCache, | ||
| ResponseListener<ExecutionEngine.QueryResponse> | ||
| queryResponseListener) { | ||
| super(queryId); | ||
| this.cursor = cursor; | ||
| this.paginatedPlanCache = planCache; | ||
| this.queryService = queryService; | ||
| this.queryResponseListener = queryResponseListener; | ||
| } | ||
|
|
||
| @Override | ||
| public void execute() { | ||
| try { | ||
| PhysicalPlan plan = paginatedPlanCache.convertToPlan(cursor); | ||
| queryService.executePlan(plan, queryResponseListener); | ||
| } catch (Exception e) { | ||
| queryResponseListener.onFailure(e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void explain(ResponseListener<ExecutionEngine.ExplainResponse> listener) { | ||
| listener.onFailure(new UnsupportedOperationException( | ||
acarbonetto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "Explain of a paged query continuation is not supported. " | ||
| + "Use `explain` for the initial query request.")); | ||
| } | ||
| } | ||
53 changes: 53 additions & 0 deletions
53
core/src/main/java/org/opensearch/sql/executor/execution/PaginatedPlan.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.executor.execution; | ||
|
|
||
| import org.apache.commons.lang3.NotImplementedException; | ||
| import org.opensearch.sql.ast.tree.Paginate; | ||
| import org.opensearch.sql.ast.tree.UnresolvedPlan; | ||
| import org.opensearch.sql.common.response.ResponseListener; | ||
| import org.opensearch.sql.executor.ExecutionEngine; | ||
| import org.opensearch.sql.executor.QueryId; | ||
| import org.opensearch.sql.executor.QueryService; | ||
|
|
||
| /** | ||
| * PaginatedPlan represents a page request. Dislike a regular QueryPlan, | ||
| * it returns paged response to the user and cursor, which allows to query | ||
| * next page. | ||
| * {@link ContinuePaginatedPlan} | ||
| */ | ||
| public class PaginatedPlan extends AbstractPlan { | ||
| final UnresolvedPlan plan; | ||
| final int fetchSize; | ||
| final QueryService queryService; | ||
| final ResponseListener<ExecutionEngine.QueryResponse> | ||
| queryResponseResponseListener; | ||
|
|
||
| /** | ||
| * Create an abstract plan that can start paging a query. | ||
| */ | ||
| public PaginatedPlan(QueryId queryId, UnresolvedPlan plan, int fetchSize, | ||
| QueryService queryService, | ||
| ResponseListener<ExecutionEngine.QueryResponse> | ||
| queryResponseResponseListener) { | ||
| super(queryId); | ||
| this.plan = plan; | ||
| this.fetchSize = fetchSize; | ||
| this.queryService = queryService; | ||
| this.queryResponseResponseListener = queryResponseResponseListener; | ||
| } | ||
|
|
||
| @Override | ||
| public void execute() { | ||
| queryService.execute(new Paginate(fetchSize, plan), queryResponseResponseListener); | ||
| } | ||
|
|
||
| @Override | ||
| public void explain(ResponseListener<ExecutionEngine.ExplainResponse> listener) { | ||
| listener.onFailure(new NotImplementedException( | ||
| "`explain` feature for paginated requests is not implemented yet.")); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.