generated from amazon-archives/__template_Custom
-
Notifications
You must be signed in to change notification settings - Fork 178
Support pagination in V2 engine, phase 1 #1497
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
Yury-Fridlyand
merged 19 commits into
feature/pagination/integ
from
feature/pagination/P1
Apr 27, 2023
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e951192
Support pagination in V2 engine, phase 1 (#226)
Yury-Fridlyand 4948ac4
Make scroll timeout configurable.
Yury-Fridlyand 37e7ebf
Fix IT to set cursor keep alive parameter.
Yury-Fridlyand 529df99
Remove `QueryId.None`.
Yury-Fridlyand 64386f3
Rename according to PR feedback.
Yury-Fridlyand bc8c73f
Remove default implementations of `PushDownRequestBuilder`.
Yury-Fridlyand b9cb0d0
Merge paginated plan optimizer into the regular optimizer. (#1516)
9a1a17c
Complete rework on serialization and deserialization. (#1498)
Yury-Fridlyand e42bcd4
Resolve merge conflicts and fix tests.
Yury-Fridlyand 899d083
Merge remote-tracking branch 'upstream/feature/pagination/integ' into…
Yury-Fridlyand df54e79
Minor cleanup.
Yury-Fridlyand ce509b0
Minor cleanup - missing changes for the previous commit.
Yury-Fridlyand dd3df8c
Remove paginate operator (#1528)
1f6cf70
Remove `PaginatedPlan` - move logic to `QueryPlan`.
Yury-Fridlyand e745d2d
Remove default implementations from `SerializablePlan`.
Yury-Fridlyand 0f66341
Add a doc.
Yury-Fridlyand 7dd445c
Update design graphs.
Yury-Fridlyand 97b7435
Merge branch 'upstream-main' into feature/pagination/P1
f9ae484
More fixes for merge from upstream/main.
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 { | ||
| @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; | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
core/src/main/java/org/opensearch/sql/exception/NoCursorException.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,13 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.exception; | ||
|
|
||
| /** | ||
| * This should be thrown on serialization of a PhysicalPlan tree if paging is finished. | ||
| * Processing of such exception should outcome of responding no cursor to the user. | ||
| */ | ||
| public class NoCursorException extends RuntimeException { | ||
| } |
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 { | ||
| } |
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
58 changes: 58 additions & 0 deletions
58
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,58 @@ | ||
| /* | ||
| * 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.PlanSerializer; | ||
| import org.opensearch.sql.planner.physical.PhysicalPlan; | ||
|
|
||
| /** | ||
| * ContinuePaginatedPlan represents cursor a request. | ||
| * It returns subsequent pages to the user (2nd page and all next). | ||
| */ | ||
| public class ContinuePaginatedPlan extends AbstractPlan { | ||
|
|
||
| private final String cursor; | ||
| private final QueryService queryService; | ||
| private final PlanSerializer planSerializer; | ||
|
|
||
| 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, | ||
| PlanSerializer planCache, | ||
| ResponseListener<ExecutionEngine.QueryResponse> | ||
| queryResponseListener) { | ||
| super(queryId); | ||
| this.cursor = cursor; | ||
| this.planSerializer = planCache; | ||
| this.queryService = queryService; | ||
| this.queryResponseListener = queryResponseListener; | ||
| } | ||
|
|
||
| @Override | ||
| public void execute() { | ||
| try { | ||
| PhysicalPlan plan = planSerializer.convertToPlan(cursor); | ||
| queryService.executePlan(plan, queryResponseListener); | ||
| } catch (Exception e) { | ||
| queryResponseListener.onFailure(e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void explain(ResponseListener<ExecutionEngine.ExplainResponse> listener) { | ||
| listener.onFailure(new UnsupportedOperationException( | ||
| "Explain of a paged query continuation is not supported. " | ||
| + "Use `explain` for the initial query request.")); | ||
| } | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -18,9 +18,11 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||
| import org.opensearch.sql.ast.statement.Query; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.opensearch.sql.ast.statement.Statement; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.opensearch.sql.common.response.ResponseListener; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.opensearch.sql.exception.UnsupportedCursorRequestException; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.opensearch.sql.executor.ExecutionEngine; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.opensearch.sql.executor.QueryId; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.opensearch.sql.executor.QueryService; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.opensearch.sql.executor.pagination.PlanSerializer; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * QueryExecution Factory. | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -37,9 +39,10 @@ public class QueryPlanFactory | |||||||||||||||||||||||||||||||||||||||||||||||||
| * Query Service. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| private final QueryService queryService; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| private final PlanSerializer planSerializer; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * NO_CONSUMER_RESPONSE_LISTENER should never been called. It is only used as constructor | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * NO_CONSUMER_RESPONSE_LISTENER should never be called. It is only used as constructor | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * parameter of {@link QueryPlan}. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| @VisibleForTesting | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -62,39 +65,62 @@ public void onFailure(Exception e) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * Create QueryExecution from Statement. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| public AbstractPlan create( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| public AbstractPlan createContinuePaginatedPlan( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Statement statement, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Optional<ResponseListener<ExecutionEngine.QueryResponse>> queryListener, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Optional<ResponseListener<ExecutionEngine.ExplainResponse>> explainListener) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return statement.accept(this, Pair.of(queryListener, explainListener)); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * Creates a ContinuePaginatedPlan from a cursor. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| public AbstractPlan createContinuePaginatedPlan(String cursor, boolean isExplain, | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| ResponseListener<ExecutionEngine.QueryResponse> queryResponseListener, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ResponseListener<ExecutionEngine.ExplainResponse> explainListener) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| QueryId queryId = QueryId.queryId(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| var plan = new ContinuePaginatedPlan(queryId, cursor, queryService, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| planSerializer, queryResponseListener); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return isExplain ? new ExplainPlan(queryId, plan, explainListener) : plan; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||||||||||
| public AbstractPlan visitQuery( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Query node, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Pair< | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Optional<ResponseListener<ExecutionEngine.QueryResponse>>, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Optional<ResponseListener<ExecutionEngine.ExplainResponse>>> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Pair<Optional<ResponseListener<ExecutionEngine.QueryResponse>>, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Optional<ResponseListener<ExecutionEngine.ExplainResponse>>> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| context) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Preconditions.checkArgument( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| context.getLeft().isPresent(), "[BUG] query listener must be not null"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| return new QueryPlan(QueryId.queryId(), node.getPlan(), queryService, context.getLeft().get()); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (node.getFetchSize() > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (planSerializer.canConvertToCursor(node.getPlan())) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return new QueryPlan(QueryId.queryId(), node.getPlan(), node.getFetchSize(), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| queryService, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| context.getLeft().get()); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| // This should be picked up by the legacy engine. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new UnsupportedCursorRequestException(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return new QueryPlan(QueryId.queryId(), node.getPlan(), queryService, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| context.getLeft().get()); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||||||||||
| public AbstractPlan visitExplain( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Explain node, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Pair< | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Optional<ResponseListener<ExecutionEngine.QueryResponse>>, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Optional<ResponseListener<ExecutionEngine.ExplainResponse>>> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Pair<Optional<ResponseListener<ExecutionEngine.QueryResponse>>, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Optional<ResponseListener<ExecutionEngine.ExplainResponse>>> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| context) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Preconditions.checkArgument( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| context.getRight().isPresent(), "[BUG] explain listener must be not null"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| return new ExplainPlan( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| QueryId.queryId(), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| create(node.getStatement(), Optional.of(NO_CONSUMER_RESPONSE_LISTENER), Optional.empty()), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| createContinuePaginatedPlan(node.getStatement(), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Optional.of(NO_CONSUMER_RESPONSE_LISTENER), Optional.empty()), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| context.getRight().get()); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
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.