-
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.
Extract SessionStorageService and StatementStorageService (#2665)
* Extract SessionStorageService and StatementStorageService Signed-off-by: Tomoyuki Morita <[email protected]> * Reformat Signed-off-by: Tomoyuki Morita <[email protected]> * Add copyright comment Signed-off-by: Tomoyuki Morita <[email protected]> * Add comments and remove unused methods Signed-off-by: Tomoyuki Morita <[email protected]> * Remove unneeded imports Signed-off-by: Tomoyuki Morita <[email protected]> * Fix code format issue Signed-off-by: Tomoyuki Morita <[email protected]> --------- Signed-off-by: Tomoyuki Morita <[email protected]> (cherry picked from commit 1985459)
- Loading branch information
Showing
17 changed files
with
423 additions
and
383 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
41 changes: 41 additions & 0 deletions
41
...n/java/org/opensearch/sql/spark/execution/statestore/OpenSearchSessionStorageService.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,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 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 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.