Skip to content

Commit ac8678c

Browse files
authored
Disable join types in validators (#3056)
* Disable join types in validators Signed-off-by: Tomoyuki Morita <[email protected]> * Removed methods from SQLQueryValidationVisitor due to grammar file change Signed-off-by: Tomoyuki Morita <[email protected]> --------- Signed-off-by: Tomoyuki Morita <[email protected]>
1 parent 564ab60 commit ac8678c

File tree

4 files changed

+32
-45
lines changed

4 files changed

+32
-45
lines changed

async-query-core/src/main/java/org/opensearch/sql/spark/validator/S3GlueGrammarElementValidator.java

+10
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,25 @@
99
import static org.opensearch.sql.spark.validator.GrammarElement.CLUSTER_BY;
1010
import static org.opensearch.sql.spark.validator.GrammarElement.CREATE_FUNCTION;
1111
import static org.opensearch.sql.spark.validator.GrammarElement.CREATE_VIEW;
12+
import static org.opensearch.sql.spark.validator.GrammarElement.CROSS_JOIN;
1213
import static org.opensearch.sql.spark.validator.GrammarElement.DESCRIBE_FUNCTION;
1314
import static org.opensearch.sql.spark.validator.GrammarElement.DISTRIBUTE_BY;
1415
import static org.opensearch.sql.spark.validator.GrammarElement.DROP_FUNCTION;
1516
import static org.opensearch.sql.spark.validator.GrammarElement.DROP_VIEW;
1617
import static org.opensearch.sql.spark.validator.GrammarElement.FILE;
18+
import static org.opensearch.sql.spark.validator.GrammarElement.FULL_OUTER_JOIN;
1719
import static org.opensearch.sql.spark.validator.GrammarElement.HINTS;
1820
import static org.opensearch.sql.spark.validator.GrammarElement.INLINE_TABLE;
1921
import static org.opensearch.sql.spark.validator.GrammarElement.INSERT;
22+
import static org.opensearch.sql.spark.validator.GrammarElement.LEFT_ANTI_JOIN;
23+
import static org.opensearch.sql.spark.validator.GrammarElement.LEFT_SEMI_JOIN;
2024
import static org.opensearch.sql.spark.validator.GrammarElement.LOAD;
2125
import static org.opensearch.sql.spark.validator.GrammarElement.MANAGE_RESOURCE;
2226
import static org.opensearch.sql.spark.validator.GrammarElement.MISC_FUNCTIONS;
2327
import static org.opensearch.sql.spark.validator.GrammarElement.REFRESH_FUNCTION;
2428
import static org.opensearch.sql.spark.validator.GrammarElement.REFRESH_RESOURCE;
2529
import static org.opensearch.sql.spark.validator.GrammarElement.RESET;
30+
import static org.opensearch.sql.spark.validator.GrammarElement.RIGHT_OUTER_JOIN;
2631
import static org.opensearch.sql.spark.validator.GrammarElement.SET;
2732
import static org.opensearch.sql.spark.validator.GrammarElement.SHOW_FUNCTIONS;
2833
import static org.opensearch.sql.spark.validator.GrammarElement.SHOW_VIEWS;
@@ -50,6 +55,11 @@ public class S3GlueGrammarElementValidator extends DenyListGrammarElementValidat
5055
HINTS,
5156
INLINE_TABLE,
5257
FILE,
58+
CROSS_JOIN,
59+
LEFT_SEMI_JOIN,
60+
RIGHT_OUTER_JOIN,
61+
FULL_OUTER_JOIN,
62+
LEFT_ANTI_JOIN,
5363
TABLESAMPLE,
5464
TABLE_VALUED_FUNCTION,
5565
TRANSFORM,

async-query-core/src/main/java/org/opensearch/sql/spark/validator/SQLQueryValidationVisitor.java

-28
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,12 @@
99
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser;
1010
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser.AddTableColumnsContext;
1111
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser.AddTablePartitionContext;
12-
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser.AlterClusterByContext;
1312
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser.AlterTableAlterColumnContext;
1413
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser.AlterViewQueryContext;
15-
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser.AlterViewSchemaBindingContext;
1614
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser.AnalyzeContext;
1715
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser.AnalyzeTablesContext;
1816
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser.CacheTableContext;
1917
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser.ClearCacheContext;
20-
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser.ClusterBySpecContext;
2118
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser.CreateNamespaceContext;
2219
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser.CreateTableContext;
2320
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser.CreateTableLikeContext;
@@ -81,7 +78,6 @@
8178
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser.TransformClauseContext;
8279
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser.TruncateTableContext;
8380
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser.UncacheTableContext;
84-
import org.opensearch.sql.spark.antlr.parser.SqlBaseParser.UnsetNamespacePropertiesContext;
8581
import org.opensearch.sql.spark.antlr.parser.SqlBaseParserBaseVisitor;
8682

8783
/** This visitor validate grammar using GrammarElementValidator */
@@ -101,12 +97,6 @@ public Void visitSetNamespaceProperties(SetNamespacePropertiesContext ctx) {
10197
return super.visitSetNamespaceProperties(ctx);
10298
}
10399

104-
@Override
105-
public Void visitUnsetNamespaceProperties(UnsetNamespacePropertiesContext ctx) {
106-
validateAllowed(GrammarElement.ALTER_NAMESPACE);
107-
return super.visitUnsetNamespaceProperties(ctx);
108-
}
109-
110100
@Override
111101
public Void visitAddTableColumns(AddTableColumnsContext ctx) {
112102
validateAllowed(GrammarElement.ALTER_NAMESPACE);
@@ -173,12 +163,6 @@ public Void visitRecoverPartitions(RecoverPartitionsContext ctx) {
173163
return super.visitRecoverPartitions(ctx);
174164
}
175165

176-
@Override
177-
public Void visitAlterClusterBy(AlterClusterByContext ctx) {
178-
validateAllowed(GrammarElement.ALTER_NAMESPACE);
179-
return super.visitAlterClusterBy(ctx);
180-
}
181-
182166
@Override
183167
public Void visitSetNamespaceLocation(SetNamespaceLocationContext ctx) {
184168
validateAllowed(GrammarElement.ALTER_NAMESPACE);
@@ -191,12 +175,6 @@ public Void visitAlterViewQuery(AlterViewQueryContext ctx) {
191175
return super.visitAlterViewQuery(ctx);
192176
}
193177

194-
@Override
195-
public Void visitAlterViewSchemaBinding(AlterViewSchemaBindingContext ctx) {
196-
validateAllowed(GrammarElement.ALTER_VIEW);
197-
return super.visitAlterViewSchemaBinding(ctx);
198-
}
199-
200178
@Override
201179
public Void visitRenameTable(RenameTableContext ctx) {
202180
if (ctx.VIEW() != null) {
@@ -337,12 +315,6 @@ public Void visitCtes(CtesContext ctx) {
337315
return super.visitCtes(ctx);
338316
}
339317

340-
@Override
341-
public Void visitClusterBySpec(ClusterBySpecContext ctx) {
342-
validateAllowed(GrammarElement.CLUSTER_BY);
343-
return super.visitClusterBySpec(ctx);
344-
}
345-
346318
@Override
347319
public Void visitQueryOrganization(QueryOrganizationContext ctx) {
348320
if (ctx.CLUSTER() != null) {

async-query-core/src/main/java/org/opensearch/sql/spark/validator/SecurityLakeGrammarElementValidator.java

+10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import static org.opensearch.sql.spark.validator.GrammarElement.CREATE_FUNCTION;
1515
import static org.opensearch.sql.spark.validator.GrammarElement.CREATE_NAMESPACE;
1616
import static org.opensearch.sql.spark.validator.GrammarElement.CREATE_VIEW;
17+
import static org.opensearch.sql.spark.validator.GrammarElement.CROSS_JOIN;
1718
import static org.opensearch.sql.spark.validator.GrammarElement.CSV_FUNCTIONS;
1819
import static org.opensearch.sql.spark.validator.GrammarElement.DESCRIBE_FUNCTION;
1920
import static org.opensearch.sql.spark.validator.GrammarElement.DESCRIBE_NAMESPACE;
@@ -24,9 +25,12 @@
2425
import static org.opensearch.sql.spark.validator.GrammarElement.DROP_NAMESPACE;
2526
import static org.opensearch.sql.spark.validator.GrammarElement.DROP_VIEW;
2627
import static org.opensearch.sql.spark.validator.GrammarElement.FILE;
28+
import static org.opensearch.sql.spark.validator.GrammarElement.FULL_OUTER_JOIN;
2729
import static org.opensearch.sql.spark.validator.GrammarElement.HINTS;
2830
import static org.opensearch.sql.spark.validator.GrammarElement.INLINE_TABLE;
2931
import static org.opensearch.sql.spark.validator.GrammarElement.INSERT;
32+
import static org.opensearch.sql.spark.validator.GrammarElement.LEFT_ANTI_JOIN;
33+
import static org.opensearch.sql.spark.validator.GrammarElement.LEFT_SEMI_JOIN;
3034
import static org.opensearch.sql.spark.validator.GrammarElement.LOAD;
3135
import static org.opensearch.sql.spark.validator.GrammarElement.MANAGE_RESOURCE;
3236
import static org.opensearch.sql.spark.validator.GrammarElement.MISC_FUNCTIONS;
@@ -35,6 +39,7 @@
3539
import static org.opensearch.sql.spark.validator.GrammarElement.REFRESH_TABLE;
3640
import static org.opensearch.sql.spark.validator.GrammarElement.REPAIR_TABLE;
3741
import static org.opensearch.sql.spark.validator.GrammarElement.RESET;
42+
import static org.opensearch.sql.spark.validator.GrammarElement.RIGHT_OUTER_JOIN;
3843
import static org.opensearch.sql.spark.validator.GrammarElement.SET;
3944
import static org.opensearch.sql.spark.validator.GrammarElement.SHOW_COLUMNS;
4045
import static org.opensearch.sql.spark.validator.GrammarElement.SHOW_CREATE_TABLE;
@@ -76,6 +81,11 @@ public class SecurityLakeGrammarElementValidator extends DenyListGrammarElementV
7681
HINTS,
7782
INLINE_TABLE,
7883
FILE,
84+
CROSS_JOIN,
85+
LEFT_SEMI_JOIN,
86+
RIGHT_OUTER_JOIN,
87+
FULL_OUTER_JOIN,
88+
LEFT_ANTI_JOIN,
7989
TABLESAMPLE,
8090
TABLE_VALUED_FUNCTION,
8191
TRANSFORM,

async-query-core/src/test/java/org/opensearch/sql/spark/validator/SQLQueryValidatorTest.java

+12-17
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,9 @@ private enum TestElement {
3434
// DDL Statements
3535
ALTER_DATABASE(
3636
"ALTER DATABASE inventory SET DBPROPERTIES ('Edit-date' = '01/01/2001');",
37-
"ALTER DATABASE dbx.tab1 UNSET PROPERTIES ('winner');",
3837
"ALTER DATABASE dbx.tab1 SET LOCATION '/path/to/part/ways';"),
3938
ALTER_TABLE(
4039
"ALTER TABLE default.StudentInfo PARTITION (age='10') RENAME TO PARTITION (age='15');",
41-
"ALTER TABLE dbx.tab1 UNSET TBLPROPERTIES ('winner');",
4240
"ALTER TABLE StudentInfo ADD columns (LastName string, DOB timestamp);",
4341
"ALTER TABLE StudentInfo ADD IF NOT EXISTS PARTITION (age=18);",
4442
"ALTER TABLE StudentInfo RENAME COLUMN name TO FirstName;",
@@ -50,12 +48,10 @@ private enum TestElement {
5048
"ALTER TABLE StudentInfo DROP IF EXISTS PARTITION (age=18);",
5149
"ALTER TABLE dbx.tab1 PARTITION (a='1', b='2') SET LOCATION '/path/to/part/ways';",
5250
"ALTER TABLE dbx.tab1 RECOVER PARTITIONS;",
53-
"ALTER TABLE dbx.tab1 CLUSTER BY NONE;",
5451
"ALTER TABLE dbx.tab1 SET LOCATION '/path/to/part/ways';"),
5552
ALTER_VIEW(
5653
"ALTER VIEW tempdb1.v1 RENAME TO tempdb1.v2;",
57-
"ALTER VIEW tempdb1.v2 AS SELECT * FROM tempdb1.v1;",
58-
"ALTER VIEW tempdb1.v2 WITH SCHEMA BINDING"),
54+
"ALTER VIEW tempdb1.v2 AS SELECT * FROM tempdb1.v1;"),
5955
CREATE_DATABASE("CREATE DATABASE IF NOT EXISTS customer_db;\n"),
6056
CREATE_FUNCTION("CREATE FUNCTION simple_udf AS 'SimpleUdf' USING JAR '/tmp/SimpleUdf.jar';"),
6157
CREATE_TABLE(
@@ -94,8 +90,7 @@ private enum TestElement {
9490
EXPLAIN("EXPLAIN SELECT * FROM my_table;"),
9591
COMMON_TABLE_EXPRESSION(
9692
"WITH cte AS (SELECT * FROM my_table WHERE age > 30) SELECT * FROM cte;"),
97-
CLUSTER_BY_CLAUSE(
98-
"SELECT * FROM my_table CLUSTER BY age;", "ALTER TABLE testTable CLUSTER BY (age);"),
93+
CLUSTER_BY_CLAUSE("SELECT * FROM my_table CLUSTER BY age;"),
9994
DISTRIBUTE_BY_CLAUSE("SELECT * FROM my_table DISTRIBUTE BY name;"),
10095
GROUP_BY_CLAUSE("SELECT name, count(*) FROM my_table GROUP BY name;"),
10196
HAVING_CLAUSE("SELECT name, count(*) FROM my_table GROUP BY name HAVING count(*) > 1;"),
@@ -370,12 +365,12 @@ void testS3glueQueries() {
370365
v.ng(TestElement.INLINE_TABLE);
371366
v.ng(TestElement.FILE);
372367
v.ok(TestElement.INNER_JOIN);
373-
v.ok(TestElement.CROSS_JOIN);
368+
v.ng(TestElement.CROSS_JOIN);
374369
v.ok(TestElement.LEFT_OUTER_JOIN);
375-
v.ok(TestElement.LEFT_SEMI_JOIN);
376-
v.ok(TestElement.RIGHT_OUTER_JOIN);
377-
v.ok(TestElement.FULL_OUTER_JOIN);
378-
v.ok(TestElement.LEFT_ANTI_JOIN);
370+
v.ng(TestElement.LEFT_SEMI_JOIN);
371+
v.ng(TestElement.RIGHT_OUTER_JOIN);
372+
v.ng(TestElement.FULL_OUTER_JOIN);
373+
v.ng(TestElement.LEFT_ANTI_JOIN);
379374
v.ok(TestElement.LIKE_PREDICATE);
380375
v.ok(TestElement.LIMIT_CLAUSE);
381376
v.ok(TestElement.OFFSET_CLAUSE);
@@ -487,12 +482,12 @@ void testSecurityLakeQueries() {
487482
v.ng(TestElement.INLINE_TABLE);
488483
v.ng(TestElement.FILE);
489484
v.ok(TestElement.INNER_JOIN);
490-
v.ok(TestElement.CROSS_JOIN);
485+
v.ng(TestElement.CROSS_JOIN);
491486
v.ok(TestElement.LEFT_OUTER_JOIN);
492-
v.ok(TestElement.LEFT_SEMI_JOIN);
493-
v.ok(TestElement.RIGHT_OUTER_JOIN);
494-
v.ok(TestElement.FULL_OUTER_JOIN);
495-
v.ok(TestElement.LEFT_ANTI_JOIN);
487+
v.ng(TestElement.LEFT_SEMI_JOIN);
488+
v.ng(TestElement.RIGHT_OUTER_JOIN);
489+
v.ng(TestElement.FULL_OUTER_JOIN);
490+
v.ng(TestElement.LEFT_ANTI_JOIN);
496491
v.ok(TestElement.LIKE_PREDICATE);
497492
v.ok(TestElement.LIMIT_CLAUSE);
498493
v.ok(TestElement.OFFSET_CLAUSE);

0 commit comments

Comments
 (0)