-
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 Highlight Support in PPL and Wildcard in SQL and PPL #110
Conversation
Codecov Report
@@ Coverage Diff @@
## integ-highlight-in-ppl #110 +/- ##
============================================================
+ Coverage 94.85% 94.88% +0.02%
- Complexity 2910 2925 +15
============================================================
Files 288 288
Lines 7830 7875 +45
Branches 570 575 +5
============================================================
+ Hits 7427 7472 +45
Misses 349 349
Partials 54 54
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 |
core/src/main/java/org/opensearch/sql/planner/physical/HighlightOperator.java
Outdated
Show resolved
Hide resolved
core/src/test/java/org/opensearch/sql/planner/physical/HighlightOperatorTest.java
Show resolved
Hide resolved
000537d
to
ccc29e3
Compare
integ-test/src/test/java/org/opensearch/sql/ppl/HighlightFunctionIT.java
Outdated
Show resolved
Hide resolved
// In the event of multiple returned highlights and wildcard being | ||
// used in conjunction with other highlight calls, we need to ensure | ||
// only wildcard regex matching is mapped to wildcard call. | ||
if (StringUtils.unquoteText(highlight.toString()).matches("(.+\\*)|(\\*.+)") |
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.
Is this regex only matches strings begining or ending with *
?
I.e., will it match B*o*d*y
?
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.
It will not match B*o*d*y
, yes it must start or end with a star. As well in your example opensearch would not return any value so this if statement would fail the and
section of this if statement.
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'd like to double-check that. From looking at the code, OpenSearch does support *
in the middle of the expression.
Highlight eventually uses HighlightPhase, which uses OpenSearch's Regex class which supports something like B*o*d*y
. It was not the best example, but I think B*dy
will match.
core/src/test/java/org/opensearch/sql/planner/physical/HighlightOperatorTest.java
Outdated
Show resolved
Hide resolved
integ-test/src/test/java/org/opensearch/sql/sql/HighlightFunctionIT.java
Outdated
Show resolved
Hide resolved
@forestmvey I'd like to have a second look at I understand that in context it provides required data, but semantically |
Can you please be more specific and give an example of what you would like revised. |
ccc29e3
to
4fa96cf
Compare
private Pair<String, ExprValue> mapHighlight(Environment<Expression, ExprValue> env) { | ||
String osHighlightKey = "_highlight"; | ||
if (!highlight.toString().contains("*")) { | ||
osHighlightKey += "." + StringUtils.unquoteText(highlight.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.
StringUtils.unquoteText(highlight.toString())
is the same as highlight.valueOf(null).string()
.
It is also used here several times and can be calculated once and stored in a variable.
This is the part I was thinking of. |
Also, based on this comment, it'd be better if That should also allow us to use OpenSearch's Regex class and make pattern matching consistent. |
458bb34
to
ca08438
Compare
…t in SQL and PPL. Signed-off-by: forestmvey <forestv@bitquilltech.com>
ca08438
to
43b841d
Compare
// In the event of multiple returned highlights and wildcard being | ||
// used in conjunction with other highlight calls, we need to ensure | ||
// only wildcard regex matching is mapped to wildcard call. | ||
if (highlightStr.contains("*") && value.type() == STRUCT) { | ||
value = new ExprTupleValue( | ||
new LinkedHashMap<String, ExprValue>(value.tupleValue() | ||
.entrySet() | ||
.stream() | ||
.filter(s -> matchesHighlightRegex(s.getKey(), highlightStr)) | ||
.collect(Collectors.toMap( | ||
e -> e.getKey(), | ||
e -> e.getValue())))); | ||
} |
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 like the comment and the use of filter.
Description
Support the highlight function in PPL. Add support for wildcard in SQL and PPL.
Issues Resolved
Issue: github:636
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.