Skip to content
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

[Backport 2.x] Throw exception for RECOVER INDEX JOB query #3005

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ private AsyncQueryHandler getQueryHandlerForFlintExtensionQuery(
} else if (IndexQueryActionType.REFRESH.equals(indexQueryDetails.getIndexQueryActionType())) {
// Manual refresh should be handled by batch handler
return queryHandlerFactory.getRefreshQueryHandler(dispatchQueryRequest.getAccountId());
} else if (IndexQueryActionType.RECOVER.equals(indexQueryDetails.getIndexQueryActionType())) {
// RECOVER INDEX JOB should not be executed from async-query-core
throw new IllegalArgumentException("RECOVER INDEX JOB is not allowed.");
} else {
return getDefaultAsyncQueryHandler(dispatchQueryRequest.getAccountId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ public enum IndexQueryActionType {
SHOW,
DROP,
VACUUM,
ALTER
ALTER,
RECOVER
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.opensearch.sql.spark.antlr.parser.FlintSparkSqlExtensionsLexer;
import org.opensearch.sql.spark.antlr.parser.FlintSparkSqlExtensionsParser;
import org.opensearch.sql.spark.antlr.parser.FlintSparkSqlExtensionsParser.MaterializedViewQueryContext;
import org.opensearch.sql.spark.antlr.parser.FlintSparkSqlExtensionsParser.RecoverIndexJobStatementContext;
import org.opensearch.sql.spark.antlr.parser.SqlBaseLexer;
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser;
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser.IdentifierReferenceContext;
Expand Down Expand Up @@ -386,6 +387,12 @@ public Void visitMaterializedViewQuery(MaterializedViewQueryContext ctx) {
return super.visitMaterializedViewQuery(ctx);
}

@Override
public Void visitRecoverIndexJobStatement(RecoverIndexJobStatementContext ctx) {
indexQueryDetailsBuilder.indexQueryActionType(IndexQueryActionType.RECOVER);
return super.visitRecoverIndexJobStatement(ctx);
}

private String propertyKey(FlintSparkSqlExtensionsParser.PropertyKeyContext key) {
if (key.STRING() != null) {
return key.STRING().getText();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,16 @@ void testDispatchVacuumIndexQuery() {
testDispatchBatchQuery("VACUUM INDEX elb_and_requestUri ON my_glue.default.http_logs");
}

@Test
void testDispatchRecoverIndexQuery() {
String query = "RECOVER INDEX JOB `flint_spark_catalog_default_test_skipping_index`";
Assertions.assertThrows(
IllegalArgumentException.class,
() ->
sparkQueryDispatcher.dispatch(
getBaseDispatchQueryRequest(query), asyncQueryRequestContext));
}

@Test
void testDispatchWithUnSupportedDataSourceType() {
when(dataSourceService.verifyDataSourceAccessAndGetRawMetadata(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,15 @@ void testAutoRefresh() {
.autoRefresh());
}

@Test
void testRecoverIndex() {
String refreshSkippingIndex =
"RECOVER INDEX JOB `flint_spark_catalog_default_test_skipping_index`";
assertTrue(SQLQueryUtils.isFlintExtensionQuery(refreshSkippingIndex));
IndexQueryDetails indexDetails = SQLQueryUtils.extractIndexDetails(refreshSkippingIndex);
assertEquals(IndexQueryActionType.RECOVER, indexDetails.getIndexQueryActionType());
}

@Test
void testValidateSparkSqlQuery_ValidQuery() {
List<String> errors =
Expand Down
Loading