Skip to content

Commit

Permalink
Implementing wildcard with support of nested fields in both SQL and PPL.
Browse files Browse the repository at this point in the history
Signed-off-by: forestmvey <forestv@bitquilltech.com>
  • Loading branch information
forestmvey committed Aug 29, 2022
1 parent b8eba59 commit 5f60b7d
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ public Expression visitWindowFunction(WindowFunction node, AnalysisContext conte
@Override
public Expression visitHighlightFunction(HighlightFunction node, AnalysisContext context) {
Expression expr = node.getHighlightField().accept(this, context);
String highlightStr = "highlight(" + expr.toString() + ")";
String nestedFields = (node.getNestedFields() != null) ? "." + node.getNestedFields() : "";
String highlightStr = "highlight(" + expr.toString() + ")" + nestedFields;
return new ReferenceExpression(highlightStr, ExprCoreType.STRING);
}

Expand Down
4 changes: 0 additions & 4 deletions core/src/main/java/org/opensearch/sql/ast/dsl/AstDSL.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,6 @@ public When when(UnresolvedExpression condition, UnresolvedExpression result) {
return new When(condition, result);
}

public UnresolvedExpression highlight(UnresolvedExpression fieldName) {
return new HighlightFunction(fieldName);
}

public UnresolvedExpression window(UnresolvedExpression function,
List<UnresolvedExpression> partitionByList,
List<Pair<SortOption, UnresolvedExpression>> sortList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
@ToString
public class HighlightFunction extends UnresolvedExpression {
private final UnresolvedExpression highlightField;
private final UnresolvedExpression nestedFields;

@Override
public <T, C> T accept(AbstractNodeVisitor<T, C> nodeVisitor, C context) {
Expand Down
2 changes: 1 addition & 1 deletion ppl/src/main/antlr/OpenSearchPPLParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ evalFunctionCall
;

highlightFunction
: HIGHLIGHT LT_PRTHS field=relevanceField RT_PRTHS #highlightFunctionCall
: HIGHLIGHT LT_PRTHS field=relevanceField RT_PRTHS (DOT qualifiedName)* #highlightFunctionCall
;

/** cast function */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ public UnresolvedExpression visitDistinctCountFunctionCall(DistinctCountFunction
@Override
public UnresolvedExpression visitHighlightFunctionCall(
OpenSearchPPLParser.HighlightFunctionCallContext ctx) {
return new HighlightFunction(visit(ctx.relevanceField()));
return new HighlightFunction(visit(ctx.relevanceField()),
visitChildren(ctx.getRuleContext()));
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion sql/src/main/antlr/OpenSearchSQLParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ functionCall
;

highlightFunction
: HIGHLIGHT LR_BRACKET relevanceField RR_BRACKET
: HIGHLIGHT LR_BRACKET relevanceField RR_BRACKET (DOT qualifiedName)*
;

scalarFunctionName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ public UnresolvedExpression visitScalarFunctionCall(ScalarFunctionCallContext ct
@Override
public UnresolvedExpression visitHighlightFunctionCall(
OpenSearchSQLParser.HighlightFunctionCallContext ctx) {
return new HighlightFunction(visit(ctx.highlightFunction().relevanceField()));
return new HighlightFunction(visit(ctx.highlightFunction().relevanceField()),
visitChildren(ctx.highlightFunction().getRuleContext()));
}

@Override
Expand Down

0 comments on commit 5f60b7d

Please sign in to comment.