Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,95 @@ public void matchCombinedWithBooleanFilter() {
LogicalTableScan(table=[[catalog, employees]])
""");
}

@Test
public void matchQuery() {
givenQuery("SELECT * FROM catalog.employees WHERE match_query(name, 'John')")
.assertPlan(
"""
LogicalFilter(condition=[match(MAP('field', $1), MAP('query', 'John':VARCHAR))])
LogicalTableScan(table=[[catalog, employees]])
""");
}

@Test
public void matchquery() {
givenQuery("SELECT * FROM catalog.employees WHERE matchquery(name, 'John')")
.assertPlan(
"""
LogicalFilter(condition=[match(MAP('field', $1), MAP('query', 'John':VARCHAR))])
LogicalTableScan(table=[[catalog, employees]])
""");
}

@Test
public void matchphrase() {
givenQuery("SELECT * FROM catalog.employees WHERE matchphrase(name, 'John Doe')")
.assertPlan(
"""
LogicalFilter(condition=[match_phrase(MAP('field', $1), MAP('query', 'John Doe':VARCHAR))])
LogicalTableScan(table=[[catalog, employees]])
""");
}

@Test
public void matchphrasequery() {
givenQuery("SELECT * FROM catalog.employees WHERE matchphrasequery(name, 'John Doe')")
.assertPlan(
"""
LogicalFilter(condition=[match_phrase(MAP('field', $1), MAP('query', 'John Doe':VARCHAR))])
LogicalTableScan(table=[[catalog, employees]])
""");
}

@Test
public void multimatch() {
givenQuery("SELECT * FROM catalog.employees WHERE multimatch(['name', 'department'], 'John')")
.assertPlan(
"""
LogicalFilter(condition=[multi_match(MAP('fields', MAP('name':VARCHAR, 1.0E0:DOUBLE, 'department':VARCHAR, 1.0E0:DOUBLE)), MAP('query', 'John':VARCHAR))])
LogicalTableScan(table=[[catalog, employees]])
""");
}

@Test
public void multimatchquery() {
givenQuery(
"SELECT * FROM catalog.employees WHERE multimatchquery(['name', 'department'], 'John')")
.assertPlan(
"""
LogicalFilter(condition=[multi_match(MAP('fields', MAP('name':VARCHAR, 1.0E0:DOUBLE, 'department':VARCHAR, 1.0E0:DOUBLE)), MAP('query', 'John':VARCHAR))])
LogicalTableScan(table=[[catalog, employees]])
""");
}

@Test
public void query() {
givenQuery("SELECT * FROM catalog.employees WHERE query('name:John')")
.assertPlan(
"""
LogicalFilter(condition=[query(MAP('query', 'name:John':VARCHAR))])
LogicalTableScan(table=[[catalog, employees]])
""");
}

@Test
public void wildcardQuery() {
givenQuery("SELECT * FROM catalog.employees WHERE wildcard_query(name, 'John*')")
.assertPlan(
"""
LogicalFilter(condition=[wildcard_query(MAP('field', $1), MAP('query', 'John*':VARCHAR))])
LogicalTableScan(table=[[catalog, employees]])
""");
}

@Test
public void wildcardquery() {
givenQuery("SELECT * FROM catalog.employees WHERE wildcardquery(name, 'John*')")
.assertPlan(
"""
LogicalFilter(condition=[wildcard_query(MAP('field', $1), MAP('query', 'John*':VARCHAR))])
LogicalTableScan(table=[[catalog, employees]])
""");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,9 @@ public class PPLBuiltinOperators extends ReflectiveSqlOperatorTable {
RELEVANCE_QUERY_FUNCTION_INSTANCE.toUDF("query_string", false);
public static final SqlOperator MULTI_MATCH =
RELEVANCE_QUERY_FUNCTION_INSTANCE.toUDF("multi_match", false);
public static final SqlOperator QUERY = RELEVANCE_QUERY_FUNCTION_INSTANCE.toUDF("query");
public static final SqlOperator WILDCARD_QUERY =
RELEVANCE_QUERY_FUNCTION_INSTANCE.toUDF("wildcard_query");
public static final SqlOperator NUMBER_TO_STRING =
new NumberToStringFunction().toUDF("NUMBER_TO_STRING");
public static final SqlOperator TONUMBER = new ToNumberFunction().toUDF("TONUMBER");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,13 @@
import static org.opensearch.sql.expression.function.BuiltinFunctionName.MAP_CONCAT;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.MAP_REMOVE;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.MATCH;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.MATCHPHRASE;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.MATCHPHRASEQUERY;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.MATCHQUERY;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.MATCH_BOOL_PREFIX;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.MATCH_PHRASE;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.MATCH_PHRASE_PREFIX;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.MATCH_QUERY;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.MAX;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.MD5;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.MEDIAN;
Expand All @@ -154,6 +158,8 @@
import static org.opensearch.sql.expression.function.BuiltinFunctionName.MONTHNAME;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.MONTH_OF_YEAR;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.MSTIME;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.MULTIMATCH;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.MULTIMATCHQUERY;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.MULTIPLY;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.MULTIPLYFUNCTION;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.MULTI_MATCH;
Expand All @@ -178,6 +184,7 @@
import static org.opensearch.sql.expression.function.BuiltinFunctionName.POW;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.POWER;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.QUARTER;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.QUERY;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.QUERY_STRING;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.RADIANS;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.RAND;
Expand Down Expand Up @@ -254,6 +261,8 @@
import static org.opensearch.sql.expression.function.BuiltinFunctionName.WEEKOFYEAR;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.WEEK_OF_YEAR;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.WIDTH_BUCKET;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.WILDCARDQUERY;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.WILDCARD_QUERY;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.XOR;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.YEAR;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.YEARWEEK;
Expand Down Expand Up @@ -908,6 +917,15 @@ void populate() {
registerOperator(SIMPLE_QUERY_STRING, PPLBuiltinOperators.SIMPLE_QUERY_STRING);
registerOperator(QUERY_STRING, PPLBuiltinOperators.QUERY_STRING);
registerOperator(MULTI_MATCH, PPLBuiltinOperators.MULTI_MATCH);
registerOperator(QUERY, PPLBuiltinOperators.QUERY);
registerOperator(WILDCARD_QUERY, PPLBuiltinOperators.WILDCARD_QUERY);
registerOperator(WILDCARDQUERY, PPLBuiltinOperators.WILDCARD_QUERY);
registerOperator(MATCH_QUERY, PPLBuiltinOperators.MATCH);
registerOperator(MATCHQUERY, PPLBuiltinOperators.MATCH);
registerOperator(MATCHPHRASE, PPLBuiltinOperators.MATCH_PHRASE);
registerOperator(MATCHPHRASEQUERY, PPLBuiltinOperators.MATCH_PHRASE);
registerOperator(MULTIMATCH, PPLBuiltinOperators.MULTI_MATCH);
registerOperator(MULTIMATCHQUERY, PPLBuiltinOperators.MULTI_MATCH);
registerOperator(REX_EXTRACT, PPLBuiltinOperators.REX_EXTRACT);
registerOperator(REX_EXTRACT_MULTI, PPLBuiltinOperators.REX_EXTRACT_MULTI);
registerOperator(REX_OFFSET, PPLBuiltinOperators.REX_OFFSET);
Expand Down
Loading