Skip to content

simple_query_string implementation. - #66

Merged
Yury-Fridlyand merged 9 commits into
dev-simple_query_string-#192from
dev-simple_query_string-#192-impl3
Jun 6, 2022
Merged

Yury-Fridlyand merged 9 commits into
dev-simple_query_string-#192from
dev-simple_query_string-#192-impl3

Conversation

@Yury-Fridlyand

Copy link
Copy Markdown

Implementation for simple_query_string copied from dev-simple_query_string-#192-impl2, since that branch was corrupted by incorrect merge.
See also #61.
All PR review notes have been addressed.

Signed-off-by: Yury Fridlyand [email protected]

Description

Issues Resolved

Check List

  • New functionality includes testing.
    • All tests pass, including unit test, integration test and doctest
  • New functionality has been documented.
    • New functionality has javadoc added
    • New functionality has user manual doc added
  • Commits are signed per the DCO using --signoff

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.

#192-impl2`, since that branch was corrupted by incorrect merge.

Signed-off-by: Yury Fridlyand <[email protected]>
@Yury-Fridlyand
Yury-Fridlyand requested a review from a team June 2, 2022 23:06
@codecov

codecov Bot commented Jun 2, 2022 •

Copy link
Copy Markdown

Codecov Report

Merging #66 (b3bca7c) into dev-simple_query_string-#192 (26058b8) will increase coverage by 0.02%.
The diff coverage is 100.00%.

@@                        Coverage Diff                         @@
##             dev-simple_query_string-#192      #66      +/-   ##
==================================================================
+ Coverage                           97.66%   97.69%   +0.02%     
- Complexity                           2743     2777      +34     
==================================================================
  Files                                 268      269       +1     
  Lines                                6772     6859      +87     
  Branches                              435      437       +2     
==================================================================
+ Hits                                 6614     6701      +87     
  Misses                                157      157              
  Partials                                1        1              
Flag Coverage Δ
sql-engine 97.69% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ensearch/sql/expression/ExpressionNodeVisitor.java 100.00% <ø> (ø)
...arch/storage/script/filter/FilterQueryBuilder.java 100.00% <ø> (ø)
...rg/opensearch/sql/analysis/ExpressionAnalyzer.java 100.00% <100.00%> (ø)
...opensearch/sql/data/model/ExprCollectionValue.java 100.00% <100.00%> (ø)
...c/main/java/org/opensearch/sql/expression/DSL.java 100.00% <100.00%> (ø)
...h/sql/expression/function/BuiltinFunctionName.java 100.00% <100.00%> (ø)
...h/sql/expression/function/OpenSearchFunctions.java 100.00% <100.00%> (ø)
...ilter/lucene/relevance/SimpleQueryStringQuery.java 100.00% <100.00%> (ø)
...pensearch/sql/ppl/parser/AstExpressionBuilder.java 100.00% <100.00%> (ø)
...pensearch/sql/sql/parser/AstExpressionBuilder.java 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 26058b8...b3bca7c. Read the comment docs.

import org.opensearch.sql.expression.NamedArgumentExpression;
import org.opensearch.sql.opensearch.storage.script.filter.lucene.LuceneQuery;

public class SimpleQueryStringQuery extends LuceneQuery {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a base class for common code for relevance queries -- RelevanceQuery.

Let's refactor it so that SimpleQueryStringQuery can use it as well before we send this to upstream.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 521beca.

// 1) DSL reverses order of the `fields`
// 2) `flags` are printed by OpenSearch (not by the plugin) as an integer
// 3) parameters are printed -//- not in lexicographical order
@Disabled

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the test does not work, can we remove it? If not, then let's fix it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 2ac159f.

return new Function(
ctx.relevanceFunctionName().getText().toLowerCase(),
relevanceArguments(ctx));
if (ctx.singleFieldRelevanceFunction() != null) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is visitSingleFieldRelevanceFunction in the base class that would be more appropriate place for this code.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0817d9e.

.singleFieldRelevanceFunctionName().getText().toLowerCase(),
singleFieldRelevanceArguments(ctx.singleFieldRelevanceFunction()));
} else {
return new Function(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is visitMultiFieldRelevanceFunction in the base class that would be more appropriate place for this code.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0817d9e.

// - fields' weights inside quotes
// - `flags` as an integer, but not as an enum
// - parameters not in alphabetical order
@Disabled

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this test work or remove it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 2ac159f.

@AllArgsConstructor
public class RelevanceFieldList extends UnresolvedExpression {
@Getter
private java.util.Map<UnresolvedExpression, UnresolvedExpression> fieldList;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we can make this into a string-float map.
This would improve and simplify the places that use the class as well.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We talked about using the Field class to store the string/float parameters. If that doesn't work, we should consider creating an Object to store this information.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 015aa06.

.stream()
.collect(ImmutableMap.toImmutableMap(
n -> n.getKey().toString(),
n -> ExprValueUtils.floatValue((Float) ((Literal) n.getValue()).getValue())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without simplified RelevanceFieldList, this will fail if RelevanceFieldList is anything other than string-float map.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 015aa06.

+ Index.BEER.getName() + " WHERE simple_query_string(['Tags'], 'taste')";
var result1 = new JSONObject(executeQuery(query1, "jdbc"));
String query2 = "SELECT count(*) FROM "
+ Index.BEER.getName() + " WHERE simple_query_string(['T*'], 'taste')";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't TestConstants.TEST_INDEX_BEER be used here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c1a91fc.

// Field is a list of columns
multiFieldRelevanceFunction
: multiFieldRelevanceFunctionName LR_BRACKET
LT_SQR_PRTHS field=relevanceFieldAndWeight (COMMA field=relevanceFieldAndWeight)* RT_SQR_PRTHS

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe if we add a separate rule for field list (everything between square brackets), we can simplify AstExpressionBuilder.

return new Function(
ctx.relevanceFunctionName().getText().toLowerCase(),
relevanceArguments(ctx));
if (ctx.singleFieldRelevanceFunction() != null) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar comments I made for PPL AstExpressionBuilder apply here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0817d9e.

@Yury-Fridlyand Yury-Fridlyand mentioned this pull request Jun 6, 2022
5 of 6 tasks
// Operators. Bit

BIT_NOT_OP: '~';
//BIT_OR_OP: '|';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented code can be removed

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b3bca7c.

REWRITE: 'REWRITE';
SLOP: 'SLOP';
TIE_BREAKER: 'TIE_BREAKER';
//TIME_ZONE: 'TIME_ZONE'; // already defined on line 63

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented code can be removed

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b3bca7c.

Signed-off-by: Yury Fridlyand <[email protected]>
@Yury-Fridlyand
Yury-Fridlyand merged commit 30bc724 into dev-simple_query_string-#192 Jun 6, 2022
@Yury-Fridlyand
Yury-Fridlyand deleted the dev-simple_query_string-#192-impl3 branch June 6, 2022 23:41
andy-k-improving pushed a commit that referenced this pull request Nov 16, 2024
Adding workflow for creating documentation issues
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants