-
Notifications
You must be signed in to change notification settings - Fork 144
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 session and statement state for all query types #2413
Closed
penghuo
wants to merge
2
commits into
opensearch-project:main
from
penghuo:issue2401/addSessionState
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,12 @@ | |
package org.opensearch.sql.spark.dispatcher; | ||
|
||
import static org.opensearch.sql.spark.execution.statestore.StateStore.createIndexDMLResult; | ||
import static org.opensearch.sql.spark.execution.statestore.StateStore.getStatementModelByQueryId; | ||
|
||
import com.amazonaws.services.emrserverless.model.JobRunState; | ||
import lombok.RequiredArgsConstructor; | ||
import java.util.Locale; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.json.JSONObject; | ||
import org.opensearch.client.Client; | ||
import org.opensearch.sql.datasource.DataSourceService; | ||
import org.opensearch.sql.datasource.model.DataSourceMetadata; | ||
|
@@ -24,6 +24,8 @@ | |
import org.opensearch.sql.spark.dispatcher.model.DispatchQueryResponse; | ||
import org.opensearch.sql.spark.dispatcher.model.IndexDMLResult; | ||
import org.opensearch.sql.spark.dispatcher.model.IndexQueryDetails; | ||
import org.opensearch.sql.spark.execution.session.SessionType; | ||
import org.opensearch.sql.spark.execution.statement.StatementState; | ||
import org.opensearch.sql.spark.execution.statestore.StateStore; | ||
import org.opensearch.sql.spark.flint.FlintIndexMetadata; | ||
import org.opensearch.sql.spark.flint.FlintIndexMetadataReader; | ||
|
@@ -33,7 +35,6 @@ | |
import org.opensearch.sql.spark.response.JobExecutionResponseReader; | ||
|
||
/** Handle Index DML query. includes * DROP * ALT? */ | ||
@RequiredArgsConstructor | ||
public class IndexDMLHandler extends AsyncQueryHandler { | ||
private static final Logger LOG = LogManager.getLogger(); | ||
|
||
|
@@ -53,6 +54,24 @@ public class IndexDMLHandler extends AsyncQueryHandler { | |
|
||
private final StateStore stateStore; | ||
|
||
public IndexDMLHandler( | ||
EMRServerlessClient emrServerlessClient, | ||
DataSourceService dataSourceService, | ||
DataSourceUserAuthorizationHelperImpl dataSourceUserAuthorizationHelper, | ||
JobExecutionResponseReader jobExecutionResponseReader, | ||
FlintIndexMetadataReader flintIndexMetadataReader, | ||
Client client, | ||
StateStore stateStore) { | ||
super(jobExecutionResponseReader, stateStore); | ||
this.emrServerlessClient = emrServerlessClient; | ||
this.dataSourceService = dataSourceService; | ||
this.dataSourceUserAuthorizationHelper = dataSourceUserAuthorizationHelper; | ||
this.jobExecutionResponseReader = jobExecutionResponseReader; | ||
this.flintIndexMetadataReader = flintIndexMetadataReader; | ||
this.client = client; | ||
this.stateStore = stateStore; | ||
} | ||
|
||
public static boolean isIndexDMLQuery(String jobId) { | ||
return DROP_INDEX_JOB_ID.equalsIgnoreCase(jobId); | ||
} | ||
|
@@ -93,22 +112,20 @@ public DispatchQueryResponse submit( | |
System.currentTimeMillis()); | ||
String resultIndex = dataSourceMetadata.getResultIndex(); | ||
createIndexDMLResult(stateStore, resultIndex).apply(indexDMLResult); | ||
|
||
createSessionAndStatement( | ||
dispatchQueryRequest, | ||
dispatchQueryRequest.getApplicationId(), | ||
DROP_INDEX_JOB_ID, | ||
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. does that mean there is only one job id for all DML queries? Would it cause issues if there is a concurrent DML running? |
||
SessionType.BATCH, | ||
dataSourceMetadata.getName(), | ||
asyncQueryId); | ||
StateStore.updateStatementState(stateStore, asyncQueryId.getDataSourceName()) | ||
.apply( | ||
getStatementModelByQueryId(stateStore, asyncQueryId), | ||
StatementState.fromString(status.toLowerCase(Locale.ROOT))); | ||
return new DispatchQueryResponse(asyncQueryId, DROP_INDEX_JOB_ID, resultIndex, null); | ||
} | ||
|
||
@Override | ||
protected JSONObject getResponseFromResultIndex(AsyncQueryJobMetadata asyncQueryJobMetadata) { | ||
String queryId = asyncQueryJobMetadata.getQueryId().getId(); | ||
return jobExecutionResponseReader.getResultWithQueryId( | ||
queryId, asyncQueryJobMetadata.getResultIndex()); | ||
} | ||
|
||
@Override | ||
protected JSONObject getResponseFromExecutor(AsyncQueryJobMetadata asyncQueryJobMetadata) { | ||
throw new IllegalStateException("[BUG] can't fetch result of index DML query form server"); | ||
} | ||
|
||
@Override | ||
public String cancelJob(AsyncQueryJobMetadata asyncQueryJobMetadata) { | ||
throw new IllegalArgumentException("can't cancel index DML query"); | ||
|
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.
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.
is error written to result index or statement model in request index?
Are these different cases?
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.
both, Flint spark job,
@kaituo please help confirm also.
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.
yes