Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
Signed-off-by: Tomoyuki Morita <[email protected]>
  • Loading branch information
ykmr1224 committed Sep 19, 2024
1 parent 7dde72a commit 71cfa18
Show file tree
Hide file tree
Showing 4 changed files with 388 additions and 238 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ enum GrammarElement {
WITH("WITH"),
CLUSTER_BY("CLUSTER BY"),
DISTRIBUTE_BY("DISTRIBUTE BY"),
GROUP_BY("GROUP BY"),
HAVING("HAVING"),
// GROUP_BY("GROUP BY"),
// HAVING("HAVING"),
HINTS("HINTS"),
INLINE_TABLE("Inline Table(VALUES)"),
FILE("File"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package org.opensearch.sql.spark.validator;

import lombok.AllArgsConstructor;
import org.antlr.v4.runtime.tree.TerminalNode;
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser;
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser.AddTableColumnsContext;
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser.AddTablePartitionContext;
Expand Down Expand Up @@ -35,7 +34,6 @@
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser.DropTablePartitionsContext;
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser.DropViewContext;
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser.ExplainContext;
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser.FunctionIdentifierContext;
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser.FunctionNameContext;
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser.HintContext;
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser.HiveReplaceColumnsContext;
Expand Down Expand Up @@ -67,7 +65,6 @@
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser.SetConfigurationContext;
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser.SetNamespaceLocationContext;
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser.SetNamespacePropertiesContext;
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser.SetQuantifierContext;
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser.SetTableLocationContext;
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser.SetTableSerDeContext;
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser.ShowColumnsContext;
Expand Down Expand Up @@ -201,8 +198,6 @@ public Void visitAlterViewSchemaBinding(AlterViewSchemaBindingContext ctx) {

@Override
public Void visitRenameTable(RenameTableContext ctx) {
TerminalNode view = ctx.VIEW();
TerminalNode table = ctx.TABLE();
if (ctx.VIEW() != null) {
validateAllowed(GrammarElement.ALTER_VIEW);
} else if (ctx.TABLE() != null) {
Expand Down Expand Up @@ -521,12 +516,6 @@ public Void visitSetConfiguration(SetConfigurationContext ctx) {
return super.visitSetConfiguration(ctx);
}

@Override
public Void visitSetQuantifier(SetQuantifierContext ctx) {
validateAllowed(GrammarElement.SET);
return super.visitSetQuantifier(ctx);
}

@Override
public Void visitShowColumns(ShowColumnsContext ctx) {
validateAllowed(GrammarElement.SHOW_COLUMNS);
Expand Down Expand Up @@ -587,12 +576,6 @@ public Void visitUncacheTable(UncacheTableContext ctx) {
return super.visitUncacheTable(ctx);
}

@Override
public Void visitFunctionIdentifier(FunctionIdentifierContext ctx) {
validateFunctionAllowed(ctx.function.getText());
return super.visitFunctionIdentifier(ctx);
}

@Override
public Void visitFunctionName(FunctionNameContext ctx) {
validateFunctionAllowed(ctx.qualifiedName().getText());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,19 +357,12 @@ void testDispatchWithSparkUDFQuery() {
sparkQueryDispatcher.dispatch(
getBaseDispatchQueryRequestBuilder(query).langType(LangType.SQL).build(),
asyncQueryRequestContext));
assertEquals(
"Query is not allowed: Creating user-defined functions is not allowed",
illegalArgumentException.getMessage());
assertEquals("CREATE FUNCTION is not allowed.", illegalArgumentException.getMessage());
verifyNoInteractions(emrServerlessClient);
verifyNoInteractions(flintIndexMetadataService);
}
}

@Test
void testInvalidSQLQueryDispatchToSpark() {
testDispatchBatchQuery("myselect 1");
}

@Test
void testDispatchQueryWithoutATableAndDataSourceName() {
testDispatchBatchQuery("show tables");
Expand Down
Loading

0 comments on commit 71cfa18

Please sign in to comment.