Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosdelest committed Jan 16, 2025
1 parent 318b06e commit b4221e4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 61 deletions.
1 change: 1 addition & 0 deletions x-pack/plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,6 @@ tasks.named("yamlRestCompatTestTransform").configure({ task ->
task.skipTest("esql/180_match_operator/match with non text field", "Match operator can now be used on non-text fields")
task.skipTest("esql/180_match_operator/match with functions", "Error message changed")
task.skipTest("esql/40_unsupported_types/semantic_text declared in mapping", "The semantic text field format changed")
task.skipTest("esql/180_match_operator/match with disjunctions", "Disjunctions in full text functions work now")
})

Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ public void setupIndex() {
createAndPopulateIndex();
}

@Override
protected EsqlQueryResponse run(EsqlQueryRequest request) {
assumeTrue("match function capability not available", EsqlCapabilities.Cap.MATCH_FUNCTION.isEnabled());
return super.run(request);
}

public void testSimpleWhereMatch() {
var query = """
FROM test
Expand Down Expand Up @@ -230,20 +224,19 @@ public void testWhereMatchAfterStats() {
assertThat(error.getMessage(), containsString("Unknown column [content]"));
}

public void testWhereMatchWithFunctions() {
public void testWhereMatchNotPushedDown() {
var query = """
FROM test
| WHERE match(content, "fox") OR to_upper(content) == "FOX"
| WHERE match(content, "fox") OR length(content) < 20
| KEEP id
| SORT id
""";
var error = expectThrows(ElasticsearchException.class, () -> run(query));
assertThat(
error.getMessage(),
containsString(
"Invalid condition [match(content, \"fox\") OR to_upper(content) == \"FOX\"]. "
+ "Full text functions can be used in an OR condition,"
+ " but only if just full text functions are used in the OR condition"
)
);

try (var resp = run(query)) {
assertColumnNames(resp.columns(), List.of("id"));
assertColumnTypes(resp.columns(), List.of("integer"));
assertValues(resp.values(), List.of(List.of(1), List.of(2), List.of(6)));
}
}

public void testWhereMatchWithRow() {
Expand All @@ -269,21 +262,6 @@ public void testMatchWithinEval() {
assertThat(error.getMessage(), containsString("[MATCH] function is only supported in WHERE commands"));
}

public void testMatchNonPushedDown() {
var query = """
FROM test
| WHERE match(content, "fox") OR length(content) < 20
| KEEP id
| SORT id
""";

try (var resp = run(query)) {
assertColumnNames(resp.columns(), List.of("id"));
assertColumnTypes(resp.columns(), List.of("integer"));
assertValues(resp.values(), List.of(List.of(1), List.of(2), List.of(6)));
}
}

private void createAndPopulateIndex() {
var indexName = "test";
var client = client().admin().indices();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,20 +206,19 @@ public void testWhereMatchAfterStats() {
assertThat(error.getMessage(), containsString("Unknown column [content]"));
}

public void testWhereMatchWithFunctions() {
public void testWhereMatchNotPushedDown() {
var query = """
FROM test
| WHERE content:"fox" OR to_upper(content) == "FOX"
| WHERE content:"fox" OR length(content) < 20
| KEEP id
| SORT id
""";
var error = expectThrows(ElasticsearchException.class, () -> run(query));
assertThat(
error.getMessage(),
containsString(
"Invalid condition [content:\"fox\" OR to_upper(content) == \"FOX\"]. "
+ "Full text functions can be used in an OR condition, "
+ "but only if just full text functions are used in the OR condition"
)
);

try (var resp = run(query)) {
assertColumnNames(resp.columns(), List.of("id"));
assertColumnTypes(resp.columns(), List.of("integer"));
assertValues(resp.values(), List.of(List.of(1), List.of(2), List.of(6)));
}
}

public void testWhereMatchWithRow() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,30 +171,21 @@ setup:

---
"match with disjunctions":
- requires:
capabilities:
- method: POST
path: /_query
parameters: [ method, path, parameters, capabilities ]
capabilities: [ full_text_functions_disjunctions ]
reason: "Full text functions disjunctions support"
- do:
catch: bad_request
allowed_warnings_regex:
- "No limit defined, adding default limit of \\[.*\\]"
esql.query:
body:
query: 'FROM test | WHERE content:"fox" OR to_upper(content) == "FOX"'

- match: { status: 400 }
- match: { error.type: verification_exception }
- match: { error.reason: "/.+Invalid\\ condition\\ \\[content\\:\"fox\"\\ OR\\ to_upper\\(content\\)\\ ==\\ \"FOX\"\\]\\./" }

- do:
catch: bad_request
allowed_warnings_regex:
- "No limit defined, adding default limit of \\[.*\\]"
esql.query:
body:
query: 'FROM test | WHERE content:"fox" OR to_upper(content) == "FOX"'

- match: { status: 400 }
- match: { error.type: verification_exception }
- match: { error.reason: "/.+Invalid\\ condition\\ \\[content\\:\"fox\"\\ OR\\ to_upper\\(content\\)\\ ==\\ \"FOX\"\\]\\./" }
query: 'FROM test | WHERE content:"fox" OR length(content) < 20'

- length: { values: 3 }

---
"match within eval":
Expand Down

0 comments on commit b4221e4

Please sign in to comment.