-
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 In SQL #96
Conversation
Signed-off-by: MaxKsyunz <maxk@bitquilltech.com>
Signed-off-by: MaxKsyunz <maxk@bitquilltech.com>
Signed-off-by: MaxKsyunz <maxk@bitquilltech.com>
Signed-off-by: MaxKsyunz <maxk@bitquilltech.com>
Signed-off-by: MaxKsyunz <maxk@bitquilltech.com>
Signed-off-by: MaxKsyunz <maxk@bitquilltech.com>
In particular, highlightField is an expression now. Signed-off-by: MaxKsyunz <maxk@bitquilltech.com>
HighlightFunction is converted to LogicalHighlight logical plan. Signed-off-by: MaxKsyunz <maxk@bitquilltech.com>
Signed-off-by: MaxKsyunz <maxk@bitquilltech.com>
Signed-off-by: MaxKsyunz <maxk@bitquilltech.com>
Signed-off-by: MaxKsyunz <maxk@bitquilltech.com>
Signed-off-by: MaxKsyunz <maxk@bitquilltech.com>
Signed-off-by: MaxKsyunz <maxk@bitquilltech.com>
Signed-off-by: forestmvey <forestv@bitquilltech.com>
Signed-off-by: forestmvey <forestv@bitquilltech.com>
Signed-off-by: forestmvey <forestv@bitquilltech.com>
Signed-off-by: forestmvey <forestv@bitquilltech.com>
Signed-off-by: forestmvey <forestv@bitquilltech.com>
Signed-off-by: forestmvey <forestv@bitquilltech.com>
Signed-off-by: forestmvey <forestv@bitquilltech.com>
/** | ||
* Return String or Map value matching highlight field. | ||
* @param valueEnv : Dataset to parse value from. | ||
* @return : String or Map value of highlight fields. | ||
*/ | ||
@Override | ||
public ExprValue valueOf(Environment<Expression, ExprValue> valueEnv) { | ||
String refName = "_highlight"; | ||
if (!getHighlightField().toString().contains("*")) { | ||
refName += "." + StringUtils.unquoteText(getHighlightField().toString()); | ||
} | ||
ExprValue retVal = valueEnv.resolve(DSL.ref(refName, ExprCoreType.STRING)); | ||
ImmutableMap.Builder<String, ExprValue> builder = new ImmutableMap.Builder<>(); | ||
|
||
if (retVal.isMissing() || retVal.type() != ExprCoreType.STRUCT) { | ||
return retVal; | ||
} | ||
|
||
var hlBuilder = ImmutableMap.<String, ExprValue>builder(); | ||
hlBuilder.putAll(retVal.tupleValue()); | ||
|
||
for (var entry : retVal.tupleValue().entrySet()) { | ||
String entryKey = "highlight(" + getHighlightField() + ")." + entry.getKey(); | ||
builder.put(entryKey, ExprValueUtils.stringValue(entry.getValue().toString())); | ||
} | ||
|
||
return ExprTupleValue.fromExprValueMap(builder.build()); | ||
} |
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 it worth returning always a map?
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.
Line 55 returns only one field in the instance there aren't multiple highlight fields returned.
ExprValue retVal = valueEnv.resolve(DSL.ref(refName, ExprCoreType.STRING)); | ||
ImmutableMap.Builder<String, ExprValue> builder = new ImmutableMap.Builder<>(); | ||
|
||
if (retVal.isMissing() || retVal.type() != ExprCoreType.STRUCT) { |
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.
When this condition is true?
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.
If there was no highlight value parsed from the return, or only a single highlight field is found.
public class HighlightOperator extends PhysicalPlan { | ||
@NonNull | ||
private final PhysicalPlan input; |
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.
Why do you store a parent class instance there?
I think you can call super.next()
and super.hasNext()
instead of input.next()
and input.hasNext()
and so on.
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.
In line with Peng's comment in the POC, this class ended up not doing anything and can be removed.
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.
Seems to be standard considering other operators also store the parent class instance like this.
@@ -274,7 +292,7 @@ public void project_values() { | |||
AstDSL.project( | |||
AstDSL.values(ImmutableList.of(AstDSL.intLiteral(123))), | |||
AstDSL.alias("123", AstDSL.intLiteral(123)), | |||
AstDSL.alias("hello", AstDSL.stringLiteral("hello")), | |||
AstDSL.alias("hello", stringLiteral("hello")), |
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.
Why?
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 believe this was an accidental change done in a previous draft PR. Should be fixed under 57ec0691b36f1e0010c034df1a59ef6b364feaf4.
@@ -694,7 +712,7 @@ public void parse_relation() { | |||
AstDSL.parse( | |||
AstDSL.relation("schema"), | |||
AstDSL.field("string_value"), | |||
AstDSL.stringLiteral("(?<group>.*)")), | |||
stringLiteral("(?<group>.*)")), |
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.
Why?
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 believe this was an accidental change done in a previous draft PR. Should be fixed under 57ec0691b36f1e0010c034df1a59ef6b364feaf4.
integ-test/src/test/java/org/opensearch/sql/sql/HighlightFunctionIT.java
Show resolved
Hide resolved
Signed-off-by: forestmvey <forestv@bitquilltech.com>
9c777fc
to
6c17cd7
Compare
57ec069
to
7e1eab3
Compare
import org.opensearch.sql.planner.logical.LogicalPlan; | ||
|
||
@RequiredArgsConstructor | ||
public class HighlightAnalyzer extends AbstractNodeVisitor<LogicalPlan, AnalysisContext> { |
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.
Class needs a javadoc
core/src/main/java/org/opensearch/sql/ast/expression/HighlightFunction.java
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/expression/HighlightExpression.java
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/expression/HighlightExpression.java
Show resolved
Hide resolved
refName += "." + StringUtils.unquoteText(getHighlightField().toString()); | ||
} | ||
ExprValue retVal = valueEnv.resolve(DSL.ref(refName, ExprCoreType.STRING)); | ||
ImmutableMap.Builder<String, ExprValue> builder = new ImmutableMap.Builder<>(); |
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.
You can declare this after the is statement.
core/src/main/java/org/opensearch/sql/expression/HighlightExpression.java
Show resolved
Hide resolved
return retVal; | ||
} | ||
|
||
var hlBuilder = ImmutableMap.<String, ExprValue>builder(); |
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.
mapBuilder
or highlightMapBuilder
?
Signed-off-by: forestmvey <forestv@bitquilltech.com>
…ing coverage for OpenSearchIndexScan Signed-off-by: forestmvey <forestv@bitquilltech.com>
core/src/main/java/org/opensearch/sql/expression/HighlightExpression.java
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/expression/function/OpenSearchFunctions.java
Show resolved
Hide resolved
public class HighlightOperatorTest extends PhysicalPlanTestBase { | ||
|
||
@Test | ||
public void highlight_all_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.
what is this testing? that highlight all doesn't break anything?
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 suppose this should be renamed to valid_highlight_operator_test
. It is required for HighlightOperator coverage. The *
isn't necessary for the highlight field.
opensearch/src/main/java/org/opensearch/sql/opensearch/storage/OpenSearchIndexScan.java
Show resolved
Hide resolved
…light acceptance as a string literal as well as qualified name. Signed-off-by: forestmvey <forestv@bitquilltech.com>
c0869c4
to
3ee3491
Compare
public class HighlightOperator extends PhysicalPlan { | ||
@NonNull | ||
private final PhysicalPlan input; |
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.
In line with Peng's comment in the POC, this class ended up not doing anything and can be removed.
@forestmvey looks like a test is failing now fyi.
|
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.
Once HighlightOperator goes away (or we can explain what it's for), other comments are addressed, and the CI tasks pass, I think it's good to go.
… PR. Signed-off-by: forestmvey <forestv@bitquilltech.com>
Signed-off-by: forestmvey <forestv@bitquilltech.com>
Codecov Report
@@ Coverage Diff @@
## integ_highlight-in-sql #96 +/- ##
============================================================
+ Coverage 97.74% 97.77% +0.02%
- Complexity 2858 2883 +25
============================================================
Files 273 276 +3
Lines 7020 7088 +68
Branches 442 450 +8
============================================================
+ Hits 6862 6930 +68
Misses 157 157
Partials 1 1
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. |
Signed-off-by: forestmvey <forestv@bitquilltech.com>
At least, the two failing actions would be fixed by merging from upstream:main (opensearch-project#704) - I believe |
Description
Support highlighting function in SQL query engine.
Issues Resolved
Github 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.