Skip to content
Open
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 @@ -165,10 +165,11 @@ public void unsupportedWindowFunctionIsRethrownAsSemanticCheckException() {
// CalciteRexNodeVisitor#visitWindowFunction's
// orElseThrow. The throw site emits CalciteUnsupportedException so this path normalizes to a
// 4xx SemanticCheckException rather than escaping as a 500.
givenInvalidQuery("source = catalog.employees | eventstats rank()")
givenInvalidQuery("source = catalog.employees | eventstats percent_rank()")
.assertErrorType(SemanticCheckException.class)
.assertCauseType(CalciteUnsupportedException.class)
.assertErrorMessageContains("Unexpected window function: 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 @@ -705,7 +705,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."));
}

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 @@ -832,8 +832,6 @@ windowFunctionName

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