Skip to content

Commit

Permalink
Add support for LIKE with nested query in predicate expression.
Browse files Browse the repository at this point in the history
Signed-off-by: forestmvey <forestv@bitquilltech.com>
  • Loading branch information
forestmvey committed May 30, 2023
1 parent 0c0eb1a commit eb48a0a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
10 changes: 10 additions & 0 deletions integ-test/src/test/java/org/opensearch/sql/sql/NestedIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,16 @@ public void test_nested_in_where_as_predicate_expression() {
verifyDataRows(result, rows("a"), rows("c"));
}

@Test
public void test_nested_in_where_as_predicate_expression_with_like() {
String query = "SELECT message.info FROM " + TEST_INDEX_NESTED_TYPE
+ " WHERE nested(message.info) LIKE 'a'";
JSONObject result = executeJdbcRequest(query);
assertEquals(2, result.getInt("total"));
// Only first index of array is returned. Second index has 'a'
verifyDataRows(result, rows("a"), rows("c"));
}

@Test
public void test_nested_in_where_as_predicate_expression_with_multiple_conditions() {
String query = "SELECT message.info, comment.data, message.dayOfWeek FROM " + TEST_INDEX_NESTED_TYPE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,15 @@
import org.opensearch.index.query.QueryBuilders;
import org.opensearch.index.query.WildcardQueryBuilder;
import org.opensearch.sql.data.model.ExprValue;
import org.opensearch.sql.expression.Expression;
import org.opensearch.sql.expression.FunctionExpression;
import org.opensearch.sql.expression.ReferenceExpression;
import org.opensearch.sql.data.type.ExprType;
import org.opensearch.sql.opensearch.data.type.OpenSearchTextType;
import org.opensearch.sql.opensearch.storage.script.StringUtils;

public class LikeQuery extends LuceneQuery {
@Override
public QueryBuilder build(FunctionExpression func) {
ReferenceExpression ref = (ReferenceExpression) func.getArguments().get(0);
String field = OpenSearchTextType.convertTextToKeyword(ref.getAttr(), ref.type());
Expression expr = func.getArguments().get(1);
ExprValue literalValue = expr.valueOf();
return createBuilder(field, literalValue.stringValue());
public QueryBuilder doBuild(String fieldName, ExprType fieldType, ExprValue literal) {
String field = OpenSearchTextType.convertTextToKeyword(fieldName, fieldType);
return createBuilder(field, literal.stringValue());
}

/**
Expand Down

0 comments on commit eb48a0a

Please sign in to comment.