Skip to content

Commit

Permalink
Added LogicalHighlightTest and removed check for instance of Highligh…
Browse files Browse the repository at this point in the history
…tFunction in Analyzer as this case should not be reachable.

Signed-off-by: forestmvey <forestv@bitquilltech.com>
  • Loading branch information
forestmvey committed Aug 22, 2022
1 parent 13ce12b commit ec1e504
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
4 changes: 0 additions & 4 deletions core/src/main/java/org/opensearch/sql/analysis/Analyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,6 @@ public LogicalPlan visitEval(Eval node, AnalysisContext context) {
public LogicalPlan visitHighlight(Highlight node, AnalysisContext context) {
LogicalPlan child = node.getChild().get(0).accept(this, context);

if (!(((Alias)node.getExpression()).getDelegated() instanceof HighlightFunction)) {
return null;
}

// Replace all single quotes with double quotes for parsing mapping in HighlightOperator
TypeEnvironment env = context.peek();
env.define(new Symbol(Namespace.FIELD_NAME,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.sql.planner.logical;

import static org.opensearch.sql.ast.dsl.AstDSL.alias;
import static org.opensearch.sql.ast.dsl.AstDSL.highlight;
import static org.opensearch.sql.ast.dsl.AstDSL.relation;
import static org.opensearch.sql.ast.dsl.AstDSL.stringLiteral;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
import org.opensearch.sql.analysis.AnalyzerTestBase;
import org.opensearch.sql.ast.tree.Highlight;
import org.opensearch.sql.expression.DSL;
import org.opensearch.sql.expression.config.ExpressionConfig;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;

@Configuration
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = {ExpressionConfig.class, AnalyzerTestBase.class})
@ExtendWith(MockitoExtension.class)
public class LogicalHighlightTest extends AnalyzerTestBase {
@Test
public void analyze_highlight_with_one_field() {
assertAnalyzeEqual(
LogicalPlanDSL.highlight(
LogicalPlanDSL.relation("schema"),
DSL.literal("field")),
new Highlight(
alias("highlight('field')",
highlight(stringLiteral("field"))))
.attach(relation("schema")));
}
}

0 comments on commit ec1e504

Please sign in to comment.