From 500c554eb1d42abc343da325b7f91a25fc11f138 Mon Sep 17 00:00:00 2001 From: forestmvey Date: Wed, 1 Jun 2022 12:10:34 -0700 Subject: [PATCH] Fixing compilation errors, checkstyle errors, and code coverage Signed-off-by: forestmvey --- .../semantic/SemanticAnalyzerBasicTest.java | 102 +++++++++--------- .../antlr/semantic/scope/EnvironmentTest.java | 2 +- .../lucene/MatchBoolPrefixQueryTest.java | 37 ++++--- .../sql/antlr/MatchBoolPrefixParserTest.java | 19 ++-- 4 files changed, 87 insertions(+), 73 deletions(-) diff --git a/legacy/src/test/java/org/opensearch/sql/legacy/antlr/semantic/SemanticAnalyzerBasicTest.java b/legacy/src/test/java/org/opensearch/sql/legacy/antlr/semantic/SemanticAnalyzerBasicTest.java index 22400f84be..f2c4aafbfe 100644 --- a/legacy/src/test/java/org/opensearch/sql/legacy/antlr/semantic/SemanticAnalyzerBasicTest.java +++ b/legacy/src/test/java/org/opensearch/sql/legacy/antlr/semantic/SemanticAnalyzerBasicTest.java @@ -61,7 +61,7 @@ public void contextShouldIncludeAllFieldsAfterVisitingIndexNameInFromClause() { typeByName, allOf( aMapWithSize(21), - hasEntry("semantics", new OpenSearchIndex("semantics", INDEX)), + hasEntry("semantics", (Type) new OpenSearchIndex("semantics", INDEX)), hasEntry("address", TEXT), hasEntry("age", INTEGER), hasEntry("balance", DOUBLE), @@ -72,10 +72,10 @@ public void contextShouldIncludeAllFieldsAfterVisitingIndexNameInFromClause() { hasEntry("field with spaces", TEXT), hasEntry("employer", TEXT), hasEntry("employer.keyword", KEYWORD), - hasEntry("projects", new OpenSearchIndex("projects", NESTED_FIELD)), + hasEntry("projects", (Type) new OpenSearchIndex("projects", NESTED_FIELD)), hasEntry("projects.active", BOOLEAN), hasEntry("projects.release", DATE), - hasEntry("projects.members", new OpenSearchIndex("projects.members", NESTED_FIELD)), + hasEntry("projects.members", (Type) new OpenSearchIndex("projects.members", NESTED_FIELD)), hasEntry("projects.members.name", TEXT), hasEntry("manager", OBJECT), hasEntry("manager.name", TEXT), @@ -91,7 +91,7 @@ public void contextShouldIncludeAllFieldsAfterVisitingIndexNameInFromClause() { typeByName, allOf( aMapWithSize(41), - hasEntry("semantics", new OpenSearchIndex("semantics", INDEX)), + hasEntry("semantics", (Type) new OpenSearchIndex("semantics", INDEX)), hasEntry("address", TEXT), hasEntry("age", INTEGER), hasEntry("balance", DOUBLE), @@ -102,10 +102,10 @@ public void contextShouldIncludeAllFieldsAfterVisitingIndexNameInFromClause() { hasEntry("field with spaces", TEXT), hasEntry("employer", TEXT), hasEntry("employer.keyword", KEYWORD), - hasEntry("projects", new OpenSearchIndex("projects", NESTED_FIELD)), + hasEntry("projects", (Type) new OpenSearchIndex("projects", NESTED_FIELD)), hasEntry("projects.active", BOOLEAN), hasEntry("projects.release", DATE), - hasEntry("projects.members", new OpenSearchIndex("projects.members", NESTED_FIELD)), + hasEntry("projects.members", (Type) new OpenSearchIndex("projects.members", NESTED_FIELD)), hasEntry("projects.members.name", TEXT), hasEntry("manager", OBJECT), hasEntry("manager.name", TEXT), @@ -124,11 +124,11 @@ public void contextShouldIncludeAllFieldsAfterVisitingIndexNameInFromClause() { hasEntry("semantics.employer", TEXT), hasEntry("semantics.employer.keyword", KEYWORD), hasEntry("semantics.projects", - new OpenSearchIndex("semantics.projects", NESTED_FIELD)), + (Type) new OpenSearchIndex("semantics.projects", NESTED_FIELD)), hasEntry("semantics.projects.active", BOOLEAN), hasEntry("semantics.projects.release", DATE), hasEntry("semantics.projects.members", - new OpenSearchIndex("semantics.projects.members", NESTED_FIELD)), + (Type) new OpenSearchIndex("semantics.projects.members", NESTED_FIELD)), hasEntry("semantics.projects.members.name", TEXT), hasEntry("semantics.manager", OBJECT), hasEntry("semantics.manager.name", TEXT), @@ -150,7 +150,7 @@ public void contextShouldIncludeAllFieldsPrefixedByIndexAliasAfterVisitingIndexN typeByName, allOf( aMapWithSize(41), - hasEntry("semantics", indexType), + hasEntry("semantics", (Type) indexType), // These are also valid because alias is optional in SQL hasEntry("address", TEXT), hasEntry("age", INTEGER), @@ -162,10 +162,10 @@ public void contextShouldIncludeAllFieldsPrefixedByIndexAliasAfterVisitingIndexN hasEntry("field with spaces", TEXT), hasEntry("employer", TEXT), hasEntry("employer.keyword", KEYWORD), - hasEntry("projects", new OpenSearchIndex("projects", NESTED_FIELD)), + hasEntry("projects", (Type) new OpenSearchIndex("projects", NESTED_FIELD)), hasEntry("projects.active", BOOLEAN), hasEntry("projects.release", DATE), - hasEntry("projects.members", new OpenSearchIndex("projects.members", NESTED_FIELD)), + hasEntry("projects.members", (Type) new OpenSearchIndex("projects.members", NESTED_FIELD)), hasEntry("projects.members.name", TEXT), hasEntry("manager", OBJECT), hasEntry("manager.name", TEXT), @@ -183,11 +183,11 @@ public void contextShouldIncludeAllFieldsPrefixedByIndexAliasAfterVisitingIndexN hasEntry("s.field with spaces", TEXT), hasEntry("s.employer", TEXT), hasEntry("s.employer.keyword", KEYWORD), - hasEntry("s.projects", new OpenSearchIndex("s.projects", NESTED_FIELD)), + hasEntry("s.projects", (Type) new OpenSearchIndex("s.projects", NESTED_FIELD)), hasEntry("s.projects.active", BOOLEAN), hasEntry("s.projects.release", DATE), hasEntry("s.projects.members", - new OpenSearchIndex("s.projects.members", NESTED_FIELD)), + (Type) new OpenSearchIndex("s.projects.members", NESTED_FIELD)), hasEntry("s.projects.members.name", TEXT), hasEntry("s.manager", OBJECT), hasEntry("s.manager.name", TEXT), @@ -211,7 +211,7 @@ public void contextShouldIncludeSameFieldsAfterVisitingNestedFieldWithoutAliasIn typeByName, allOf( aMapWithSize(41), - hasEntry("semantics", indexType), + hasEntry("semantics", (Type) indexType), // These are also valid because alias is optional in SQL hasEntry("address", TEXT), hasEntry("age", INTEGER), @@ -223,10 +223,10 @@ public void contextShouldIncludeSameFieldsAfterVisitingNestedFieldWithoutAliasIn hasEntry("field with spaces", TEXT), hasEntry("employer", TEXT), hasEntry("employer.keyword", KEYWORD), - hasEntry("projects", new OpenSearchIndex("projects", NESTED_FIELD)), + hasEntry("projects", (Type) new OpenSearchIndex("projects", NESTED_FIELD)), hasEntry("projects.active", BOOLEAN), hasEntry("projects.release", DATE), - hasEntry("projects.members", new OpenSearchIndex("projects.members", NESTED_FIELD)), + hasEntry("projects.members", (Type) new OpenSearchIndex("projects.members", NESTED_FIELD)), hasEntry("projects.members.name", TEXT), hasEntry("manager", OBJECT), hasEntry("manager.name", TEXT), @@ -244,11 +244,11 @@ public void contextShouldIncludeSameFieldsAfterVisitingNestedFieldWithoutAliasIn hasEntry("s.field with spaces", TEXT), hasEntry("s.employer", TEXT), hasEntry("s.employer.keyword", KEYWORD), - hasEntry("s.projects", new OpenSearchIndex("s.projects", NESTED_FIELD)), + hasEntry("s.projects", (Type) new OpenSearchIndex("s.projects", NESTED_FIELD)), hasEntry("s.projects.active", BOOLEAN), hasEntry("s.projects.release", DATE), hasEntry("s.projects.members", - new OpenSearchIndex("s.projects.members", NESTED_FIELD)), + (Type)new OpenSearchIndex("s.projects.members", NESTED_FIELD)), hasEntry("s.projects.members.name", TEXT), hasEntry("s.manager", OBJECT), hasEntry("s.manager.name", TEXT), @@ -273,7 +273,7 @@ public void contextShouldIncludeMoreFieldsPrefixedByNestedFieldAliasAfterVisitin allOf( aMapWithSize(46), // These are also valid because alias is optional in SQL - hasEntry("semantics", indexType), + hasEntry("semantics", (Type) indexType), // These are also valid because alias is optional in SQL hasEntry("address", TEXT), hasEntry("age", INTEGER), @@ -285,10 +285,10 @@ public void contextShouldIncludeMoreFieldsPrefixedByNestedFieldAliasAfterVisitin hasEntry("field with spaces", TEXT), hasEntry("employer", TEXT), hasEntry("employer.keyword", KEYWORD), - hasEntry("projects", new OpenSearchIndex("projects", NESTED_FIELD)), + hasEntry("projects", (Type) new OpenSearchIndex("projects", NESTED_FIELD)), hasEntry("projects.active", BOOLEAN), hasEntry("projects.release", DATE), - hasEntry("projects.members", new OpenSearchIndex("projects.members", NESTED_FIELD)), + hasEntry("projects.members", (Type) new OpenSearchIndex("projects.members", NESTED_FIELD)), hasEntry("projects.members.name", TEXT), hasEntry("manager", OBJECT), hasEntry("manager.name", TEXT), @@ -306,11 +306,11 @@ public void contextShouldIncludeMoreFieldsPrefixedByNestedFieldAliasAfterVisitin hasEntry("s.field with spaces", TEXT), hasEntry("s.employer", TEXT), hasEntry("s.employer.keyword", KEYWORD), - hasEntry("s.projects", new OpenSearchIndex("s.projects", NESTED_FIELD)), + hasEntry("s.projects", (Type) new OpenSearchIndex("s.projects", NESTED_FIELD)), hasEntry("s.projects.active", BOOLEAN), hasEntry("s.projects.release", DATE), hasEntry("s.projects.members", - new OpenSearchIndex("s.projects.members", NESTED_FIELD)), + (Type) new OpenSearchIndex("s.projects.members", NESTED_FIELD)), hasEntry("s.projects.members.name", TEXT), hasEntry("s.manager", OBJECT), hasEntry("s.manager.name", TEXT), @@ -318,10 +318,10 @@ public void contextShouldIncludeMoreFieldsPrefixedByNestedFieldAliasAfterVisitin hasEntry("s.manager.address", KEYWORD), hasEntry("s.manager.salary", LONG), // Valid because of nested field alias specified - hasEntry("p", new OpenSearchIndex("s.projects", NESTED_FIELD)), + hasEntry("p", (Type) new OpenSearchIndex("s.projects", NESTED_FIELD)), hasEntry("p.active", BOOLEAN), hasEntry("p.release", DATE), - hasEntry("p.members", new OpenSearchIndex("s.projects.members", NESTED_FIELD)), + hasEntry("p.members", (Type) new OpenSearchIndex("s.projects.members", NESTED_FIELD)), hasEntry("p.members.name", TEXT) ) ); @@ -341,7 +341,7 @@ public void contextShouldIncludeMoreFieldsPrefixedByNestedFieldAliasAfterVisitin typeByName, allOf( aMapWithSize(43), - hasEntry("semantics", indexType), + hasEntry("semantics", (Type) indexType), // These are also valid because alias is optional in SQL hasEntry("address", TEXT), hasEntry("age", INTEGER), @@ -353,10 +353,10 @@ public void contextShouldIncludeMoreFieldsPrefixedByNestedFieldAliasAfterVisitin hasEntry("field with spaces", TEXT), hasEntry("employer", TEXT), hasEntry("employer.keyword", KEYWORD), - hasEntry("projects", new OpenSearchIndex("projects", NESTED_FIELD)), + hasEntry("projects", (Type) new OpenSearchIndex("projects", NESTED_FIELD)), hasEntry("projects.active", BOOLEAN), hasEntry("projects.release", DATE), - hasEntry("projects.members", new OpenSearchIndex("projects.members", NESTED_FIELD)), + hasEntry("projects.members", (Type) new OpenSearchIndex("projects.members", NESTED_FIELD)), hasEntry("projects.members.name", TEXT), hasEntry("manager", OBJECT), hasEntry("manager.name", TEXT), @@ -374,11 +374,11 @@ public void contextShouldIncludeMoreFieldsPrefixedByNestedFieldAliasAfterVisitin hasEntry("s.field with spaces", TEXT), hasEntry("s.employer", TEXT), hasEntry("s.employer.keyword", KEYWORD), - hasEntry("s.projects", new OpenSearchIndex("s.projects", NESTED_FIELD)), + hasEntry("s.projects", (Type) new OpenSearchIndex("s.projects", NESTED_FIELD)), hasEntry("s.projects.active", BOOLEAN), hasEntry("s.projects.release", DATE), hasEntry("s.projects.members", - new OpenSearchIndex("s.projects.members", NESTED_FIELD)), + (Type) new OpenSearchIndex("s.projects.members", NESTED_FIELD)), hasEntry("s.projects.members.name", TEXT), hasEntry("s.manager", OBJECT), hasEntry("s.manager.name", TEXT), @@ -386,7 +386,7 @@ public void contextShouldIncludeMoreFieldsPrefixedByNestedFieldAliasAfterVisitin hasEntry("s.manager.address", KEYWORD), hasEntry("s.manager.salary", LONG), // Valid because of deep nested field alias specified - hasEntry("m", new OpenSearchIndex("s.projects.members", NESTED_FIELD)), + hasEntry("m", (Type) new OpenSearchIndex("s.projects.members", NESTED_FIELD)), hasEntry("m.name", TEXT) ) ); @@ -407,7 +407,7 @@ public void contextShouldIncludeMoreFieldsPrefixedByNestedFieldAliasAfterVisitin typeByName, allOf( aMapWithSize(48), - hasEntry("semantics", indexType), + hasEntry("semantics", (Type) indexType), // These are also valid because alias is optional in SQL hasEntry("address", TEXT), hasEntry("age", INTEGER), @@ -419,10 +419,10 @@ public void contextShouldIncludeMoreFieldsPrefixedByNestedFieldAliasAfterVisitin hasEntry("field with spaces", TEXT), hasEntry("employer", TEXT), hasEntry("employer.keyword", KEYWORD), - hasEntry("projects", new OpenSearchIndex("projects", NESTED_FIELD)), + hasEntry("projects", (Type) new OpenSearchIndex("projects", NESTED_FIELD)), hasEntry("projects.active", BOOLEAN), hasEntry("projects.release", DATE), - hasEntry("projects.members", new OpenSearchIndex("projects.members", NESTED_FIELD)), + hasEntry("projects.members", (Type) new OpenSearchIndex("projects.members", NESTED_FIELD)), hasEntry("projects.members.name", TEXT), hasEntry("manager", OBJECT), hasEntry("manager.name", TEXT), @@ -440,11 +440,11 @@ public void contextShouldIncludeMoreFieldsPrefixedByNestedFieldAliasAfterVisitin hasEntry("s.field with spaces", TEXT), hasEntry("s.employer", TEXT), hasEntry("s.employer.keyword", KEYWORD), - hasEntry("s.projects", new OpenSearchIndex("s.projects", NESTED_FIELD)), + hasEntry("s.projects", (Type) new OpenSearchIndex("s.projects", NESTED_FIELD)), hasEntry("s.projects.active", BOOLEAN), hasEntry("s.projects.release", DATE), hasEntry("s.projects.members", - new OpenSearchIndex("s.projects.members", NESTED_FIELD)), + (Type) new OpenSearchIndex("s.projects.members", NESTED_FIELD)), hasEntry("s.projects.members.name", TEXT), hasEntry("s.manager", OBJECT), hasEntry("s.manager.name", TEXT), @@ -452,13 +452,13 @@ public void contextShouldIncludeMoreFieldsPrefixedByNestedFieldAliasAfterVisitin hasEntry("s.manager.address", KEYWORD), hasEntry("s.manager.salary", LONG), // Valid because of nested field alias specified - hasEntry("p", new OpenSearchIndex("s.projects", NESTED_FIELD)), + hasEntry("p", (Type) new OpenSearchIndex("s.projects", NESTED_FIELD)), hasEntry("p.active", BOOLEAN), hasEntry("p.release", DATE), - hasEntry("p.members", new OpenSearchIndex("s.projects.members", NESTED_FIELD)), + hasEntry("p.members", (Type) new OpenSearchIndex("s.projects.members", NESTED_FIELD)), hasEntry("p.members.name", TEXT), // Valid because of deep nested field alias specified - hasEntry("m", new OpenSearchIndex("s.projects.members", NESTED_FIELD)), + hasEntry("m", (Type) new OpenSearchIndex("s.projects.members", NESTED_FIELD)), hasEntry("m.name", TEXT) ) ); @@ -480,7 +480,7 @@ public void contextShouldIncludeMoreFieldsPrefixedByNestedFieldAliasAfterVisitin allOf( aMapWithSize(46), // These are also valid because alias is optional in SQL - hasEntry("semantics", indexType), + hasEntry("semantics", (Type) indexType), // These are also valid because alias is optional in SQL hasEntry("address", TEXT), hasEntry("age", INTEGER), @@ -492,10 +492,10 @@ public void contextShouldIncludeMoreFieldsPrefixedByNestedFieldAliasAfterVisitin hasEntry("field with spaces", TEXT), hasEntry("employer", TEXT), hasEntry("employer.keyword", KEYWORD), - hasEntry("projects", new OpenSearchIndex("projects", NESTED_FIELD)), + hasEntry("projects", (Type) new OpenSearchIndex("projects", NESTED_FIELD)), hasEntry("projects.active", BOOLEAN), hasEntry("projects.release", DATE), - hasEntry("projects.members", new OpenSearchIndex("projects.members", NESTED_FIELD)), + hasEntry("projects.members", (Type) new OpenSearchIndex("projects.members", NESTED_FIELD)), hasEntry("projects.members.name", TEXT), hasEntry("manager", OBJECT), hasEntry("manager.name", TEXT), @@ -513,11 +513,11 @@ public void contextShouldIncludeMoreFieldsPrefixedByNestedFieldAliasAfterVisitin hasEntry("s.field with spaces", TEXT), hasEntry("s.employer", TEXT), hasEntry("s.employer.keyword", KEYWORD), - hasEntry("s.projects", new OpenSearchIndex("s.projects", NESTED_FIELD)), + hasEntry("s.projects", (Type) new OpenSearchIndex("s.projects", NESTED_FIELD)), hasEntry("s.projects.active", BOOLEAN), hasEntry("s.projects.release", DATE), hasEntry("s.projects.members", - new OpenSearchIndex("s.projects.members", NESTED_FIELD)), + (Type) new OpenSearchIndex("s.projects.members", NESTED_FIELD)), hasEntry("s.projects.members.name", TEXT), hasEntry("s.manager", OBJECT), hasEntry("s.manager.name", TEXT), @@ -525,10 +525,10 @@ public void contextShouldIncludeMoreFieldsPrefixedByNestedFieldAliasAfterVisitin hasEntry("s.manager.address", KEYWORD), hasEntry("s.manager.salary", LONG), // Valid because of nested field alias specified - hasEntry("p", new OpenSearchIndex("s.projects", NESTED_FIELD)), + hasEntry("p", (Type) new OpenSearchIndex("s.projects", NESTED_FIELD)), hasEntry("p.active", BOOLEAN), hasEntry("p.release", DATE), - hasEntry("p.members", new OpenSearchIndex("s.projects.members", NESTED_FIELD)), + hasEntry("p.members", (Type) new OpenSearchIndex("s.projects.members", NESTED_FIELD)), hasEntry("p.members.name", TEXT) ) ); @@ -539,7 +539,7 @@ public void contextShouldIncludeMoreFieldsPrefixedByNestedFieldAliasAfterVisitin typeByName, allOf( aMapWithSize(41), - hasEntry("semantics", indexType), + hasEntry("semantics", (Type) indexType), // These are also valid because alias is optional in SQL hasEntry("address", TEXT), hasEntry("age", INTEGER), @@ -551,10 +551,10 @@ public void contextShouldIncludeMoreFieldsPrefixedByNestedFieldAliasAfterVisitin hasEntry("field with spaces", TEXT), hasEntry("employer", TEXT), hasEntry("employer.keyword", KEYWORD), - hasEntry("projects", new OpenSearchIndex("projects", NESTED_FIELD)), + hasEntry("projects", (Type) new OpenSearchIndex("projects", NESTED_FIELD)), hasEntry("projects.active", BOOLEAN), hasEntry("projects.release", DATE), - hasEntry("projects.members", new OpenSearchIndex("projects.members", NESTED_FIELD)), + hasEntry("projects.members", (Type) new OpenSearchIndex("projects.members", NESTED_FIELD)), hasEntry("projects.members.name", TEXT), hasEntry("manager", OBJECT), hasEntry("manager.name", TEXT), @@ -572,11 +572,11 @@ public void contextShouldIncludeMoreFieldsPrefixedByNestedFieldAliasAfterVisitin hasEntry("s.field with spaces", TEXT), hasEntry("s.employer", TEXT), hasEntry("s.employer.keyword", KEYWORD), - hasEntry("s.projects", new OpenSearchIndex("s.projects", NESTED_FIELD)), + hasEntry("s.projects", (Type) new OpenSearchIndex("s.projects", NESTED_FIELD)), hasEntry("s.projects.active", BOOLEAN), hasEntry("s.projects.release", DATE), hasEntry("s.projects.members", - new OpenSearchIndex("s.projects.members", NESTED_FIELD)), + (Type) new OpenSearchIndex("s.projects.members", NESTED_FIELD)), hasEntry("s.projects.members.name", TEXT), hasEntry("s.manager", OBJECT), hasEntry("s.manager.name", TEXT), diff --git a/legacy/src/test/java/org/opensearch/sql/legacy/antlr/semantic/scope/EnvironmentTest.java b/legacy/src/test/java/org/opensearch/sql/legacy/antlr/semantic/scope/EnvironmentTest.java index 98796f5e71..d9e9271728 100644 --- a/legacy/src/test/java/org/opensearch/sql/legacy/antlr/semantic/scope/EnvironmentTest.java +++ b/legacy/src/test/java/org/opensearch/sql/legacy/antlr/semantic/scope/EnvironmentTest.java @@ -118,7 +118,7 @@ public void defineFieldSymbolShouldBeAbleToResolveAll() { typeByName, allOf( aMapWithSize(6), - hasEntry("s.projects", new OpenSearchIndex("s.projects", NESTED_FIELD)), + hasEntry("s.projects", (Type) new OpenSearchIndex("s.projects", NESTED_FIELD)), hasEntry("s.projects.release", DATE), hasEntry("s.projects.active", BOOLEAN), hasEntry("s.address", TEXT), diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/MatchBoolPrefixQueryTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/MatchBoolPrefixQueryTest.java index 6fa483528b..dda1a201be 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/MatchBoolPrefixQueryTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/MatchBoolPrefixQueryTest.java @@ -15,6 +15,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; +import org.opensearch.sql.common.antlr.SyntaxCheckException; import org.opensearch.sql.data.model.ExprValue; import org.opensearch.sql.data.type.ExprType; import org.opensearch.sql.exception.SemanticCheckException; @@ -25,13 +26,13 @@ import org.opensearch.sql.expression.config.ExpressionConfig; import org.opensearch.sql.expression.env.Environment; import org.opensearch.sql.expression.function.FunctionName; -import org.opensearch.sql.opensearch.storage.script.filter.lucene.relevance.MatchQuery; +import org.opensearch.sql.opensearch.storage.script.filter.lucene.relevance.MatchBoolPrefixQuery; @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) public class MatchBoolPrefixQueryTest { private final DSL dsl = new ExpressionConfig().dsl(new ExpressionConfig().functionRepository()); - private final MatchQuery matchQuery = new MatchQuery(); - private final FunctionName match = FunctionName.of("match_bool_prefix"); + private final MatchBoolPrefixQuery matchBoolPrefixQuery = new MatchBoolPrefixQuery(); + private final FunctionName matchBoolPrefix = FunctionName.of("match_bool_prefix"); static Stream> generateValidData() { final DSL dsl = new ExpressionConfig().dsl(new ExpressionConfig().functionRepository()); @@ -50,32 +51,40 @@ static Stream> generateValidData() { @ParameterizedTest @MethodSource("generateValidData") - public void test_valid_parameters(List validArgs) { - Assertions.assertNotNull(matchQuery.build(new MatchExpression(validArgs))); + public void test_valid_arguments(List validArgs) { + Assertions.assertNotNull(matchBoolPrefixQuery.build(new MatchExpression(validArgs))); } @Test - public void test_SemanticCheckException_when_no_arguments() { + public void test_valid_when_two_arguments() { + List arguments = List.of( + namedArgument("field", "field_value"), + namedArgument("query", "query_value")); + Assertions.assertNotNull(matchBoolPrefixQuery.build(new MatchExpression(arguments))); + } + + @Test + public void test_SyntaxCheckException_when_no_arguments() { List arguments = List.of(); - assertThrows(SemanticCheckException.class, - () -> matchQuery.build(new MatchExpression(arguments))); + assertThrows(SyntaxCheckException.class, + () -> matchBoolPrefixQuery.build(new MatchExpression(arguments))); } @Test - public void test_SemanticCheckException_when_one_argument() { + public void test_SyntaxCheckException_when_one_argument() { List arguments = List.of(namedArgument("field", "field_value")); - assertThrows(SemanticCheckException.class, - () -> matchQuery.build(new MatchExpression(arguments))); + assertThrows(SyntaxCheckException.class, + () -> matchBoolPrefixQuery.build(new MatchExpression(arguments))); } @Test - public void test_SemanticCheckException_when_invalid_parameter() { + public void test_SemanticCheckException_when_invalid_argument() { List arguments = List.of( namedArgument("field", "field_value"), namedArgument("query", "query_value"), namedArgument("unsupported", "unsupported_value")); Assertions.assertThrows(SemanticCheckException.class, - () -> matchQuery.build(new MatchExpression(arguments))); + () -> matchBoolPrefixQuery.build(new MatchExpression(arguments))); } private NamedArgumentExpression namedArgument(String name, String value) { @@ -84,7 +93,7 @@ private NamedArgumentExpression namedArgument(String name, String value) { private class MatchExpression extends FunctionExpression { public MatchExpression(List arguments) { - super(MatchBoolPrefixQueryTest.this.match, arguments); + super(MatchBoolPrefixQueryTest.this.matchBoolPrefix, arguments); } @Override diff --git a/sql/src/test/java/org/opensearch/sql/sql/antlr/MatchBoolPrefixParserTest.java b/sql/src/test/java/org/opensearch/sql/sql/antlr/MatchBoolPrefixParserTest.java index dfbc404a61..66c4d5be9d 100644 --- a/sql/src/test/java/org/opensearch/sql/sql/antlr/MatchBoolPrefixParserTest.java +++ b/sql/src/test/java/org/opensearch/sql/sql/antlr/MatchBoolPrefixParserTest.java @@ -1,32 +1,37 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + package org.opensearch.sql.sql.antlr; +import java.util.stream.Stream; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; -import java.util.stream.Stream; - public class MatchBoolPrefixParserTest extends SQLParserTest { @Test - public void testDefaultParameters() { + public void testDefaultArguments() { acceptQuery("SELECT * FROM T WHERE MATCH_BOOL_PREFIX(message, 'query')"); } - static Stream generateAvailableParameters() { + static Stream generateValidArguments() { return Stream.of( new String("minimum_should_match=3"), new String("fuzziness=AUTO"), new String("prefix_length=0"), new String("max_expansions=50"), new String("fuzzy_transpositions=true"), - new String("fuzzy_rewrite=constant_score") + new String("fuzzy_rewrite=constant_score"), + new String("boost=1") ); } @ParameterizedTest - @MethodSource("generateAvailableParameters") - public void testAvailableParameters(String arg) { + @MethodSource("generateValidArguments") + public void testValidArguments(String arg) { acceptQuery("SELECT * FROM T WHERE MATCH_BOOL_PREFIX(message, 'query', " + arg + ")"); }