Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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 @@ -171,7 +171,8 @@ public void unsupportedWindowFunctionIsRethrownAsSemanticCheckException() {
givenInvalidQuery("source = catalog.employees | eventstats percent_rank()")
.assertErrorType(SemanticCheckException.class)
.assertCauseType(CalciteUnsupportedException.class)
.assertErrorMessageContains("Unexpected window function: percent_rank");
.assertErrorMessageContains(
"Window function 'percent_rank' is not supported in eventstats/streamstats");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,14 @@ public RexNode visitWindowFunction(WindowFunction node, CalcitePlanContext conte
node.getWindowFrame());
})
.orElseThrow(
() -> new CalciteUnsupportedException("Unexpected window function: " + funcName));
() ->
new CalciteUnsupportedException(
"Window function '"
+ funcName
+ "' is not supported in eventstats/streamstats."
+ " Supported functions: avg, count, dc, distinct_count, earliest,"
+ " latest, max, min, row_number, stddev_pop, stddev_samp, sum,"
+ " var_pop, var_samp."));
Comment on lines +828 to +830

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe revert this change because this list is dynamic and defined in grammar.

}

private List<RexNode> translateOrderKeys(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.List;
import org.json.JSONObject;
import org.junit.jupiter.api.Test;
import org.opensearch.sql.common.antlr.SyntaxCheckException;
import org.opensearch.sql.ppl.PPLIntegTestCase;

public class CalcitePPLEventstatsIT extends PPLIntegTestCase {
Expand Down Expand Up @@ -329,7 +330,23 @@ public void testUnsupportedWindowFunctions() {
executeQuery(
String.format(
"source=%s | eventstats %s(age)", TEST_INDEX_STATE_COUNTRY, u)));
verifyErrorMessageContains(e, "Unexpected window function: " + u);
verifyErrorMessageContains(e, "is not supported in eventstats/streamstats");
}
}

@Test
public void testRankingWindowFunctionsUnsupportedInEventstats() {
// rank/dense_rank aren't in eventstats/streamstats' windowFunctionName grammar rule, so this
// is now a parse-time rejection rather than a semantic one.
for (String func : List.of("rank", "dense_rank")) {
Throwable e =
assertThrowsWithReplace(
SyntaxCheckException.class,
() ->
executeQuery(
String.format(
"source=%s | eventstats %s() by state", TEST_INDEX_STATE_COUNTRY, func)));
verifyErrorMessageContains(e, "is not a valid term at this part of the query");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.json.JSONObject;
import org.junit.jupiter.api.Test;
import org.opensearch.client.Request;
import org.opensearch.sql.common.antlr.SyntaxCheckException;
import org.opensearch.sql.ppl.PPLIntegTestCase;
import org.opensearch.sql.util.RequiresCapability;

Expand Down Expand Up @@ -846,7 +847,24 @@ public void testUnsupportedWindowFunctions() {
executeQuery(
String.format(
"source=%s | streamstats %s(age)", TEST_INDEX_STATE_COUNTRY, u)));
verifyErrorMessageContains(e, "Unexpected window function: " + u);
verifyErrorMessageContains(e, "is not supported in eventstats/streamstats");
}
}

@Test
public void testRankingWindowFunctionsUnsupportedInStreamstats() {
// rank/dense_rank aren't in eventstats/streamstats' windowFunctionName grammar rule, so this
// is now a parse-time rejection rather than a semantic one.
for (String func : List.of("rank", "dense_rank")) {
Throwable e =
assertThrowsWithReplace(
SyntaxCheckException.class,
() ->
executeQuery(
String.format(
"source=%s | streamstats %s() by state",
TEST_INDEX_STATE_COUNTRY, func)));
verifyErrorMessageContains(e, "is not a valid term at this part of the query");
}
}

Expand Down
2 changes: 0 additions & 2 deletions ppl/src/main/antlr/OpenSearchPPLParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -930,8 +930,6 @@ windowFunctionName

scalarWindowFunctionName
: ROW_NUMBER
| RANK
| DENSE_RANK
| PERCENT_RANK
| CUME_DIST
| FIRST
Expand Down
Loading