Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosdelest committed Dec 13, 2024
1 parent 1056909 commit b3e9a64
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public void testWhereMatchWithScoringNoSort() {
var query = """
FROM test
METADATA _score
| WHERE content:"fox"
| WHERE match(content, "fox")
| KEEP id, _score
""";

Expand All @@ -182,7 +182,7 @@ public void testWhereMatchWithScoringNoSort() {
public void testNonExistingColumn() {
var query = """
FROM test
| WHERE something:"fox"
| WHERE match(something, "fox")
""";

var error = expectThrows(VerificationException.class, () -> run(query));
Expand All @@ -193,14 +193,14 @@ public void testWhereMatchEvalColumn() {
var query = """
FROM test
| EVAL upper_content = to_upper(content)
| WHERE upper_content:"FOX"
| WHERE match(upper_content, "FOX")
| KEEP id
""";

var error = expectThrows(VerificationException.class, () -> run(query));
assertThat(
error.getMessage(),
containsString("[:] operator cannot operate on [upper_content], which is not a field from an index mapping")
containsString("[MATCH] function cannot operate on [upper_content], which is not a field from an index mapping")
);
}

Expand All @@ -209,21 +209,21 @@ public void testWhereMatchOverWrittenColumn() {
FROM test
| DROP content
| EVAL content = CONCAT("document with ID ", to_str(id))
| WHERE content:"document"
| WHERE match(content, "document")
""";

var error = expectThrows(VerificationException.class, () -> run(query));
assertThat(
error.getMessage(),
containsString("[:] operator cannot operate on [content], which is not a field from an index mapping")
containsString("[MATCH] function cannot operate on [content], which is not a field from an index mapping")
);
}

public void testWhereMatchAfterStats() {
var query = """
FROM test
| STATS count(*)
| WHERE content:"fox"
| WHERE match(content, "fox")
""";

var error = expectThrows(VerificationException.class, () -> run(query));
Expand All @@ -233,39 +233,39 @@ public void testWhereMatchAfterStats() {
public void testWhereMatchWithFunctions() {
var query = """
FROM test
| WHERE content:"fox" OR to_upper(content) == "FOX"
| WHERE match(content, "fox") OR to_upper(content) == "FOX"
""";
var error = expectThrows(ElasticsearchException.class, () -> run(query));
assertThat(
error.getMessage(),
containsString(
"Invalid condition [content:\"fox\" OR to_upper(content) == \"FOX\"]. "
+ "[:] operator can be used in an OR condition, but only if just full text functions are used in the OR condition"
"Invalid condition [match(content, \"fox\") OR to_upper(content) == \"FOX\"]. "
+ "[MATCH] function can be used in an OR condition, but only if just full text functions are used in the OR condition"
)
);
}

public void testWhereMatchWithRow() {
var query = """
ROW content = "a brown fox"
| WHERE content:"fox"
| WHERE match(content, "fox")
""";

var error = expectThrows(ElasticsearchException.class, () -> run(query));
assertThat(
error.getMessage(),
containsString("[:] operator cannot operate on [\"a brown fox\"], which is not a field from an index mapping")
containsString("[MATCH] function cannot operate on [\"a brown fox\"], which is not a field from an index mapping")
);
}

public void testMatchWithinEval() {
var query = """
FROM test
| EVAL matches_query = content:"fox"
| EVAL matches_query = match(content, "fox")
""";

var error = expectThrows(VerificationException.class, () -> run(query));
assertThat(error.getMessage(), containsString("[:] operator is only supported in WHERE commands"));
assertThat(error.getMessage(), containsString("[MATCH] function is only supported in WHERE commands"));
}

private void createAndPopulateIndex() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ public void testWhereMatchWithFunctions() {
assertThat(
error.getMessage(),
containsString(
"Invalid condition [content:\"fox\" OR to_upper(content) == \"FOX\"]. " + "[:] operator can't be used in an OR condition"
"Invalid condition [content:\"fox\" OR to_upper(content) == \"FOX\"]. "
+ "[:] operator can be used in an OR condition, but only if just full text functions are used in the OR condition"
)
);
}
Expand Down

0 comments on commit b3e9a64

Please sign in to comment.