Skip to content

Commit 120bf89

Browse files
committed
Add integration tests for vectorSearch() without k-NN plugin
Lock in that execution fails with a clear error on clusters without opensearch-knn installed, and that _explain still returns a plan so users can debug queries against such clusters. Signed-off-by: Eric Wei <mengwei.eric@gmail.com>
1 parent 3d55191 commit 120bf89

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

integ-test/src/test/java/org/opensearch/sql/sql/VectorSearchIT.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,44 @@ public void testTrailingCommaInVectorRejected() throws IOException {
669669
assertThat(ex.getMessage(), containsString("trailing or consecutive commas"));
670670
}
671671

672+
// ── k-NN plugin absent execution paths ────────────────────────────────
673+
// The default integ-test cluster does not install opensearch-knn, so execution of a
674+
// vectorSearch() must fail fast with a clear error at scan open() time while _explain and
675+
// validation-time errors keep working.
676+
677+
@Test
678+
public void testExecutionWithoutKnnPluginFailsWithClearMessage() throws IOException {
679+
ResponseException ex =
680+
expectThrows(
681+
ResponseException.class,
682+
() ->
683+
executeQuery(
684+
"SELECT v._id FROM vectorSearch(table='"
685+
+ TEST_INDEX
686+
+ "', field='embedding', vector='[1.0, 2.0]', option='k=5') AS v"));
687+
688+
assertThat(
689+
ex.getMessage(),
690+
containsString(
691+
"vectorSearch() requires the k-NN plugin, which is not installed on this cluster."));
692+
}
693+
694+
@Test
695+
public void testExplainWithoutKnnPluginStillSucceeds() throws IOException {
696+
// Plugin check is deferred to scan open(), so _explain must still return a plan — useful for
697+
// users debugging queries on clusters without k-NN installed. The DSL body is base64-encoded
698+
// inside a wrapper query in the explain output, so we assert on the scan operator name and
699+
// the wrapper marker rather than the inner "knn" string.
700+
String explain =
701+
explainQuery(
702+
"SELECT v._id FROM vectorSearch(table='"
703+
+ TEST_INDEX
704+
+ "', field='embedding', vector='[1.0, 2.0]', option='k=5') AS v");
705+
706+
assertThat(explain, containsString("VectorSearchIndexScan"));
707+
assertThat(explain, containsString("wrapper"));
708+
}
709+
672710
private void deleteIndexIfExists(String indexName) {
673711
try {
674712
client().performRequest(new Request("DELETE", "/" + indexName));

0 commit comments

Comments
 (0)