diff --git a/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java b/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java index 4d1b4bb68a09..b4bf34dbfa54 100644 --- a/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java +++ b/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java @@ -81,6 +81,7 @@ public class StatementRestrictions "Restriction on partition key column %s must not be nested under OR operator"; public static final String GEO_DISTANCE_REQUIRES_INDEX_MESSAGE = "GEO_DISTANCE requires the vector column to be indexed"; + public static final String BM25_ORDERING_REQUIRES_ANALYZED_INDEX_MESSAGE = "BM25 ordering on column %s requires an analyzed index"; public static final String NON_CLUSTER_ORDERING_REQUIRES_INDEX_MESSAGE = "Ordering on non-clustering column %s requires the column to be indexed"; public static final String NON_CLUSTER_ORDERING_REQUIRES_ALL_RESTRICTED_NON_PARTITION_KEY_COLUMNS_INDEXED_MESSAGE = "Ordering on non-clustering column requires each restricted column to be indexed except for fully-specified partition keys"; @@ -696,8 +697,12 @@ else if (indexOrderings.size() == 1) throw new InvalidRequestException(String.format("SAI based ordering on column %s of type %s is not supported", restriction.getFirstColumn(), restriction.getFirstColumn().type.asCQL3Type())); - throw new InvalidRequestException(String.format(NON_CLUSTER_ORDERING_REQUIRES_INDEX_MESSAGE, - restriction.getFirstColumn())); + if (ordering.expression instanceof Ordering.Bm25) + throw new InvalidRequestException(String.format(BM25_ORDERING_REQUIRES_ANALYZED_INDEX_MESSAGE, + restriction.getFirstColumn())); + else + throw new InvalidRequestException(String.format(NON_CLUSTER_ORDERING_REQUIRES_INDEX_MESSAGE, + restriction.getFirstColumn())); } receiver.addRestriction(restriction, false); } diff --git a/test/unit/org/apache/cassandra/index/sai/cql/BM25Test.java b/test/unit/org/apache/cassandra/index/sai/cql/BM25Test.java index 3f220527d648..44f5c76982f7 100644 --- a/test/unit/org/apache/cassandra/index/sai/cql/BM25Test.java +++ b/test/unit/org/apache/cassandra/index/sai/cql/BM25Test.java @@ -20,9 +20,11 @@ import org.junit.Test; +import org.apache.cassandra.exceptions.InvalidRequestException; import org.apache.cassandra.index.sai.SAITester; import org.apache.cassandra.index.sai.plan.QueryController; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; public class BM25Test extends SAITester @@ -43,6 +45,19 @@ public void testMatchingAllowed() throws Throwable }); } + @Test + public void testTwoIndexes() throws Throwable + { + // create un-analyzed index + createTable("CREATE TABLE %s (k int PRIMARY KEY, v text)"); + createIndex("CREATE CUSTOM INDEX ON %s(v) USING 'org.apache.cassandra.index.sai.StorageAttachedIndex'"); + + execute("INSERT INTO %s (k, v) VALUES (1, 'apple')"); + assertThatThrownBy(() -> execute("SELECT k FROM %s WHERE v : 'apple' ORDER BY v BM25 OF 'apple' LIMIT 3")) + .isInstanceOf(InvalidRequestException.class) + .hasMessage("BM25 ordering on column v requires an analyzed index"); + } + @Test public void testTermFrequencyOrdering() throws Throwable {