Skip to content

SQL: Verify Full-Text Search functions not allowed in SELECT (#51568) #51673

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
merged 1 commit into from
Jan 30, 2020
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 @@ -13,6 +13,7 @@
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.Expressions;
import org.elasticsearch.xpack.sql.expression.FieldAttribute;
import org.elasticsearch.xpack.sql.expression.NamedExpression;
import org.elasticsearch.xpack.sql.expression.UnresolvedAttribute;
import org.elasticsearch.xpack.sql.expression.function.Function;
import org.elasticsearch.xpack.sql.expression.function.FunctionAttribute;
Expand All @@ -27,6 +28,7 @@
import org.elasticsearch.xpack.sql.expression.function.grouping.GroupingFunctionAttribute;
import org.elasticsearch.xpack.sql.expression.function.scalar.ScalarFunction;
import org.elasticsearch.xpack.sql.expression.predicate.conditional.ConditionalFunction;
import org.elasticsearch.xpack.sql.expression.predicate.fulltext.FullTextPredicate;
import org.elasticsearch.xpack.sql.expression.predicate.operator.comparison.In;
import org.elasticsearch.xpack.sql.plan.logical.Aggregate;
import org.elasticsearch.xpack.sql.plan.logical.Distinct;
Expand Down Expand Up @@ -231,6 +233,8 @@ Collection<Failure> verify(LogicalPlan plan) {
validateInExpression(p, localFailures);
validateConditional(p, localFailures);

checkFullTextSearchInSelect(plan, localFailures);

checkGroupingFunctionInGroupBy(p, localFailures);
checkFilterOnAggs(p, localFailures);
checkFilterOnGrouping(p, localFailures);
Expand Down Expand Up @@ -282,6 +286,17 @@ Collection<Failure> verify(LogicalPlan plan) {
return failures;
}

private void checkFullTextSearchInSelect(LogicalPlan plan, Set<Failure> localFailures) {
plan.forEachUp(p -> {
for (NamedExpression ne : p.projections()) {
ne.forEachUp((e) ->
localFailures.add(fail(e, "Cannot use MATCH() or QUERY() full-text search " +
"functions in the SELECT clause")),
FullTextPredicate.class);
}
}, Project.class);
}

/**
* Check validity of Aggregate/GroupBy.
* This rule is needed for multiple reasons:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public void testUnsupportedTypeInFilter() {
error("SELECT * FROM test WHERE unsupported > 1"));
}

public void testTermEqualitOnInexact() {
public void testTermEqualityOnInexact() {
assertEquals("1:26: [text = 'value'] cannot operate on first argument field of data type [text]: " +
"No keyword/multi-field defined exact matches for [text]; define one or use MATCH/QUERY instead",
error("SELECT * FROM test WHERE text = 'value'"));
Expand Down Expand Up @@ -586,7 +586,20 @@ public void testInvalidTypeForRLikeMatch() {
"No keyword/multi-field defined exact matches for [text]; define one or use MATCH/QUERY instead",
error("SELECT * FROM test WHERE text RLIKE 'foo'"));
}


public void testMatchAndQueryFunctionsNotAllowedInSelect() {
assertEquals("1:8: Cannot use MATCH() or QUERY() full-text search functions in the SELECT clause",
error("SELECT MATCH(text, 'foo') FROM test"));
assertEquals("1:8: Cannot use MATCH() or QUERY() full-text search functions in the SELECT clause",
error("SELECT MATCH(text, 'foo') AS fullTextSearch FROM test"));
assertEquals("1:38: Cannot use MATCH() or QUERY() full-text search functions in the SELECT clause",
error("SELECT int > 10 AND (bool = false OR QUERY('foo*')) AS fullTextSearch FROM test"));
assertEquals("1:8: Cannot use MATCH() or QUERY() full-text search functions in the SELECT clause\n" +
"line 1:28: Cannot use MATCH() or QUERY() full-text search functions in the SELECT clause",
error("SELECT MATCH(text, 'foo'), MATCH(text, 'bar') FROM test"));
accept("SELECT * FROM test WHERE MATCH(text, 'foo')");
}

public void testAllowCorrectFieldsInIncompatibleMappings() {
assertNotNull(incompatibleAccept("SELECT languages FROM \"*\""));
}
Expand Down