Skip to content

Commit

Permalink
Add [] to function name in error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosdelest committed Sep 16, 2024
1 parent 5fff05e commit 0c3e2f4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void testQueryStringWithinEval() {
""";

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

private void createAndPopulateIndex() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ private static void checkFullTextQueryFunctions(LogicalPlan plan, Set<Failure> f
failures.add(
fail(
plan,
"{} function cannot be used after {}",
"[{}] function cannot be used after {}",
ftf.functionName(),
lp.sourceText().split(" ")[0].toUpperCase(Locale.ROOT)
)
Expand All @@ -682,7 +682,7 @@ private static void checkFullTextQueryFunctions(LogicalPlan plan, Set<Failure> f
}
} else {
plan.forEachExpression(FullTextFunction.class, ftf -> {
failures.add(fail(ftf, "{} function is only supported in WHERE commands", ftf.functionName()));
failures.add(fail(ftf, "[{}] function is only supported in WHERE commands", ftf.functionName()));
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1094,63 +1094,63 @@ public void testQueryStringFunctionsNotAllowedAfterCommands() throws Exception {
assumeTrue("skipping because QSTR is not enabled", EsqlCapabilities.Cap.QSTR_FUNCTION.isEnabled());

// Source commands
assertEquals("1:13: QSTR function cannot be used after SHOW", error("show info | where qstr(\"8.16.0\")"));
assertEquals("1:17: QSTR function cannot be used after ROW", error("row a= \"Anna\" | where qstr(\"Anna\")"));
assertEquals("1:13: [QSTR] function cannot be used after SHOW", error("show info | where qstr(\"8.16.0\")"));
assertEquals("1:17: [QSTR] function cannot be used after ROW", error("row a= \"Anna\" | where qstr(\"Anna\")"));

// Processing commands
assertEquals(
"1:43: QSTR function cannot be used after DISSECT",
"1:43: [QSTR] function cannot be used after DISSECT",
error("from test | dissect first_name \"%{foo}\" | where qstr(\"Connection\")")
);
assertEquals("1:27: QSTR function cannot be used after DROP", error("from test | drop emp_no | where qstr(\"Anna\")"));
assertEquals("1:27: [QSTR] function cannot be used after DROP", error("from test | drop emp_no | where qstr(\"Anna\")"));
assertEquals(
"1:71: QSTR function cannot be used after ENRICH",
"1:71: [QSTR] function cannot be used after ENRICH",
error("from test | enrich languages on languages with lang = language_name | where qstr(\"Anna\")")
);
assertEquals("1:26: QSTR function cannot be used after EVAL", error("from test | eval z = 2 | where qstr(\"Anna\")"));
assertEquals("1:26: [QSTR] function cannot be used after EVAL", error("from test | eval z = 2 | where qstr(\"Anna\")"));
assertEquals(
"1:44: QSTR function cannot be used after GROK",
"1:44: [QSTR] function cannot be used after GROK",
error("from test | grok last_name \"%{WORD:foo}\" | where qstr(\"Anna\")")
);
assertEquals("1:27: QSTR function cannot be used after KEEP", error("from test | keep emp_no | where qstr(\"Anna\")"));
assertEquals("1:24: QSTR function cannot be used after LIMIT", error("from test | limit 10 | where qstr(\"Anna\")"));
assertEquals("1:35: QSTR function cannot be used after MV_EXPAND", error("from test | mv_expand last_name | where qstr(\"Anna\")"));
assertEquals("1:27: [QSTR] function cannot be used after KEEP", error("from test | keep emp_no | where qstr(\"Anna\")"));
assertEquals("1:24: [QSTR] function cannot be used after LIMIT", error("from test | limit 10 | where qstr(\"Anna\")"));
assertEquals("1:35: [QSTR] function cannot be used after MV_EXPAND", error("from test | mv_expand last_name | where qstr(\"Anna\")"));
assertEquals(
"1:45: QSTR function cannot be used after RENAME",
"1:45: [QSTR] function cannot be used after RENAME",
error("from test | rename last_name as full_name | where qstr(\"Anna\")")
);
assertEquals(
"1:52: QSTR function cannot be used after STATS",
"1:52: [QSTR] function cannot be used after STATS",
error("from test | STATS c = COUNT(emp_no) BY languages | where qstr(\"Anna\")")
);

// Some combination of processing commands
assertEquals("1:38: QSTR function cannot be used after LIMIT", error("from test | keep emp_no | limit 10 | where qstr(\"Anna\")"));
assertEquals("1:38: [QSTR] function cannot be used after LIMIT", error("from test | keep emp_no | limit 10 | where qstr(\"Anna\")"));
assertEquals(
"1:46: QSTR function cannot be used after MV_EXPAND",
"1:46: [QSTR] function cannot be used after MV_EXPAND",
error("from test | limit 10 | mv_expand last_name | where qstr(\"Anna\")")
);
assertEquals(
"1:52: QSTR function cannot be used after KEEP",
"1:52: [QSTR] function cannot be used after KEEP",
error("from test | mv_expand last_name | keep last_name | where qstr(\"Anna\")")
);
assertEquals(
"1:77: QSTR function cannot be used after RENAME",
"1:77: [QSTR] function cannot be used after RENAME",
error("from test | STATS c = COUNT(emp_no) BY languages | rename c as total_emps | where qstr(\"Anna\")")
);
assertEquals(
"1:54: QSTR function cannot be used after KEEP",
"1:54: [QSTR] function cannot be used after KEEP",
error("from test | rename last_name as name | keep emp_no | where qstr(\"Anna\")")
);
}

public void testQueryStringFunctionsOnlyAllowedInWhere() throws Exception {
assumeTrue("skipping because QSTR is not enabled", EsqlCapabilities.Cap.QSTR_FUNCTION.isEnabled());

assertEquals("1:22: QSTR function is only supported in WHERE commands", error("from test | eval y = qstr(\"Anna\")"));
assertEquals("1:18: QSTR function is only supported in WHERE commands", error("from test | sort qstr(\"Connection\") asc"));
assertEquals("1:5: QSTR function is only supported in WHERE commands", error("row qstr(\"Connection\")"));
assertEquals("1:23: QSTR function is only supported in WHERE commands", error("from test | STATS c = qstr(\"foo\") BY languages"));
assertEquals("1:22: [QSTR] function is only supported in WHERE commands", error("from test | eval y = qstr(\"Anna\")"));
assertEquals("1:18: [QSTR] function is only supported in WHERE commands", error("from test | sort qstr(\"Connection\") asc"));
assertEquals("1:5: [QSTR] function is only supported in WHERE commands", error("row qstr(\"Connection\")"));
assertEquals("1:23: [QSTR] function is only supported in WHERE commands", error("from test | STATS c = qstr(\"foo\") BY languages"));
}

public void testQueryStringFunctionArgNotNullOrConstant() throws Exception {
Expand Down

0 comments on commit 0c3e2f4

Please sign in to comment.