Skip to content

Commit d249a47

Browse files
authored
[Enhancement] Classify unsupported-feature errors as client errors (4xx) on the SQL path (#5569)
Signed-off-by: Jialiang Liang <jiallian@amazon.com>
1 parent d055163 commit d249a47

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

api/src/main/java/org/opensearch/sql/api/UnifiedQueryPlanner.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.opensearch.sql.calcite.CalciteRelNodeVisitor;
2828
import org.opensearch.sql.common.antlr.SyntaxCheckException;
2929
import org.opensearch.sql.common.error.ErrorReport;
30+
import org.opensearch.sql.exception.CalciteUnsupportedException;
3031
import org.opensearch.sql.exception.QueryEngineException;
3132
import org.opensearch.sql.exception.SemanticCheckException;
3233

@@ -73,6 +74,10 @@ public RelNode plan(String query) {
7374
}
7475
return plan;
7576
});
77+
} catch (CalciteUnsupportedException e) {
78+
// Unsupported feature (e.g. table functions) is an invalid query, i.e. a client error.
79+
// Must precede the QueryEngineException branch as it is a subclass.
80+
throw new SemanticCheckException(e.getMessage(), e);
7681
} catch (SyntaxCheckException
7782
| QueryEngineException
7883
| UnsupportedOperationException

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.junit.Test;
1717
import org.opensearch.sql.common.antlr.SyntaxCheckException;
1818
import org.opensearch.sql.common.error.ErrorReport;
19+
import org.opensearch.sql.exception.CalciteUnsupportedException;
1920
import org.opensearch.sql.exception.SemanticCheckException;
2021
import org.opensearch.sql.executor.QueryType;
2122

@@ -147,6 +148,17 @@ public void invalidTableIsRethrownAsSemanticCheckException() {
147148
.assertCauseType(CalciteException.class);
148149
}
149150

151+
@Test
152+
public void unsupportedFeatureIsRethrownAsSemanticCheckException() {
153+
// A feature unsupported on the analytics engine (here a PPL command that raises
154+
// CalciteUnsupportedException; SQL table functions like vectorSearch() take the same path) is
155+
// an invalid query, normalized to a SemanticCheckException so callers classify it as a 4xx.
156+
givenInvalidQuery("source = catalog.employees | kmeans")
157+
.assertErrorType(SemanticCheckException.class)
158+
.assertCauseType(CalciteUnsupportedException.class)
159+
.assertErrorMessageContains("unsupported in Calcite");
160+
}
161+
150162
@Test
151163
public void assertionErrorIsWrappedAsSemanticCheckException() {
152164
// Remove when the underlying Calcite assertion is fixed.

0 commit comments

Comments
 (0)