-
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.
* add InteractiveSession and SessionManager Signed-off-by: Peng Huo <[email protected]> * add statement Signed-off-by: Peng Huo <[email protected]> * add statement Signed-off-by: Peng Huo <[email protected]> * fix format Signed-off-by: Peng Huo <[email protected]> * address comments Signed-off-by: Peng Huo <[email protected]> --------- Signed-off-by: Peng Huo <[email protected]>
- Loading branch information
Showing
19 changed files
with
1,055 additions
and
169 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
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
15 changes: 15 additions & 0 deletions
15
spark/src/main/java/org/opensearch/sql/spark/execution/statement/QueryRequest.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,15 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.spark.execution.statement; | ||
|
||
import lombok.Data; | ||
import org.opensearch.sql.spark.rest.model.LangType; | ||
|
||
@Data | ||
public class QueryRequest { | ||
private final LangType langType; | ||
private final String query; | ||
} |
85 changes: 85 additions & 0 deletions
85
spark/src/main/java/org/opensearch/sql/spark/execution/statement/Statement.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,85 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.spark.execution.statement; | ||
|
||
import static org.opensearch.sql.spark.execution.statement.StatementModel.submitStatement; | ||
import static org.opensearch.sql.spark.execution.statestore.StateStore.createStatement; | ||
import static org.opensearch.sql.spark.execution.statestore.StateStore.getStatement; | ||
import static org.opensearch.sql.spark.execution.statestore.StateStore.updateStatementState; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.opensearch.index.engine.DocumentMissingException; | ||
import org.opensearch.index.engine.VersionConflictEngineException; | ||
import org.opensearch.sql.spark.execution.session.SessionId; | ||
import org.opensearch.sql.spark.execution.statestore.StateStore; | ||
import org.opensearch.sql.spark.rest.model.LangType; | ||
|
||
/** Statement represent query to execute in session. One statement map to one session. */ | ||
@Getter | ||
@Builder | ||
public class Statement { | ||
private static final Logger LOG = LogManager.getLogger(); | ||
|
||
private final SessionId sessionId; | ||
private final String applicationId; | ||
private final String jobId; | ||
private final StatementId statementId; | ||
private final LangType langType; | ||
private final String query; | ||
private final String queryId; | ||
private final StateStore stateStore; | ||
|
||
@Setter private StatementModel statementModel; | ||
|
||
/** Open a statement. */ | ||
public void open() { | ||
try { | ||
statementModel = | ||
submitStatement(sessionId, applicationId, jobId, statementId, langType, query, queryId); | ||
statementModel = createStatement(stateStore).apply(statementModel); | ||
} catch (VersionConflictEngineException e) { | ||
String errorMsg = "statement already exist. " + statementId; | ||
LOG.error(errorMsg); | ||
throw new IllegalStateException(errorMsg); | ||
} | ||
} | ||
|
||
/** Cancel a statement. */ | ||
public void cancel() { | ||
if (statementModel.getStatementState().equals(StatementState.RUNNING)) { | ||
String errorMsg = | ||
String.format("can't cancel statement in waiting state. statement: %s.", statementId); | ||
LOG.error(errorMsg); | ||
throw new IllegalStateException(errorMsg); | ||
} | ||
try { | ||
this.statementModel = | ||
updateStatementState(stateStore).apply(this.statementModel, StatementState.CANCELLED); | ||
} catch (DocumentMissingException e) { | ||
String errorMsg = | ||
String.format("cancel statement failed. no statement found. statement: %s.", statementId); | ||
LOG.error(errorMsg); | ||
throw new IllegalStateException(errorMsg); | ||
} catch (VersionConflictEngineException e) { | ||
this.statementModel = | ||
getStatement(stateStore).apply(statementModel.getId()).orElse(this.statementModel); | ||
String errorMsg = | ||
String.format( | ||
"cancel statement failed. current statementState: %s " + "statement: %s.", | ||
this.statementModel.getStatementState(), statementId); | ||
LOG.error(errorMsg); | ||
throw new IllegalStateException(errorMsg); | ||
} | ||
} | ||
|
||
public StatementState getStatementState() { | ||
return statementModel.getStatementState(); | ||
} | ||
} |
Oops, something went wrong.