generated from amazon-archives/__template_Custom
-
Notifications
You must be signed in to change notification settings - Fork 181
Extract SessionStorageService and StatementStorageService #2665
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
ykmr1224
merged 6 commits into
opensearch-project:main
from
ykmr1224:dqs/refactor-session
May 15, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b7bb16a
Extract SessionStorageService and StatementStorageService
ykmr1224 8e7fc7c
Reformat
ykmr1224 9a0b1c3
Add copyright comment
ykmr1224 2c1a204
Add comments and remove unused methods
ykmr1224 8c195ae
Remove unneeded imports
ykmr1224 970b551
Fix code format issue
ykmr1224 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
41 changes: 41 additions & 0 deletions
41
...n/java/org/opensearch/sql/spark/execution/statestore/OpenSearchSessionStorageService.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,41 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.spark.execution.statestore; | ||
|
|
||
| import static org.opensearch.sql.spark.execution.statestore.StateStore.DATASOURCE_TO_REQUEST_INDEX; | ||
|
|
||
| import java.util.Optional; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.opensearch.sql.spark.execution.session.SessionModel; | ||
| import org.opensearch.sql.spark.execution.session.SessionState; | ||
|
|
||
| @RequiredArgsConstructor | ||
| public class OpenSearchSessionStorageService implements SessionStorageService { | ||
|
|
||
| private final StateStore stateStore; | ||
|
|
||
| @Override | ||
| public SessionModel createSession(SessionModel sessionModel, String datasourceName) { | ||
| return stateStore.create( | ||
| sessionModel, SessionModel::of, DATASOURCE_TO_REQUEST_INDEX.apply(datasourceName)); | ||
| } | ||
|
|
||
| @Override | ||
| public Optional<SessionModel> getSession(String id, String datasourceName) { | ||
| return stateStore.get( | ||
| id, SessionModel::fromXContent, DATASOURCE_TO_REQUEST_INDEX.apply(datasourceName)); | ||
| } | ||
|
|
||
| @Override | ||
| public SessionModel updateSessionState( | ||
| SessionModel sessionModel, SessionState sessionState, String datasourceName) { | ||
| return stateStore.updateState( | ||
| sessionModel, | ||
| sessionState, | ||
| SessionModel::copyWithState, | ||
| DATASOURCE_TO_REQUEST_INDEX.apply(datasourceName)); | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
...java/org/opensearch/sql/spark/execution/statestore/OpenSearchStatementStorageService.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,41 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.spark.execution.statestore; | ||
|
|
||
| import static org.opensearch.sql.spark.execution.statestore.StateStore.DATASOURCE_TO_REQUEST_INDEX; | ||
|
|
||
| import java.util.Optional; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.opensearch.sql.spark.execution.statement.StatementModel; | ||
| import org.opensearch.sql.spark.execution.statement.StatementState; | ||
|
|
||
| @RequiredArgsConstructor | ||
| public class OpenSearchStatementStorageService implements StatementStorageService { | ||
|
|
||
| private final StateStore stateStore; | ||
|
|
||
| @Override | ||
| public StatementModel createStatement(StatementModel statementModel, String datasourceName) { | ||
| return stateStore.create( | ||
| statementModel, StatementModel::copy, DATASOURCE_TO_REQUEST_INDEX.apply(datasourceName)); | ||
| } | ||
|
|
||
| @Override | ||
| public Optional<StatementModel> getStatement(String id, String datasourceName) { | ||
| return stateStore.get( | ||
| id, StatementModel::fromXContent, DATASOURCE_TO_REQUEST_INDEX.apply(datasourceName)); | ||
| } | ||
|
|
||
| @Override | ||
| public StatementModel updateStatementState( | ||
| StatementModel oldStatementModel, StatementState statementState, String datasourceName) { | ||
| return stateStore.updateState( | ||
| oldStatementModel, | ||
| statementState, | ||
| StatementModel::copyWithState, | ||
| DATASOURCE_TO_REQUEST_INDEX.apply(datasourceName)); | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
spark/src/main/java/org/opensearch/sql/spark/execution/statestore/SessionStorageService.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,21 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.spark.execution.statestore; | ||
|
|
||
| import java.util.Optional; | ||
| import org.opensearch.sql.spark.execution.session.SessionModel; | ||
| import org.opensearch.sql.spark.execution.session.SessionState; | ||
|
|
||
| /** Interface for accessing {@link SessionModel} data storage. */ | ||
| public interface SessionStorageService { | ||
|
|
||
| SessionModel createSession(SessionModel sessionModel, String datasourceName); | ||
|
|
||
| Optional<SessionModel> getSession(String id, String datasourceName); | ||
|
|
||
| SessionModel updateSessionState( | ||
| SessionModel sessionModel, SessionState sessionState, String datasourceName); | ||
| } |
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.