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] Add validation method for Flint extension queries and wire it into the dispatcher #3130

Merged
merged 1 commit into from
Oct 29, 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 @@ -51,6 +51,7 @@ public DispatchQueryResponse dispatch(
String query = dispatchQueryRequest.getQuery();

if (SQLQueryUtils.isFlintExtensionQuery(query)) {
sqlQueryValidator.validateFlintExtensionQuery(query, dataSourceMetadata.getConnector());
return handleFlintExtensionQuery(
dispatchQueryRequest, asyncQueryRequestContext, dataSourceMetadata);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,12 @@ public void validate(String sqlQuery, DataSourceType datasourceType) {
throw e;
}
}

/**
* Validates a query from the Flint extension grammar. The method is currently a no-op.
*
* @param sqlQuery The Flint extension query to be validated
* @param dataSourceType The type of the datasource the query is being run on
*/
public void validateFlintExtensionQuery(String sqlQuery, DataSourceType dataSourceType) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,11 @@ void testDispatchVacuumIndexQuery() {

@Test
void testDispatchRecoverIndexQuery() {
DataSourceMetadata dataSourceMetadata = constructMyGlueDataSourceMetadata();
when(dataSourceService.verifyDataSourceAccessAndGetRawMetadata(
MY_GLUE, asyncQueryRequestContext))
.thenReturn(dataSourceMetadata);

String query = "RECOVER INDEX JOB `flint_spark_catalog_default_test_skipping_index`";
Assertions.assertThrows(
IllegalArgumentException.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@

package org.opensearch.sql.spark.validator;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

import java.util.Arrays;
import java.util.UUID;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.antlr.v4.runtime.CommonTokenStream;
Expand Down Expand Up @@ -561,6 +563,14 @@ void testSecurityLakeQueries() {
v.ng(TestElement.INTEGRATION_WITH_HIVE_UDFS_UDAFS_UDTFS);
}

@Test
void testValidateFlintExtensionQuery() {
assertDoesNotThrow(
() ->
sqlQueryValidator.validateFlintExtensionQuery(
UUID.randomUUID().toString(), DataSourceType.SECURITY_LAKE));
}

@AllArgsConstructor
private static class VerifyValidator {
private final SQLQueryValidator validator;
Expand Down
Loading