Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update grammar validation settings #3165

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ public enum GrammarElement {

// Functions
MAP_FUNCTIONS("Map functions"),
BITWISE_FUNCTIONS("Bitwise functions"),
CSV_FUNCTIONS("CSV functions"),
GENERATOR_FUNCTIONS("Generator functions"),
MISC_FUNCTIONS("Misc functions"),

// UDF
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package org.opensearch.sql.spark.validator;

import static org.opensearch.sql.spark.validator.GrammarElement.ALTER_VIEW;
import static org.opensearch.sql.spark.validator.GrammarElement.BITWISE_FUNCTIONS;
import static org.opensearch.sql.spark.validator.GrammarElement.CLUSTER_BY;
import static org.opensearch.sql.spark.validator.GrammarElement.CREATE_FUNCTION;
import static org.opensearch.sql.spark.validator.GrammarElement.CREATE_VIEW;
Expand Down Expand Up @@ -71,6 +72,7 @@ public class S3GlueGrammarElementValidator extends DenyListGrammarElementValidat
SET,
SHOW_FUNCTIONS,
SHOW_VIEWS,
BITWISE_FUNCTIONS,
MISC_FUNCTIONS,
UDF)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,12 +561,18 @@ private void validateFunctionAllowed(String function) {
case MAP:
validateAllowed(GrammarElement.MAP_FUNCTIONS);
break;
case BITWISE:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we need to keep adding case and there is no way to convert function to grammar element?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can have a map if we want. Let me try that approach.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me go ahead with the current approach for now, I found some test case conflict if I enable validation for all the function types.

validateAllowed(GrammarElement.BITWISE_FUNCTIONS);
break;
case CSV:
validateAllowed(GrammarElement.CSV_FUNCTIONS);
break;
case MISC:
validateAllowed(GrammarElement.MISC_FUNCTIONS);
break;
case GENERATOR:
validateAllowed(GrammarElement.GENERATOR_FUNCTIONS);
break;
case UDF:
validateAllowed(GrammarElement.UDF);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ void testDenyAllValidator() {
v.ok(TestElement.JSON_FUNCTIONS);
v.ok(TestElement.MATHEMATICAL_FUNCTIONS);
v.ok(TestElement.STRING_FUNCTIONS);
v.ok(TestElement.BITWISE_FUNCTIONS);
v.ng(TestElement.BITWISE_FUNCTIONS);
v.ok(TestElement.CONVERSION_FUNCTIONS);
v.ok(TestElement.CONDITIONAL_FUNCTIONS);
v.ok(TestElement.PREDICATE_FUNCTIONS);
Expand All @@ -321,7 +321,7 @@ void testDenyAllValidator() {
v.ok(TestElement.WINDOW_FUNCTIONS);

// Generator Functions
v.ok(TestElement.GENERATOR_FUNCTIONS);
v.ng(TestElement.GENERATOR_FUNCTIONS);

// UDFs
v.ng(TestElement.SCALAR_USER_DEFINED_FUNCTIONS);
Expand Down Expand Up @@ -426,7 +426,7 @@ void testS3glueQueries() {
v.ok(TestElement.JSON_FUNCTIONS);
v.ok(TestElement.MATHEMATICAL_FUNCTIONS);
v.ok(TestElement.STRING_FUNCTIONS);
v.ok(TestElement.BITWISE_FUNCTIONS);
v.ng(TestElement.BITWISE_FUNCTIONS);
v.ok(TestElement.CONVERSION_FUNCTIONS);
v.ok(TestElement.CONDITIONAL_FUNCTIONS);
v.ok(TestElement.PREDICATE_FUNCTIONS);
Expand Down
Loading