-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add an integration test for match_phrase_prefix with required parameters Signed-off-by: MaxKsyunz <maxk@bitquilltech.com> * Update SQL ANTLR files to support match_phrase_prefix. Signed-off-by: MaxKsyunz <maxk@bitquilltech.com> * SQL parser test for match_phrase_prefix with required arguments. Change generateQueries signature to use more appropriate Map type. Signed-off-by: MaxKsyunz <maxk@bitquilltech.com> * The rest of the match_phrase_prefix owl with required parameters. Signed-off-by: MaxKsyunz <maxk@bitquilltech.com> * Checkstyle fix. Signed-off-by: MaxKsyunz <maxk@bitquilltech.com> * Add a license header. Signed-off-by: MaxKsyunz <maxk@bitquilltech.com> * Make MATCH_PHRASE_PREFIX_MAX_NUM_PARAMETERS public. Private constants look odd. Signed-off-by: MaxKsyunz <maxk@bitquilltech.com> * Add support for boost parameter in match_phrase. Signed-off-by: MaxKsyunz <maxk@bitquilltech.com> * Add SQL parser unit tests for optional parameters. Signed-off-by: MaxKsyunz <maxk@bitquilltech.com> * Add support for optional parameters for match_phrase_prefix. Signed-off-by: MaxKsyunz <maxk@bitquilltech.com> * Add unit test for AstExpressionBuilderTest that includes all parameters. Signed-off-by: MaxKsyunz <maxk@bitquilltech.com> * Add DSL.namedArgument(String, String) A convenience method to simplify writing tests. Signed-off-by: MaxKsyunz <maxk@bitquilltech.com> * ExpressionAnalyzer test for match_phrase_prefix with all parameters. Signed-off-by: MaxKsyunz <maxk@bitquilltech.com> * Support correct max number of optional parameters. Signed-off-by: MaxKsyunz <maxk@bitquilltech.com> * Address checkstyle issues. Signed-off-by: MaxKsyunz <maxk@bitquilltech.com> * Update getRelevanceFunctionResolver usage to pass field argument type. Signed-off-by: MaxKsyunz <maxk@bitquilltech.com> * match_phrase_prefix PPL required parameters integration test. Signed-off-by: MaxKsyunz <maxk@bitquilltech.com> * match_phrase_prefix with required parameters in PPL. Signed-off-by: MaxKsyunz <maxk@bitquilltech.com> * Integration test for match_phrase_prefix in PPL with all parameters. Signed-off-by: MaxKsyunz <maxk@bitquilltech.com> * match_phrase_prefix SQL integration tests. Signed-off-by: MaxKsyunz <maxk@bitquilltech.com> * Add FilterQueryBuilderTest test for match_phrase_prefix with analyzer Signed-off-by: MaxKsyunz <maxk@bitquilltech.com> * Fix flaky tests Signed-off-by: MaxKsyunz <maxk@bitquilltech.com> * match_phrase_prefix documentation for SQL and PPL Signed-off-by: MaxKsyunz <maxk@bitquilltech.com> * Improve PPL documentation for match_phrase_prefix - match_phrase was used in a couple places. - some optional parameters were missing. Signed-off-by: MaxKsyunz <maxk@bitquilltech.com> * Add integration tests for match_phrase_prefix in PPL Signed-off-by: MaxKsyunz <maxk@bitquilltech.com> * Remove an empty unit test. Signed-off-by: MaxKsyunz <maxk@bitquilltech.com> * Updated incorrect references to match_phrase. Signed-off-by: MaxKsyunz <maxk@bitquilltech.com>
- Loading branch information
Showing
20 changed files
with
616 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
integ-test/src/test/java/org/opensearch/sql/ppl/MatchPhrasePrefixWhereCommandIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.ppl; | ||
|
||
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_BEER; | ||
import static org.opensearch.sql.util.MatcherUtils.rows; | ||
import static org.opensearch.sql.util.MatcherUtils.verifyDataRows; | ||
|
||
import java.io.IOException; | ||
import org.json.JSONObject; | ||
import org.junit.Test; | ||
|
||
public class MatchPhrasePrefixWhereCommandIT extends PPLIntegTestCase { | ||
|
||
@Override | ||
public void init() throws IOException { | ||
loadIndex(Index.BEER); | ||
} | ||
|
||
@Test | ||
public void required_parameters() throws IOException { | ||
String query = "source = %s | WHERE match_phrase_prefix(Title, 'champagne be') | fields Title"; | ||
JSONObject result = executeQuery(String.format(query, TEST_INDEX_BEER)); | ||
verifyDataRows(result, | ||
rows("Can old flat champagne be used for vinegar?"), | ||
rows("Elder flower champagne best to use natural yeast or add a wine yeast?")); | ||
} | ||
|
||
|
||
@Test | ||
public void all_optional_parameters() throws IOException { | ||
// The values for optional parameters are valid but arbitrary. | ||
String query = "source = %s " + | ||
"| WHERE match_phrase_prefix(Title, 'flat champ', boost = 1.0, " + | ||
"zero_terms_query='ALL', max_expansions = 2, analyzer=standard, slop=0) " + | ||
"| fields Title"; | ||
JSONObject result = executeQuery(String.format(query, TEST_INDEX_BEER)); | ||
verifyDataRows(result, rows("Can old flat champagne be used for vinegar?")); | ||
} | ||
|
||
|
||
@Test | ||
public void max_expansions_is_3() throws IOException { | ||
// max_expansions applies to the last term in the query -- 'bottl' | ||
// It tells OpenSearch to consider only the first 3 terms that start with 'bottl' | ||
// In this dataset these are 'bottle-conditioning', 'bottling', 'bottles'. | ||
|
||
String query = "source = %s " + | ||
"| WHERE match_phrase_prefix(Tags, 'draught bottl', max_expansions=3) | fields Tags"; | ||
JSONObject result = executeQuery(String.format(query, TEST_INDEX_BEER)); | ||
verifyDataRows(result, rows("brewing draught bottling"), | ||
rows("draught bottles")); | ||
} | ||
|
||
@Test | ||
public void analyzer_english() throws IOException { | ||
// English analyzer removes 'in' and 'to' as they are common words. | ||
// This results in an empty query. | ||
String query = "source = %s " + | ||
"| WHERE match_phrase_prefix(Title, 'in to', analyzer=english)" + | ||
"| fields Title"; | ||
JSONObject result = executeQuery(String.format(query, TEST_INDEX_BEER)); | ||
assertTrue("Expect English analyzer to filter out common words 'in' and 'to'", | ||
result.getInt("total") == 0); | ||
} | ||
|
||
@Test | ||
public void analyzer_standard() throws IOException { | ||
// Standard analyzer does not treat 'in' and 'to' as special terms. | ||
// This results in 'to' being used as a phrase prefix given us 'Tokyo'. | ||
String query = "source = %s " + | ||
"| WHERE match_phrase_prefix(Title, 'in to', analyzer=standard)" + | ||
"| fields Title"; | ||
JSONObject result = executeQuery(String.format(query, TEST_INDEX_BEER)); | ||
verifyDataRows(result, rows("Local microbreweries and craft beer in Tokyo")); | ||
} | ||
|
||
@Test | ||
public void zero_term_query_all() throws IOException { | ||
// English analyzer removes 'in' and 'to' as they are common words. | ||
// zero_terms_query of 'ALL' causes all rows to be returned. | ||
// ORDER BY ... LIMIT helps make the test understandable. | ||
String query = "source = %s" + | ||
"| WHERE match_phrase_prefix(Title, 'in to', analyzer=english, zero_terms_query='ALL') " + | ||
"| sort -Title | head 1 | fields Title"; | ||
JSONObject result = executeQuery(String.format(query, TEST_INDEX_BEER)); | ||
verifyDataRows(result, rows("was working great, now all foam")); | ||
} | ||
|
||
|
||
@Test | ||
public void slop_is_2() throws IOException { | ||
// When slop is 0, the terms are matched exactly in the order specified. | ||
// 'open' is used to match prefix of the next term. | ||
String query = "source = %s" + | ||
"| where match_phrase_prefix(Tags, 'gas ta', slop=2) " + | ||
"| fields Tags"; | ||
JSONObject result = executeQuery(String.format(query, TEST_INDEX_BEER)); | ||
verifyDataRows(result, rows("taste gas")); | ||
} | ||
|
||
@Test | ||
public void slop_is_3() throws IOException { | ||
// When slop is 2, results will include phrases where the query terms are transposed. | ||
String query = "source = %s" + | ||
"| where match_phrase_prefix(Tags, 'gas ta', slop=3)" + | ||
"| fields Tags"; | ||
JSONObject result = executeQuery(String.format(query, TEST_INDEX_BEER)); | ||
verifyDataRows(result, | ||
rows("taste draught gas"), | ||
rows("taste gas")); | ||
} | ||
} |
Oops, something went wrong.