-
Notifications
You must be signed in to change notification settings - Fork 141
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
Add missing refactoring of Scroll to PIT API calls for Joins and Pagination query #2981
Merged
ykmr1224
merged 6 commits into
opensearch-project:main
from
manasvinibs:SQL-PIT-Refactor2
Sep 23, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e25fb26
Adding PIT for pagination queries in new SQL engine code paths
manasvinibs fa00ea5
Fix legacy code using scroll API instead of PIT for batch physical op…
manasvinibs f364e52
Fix local debugger issue
manasvinibs e70dc4f
Refactor integ-tests data for PIT and fix unit tests
manasvinibs edbc586
Address feedback comments
manasvinibs 770ae41
Adding test coverage
manasvinibs 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 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
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
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
144 changes: 144 additions & 0 deletions
144
legacy/src/main/java/org/opensearch/sql/legacy/query/planner/physical/node/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,144 @@ | ||
package org.opensearch.sql.legacy.query.planner.physical.node; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.Objects; | ||
import org.opensearch.action.search.SearchResponse; | ||
import org.opensearch.client.Client; | ||
import org.opensearch.common.xcontent.XContentType; | ||
import org.opensearch.core.common.Strings; | ||
import org.opensearch.index.query.BoolQueryBuilder; | ||
import org.opensearch.index.query.QueryBuilder; | ||
import org.opensearch.search.SearchHit; | ||
import org.opensearch.sql.legacy.domain.Where; | ||
import org.opensearch.sql.legacy.exception.SqlParseException; | ||
import org.opensearch.sql.legacy.query.join.TableInJoinRequestBuilder; | ||
import org.opensearch.sql.legacy.query.maker.QueryMaker; | ||
import org.opensearch.sql.legacy.query.planner.core.ExecuteParams; | ||
import org.opensearch.sql.legacy.query.planner.core.PlanNode; | ||
import org.opensearch.sql.legacy.query.planner.physical.Row; | ||
import org.opensearch.sql.legacy.query.planner.physical.estimation.Cost; | ||
import org.opensearch.sql.legacy.query.planner.resource.ResourceManager; | ||
|
||
public abstract class Paginate extends BatchPhysicalOperator<SearchHit> { | ||
|
||
/** Request to submit to OpenSearch to scan over */ | ||
protected final TableInJoinRequestBuilder request; | ||
|
||
protected final int pageSize; | ||
|
||
protected Client client; | ||
|
||
protected SearchResponse searchResponse; | ||
|
||
protected Integer timeout; | ||
|
||
protected ResourceManager resourceMgr; | ||
|
||
public Paginate(TableInJoinRequestBuilder request, int pageSize) { | ||
this.request = request; | ||
this.pageSize = pageSize; | ||
} | ||
|
||
@Override | ||
public PlanNode[] children() { | ||
return new PlanNode[0]; | ||
} | ||
|
||
@Override | ||
public Cost estimate() { | ||
return new Cost(); | ||
} | ||
|
||
@Override | ||
public void open(ExecuteParams params) throws Exception { | ||
super.open(params); | ||
client = params.get(ExecuteParams.ExecuteParamType.CLIENT); | ||
timeout = params.get(ExecuteParams.ExecuteParamType.TIMEOUT); | ||
resourceMgr = params.get(ExecuteParams.ExecuteParamType.RESOURCE_MANAGER); | ||
|
||
Object filter = params.get(ExecuteParams.ExecuteParamType.EXTRA_QUERY_FILTER); | ||
if (filter instanceof BoolQueryBuilder) { | ||
request | ||
.getRequestBuilder() | ||
.setQuery(generateNewQueryWithExtraFilter((BoolQueryBuilder) filter)); | ||
|
||
if (LOG.isDebugEnabled()) { | ||
manasvinibs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
LOG.debug( | ||
"Received extra query filter, re-build query: {}", | ||
Strings.toString( | ||
XContentType.JSON, request.getRequestBuilder().request().source(), true, true)); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
protected Collection<Row<SearchHit>> prefetch() { | ||
Objects.requireNonNull(client, "Client connection is not ready"); | ||
Objects.requireNonNull(resourceMgr, "ResourceManager is not set"); | ||
Objects.requireNonNull(timeout, "Time out is not set"); | ||
|
||
if (searchResponse == null) { | ||
loadFirstBatch(); | ||
updateMetaResult(); | ||
} else { | ||
loadNextBatch(); | ||
} | ||
return wrapRowForCurrentBatch(); | ||
} | ||
|
||
protected abstract void loadFirstBatch(); | ||
|
||
protected abstract void loadNextBatch(); | ||
|
||
/** | ||
* Extra filter pushed down from upstream. Re-parse WHERE clause with extra filter because | ||
* OpenSearch RequestBuilder doesn't allow QueryBuilder inside be changed after added. | ||
*/ | ||
protected QueryBuilder generateNewQueryWithExtraFilter(BoolQueryBuilder filter) | ||
throws SqlParseException { | ||
Where where = request.getOriginalSelect().getWhere(); | ||
BoolQueryBuilder newQuery; | ||
if (where != null) { | ||
newQuery = QueryMaker.explain(where, false); | ||
newQuery.must(filter); | ||
} else { | ||
newQuery = filter; | ||
} | ||
return newQuery; | ||
} | ||
|
||
protected void updateMetaResult() { | ||
resourceMgr.getMetaResult().addTotalNumOfShards(searchResponse.getTotalShards()); | ||
resourceMgr.getMetaResult().addSuccessfulShards(searchResponse.getSuccessfulShards()); | ||
resourceMgr.getMetaResult().addFailedShards(searchResponse.getFailedShards()); | ||
resourceMgr.getMetaResult().updateTimeOut(searchResponse.isTimedOut()); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
protected Collection<Row<SearchHit>> wrapRowForCurrentBatch() { | ||
SearchHit[] hits = searchResponse.getHits().getHits(); | ||
Row[] rows = new Row[hits.length]; | ||
for (int i = 0; i < hits.length; i++) { | ||
rows[i] = new SearchHitRow(hits[i], request.getAlias()); | ||
} | ||
return Arrays.asList(rows); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getClass().getSimpleName() + " [ " + describeTable() + ", pageSize=" + pageSize + " ]"; | ||
} | ||
|
||
protected String describeTable() { | ||
return request.getOriginalSelect().getFrom().get(0).getIndex() + " as " + request.getAlias(); | ||
} | ||
|
||
/********************************************* | ||
* Getters for Explain | ||
*********************************************/ | ||
|
||
public String getRequest() { | ||
return Strings.toString(XContentType.JSON, request.getRequestBuilder().request().source()); | ||
} | ||
} |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot whether this class is the main IT for pagination? Is the new PIT logic enabled to test now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class is only responsible for legacy/v1 engine pagination queries. For v2 engine queries, there is a different base class. Currently, integ-test cluster does not set the feature flag settings and by default the cluster settings will have PIT feature flag enabled/set to true. Hence there are around 80+ tests testing new PIT changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not urgent but I think it would be helpful to get the IT run with PIT and Scroll both. In case we need to rollback to Scroll if anything wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually we are not disabling/removing Scroll implementation. There is a cluster level settings called
SQL_PAGINATION_API_SEARCH_AFTER
which is set to true to use PIT or false to default to Scroll API. So current IT tests run based on the setting of the above key and it covers both Scroll and PIT.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean the same IT set run 1 pass for PIT and another pass for Scroll?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh you meant running 2 passes of same set of tests for both PIT and Scroll? Ok I think that can be done by modifying the integ-test cluster settings as required. But currently we do not explicitly set the API settings in the test-cluster, so by default PIT changes are covered as part of IT tests and only 1 pass is run. I'll add this as part of the changes here - #2945