Skip to content

Commit

Permalink
Add validation method for Flint extension queries and wire it into th…
Browse files Browse the repository at this point in the history
…e dispatcher (opensearch-project#3096)

* Add validation method for Flint extension queries and wire it into the dispatcher

Signed-off-by: Chase Engelbrecht <[email protected]>

* Add unit test

Signed-off-by: Chase Engelbrecht <[email protected]>

* Run spotless

Signed-off-by: Chase Engelbrecht <[email protected]>

* Fix NPE in test

Signed-off-by: Chase Engelbrecht <[email protected]>

* Add java doc

Signed-off-by: Chase Engelbrecht <[email protected]>

---------

Signed-off-by: Chase Engelbrecht <[email protected]>
  • Loading branch information
engechas authored Oct 28, 2024
1 parent f00244e commit 3b86612
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
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

0 comments on commit 3b86612

Please sign in to comment.