Skip to content

Commit a722d51

Browse files
committed
Adding alternate multi_match parameter syntax.
Signed-off-by: forestmvey <forestv@bitquilltech.com>
1 parent e597225 commit a722d51

File tree

4 files changed

+19
-22
lines changed

4 files changed

+19
-22
lines changed

integ-test/src/test/java/org/opensearch/sql/sql/MultiMatchIT.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public void init() throws IOException {
3232
public void test_mandatory_params() {
3333
String query = "SELECT Id FROM " + TEST_INDEX_BEER
3434
+ " WHERE multi_match([\\\"Tags\\\" ^ 1.5, Title, `Body` 4.2], 'taste')";
35-
var result = new JSONObject(executeQuery(query, "jdbc"));
35+
JSONObject result = executeJdbcRequest(query);
3636
assertEquals(16, result.getInt("total"));
3737
}
3838

@@ -44,39 +44,39 @@ public void test_all_params() {
4444
+ "fuzziness = 'AUTO:1,5', fuzzy_transpositions = false, lenient = true, max_expansions = 25,"
4545
+ "minimum_should_match = '2<-25% 9<-3', prefix_length = 7, tie_breaker = 0.3,"
4646
+ "type = most_fields, slop = 2, zero_terms_query = 'ALL');";
47-
var result = new JSONObject(executeQuery(query, "jdbc"));
47+
JSONObject result = executeJdbcRequest(query);
4848
assertEquals(10, result.getInt("total"));
4949
}
5050

5151
@Test
5252
public void verify_wildcard_test() {
5353
String query1 = "SELECT Id FROM " + TEST_INDEX_BEER
5454
+ " WHERE multi_match(['Tags'], 'taste')";
55-
var result1 = new JSONObject(executeQuery(query1, "jdbc"));
55+
JSONObject result1 = executeJdbcRequest(query1);
5656
String query2 = "SELECT Id FROM " + TEST_INDEX_BEER
5757
+ " WHERE multi_match(['T*'], 'taste')";
58-
var result2 = new JSONObject(executeQuery(query2, "jdbc"));
58+
JSONObject result2 = executeJdbcRequest(query2);
5959
assertNotEquals(result2.getInt("total"), result1.getInt("total"));
6060

6161
String query = "SELECT Id FROM " + TEST_INDEX_BEER
6262
+ " WHERE multi_match(['*Date'], '2014-01-22');";
63-
var result = new JSONObject(executeQuery(query, "jdbc"));
63+
JSONObject result = executeJdbcRequest(query);
6464
assertEquals(10, result.getInt("total"));
6565
}
6666

6767
@Test
6868
public void test_multimatch_alternate_parameter_syntax() {
6969
String query = "SELECT Tags FROM " + TEST_INDEX_BEER
7070
+ " WHERE multimatch('query'='taste', 'fields'='Tags')";
71-
var result = new JSONObject(executeQuery(query, "jdbc"));
71+
JSONObject result = executeJdbcRequest(query);
7272
assertEquals(8, result.getInt("total"));
7373
}
7474

7575
@Test
7676
public void test_multimatchquery_alternate_parameter_syntax() {
7777
String query = "SELECT Tags FROM " + TEST_INDEX_BEER
7878
+ " WHERE multimatchquery(query='cicerone', fields='Tags')";
79-
var result = new JSONObject(executeQuery(query, "jdbc"));
79+
JSONObject result = executeJdbcRequest(query);
8080
assertEquals(2, result.getInt("total"));
8181
verifyDataRows(result, rows("serving cicerone restaurants"),
8282
rows("taste cicerone"));
@@ -86,7 +86,7 @@ public void test_multimatchquery_alternate_parameter_syntax() {
8686
public void test_quoted_multi_match_alternate_parameter_syntax() {
8787
String query = "SELECT Tags FROM " + TEST_INDEX_BEER
8888
+ " WHERE multi_match('query'='cicerone', 'fields'='Tags')";
89-
var result = new JSONObject(executeQuery(query, "jdbc"));
89+
JSONObject result = executeJdbcRequest(query);
9090
assertEquals(2, result.getInt("total"));
9191
verifyDataRows(result, rows("serving cicerone restaurants"),
9292
rows("taste cicerone"));
@@ -96,7 +96,7 @@ public void test_quoted_multi_match_alternate_parameter_syntax() {
9696
public void test_multi_match_alternate_parameter_syntax() {
9797
String query = "SELECT Tags FROM " + TEST_INDEX_BEER
9898
+ " WHERE multi_match(query='cicerone', fields='Tags')";
99-
var result = new JSONObject(executeQuery(query, "jdbc"));
99+
JSONObject result = executeJdbcRequest(query);
100100
assertEquals(2, result.getInt("total"));
101101
verifyDataRows(result, rows("serving cicerone restaurants"),
102102
rows("taste cicerone"));
@@ -106,7 +106,7 @@ public void test_multi_match_alternate_parameter_syntax() {
106106
public void test_wildcard_multi_match_alternate_parameter_syntax() {
107107
String query = "SELECT Body FROM " + TEST_INDEX_BEER
108108
+ " WHERE multi_match(query='IPA', fields='B*') LIMIT 1";
109-
var result = new JSONObject(executeQuery(query, "jdbc"));
109+
JSONObject result = executeJdbcRequest(query);
110110
verifyDataRows(result, rows("<p>I know what makes an IPA an IPA, but what are the unique" +
111111
" characteristics of it's common variants? To be specific, the ones I'm interested in are Double IPA" +
112112
" and Black IPA, but general differences between any other styles would be welcome too. </p>\n"));
@@ -121,7 +121,7 @@ public void test_all_params_multimatchquery_alternate_parameter_syntax() {
121121
+ "minimum_should_match = '2<-25% 9<-3', prefix_length = 7, tie_breaker = 0.3,"
122122
+ "type = most_fields, slop = 2, zero_terms_query = 'ALL');";
123123

124-
var result = new JSONObject(executeQuery(query, "jdbc"));
124+
JSONObject result = executeJdbcRequest(query);
125125
assertEquals(2, result.getInt("total"));
126126
}
127127
}

sql/src/main/antlr/OpenSearchSQLParser.g4

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -509,17 +509,12 @@ alternateMultiMatchArgName
509509
| stringLiteral
510510
;
511511

512-
alternateMultiMatchArgVal
513-
: qualifiedName
514-
| stringLiteral
515-
;
516-
517512
alternateMultiMatchQuery
518-
: argName=alternateMultiMatchArgName EQUAL_SYMBOL argVal=alternateMultiMatchArgVal
513+
: argName=alternateMultiMatchArgName EQUAL_SYMBOL argVal=relevanceArgValue
519514
;
520515

521516
alternateMultiMatchField
522-
: argName=alternateMultiMatchArgName EQUAL_SYMBOL argVal=alternateMultiMatchArgVal
517+
: argName=alternateMultiMatchArgName EQUAL_SYMBOL argVal=relevanceArgValue
523518
| argName=alternateMultiMatchArgName EQUAL_SYMBOL
524-
LT_SQR_PRTHS argVal=alternateMultiMatchArgVal RT_SQR_PRTHS
519+
LT_SQR_PRTHS argVal=relevanceArgValue RT_SQR_PRTHS
525520
;

sql/src/main/java/org/opensearch/sql/sql/parser/AstExpressionBuilder.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@
8181
import org.opensearch.sql.ast.expression.When;
8282
import org.opensearch.sql.ast.expression.WindowFunction;
8383
import org.opensearch.sql.ast.tree.Sort.SortOption;
84-
import org.opensearch.sql.catalog.model.auth.AuthenticationType;
8584
import org.opensearch.sql.common.utils.StringUtils;
86-
import org.opensearch.sql.exception.SemanticCheckException;
8785
import org.opensearch.sql.expression.function.BuiltinFunctionName;
8886
import org.opensearch.sql.sql.antlr.parser.OpenSearchSQLParser;
8987
import org.opensearch.sql.sql.antlr.parser.OpenSearchSQLParser.AndExpressionContext;
@@ -458,7 +456,7 @@ private QualifiedName visitIdentifiers(List<IdentContext> identifiers) {
458456
private void fillRelevanceArgs(List<OpenSearchSQLParser.RelevanceArgContext> args,
459457
ImmutableList.Builder<UnresolvedExpression> builder) {
460458
// To support old syntax we must support argument keys as quoted strings.
461-
args.forEach(v -> builder.add(v.relevanceArgName() != null
459+
args.forEach(v -> builder.add(v.argName == null
462460
? new UnresolvedArgument(v.relevanceArgName().getText().toLowerCase(),
463461
new Literal(StringUtils.unquoteText(v.relevanceArgValue().getText()),
464462
DataType.STRING))

sql/src/test/java/org/opensearch/sql/sql/antlr/SQLSyntaxParserTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ public void can_parse_now_like_functions(String name, Boolean hasFsp, Boolean ha
193193

194194
@Test
195195
public void can_parse_multi_match_relevance_function() {
196+
assertNotNull(parser.parse(
197+
"SELECT id FROM test WHERE multimatch(\"fields\"=\"field\", query=\"query\")"));
198+
assertNotNull(parser.parse(
199+
"SELECT id FROM test WHERE multimatchquery(fields=\"field\", \"query\"=\"query\")"));
196200
assertNotNull(parser.parse(
197201
"SELECT id FROM test WHERE multi_match(\"fields\"=\"field\", \"query\"=\"query\")"));
198202
assertNotNull(parser.parse(

0 commit comments

Comments
 (0)