-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for pagination in v2 engine of
SELECT * FROM <table>
queries (
#1666) v2 SQL engine can now paginate simple queries. Pagination is initiated by setting fetch_size property in the request JSON. Pagination is implemented using the OpenSearch Scroll API. Please see pagination-v2.md for implementation details. --------- Signed-off-by: MaxKsyunz <maxk@bitquilltech.com> Signed-off-by: Yury-Fridlyand <yury.fridlyand@improving.com> Signed-off-by: Max Ksyunz <maxk@bitquilltech.com> Co-authored-by: Yury-Fridlyand <yury.fridlyand@improving.com> Co-authored-by: GabeFernandez310 <Gabriel.Fernandez@improving.com> Co-authored-by: Andrew Carbonetto <andrewc@bitquilltech.com> (cherry picked from commit 57ce303)
- Loading branch information
1 parent
17033a3
commit f5fd596
Showing
140 changed files
with
6,383 additions
and
1,401 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
38 changes: 38 additions & 0 deletions
38
core/src/main/java/org/opensearch/sql/ast/tree/CloseCursor.java
This file contains 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,38 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.ast.tree; | ||
|
||
import java.util.List; | ||
import org.opensearch.sql.ast.AbstractNodeVisitor; | ||
import org.opensearch.sql.ast.Node; | ||
|
||
/** | ||
* AST node to represent close cursor operation. | ||
* Actually a wrapper to the AST. | ||
*/ | ||
public class CloseCursor extends UnresolvedPlan { | ||
|
||
/** | ||
* An instance of {@link FetchCursor}. | ||
*/ | ||
private UnresolvedPlan cursor; | ||
|
||
@Override | ||
public <T, C> T accept(AbstractNodeVisitor<T, C> nodeVisitor, C context) { | ||
return nodeVisitor.visitCloseCursor(this, context); | ||
} | ||
|
||
@Override | ||
public UnresolvedPlan attach(UnresolvedPlan child) { | ||
this.cursor = child; | ||
return this; | ||
} | ||
|
||
@Override | ||
public List<? extends Node> getChild() { | ||
return List.of(cursor); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
core/src/main/java/org/opensearch/sql/ast/tree/FetchCursor.java
This file contains 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,32 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.ast.tree; | ||
|
||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.opensearch.sql.ast.AbstractNodeVisitor; | ||
|
||
/** | ||
* An unresolved plan that represents fetching the next | ||
* batch in paginationed plan. | ||
*/ | ||
@RequiredArgsConstructor | ||
@EqualsAndHashCode(callSuper = false) | ||
public class FetchCursor extends UnresolvedPlan { | ||
@Getter | ||
final String cursor; | ||
|
||
@Override | ||
public <T, C> T accept(AbstractNodeVisitor<T, C> nodeVisitor, C context) { | ||
return nodeVisitor.visitFetchCursor(this, context); | ||
} | ||
|
||
@Override | ||
public UnresolvedPlan attach(UnresolvedPlan child) { | ||
throw new UnsupportedOperationException("Cursor unresolved plan does not support children"); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
core/src/main/java/org/opensearch/sql/ast/tree/Paginate.java
This file contains 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 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 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 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
53 changes: 53 additions & 0 deletions
53
core/src/main/java/org/opensearch/sql/executor/execution/CommandPlan.java
This file contains 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 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.sql.executor.execution; | ||
|
||
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; | ||
|
||
/** | ||
* Query plan which does not reflect a search query being executed. | ||
* It contains a command or an action, for example, a DDL query. | ||
*/ | ||
public class CommandPlan extends AbstractPlan { | ||
|
||
/** | ||
* The query plan ast. | ||
*/ | ||
protected final UnresolvedPlan plan; | ||
|
||
/** | ||
* Query service. | ||
*/ | ||
protected final QueryService queryService; | ||
|
||
protected final ResponseListener<ExecutionEngine.QueryResponse> listener; | ||
|
||
/** Constructor. */ | ||
public CommandPlan(QueryId queryId, UnresolvedPlan plan, QueryService queryService, | ||
ResponseListener<ExecutionEngine.QueryResponse> listener) { | ||
super(queryId); | ||
this.plan = plan; | ||
this.queryService = queryService; | ||
this.listener = listener; | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
queryService.execute(plan, listener); | ||
} | ||
|
||
@Override | ||
public void explain(ResponseListener<ExecutionEngine.ExplainResponse> listener) { | ||
throw new UnsupportedOperationException("CommandPlan does not support explain"); | ||
} | ||
} |
Oops, something went wrong.