-
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.
Browse files
Browse the repository at this point in the history
* Bug Fix, delete opensearch index when DROP INDEX * address comments --------- (cherry picked from commit 0c78105) Signed-off-by: Peng Huo <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
3297502
commit a877ea8
Showing
13 changed files
with
492 additions
and
80 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
37 changes: 37 additions & 0 deletions
37
spark/src/main/java/org/opensearch/sql/spark/flint/FlintIndexMetadata.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,37 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.spark.flint; | ||
|
||
import java.util.Locale; | ||
import java.util.Map; | ||
import lombok.Data; | ||
|
||
@Data | ||
public class FlintIndexMetadata { | ||
public static final String PROPERTIES_KEY = "properties"; | ||
public static final String ENV_KEY = "env"; | ||
public static final String OPTIONS_KEY = "options"; | ||
|
||
public static final String SERVERLESS_EMR_JOB_ID = "SERVERLESS_EMR_JOB_ID"; | ||
public static final String AUTO_REFRESH = "auto_refresh"; | ||
public static final String AUTO_REFRESH_DEFAULT = "false"; | ||
|
||
private final String jobId; | ||
private final boolean autoRefresh; | ||
|
||
public static FlintIndexMetadata fromMetatdata(Map<String, Object> metaMap) { | ||
Map<String, Object> propertiesMap = (Map<String, Object>) metaMap.get(PROPERTIES_KEY); | ||
Map<String, Object> envMap = (Map<String, Object>) propertiesMap.get(ENV_KEY); | ||
Map<String, Object> options = (Map<String, Object>) metaMap.get(OPTIONS_KEY); | ||
String jobId = (String) envMap.get(SERVERLESS_EMR_JOB_ID); | ||
|
||
boolean autoRefresh = | ||
!((String) options.getOrDefault(AUTO_REFRESH, AUTO_REFRESH_DEFAULT)) | ||
.toLowerCase(Locale.ROOT) | ||
.equalsIgnoreCase(AUTO_REFRESH_DEFAULT); | ||
return new FlintIndexMetadata(jobId, autoRefresh); | ||
} | ||
} |
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
51 changes: 51 additions & 0 deletions
51
spark/src/test/java/org/opensearch/sql/spark/dispatcher/DropIndexResultTest.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,51 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.spark.dispatcher; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.opensearch.sql.spark.data.constants.SparkConstants.DATA_FIELD; | ||
import static org.opensearch.sql.spark.data.constants.SparkConstants.ERROR_FIELD; | ||
import static org.opensearch.sql.spark.data.constants.SparkConstants.STATUS_FIELD; | ||
|
||
import com.amazonaws.services.emrserverless.model.JobRunState; | ||
import org.json.JSONObject; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class DropIndexResultTest { | ||
// todo, remove this UT after response refactor. | ||
@Test | ||
public void successRespEncodeDecode() { | ||
// encode jobId | ||
String jobId = | ||
new SparkQueryDispatcher.DropIndexResult(JobRunState.SUCCESS.toString()).toJobId(); | ||
|
||
// decode jobId | ||
SparkQueryDispatcher.DropIndexResult dropIndexResult = | ||
SparkQueryDispatcher.DropIndexResult.fromJobId(jobId); | ||
|
||
JSONObject result = dropIndexResult.result(); | ||
assertEquals(JobRunState.SUCCESS.toString(), result.get(STATUS_FIELD)); | ||
assertEquals( | ||
"{\"result\":[],\"schema\":[],\"applicationId\":\"fakeDropIndexApplicationId\"}", | ||
result.get(DATA_FIELD).toString()); | ||
} | ||
|
||
// todo, remove this UT after response refactor. | ||
@Test | ||
public void failedRespEncodeDecode() { | ||
// encode jobId | ||
String jobId = | ||
new SparkQueryDispatcher.DropIndexResult(JobRunState.FAILED.toString()).toJobId(); | ||
|
||
// decode jobId | ||
SparkQueryDispatcher.DropIndexResult dropIndexResult = | ||
SparkQueryDispatcher.DropIndexResult.fromJobId(jobId); | ||
|
||
JSONObject result = dropIndexResult.result(); | ||
assertEquals(JobRunState.FAILED.toString(), result.get(STATUS_FIELD)); | ||
assertEquals("failed to drop index", result.get(ERROR_FIELD)); | ||
} | ||
} |
Oops, something went wrong.