Skip to content

Commit

Permalink
Remove specific PPL grammar validator
Browse files Browse the repository at this point in the history
Signed-off-by: Tomoyuki Morita <[email protected]>
  • Loading branch information
ykmr1224 committed Nov 26, 2024
1 parent 9e4d2eb commit 3a0be81
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 48 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -88,10 +101,32 @@ void testAllowAllByDefault() {
Arrays.stream(PPLQueryValidatorTest.TestElement.values()).forEach(v::ok);
}

private static class TestPPLGrammarElementValidator extends DenyListGrammarElementValidator {
private static final Set<GrammarElement> DENY_LIST =
ImmutableSet.<GrammarElement>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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 3a0be81

Please sign in to comment.