Skip to content

Commit f414ef9

Browse files
committed
Add uncategorized functions to SQL query validator
Signed-off-by: Tomoyuki Morita <moritato@amazon.com>
1 parent 82eebce commit f414ef9

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package org.opensearch.sql.spark.validator;
77

88
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
9+
import static org.junit.jupiter.api.Assertions.assertEquals;
910
import static org.junit.jupiter.api.Assertions.assertThrows;
1011
import static org.mockito.ArgumentMatchers.any;
1112
import static org.mockito.Mockito.when;
@@ -192,15 +193,14 @@ private enum TestElement {
192193
// Generator Functions
193194
GENERATOR_FUNCTIONS("SELECT explode(array(1, 2, 3));"),
194195

195-
// UNCATEGORIZED functions
196+
// Ucategorized functions
196197
NAMED_STRUCT("SELECT named_struct('a', 1);"),
197-
PARSE_URL("SELECT parse_url(url) FROM my_table;");
198+
PARSE_URL("SELECT parse_url(url) FROM my_table;"),
198199

199200
// UDFs (User-Defined Functions)
200201
SCALAR_USER_DEFINED_FUNCTIONS("SELECT my_udf(name) FROM my_table;"),
201202
USER_DEFINED_AGGREGATE_FUNCTIONS("SELECT my_udaf(age) FROM my_table GROUP BY name;"),
202-
INTEGRATION_WITH_HIVE_UDFS_UDAFS_UDTFS("SELECT my_hive_udf(name) FROM my_table;"),
203-
;
203+
INTEGRATION_WITH_HIVE_UDFS_UDAFS_UDTFS("SELECT my_hive_udf(name) FROM my_table;");
204204

205205
@Getter private final String[] queries;
206206

@@ -328,14 +328,14 @@ void testDenyAllValidator() {
328328
// Generator Functions
329329
v.ng(TestElement.GENERATOR_FUNCTIONS);
330330

331+
// Uncategorized Functions
332+
v.ng(TestElement.NAMED_STRUCT);
333+
v.ng(TestElement.PARSE_URL);
334+
331335
// UDFs
332336
v.ng(TestElement.SCALAR_USER_DEFINED_FUNCTIONS);
333337
v.ng(TestElement.USER_DEFINED_AGGREGATE_FUNCTIONS);
334338
v.ng(TestElement.INTEGRATION_WITH_HIVE_UDFS_UDAFS_UDTFS);
335-
336-
// UNSUPPORTED Functions
337-
v.ng(TestElement.NAMED_STRUCT);
338-
v.ng(TestElement.PARSE_URL);
339339
}
340340

341341
@Test
@@ -450,8 +450,8 @@ void testS3glueQueries() {
450450
v.ok(TestElement.GENERATOR_FUNCTIONS);
451451

452452
// Uncategorized Functions
453-
v.ng(TestElement.NAMED_STRUCT);
454-
v.ng(TestElement.PARSE_URL);
453+
v.ok(TestElement.NAMED_STRUCT);
454+
v.ok(TestElement.PARSE_URL);
455455

456456
// UDFs
457457
v.ng(TestElement.SCALAR_USER_DEFINED_FUNCTIONS);
@@ -636,11 +636,10 @@ void testUnsupportedHiveNativeCommand() {
636636

637637
@Test
638638
void testException() {
639-
when(mockedProvider.getValidatorForDatasource(any()))
640-
.thenReturn(new S3GlueSQLGrammarElementValidator());
639+
when(mockedProvider.getValidatorForDatasource(any())).thenReturn(element -> false);
641640
VerifyValidator v = new VerifyValidator(sqlQueryValidator, DataSourceType.S3GLUE);
642641

643-
v.ng("SELECT named_struct('a', 1);", "Uncategorized function (named_struct) is not supported.");
642+
v.ng("SELECT named_struct('a', 1);", "Uncategorized functions (named_struct) is not allowed.");
644643
}
645644

646645
@AllArgsConstructor
@@ -668,10 +667,11 @@ public void ng(String query) {
668667
}
669668

670669
public void ng(String query, String expectedMessage) {
671-
Exception e = assertThrows(
672-
IllegalArgumentException.class,
673-
() -> runValidate(query),
674-
"The query should throw: query=`" + query.toString() + "`");
670+
Exception e =
671+
assertThrows(
672+
IllegalArgumentException.class,
673+
() -> runValidate(query),
674+
"The query should throw: query=`" + query.toString() + "`");
675675
assertEquals(expectedMessage, e.getMessage());
676676
}
677677

0 commit comments

Comments
 (0)