-
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
Adding Highlight Support in PPL #124
Adding Highlight Support in PPL #124
Conversation
Codecov Report
@@ Coverage Diff @@
## integ-highlight-refactor #124 +/- ##
==============================================================
+ Coverage 94.93% 94.96% +0.03%
- Complexity 2973 2992 +19
==============================================================
Files 291 291
Lines 7949 8000 +51
Branches 578 588 +10
==============================================================
+ Hits 7546 7597 +51
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 |
e618c8b
to
69c1e63
Compare
public UnresolvedExpression highlight(UnresolvedExpression fieldName) { | ||
return new HighlightFunction(fieldName); | ||
public UnresolvedExpression highlight(UnresolvedExpression fieldName, | ||
java.util.Map<String, Literal> arguments) { |
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.
java.util.Map
could be imported.
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.
org.opensearch.sql.ast.expression.Map
is already imported taking up that namespace unfortunately. This is less code changes than switching all the other Map
instances.
Alias alias = AstDSL.alias("highlight(invalid_field)", | ||
highlightFunction); | ||
|
||
assertThrows(SemanticCheckException.class, () -> analyze(alias)); |
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.
FYI, on upstream, you may be asked to check the exception message here.
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.
Some minor comments only
return null; | ||
} | ||
|
||
HighlightFunction unresolved = (HighlightFunction) node.getDelegated(); | ||
HighlightFunction unresolved = (HighlightFunction) delegated; |
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 wonder if a better pattern to doing this would be to catch a RuntimeException
if the casting fails, instead of checking for the instanceof. That way you don't need to check each time, but instead try and catch for a failure.
Something like:
HighlightFunction unresolved;
try {
unresolved = (HighlightFunction) delegated;
} catch (RuntimeException runtimeException) {
return null;
}
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.
Not a bad idea to use this approach, though I do think the readability and verbosity of instanceof
is nice too. It is also the more commonly found approach in the code base.
assertEquals( | ||
highlight(AstDSL.stringLiteral("fieldA")), | ||
highlight(AstDSL.stringLiteral("fieldA"), args), |
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: if you create the HashMap here, you don't need to import Map :)
assertEquals( | ||
highlight(AstDSL.qualifiedName("fieldA")), | ||
highlight(AstDSL.qualifiedName("fieldA"), args), |
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.
ditto
69c1e63
to
729afad
Compare
I run this PPL query: source=beer | where multi_match([Title, Body, Tags], 'taste') | fields highlight('Body'), highlight('T*'); A piece of the output:
There is I suppose this should be consistent - both should return |
Great job, Forest! |
729afad
to
a8e26e0
Compare
…support in SQL and PPL. Signed-off-by: forestmvey <forestv@bitquilltech.com>
a8e26e0
to
e4eeeef
Compare
Signed-off-by: forestmvey forestv@bitquilltech.com
Description
Adding support for highlight in PPL with optional arguments and wildcard support in SQL and PPL.
Issues Resolved
Issue: 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.