generated from amazon-archives/__template_Custom
-
Notifications
You must be signed in to change notification settings - Fork 180
Add Highlight In SQL #717
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
Merged
penghuo
merged 24 commits into
opensearch-project:main
from
Bit-Quill:integ_highlight-in-sql
Aug 5, 2022
Merged
Add Highlight In SQL #717
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
1097d9f
Add support for highlight to parser and AstExpressionBuilder
1a453e1
Add unit test for highlight in AstExpressionBuilder
0d5c87b
Add unit test for highlight in AstBuilderTest
26d0b7e
Support highlight as an Unresolved expression.
3f10b8b
Represent highlight as UnresolvedExpression.
543d0d7
Support highlight in Analyzer.
f47ffe7
Treat highlight as a proper function in AST
5fdb939
Add support for highlight in Analyzer
5c8db0a
Add a simple IT test for highlight.
ac9f080
Register highlight function in the BuiltInFunctionRepository
b526132
Partial support for highlight in physical plan.
807c475
Add HighlightOperator.
74b6492
Highlight alpha complete.
ad7affc
Initial implementation to upporting highlight('*')
forestmvey bb97dde
Add support for multiple highlight calls in select statement.
forestmvey 163b909
Removed OpenSearchLogicalIndexScan highlightFields and dependencies. …
forestmvey b2a90d4
Added HighlightExpressionTest
forestmvey 2c04c49
Added javadocs, minor PR revisions, and fixed jacoco errors by improv…
forestmvey 01708e3
Code cleanup, adding parsing failure tests, and adding tests for high…
forestmvey 6b96ac0
Removing HighlightOperator functionality and unnecessary visitHighlig…
forestmvey 232b19f
Adding highlight function to functions.rst and removing unecessary fu…
forestmvey 9fbea30
Change highlight fields returned format to array list. Changed highli…
forestmvey 23a24e2
Fix bug where invalid schema name was being used for returned highlig…
forestmvey 449a330
Fix failing integration tests due to schema changes for highlight exp…
forestmvey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
core/src/main/java/org/opensearch/sql/analysis/HighlightAnalyzer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.analysis; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.opensearch.sql.ast.AbstractNodeVisitor; | ||
| import org.opensearch.sql.ast.expression.Alias; | ||
| import org.opensearch.sql.ast.expression.HighlightFunction; | ||
| import org.opensearch.sql.ast.expression.UnresolvedExpression; | ||
| import org.opensearch.sql.expression.Expression; | ||
| import org.opensearch.sql.planner.logical.LogicalHighlight; | ||
| import org.opensearch.sql.planner.logical.LogicalPlan; | ||
|
|
||
| /** | ||
| * Analyze the highlight in the {@link AnalysisContext} to construct the {@link | ||
| * LogicalPlan}. | ||
| */ | ||
| @RequiredArgsConstructor | ||
| public class HighlightAnalyzer extends AbstractNodeVisitor<LogicalPlan, AnalysisContext> { | ||
| private final ExpressionAnalyzer expressionAnalyzer; | ||
| private final LogicalPlan child; | ||
|
|
||
| public LogicalPlan analyze(UnresolvedExpression projectItem, AnalysisContext context) { | ||
| LogicalPlan highlight = projectItem.accept(this, context); | ||
| return (highlight == null) ? child : highlight; | ||
| } | ||
|
|
||
| @Override | ||
| public LogicalPlan visitAlias(Alias node, AnalysisContext context) { | ||
| if (!(node.getDelegated() instanceof HighlightFunction)) { | ||
| return null; | ||
| } | ||
|
|
||
| HighlightFunction unresolved = (HighlightFunction) node.getDelegated(); | ||
| Expression field = expressionAnalyzer.analyze(unresolved.getHighlightField(), context); | ||
| return new LogicalHighlight(child, field); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
core/src/main/java/org/opensearch/sql/ast/expression/HighlightFunction.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.ast.expression; | ||
|
|
||
| import java.util.List; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.ToString; | ||
| import org.opensearch.sql.ast.AbstractNodeVisitor; | ||
|
|
||
| /** | ||
| * Expression node of Highlight function. | ||
| */ | ||
| @AllArgsConstructor | ||
| @EqualsAndHashCode(callSuper = false) | ||
| @Getter | ||
| @ToString | ||
| public class HighlightFunction extends UnresolvedExpression { | ||
| private final UnresolvedExpression highlightField; | ||
|
|
||
| @Override | ||
| public <T, C> T accept(AbstractNodeVisitor<T, C> nodeVisitor, C context) { | ||
| return nodeVisitor.visitHighlight(this, context); | ||
| } | ||
|
|
||
| @Override | ||
| public List<UnresolvedExpression> getChild() { | ||
| return List.of(highlightField); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
core/src/main/java/org/opensearch/sql/expression/HighlightExpression.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.expression; | ||
|
|
||
| import java.util.List; | ||
| import lombok.Getter; | ||
| import org.opensearch.sql.common.utils.StringUtils; | ||
| import org.opensearch.sql.data.model.ExprValue; | ||
| import org.opensearch.sql.data.type.ExprCoreType; | ||
| import org.opensearch.sql.data.type.ExprType; | ||
| import org.opensearch.sql.expression.env.Environment; | ||
| import org.opensearch.sql.expression.function.BuiltinFunctionName; | ||
|
|
||
| /** | ||
| * Highlight Expression. | ||
| */ | ||
| @Getter | ||
| public class HighlightExpression extends FunctionExpression { | ||
| private final Expression highlightField; | ||
|
|
||
| /** | ||
| * HighlightExpression Constructor. | ||
| * @param highlightField : Highlight field for expression. | ||
| */ | ||
| public HighlightExpression(Expression highlightField) { | ||
| super(BuiltinFunctionName.HIGHLIGHT.getName(), List.of(highlightField)); | ||
| this.highlightField = highlightField; | ||
| } | ||
|
|
||
| /** | ||
| * Return collection value matching highlight field. | ||
| * @param valueEnv : Dataset to parse value from. | ||
| * @return : collection value of highlight fields. | ||
| */ | ||
| @Override | ||
| public ExprValue valueOf(Environment<Expression, ExprValue> valueEnv) { | ||
| String refName = "_highlight" + "." + StringUtils.unquoteText(getHighlightField().toString()); | ||
| return valueEnv.resolve(DSL.ref(refName, ExprCoreType.STRING)); | ||
| } | ||
|
|
||
| /** | ||
| * Get type for HighlightExpression. | ||
| * @return : String type. | ||
| */ | ||
| @Override | ||
| public ExprType type() { | ||
forestmvey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return ExprCoreType.ARRAY; | ||
| } | ||
|
|
||
| @Override | ||
| public <T, C> T accept(ExpressionNodeVisitor<T, C> visitor, C context) { | ||
| return visitor.visitHighlight(this, context); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
core/src/main/java/org/opensearch/sql/planner/logical/LogicalHighlight.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.planner.logical; | ||
|
|
||
| import java.util.Collections; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.ToString; | ||
| import org.opensearch.sql.expression.Expression; | ||
|
|
||
| @EqualsAndHashCode(callSuper = true) | ||
| @Getter | ||
| @ToString | ||
| public class LogicalHighlight extends LogicalPlan { | ||
| private final Expression highlightField; | ||
|
|
||
| public LogicalHighlight(LogicalPlan childPlan, Expression field) { | ||
| super(Collections.singletonList(childPlan)); | ||
| highlightField = field; | ||
| } | ||
|
|
||
| @Override | ||
| public <R, C> R accept(LogicalPlanNodeVisitor<R, C> visitor, C context) { | ||
| return visitor.visitHighlight(this, context); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.