From 72580ed8fc38003ee020c6f394b3fc0ce4c763b7 Mon Sep 17 00:00:00 2001 From: GabeFernandez310 Date: Mon, 21 Nov 2022 07:58:26 -0800 Subject: [PATCH] Made Adjustments To Tests Signed-off-by: GabeFernandez310 --- .../org/opensearch/sql/sql/MatchPhraseIT.java | 4 +-- .../filter/lucene/MatchPhraseQueryTest.java | 34 +++++++++---------- .../sql/sql/antlr/SQLSyntaxParserTest.java | 12 +------ 3 files changed, 20 insertions(+), 30 deletions(-) diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/MatchPhraseIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/MatchPhraseIT.java index 953edc6c21..b870a60604 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/MatchPhraseIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/MatchPhraseIT.java @@ -58,7 +58,7 @@ public void test_alternate_syntax_for_match_phrase_returns_same_result() throws JSONObject result1 = executeJdbcRequest(String.format(query1, TEST_INDEX_PHRASE)); JSONObject result2 = executeJdbcRequest(String.format(query2, TEST_INDEX_PHRASE)); JSONObject result3 = executeJdbcRequest(String.format(query3, TEST_INDEX_PHRASE)); - assertEquals(result1, result2); - assertEquals(result1, result3); + assertTrue(result1.similar(result2)); + assertTrue(result1.similar(result3)); } } diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/MatchPhraseQueryTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/MatchPhraseQueryTest.java index 040f024ee4..6a298326b7 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/MatchPhraseQueryTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/MatchPhraseQueryTest.java @@ -109,7 +109,7 @@ public void test_SyntaxCheckException_when_no_arguments_match_phrase_syntax() { List arguments = List.of(); assertThrows(SyntaxCheckException.class, () -> matchPhraseQuery.build(new MatchPhraseExpression( - arguments, MatchPhraseQueryTest.this.matchPhraseWithUnderscoreName))); + arguments, matchPhraseWithUnderscoreName))); } @Test @@ -117,7 +117,7 @@ public void test_SyntaxCheckException_when_one_argument_match_phrase_syntax() { List arguments = List.of(DSL.namedArgument("field", "test")); assertThrows(SyntaxCheckException.class, () -> matchPhraseQuery.build(new MatchPhraseExpression( - arguments, MatchPhraseQueryTest.this.matchPhraseWithUnderscoreName))); + arguments, matchPhraseWithUnderscoreName))); } @@ -129,7 +129,7 @@ public void test_SyntaxCheckException_when_invalid_parameter_match_phrase_syntax DSL.namedArgument("unsupported", "3")); Assertions.assertThrows(SemanticCheckException.class, () -> matchPhraseQuery.build(new MatchPhraseExpression( - arguments, MatchPhraseQueryTest.this.matchPhraseWithUnderscoreName))); + arguments, matchPhraseWithUnderscoreName))); } @Test @@ -140,7 +140,7 @@ public void test_analyzer_parameter_match_phrase_syntax() { DSL.namedArgument("analyzer", "standard") ); Assertions.assertNotNull(matchPhraseQuery.build(new MatchPhraseExpression( - arguments, MatchPhraseQueryTest.this.matchPhraseWithUnderscoreName))); + arguments, matchPhraseWithUnderscoreName))); } @Test @@ -149,7 +149,7 @@ public void build_succeeds_with_two_arguments_match_phrase_syntax() { DSL.namedArgument("field", "test"), DSL.namedArgument("query", "test2")); Assertions.assertNotNull(matchPhraseQuery.build(new MatchPhraseExpression( - arguments, MatchPhraseQueryTest.this.matchPhraseWithUnderscoreName))); + arguments, matchPhraseWithUnderscoreName))); } @Test @@ -160,7 +160,7 @@ public void test_slop_parameter_match_phrase_syntax() { DSL.namedArgument("slop", "2") ); Assertions.assertNotNull(matchPhraseQuery.build(new MatchPhraseExpression( - arguments, MatchPhraseQueryTest.this.matchPhraseWithUnderscoreName))); + arguments, matchPhraseWithUnderscoreName))); } @Test @@ -171,7 +171,7 @@ public void test_zero_terms_query_parameter_match_phrase_syntax() { DSL.namedArgument("zero_terms_query", "ALL") ); Assertions.assertNotNull(matchPhraseQuery.build(new MatchPhraseExpression( - arguments, MatchPhraseQueryTest.this.matchPhraseWithUnderscoreName))); + arguments, matchPhraseWithUnderscoreName))); } @Test @@ -182,7 +182,7 @@ public void test_zero_terms_query_parameter_lower_case_match_phrase_syntax() { DSL.namedArgument("zero_terms_query", "all") ); Assertions.assertNotNull(matchPhraseQuery.build(new MatchPhraseExpression( - arguments, MatchPhraseQueryTest.this.matchPhraseWithUnderscoreName))); + arguments, matchPhraseWithUnderscoreName))); } @Test @@ -190,7 +190,7 @@ public void test_SyntaxCheckException_when_no_arguments_matchphrase_syntax() { List arguments = List.of(); assertThrows(SyntaxCheckException.class, () -> matchPhraseQuery.build(new MatchPhraseExpression( - arguments, MatchPhraseQueryTest.this.matchPhraseQueryName))); + arguments, matchPhraseQueryName))); } @Test @@ -198,7 +198,7 @@ public void test_SyntaxCheckException_when_one_argument_matchphrase_syntax() { List arguments = List.of(DSL.namedArgument("field", "test")); assertThrows(SyntaxCheckException.class, () -> matchPhraseQuery.build(new MatchPhraseExpression( - arguments, MatchPhraseQueryTest.this.matchPhraseQueryName))); + arguments, matchPhraseQueryName))); } @@ -210,7 +210,7 @@ public void test_SyntaxCheckException_when_invalid_parameter_matchphrase_syntax( DSL.namedArgument("unsupported", "3")); Assertions.assertThrows(SemanticCheckException.class, () -> matchPhraseQuery.build(new MatchPhraseExpression( - arguments, MatchPhraseQueryTest.this.matchPhraseQueryName))); + arguments, matchPhraseQueryName))); } @Test @@ -221,7 +221,7 @@ public void test_analyzer_parameter_matchphrase_syntax() { DSL.namedArgument("analyzer", "standard") ); Assertions.assertNotNull(matchPhraseQuery.build(new MatchPhraseExpression( - arguments, MatchPhraseQueryTest.this.matchPhraseQueryName))); + arguments, matchPhraseQueryName))); } @Test @@ -230,7 +230,7 @@ public void build_succeeds_with_two_arguments_matchphrase_syntax() { DSL.namedArgument("field", "test"), DSL.namedArgument("query", "test2")); Assertions.assertNotNull(matchPhraseQuery.build(new MatchPhraseExpression( - arguments, MatchPhraseQueryTest.this.matchPhraseQueryName))); + arguments, matchPhraseQueryName))); } @Test @@ -241,7 +241,7 @@ public void test_slop_parameter_matchphrase_syntax() { DSL.namedArgument("slop", "2") ); Assertions.assertNotNull(matchPhraseQuery.build(new MatchPhraseExpression( - arguments, MatchPhraseQueryTest.this.matchPhraseQueryName))); + arguments, matchPhraseQueryName))); } @Test @@ -252,7 +252,7 @@ public void test_zero_terms_query_parameter_matchphrase_syntax() { DSL.namedArgument("zero_terms_query", "ALL") ); Assertions.assertNotNull(matchPhraseQuery.build(new MatchPhraseExpression( - arguments, MatchPhraseQueryTest.this.matchPhraseQueryName))); + arguments, matchPhraseQueryName))); } @Test @@ -263,12 +263,12 @@ public void test_zero_terms_query_parameter_lower_case_matchphrase_syntax() { DSL.namedArgument("zero_terms_query", "all") ); Assertions.assertNotNull(matchPhraseQuery.build(new MatchPhraseExpression( - arguments, MatchPhraseQueryTest.this.matchPhraseQueryName))); + arguments, matchPhraseQueryName))); } private class MatchPhraseExpression extends FunctionExpression { public MatchPhraseExpression(List arguments) { - super(MatchPhraseQueryTest.this.matchPhraseName, arguments); + super(matchPhraseName, arguments); } public MatchPhraseExpression(List arguments, FunctionName funcName) { diff --git a/sql/src/test/java/org/opensearch/sql/sql/antlr/SQLSyntaxParserTest.java b/sql/src/test/java/org/opensearch/sql/sql/antlr/SQLSyntaxParserTest.java index ea4b408d72..1d62278b73 100644 --- a/sql/src/test/java/org/opensearch/sql/sql/antlr/SQLSyntaxParserTest.java +++ b/sql/src/test/java/org/opensearch/sql/sql/antlr/SQLSyntaxParserTest.java @@ -391,8 +391,7 @@ public void can_parse_match_relevance_function() { "matchPhraseComplexQueries", "matchPhraseGeneratedQueries", "generateMatchPhraseQueries", - "matchPhraseQueryComplexQueries", - "generateMatchPhraseQueryQueries" + "matchPhraseQueryComplexQueries" }) public void canParseComplexMatchPhraseArgsTest(String query) { assertNotNull(parser.parse(query)); @@ -466,15 +465,6 @@ private static Stream generateMatchPhraseQueries() { return generateQueries("match_phrase", matchPhraseArgs); } - private static Stream generateMatchPhraseQueryQueries() { - var matchPhraseArgs = new HashMap(); - matchPhraseArgs.put("analyzer", new String[]{ "standard", "stop", "english" }); - matchPhraseArgs.put("max_expansions", new Integer[]{ 0, 5, 20 }); - matchPhraseArgs.put("slop", new Integer[]{ 0, 1, 2 }); - - return generateQueries("matchphrasequery", matchPhraseArgs); - } - private static Stream generateMatchPhrasePrefixQueries() { return generateQueries("match_phrase_prefix", ImmutableMap.builder() .put("analyzer", new String[] {"standard", "stop", "english"})