forked from opensearch-project/sql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add query, langType, status, error in AsyncQueryJobMetadata (opensear…
…ch-project#2958) * Add query, langType, status, error in AsyncQueryJobMetadata Signed-off-by: Tomoyuki Morita <[email protected]> * Fix test Signed-off-by: Tomoyuki Morita <[email protected]> --------- Signed-off-by: Tomoyuki Morita <[email protected]> Signed-off-by: Tomoyuki MORITA <[email protected]>
- Loading branch information
Showing
12 changed files
with
119 additions
and
17 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
41 changes: 41 additions & 0 deletions
41
async-query-core/src/main/java/org/opensearch/sql/spark/asyncquery/model/QueryState.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.asyncquery.model; | ||
|
||
import java.util.Arrays; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum QueryState { | ||
WAITING("waiting"), | ||
RUNNING("running"), | ||
SUCCESS("success"), | ||
FAILED("failed"), | ||
TIMEOUT("timeout"), | ||
CANCELLED("cancelled"); | ||
|
||
private final String state; | ||
|
||
QueryState(String state) { | ||
this.state = state; | ||
} | ||
|
||
private static final Map<String, QueryState> STATES = | ||
Arrays.stream(QueryState.values()) | ||
.collect(Collectors.toMap(t -> t.name().toLowerCase(), t -> t)); | ||
|
||
public static QueryState fromString(String key) { | ||
for (QueryState ss : QueryState.values()) { | ||
if (ss.getState().toLowerCase(Locale.ROOT).equals(key)) { | ||
return ss; | ||
} | ||
} | ||
throw new IllegalArgumentException("Invalid query state: " + key); | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
async-query-core/src/test/java/org/opensearch/sql/spark/asyncquery/model/QueryStateTest.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,28 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.spark.asyncquery.model; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class QueryStateTest { | ||
@Test | ||
public void testFromString() { | ||
assertEquals(QueryState.WAITING, QueryState.fromString("waiting")); | ||
assertEquals(QueryState.RUNNING, QueryState.fromString("running")); | ||
assertEquals(QueryState.SUCCESS, QueryState.fromString("success")); | ||
assertEquals(QueryState.FAILED, QueryState.fromString("failed")); | ||
assertEquals(QueryState.CANCELLED, QueryState.fromString("cancelled")); | ||
assertEquals(QueryState.TIMEOUT, QueryState.fromString("timeout")); | ||
} | ||
|
||
@Test | ||
public void testFromStringWithUnknownState() { | ||
assertThrows(IllegalArgumentException.class, () -> QueryState.fromString("UNKNOWN_STATE")); | ||
} | ||
} |