Skip to content

Commit 1dc92d6

Browse files
authored
Return 4xx instead of 500 for unsupported window functions (#5587)
Window functions outside WINDOW_FUNC_MAPPING (e.g. RANK) used to escape the AE route as HTTP 500 because the throw site emitted a raw UnsupportedOperationException, which UnifiedQueryPlanner rethrows unchanged. Switching to CalciteUnsupportedException lets the existing 4xx wrapper added in #5569 normalize it to SemanticCheckException. Repro: SELECT RegionID, COUNT(*) AS cnt, RANK() OVER (ORDER BY COUNT(*) DESC) AS rnk FROM clickbench GROUP BY RegionID LIMIT 5 Signed-off-by: Michael Oviedo <mikeovi@amazon.com>
1 parent 0a4d40e commit 1dc92d6

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

api/src/test/java/org/opensearch/sql/api/UnifiedQueryPlannerTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,18 @@ public void unsupportedFeatureIsRethrownAsSemanticCheckException() {
159159
.assertErrorMessageContains("unsupported in Calcite");
160160
}
161161

162+
@Test
163+
public void unsupportedWindowFunctionIsRethrownAsSemanticCheckException() {
164+
// Window functions outside WINDOW_FUNC_MAPPING reach
165+
// CalciteRexNodeVisitor#visitWindowFunction's
166+
// orElseThrow. The throw site emits CalciteUnsupportedException so this path normalizes to a
167+
// 4xx SemanticCheckException rather than escaping as a 500.
168+
givenInvalidQuery("source = catalog.employees | eventstats rank()")
169+
.assertErrorType(SemanticCheckException.class)
170+
.assertCauseType(CalciteUnsupportedException.class)
171+
.assertErrorMessageContains("Unexpected window function: rank");
172+
}
173+
162174
@Test
163175
public void assertionErrorIsWrappedAsSemanticCheckException() {
164176
// Remove when the underlying Calcite assertion is fixed.

core/src/main/java/org/opensearch/sql/calcite/CalciteRexNodeVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ public RexNode visitWindowFunction(WindowFunction node, CalcitePlanContext conte
705705
node.getWindowFrame());
706706
})
707707
.orElseThrow(
708-
() -> new UnsupportedOperationException("Unexpected window function: " + funcName));
708+
() -> new CalciteUnsupportedException("Unexpected window function: " + funcName));
709709
}
710710

711711
private List<RexNode> translateOrderKeys(

0 commit comments

Comments
 (0)