-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add MatchPhraseQuery As Alternate Syntax for Match_Phrase Function #165
Add MatchPhraseQuery As Alternate Syntax for Match_Phrase Function #165
Conversation
Codecov Report
@@ Coverage Diff @@
## integ-add-legacy-syntax-for-matchphrase-function #165 +/- ##
=======================================================================================
- Coverage 98.28% 62.76% -35.53%
=======================================================================================
Files 345 10 -335
Lines 8580 658 -7922
Branches 547 119 -428
=======================================================================================
- Hits 8433 413 -8020
- Misses 142 192 +50
- Partials 5 53 +48
Flags with carried forward coverage won't be shown. Click here to find out more. 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
...st/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/MatchPhraseQueryTest.java
Outdated
Show resolved
Hide resolved
@@ -426,7 +426,8 @@ systemFunctionName | |||
|
|||
singleFieldRelevanceFunctionName | |||
: MATCH | MATCH_PHRASE | MATCHPHRASE | |||
| MATCH_BOOL_PREFIX | MATCH_PHRASE_PREFIX | |||
| MATCHPHRASEQUERY | MATCH_BOOL_PREFIX |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: add it to the previous line with MATCH_PHRASE | MATCHPHRASE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in d04916b
sql/src/test/java/org/opensearch/sql/sql/parser/AstExpressionBuilderTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make sure SQL Java CI workflow passes.
Looks to be failing on checkstyle.
Fixed! |
...st/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/MatchPhraseQueryTest.java
Outdated
Show resolved
Hide resolved
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.toString(), result2.toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertEquals(result1, result2)
should work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to just do assertEquals(result1, result2)
originally but the test was failing with the following message (I separated it onto different lines so it's more readable)...
expected:
org.json.JSONObject<{"schema":[{"name":"phrase","type":"text"}],"total":2,"datarows":[["quick fox"],["quick fox here"]],"size":2,"status":200}>
but was:
org.json.JSONObject<{"schema":[{"name":"phrase","type":"text"}],"total":2,"datarows":[["quick fox"],["quick fox here"]],"size":2,"status":200}>
I wasn't sure why it was failing, but I assumed it may have something to do with the equality operator and how the objects might be stored in memory, so I added the .toString()
as a hacky way to fix it. Is there a different way to compare the JSON objects that might be better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found that it is better to use JSONObject::similar
instead of JSONObject::equals
. So assert be like
assertTrue(result1.similar(result2));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been fixed. assertEquals
was replaced with assertTrue
.
@Test | ||
public void test_SyntaxCheckException_when_invalid_parameter_match_phrase_syntax() { | ||
List<Expression> arguments = List.of( | ||
dsl.namedArgument("field", "test"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use DSL.namedArgument
. Either works now, but dsl.namedArgument
is going away immanently upstream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a feature, this looks good @GabeFernandez310!
I do have a few stylistic comments:
MatchPhraseQueryTest.this. ...
looks odd. Is it necessary?- By convention, when writing an assert the first argument is the expected value. Some of your asserts have that flipped.
assertEquals(result1.toString(), result2.toString())
is unnecessary --JSONObject
overridesequals
directly.- Use
DSL.namedArgument
instead ofdsl.namedArgument
. I realize the later is all over the codebase, but it is unnecessary --namedArgument
is a static method, and will go away in upstream imminently.
I flagged at least one example of each with a comment, but I see there are others instances.
List<Expression> arguments = List.of(); | ||
assertThrows(SyntaxCheckException.class, | ||
() -> matchPhraseQuery.build(new MatchPhraseExpression( | ||
arguments, MatchPhraseQueryTest.this.matchPhraseWithUnderscoreName))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
arguments, MatchPhraseQueryTest.this.matchPhraseWithUnderscoreName))); | |
arguments, matchPhraseWithUnderscoreName))); |
isn't that sufficient?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been fixed
@@ -448,6 +466,15 @@ private static Stream<String> generateMatchPhraseQueries() { | |||
return generateQueries("match_phrase", matchPhraseArgs); | |||
} | |||
|
|||
private static Stream<String> generateMatchPhraseQueryQueries() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need both generateMatchPhraseQueryQueries
and `matchPhraseQueryComplexQueries?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After looking closer I felt that they weren't both needed. I removed generateMatchPhraseQueryQueries
...st/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/MatchPhraseQueryTest.java
Show resolved
Hide resolved
38b7714
to
72580ed
Compare
Signed-off-by: GabeFernandez310 <gabrielf@bitquilltech.com>
Signed-off-by: GabeFernandez310 <gabrielf@bitquilltech.com>
72580ed
to
9e112a3
Compare
Signed-off-by: GabeFernandez310 <gabrielf@bitquilltech.com>
9e112a3
to
fbcee86
Compare
9c769dd
into
integ-add-legacy-syntax-for-matchphrase-function
* Import h3 library (#154) Made following changes to make it compatible: 1. Rename package from elasticsearch to opensearch.geospatial 2. Update License headers 3. Update build file 4. Update settings to include sub projects * Use Transport Request (#164) Remove usage of deprecated BaseNodeRequest * Update http client package to resolve build failure (#168) (#171) * Introduce H3 min resolution constant (#165) H3 version 1 has 16 resolutions, numbered 0 through 15. Introduced a constant to represent min value, similar to max value. * Add geohex aggregation (#160) This aggregation will use uber's h3 to group coordinates into H3 cell. Created new aggregation type geohex_grid. The precision will be between 0 and 15. This aggreation has default precision as 5, similar to geohash and geotile. Signed-off-by: Vijayan Balasubramanian <balasvij@amazon.com> * Add integration test (#176) Included integration test for geohex_grid. Signed-off-by: Vijayan Balasubramanian <balasvij@amazon.com>
Description
Adds
matchphrasequery
as alternate syntax formatch_phrase
function which currently exists in opensearchQueries can be performed using the following syntax :
Example:
This query should return the same result as
match_phrase(field, 'query')
Issues Resolved
AOS-765
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.