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 @@ -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 @@ -95,6 +95,7 @@
import org.opensearch.sql.exception.CalciteUnsupportedException;
import org.opensearch.sql.exception.ExpressionEvaluationException;
import org.opensearch.sql.exception.SemanticCheckException;
import org.opensearch.sql.executor.QueryType;
import org.opensearch.sql.expression.function.BuiltinFunctionName;
import org.opensearch.sql.expression.function.CoercionUtils;
import org.opensearch.sql.expression.function.PPLBuiltinOperators;
Expand Down Expand Up @@ -763,6 +764,17 @@ public RexNode visitWindowFunction(WindowFunction node, CalcitePlanContext conte
.toList();
List<RexNode> orderKeys = translateOrderKeys(node.getSortList(), context);
return BuiltinFunctionName.ofWindowFunction(funcName)
// rank/dense_rank were added to WINDOW_FUNC_MAPPING to support SQL's RANK()/DENSE_RANK()
// OVER (...), but PPL only ever reaches this visitor through eventstats/streamstats
// (there's no other PPL syntax that builds a WindowFunction node), which don't support
// them - PPL has no ORDER BY syntax for eventstats/streamstats, so ranking would be
// meaningless there. Excluding them here for PPL keeps that restriction despite the
// shared mapping, without needing a PPL-specific grammar change.
.filter(
functionName ->
!(context.queryType == QueryType.PPL
&& (functionName == BuiltinFunctionName.RANK
|| functionName == BuiltinFunctionName.DENSE_RANK)))
.map(
functionName -> {
RexNode field = arguments.isEmpty() ? null : arguments.getFirst();
Expand Down Expand Up @@ -808,7 +820,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 @@ -329,7 +329,22 @@ 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() {
for (String func : List.of("rank", "dense_rank")) {
Throwable e =
assertThrowsWithReplace(
UnsupportedOperationException.class,
() ->
executeQuery(
String.format(
"source=%s | eventstats %s() by state", TEST_INDEX_STATE_COUNTRY, func)));
verifyErrorMessageContains(
e, "Window function '" + func + "' is not supported in eventstats/streamstats");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,23 @@ 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() {
for (String func : List.of("rank", "dense_rank")) {
Throwable e =
assertThrowsWithReplace(
UnsupportedOperationException.class,
() ->
executeQuery(
String.format(
"source=%s | streamstats %s() by state",
TEST_INDEX_STATE_COUNTRY, func)));
verifyErrorMessageContains(
e, "Window function '" + func + "' is not supported in eventstats/streamstats");
}
}

Expand Down
Loading