From 3a0be81522822c9895336b7a7fad441bc2c7cc4b Mon Sep 17 00:00:00 2001 From: Tomoyuki Morita Date: Mon, 25 Nov 2024 23:54:47 -0800 Subject: [PATCH] Remove specific PPL grammar validator Signed-off-by: Tomoyuki Morita --- .../CWLPPLGrammarElementValidator.java | 43 ------------------- .../validator/PPLQueryValidatorTest.java | 39 ++++++++++++++++- .../config/AsyncExecutorServiceModule.java | 4 +- 3 files changed, 38 insertions(+), 48 deletions(-) delete mode 100644 async-query-core/src/main/java/org/opensearch/sql/spark/validator/CWLPPLGrammarElementValidator.java diff --git a/async-query-core/src/main/java/org/opensearch/sql/spark/validator/CWLPPLGrammarElementValidator.java b/async-query-core/src/main/java/org/opensearch/sql/spark/validator/CWLPPLGrammarElementValidator.java deleted file mode 100644 index b0a24491c8..0000000000 --- a/async-query-core/src/main/java/org/opensearch/sql/spark/validator/CWLPPLGrammarElementValidator.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.opensearch.sql.spark.validator; - -import static org.opensearch.sql.spark.validator.PPLGrammarElement.DESCRIBE_COMMAND; -import static org.opensearch.sql.spark.validator.PPLGrammarElement.EXPAND_COMMAND; -import static org.opensearch.sql.spark.validator.PPLGrammarElement.FILLNULL_COMMAND; -import static org.opensearch.sql.spark.validator.PPLGrammarElement.FLATTEN_COMMAND; -import static org.opensearch.sql.spark.validator.PPLGrammarElement.IPADDRESS_FUNCTIONS; -import static org.opensearch.sql.spark.validator.PPLGrammarElement.JOIN_COMMAND; -import static org.opensearch.sql.spark.validator.PPLGrammarElement.JSON_FUNCTIONS; -import static org.opensearch.sql.spark.validator.PPLGrammarElement.LAMBDA_FUNCTIONS; -import static org.opensearch.sql.spark.validator.PPLGrammarElement.LOOKUP_COMMAND; -import static org.opensearch.sql.spark.validator.PPLGrammarElement.PATTERNS_COMMAND; -import static org.opensearch.sql.spark.validator.PPLGrammarElement.SUBQUERY_COMMAND; - -import com.google.common.collect.ImmutableSet; -import java.util.Set; - -public class CWLPPLGrammarElementValidator extends DenyListGrammarElementValidator { - private static final Set CWL_DENY_LIST = - ImmutableSet.builder() - .add( - PATTERNS_COMMAND, - JOIN_COMMAND, - LOOKUP_COMMAND, - SUBQUERY_COMMAND, - FLATTEN_COMMAND, - FILLNULL_COMMAND, - EXPAND_COMMAND, - DESCRIBE_COMMAND, - IPADDRESS_FUNCTIONS, - JSON_FUNCTIONS, - LAMBDA_FUNCTIONS) - .build(); - - public CWLPPLGrammarElementValidator() { - super(CWL_DENY_LIST); - } -} diff --git a/async-query-core/src/test/java/org/opensearch/sql/spark/validator/PPLQueryValidatorTest.java b/async-query-core/src/test/java/org/opensearch/sql/spark/validator/PPLQueryValidatorTest.java index 54df2874b2..8d02bb3c72 100644 --- a/async-query-core/src/test/java/org/opensearch/sql/spark/validator/PPLQueryValidatorTest.java +++ b/async-query-core/src/test/java/org/opensearch/sql/spark/validator/PPLQueryValidatorTest.java @@ -8,8 +8,21 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; - +import static org.opensearch.sql.spark.validator.PPLGrammarElement.DESCRIBE_COMMAND; +import static org.opensearch.sql.spark.validator.PPLGrammarElement.EXPAND_COMMAND; +import static org.opensearch.sql.spark.validator.PPLGrammarElement.FILLNULL_COMMAND; +import static org.opensearch.sql.spark.validator.PPLGrammarElement.FLATTEN_COMMAND; +import static org.opensearch.sql.spark.validator.PPLGrammarElement.IPADDRESS_FUNCTIONS; +import static org.opensearch.sql.spark.validator.PPLGrammarElement.JOIN_COMMAND; +import static org.opensearch.sql.spark.validator.PPLGrammarElement.JSON_FUNCTIONS; +import static org.opensearch.sql.spark.validator.PPLGrammarElement.LAMBDA_FUNCTIONS; +import static org.opensearch.sql.spark.validator.PPLGrammarElement.LOOKUP_COMMAND; +import static org.opensearch.sql.spark.validator.PPLGrammarElement.PATTERNS_COMMAND; +import static org.opensearch.sql.spark.validator.PPLGrammarElement.SUBQUERY_COMMAND; + +import com.google.common.collect.ImmutableSet; import java.util.Arrays; +import java.util.Set; import lombok.AllArgsConstructor; import lombok.Getter; import org.antlr.v4.runtime.CommonTokenStream; @@ -88,10 +101,32 @@ void testAllowAllByDefault() { Arrays.stream(PPLQueryValidatorTest.TestElement.values()).forEach(v::ok); } + private static class TestPPLGrammarElementValidator extends DenyListGrammarElementValidator { + private static final Set DENY_LIST = + ImmutableSet.builder() + .add( + PATTERNS_COMMAND, + JOIN_COMMAND, + LOOKUP_COMMAND, + SUBQUERY_COMMAND, + FLATTEN_COMMAND, + FILLNULL_COMMAND, + EXPAND_COMMAND, + DESCRIBE_COMMAND, + IPADDRESS_FUNCTIONS, + JSON_FUNCTIONS, + LAMBDA_FUNCTIONS) + .build(); + + public TestPPLGrammarElementValidator() { + super(DENY_LIST); + } + } + @Test void testCwlValidator() { when(mockedProvider.getValidatorForDatasource(any())) - .thenReturn(new CWLPPLGrammarElementValidator()); + .thenReturn(new TestPPLGrammarElementValidator()); VerifyValidator v = new VerifyValidator(pplQueryValidator, DataSourceType.SPARK); v.ok(TestElement.FIELDS); diff --git a/async-query/src/main/java/org/opensearch/sql/spark/transport/config/AsyncExecutorServiceModule.java b/async-query/src/main/java/org/opensearch/sql/spark/transport/config/AsyncExecutorServiceModule.java index a577f32e3b..d21f8c7665 100644 --- a/async-query/src/main/java/org/opensearch/sql/spark/transport/config/AsyncExecutorServiceModule.java +++ b/async-query/src/main/java/org/opensearch/sql/spark/transport/config/AsyncExecutorServiceModule.java @@ -65,7 +65,6 @@ import org.opensearch.sql.spark.response.OpenSearchJobExecutionResponseReader; import org.opensearch.sql.spark.scheduler.AsyncQueryScheduler; import org.opensearch.sql.spark.scheduler.OpenSearchAsyncQueryScheduler; -import org.opensearch.sql.spark.validator.CWLPPLGrammarElementValidator; import org.opensearch.sql.spark.validator.DefaultGrammarElementValidator; import org.opensearch.sql.spark.validator.GrammarElementValidatorProvider; import org.opensearch.sql.spark.validator.PPLQueryValidator; @@ -206,8 +205,7 @@ public SQLQueryValidator sqlQueryValidator() { public PPLQueryValidator pplQueryValidator() { GrammarElementValidatorProvider validatorProvider = new GrammarElementValidatorProvider( - ImmutableMap.of(DataSourceType.S3GLUE, new CWLPPLGrammarElementValidator()), - new DefaultGrammarElementValidator()); + ImmutableMap.of(), new DefaultGrammarElementValidator()); return new PPLQueryValidator(validatorProvider); }