Skip to content

Commit 29a6668

Browse files
Piotr Kołaczkowskidjatnieks
authored andcommitted
CNDB-13330: Fix wildcard select with BM25 order
When a wildcard selection is used, the score column must be included in the selection. Fixes: NoHostAvailable: ('Unable to complete the operation against any hosts', {<Host: 10.87.217.86:9042 us-central1>: <Error from server: code=0000 [Server error] message="java.lang.ClassCastException: class org.apache.cassandra.serializers.UTF8Serializer cannot be cast to class org.apache.cassandra.db.marshal.VectorType$VectorSerializer (org.apache.cassandra.serializers.UTF8Serializer and org.apache.cassandra.db.marshal.VectorType$VectorSerializer are in unnamed module of loader org.apache.felix.framework.BundleWiringImpl$BundleClassLoader @446c3920)">})
1 parent 744f3ea commit 29a6668

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/java/org/apache/cassandra/cql3/selection/Selection.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,14 @@ public static Selection wildcard(TableMetadata table, boolean isJson, boolean re
153153

154154
public static Selection wildcard(TableMetadata table, Set<ColumnMetadata> orderingColumns, boolean isJson, boolean returnStaticContentOnPartitionWithNoRows)
155155
{
156+
// Add all table columns, but skip orderingColumns:
156157
List<ColumnMetadata> all = new ArrayList<>(table.columns().size());
157158
Iterators.addAll(all, table.allColumnsInSelectOrder());
158-
return new SimpleSelection(table, all, orderingColumns, true, isJson, returnStaticContentOnPartitionWithNoRows);
159+
160+
Set<ColumnMetadata> newOrderingColumns = new HashSet<>(orderingColumns);
161+
all.forEach(newOrderingColumns::remove);
162+
163+
return new SimpleSelection(table, all, newOrderingColumns, true, isJson, returnStaticContentOnPartitionWithNoRows);
159164
}
160165

161166
public static Selection wildcardWithGroupByOrMaskedColumns(TableMetadata table,

src/java/org/apache/cassandra/cql3/statements/SelectStatement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1579,7 +1579,7 @@ private Selection prepareSelection(ClientState state,
15791579
{
15801580
return hasGroupBy || table.hasMaskedColumns()
15811581
? Selection.wildcardWithGroupByOrMaskedColumns(table, boundNames, resultSetOrderingColumns, isJson, returnStaticContentOnPartitionWithNoRows)
1582-
: Selection.wildcard(table, isJson, returnStaticContentOnPartitionWithNoRows);
1582+
: Selection.wildcard(table, resultSetOrderingColumns, isJson, returnStaticContentOnPartitionWithNoRows);
15831583
}
15841584

15851585
return Selection.fromSelectors(table,

test/unit/org/apache/cassandra/index/sai/cql/BM25Test.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,4 +547,18 @@ public void testBM25RaceConditionConcurrentQueriesInInvertedIndexSearcher() thro
547547
// Shutdown executor
548548
assertEquals(0, executor.shutdownNow().size());
549549
}
550+
551+
@Test
552+
public void testWildcardSelection()
553+
{
554+
createTable("CREATE TABLE %s (k int, c int, v text, PRIMARY KEY (k, c))");
555+
analyzeIndex();
556+
execute("INSERT INTO %s (k, c, v) VALUES (1, 1, 'apple')");
557+
558+
var result = execute("SELECT * FROM %s ORDER BY v BM25 OF 'apple' LIMIT 3");
559+
assertThat(result).hasSize(1);
560+
561+
var result2 = execute("SELECT * FROM %s GROUP BY k, c ORDER BY v BM25 OF 'apple' LIMIT 3");
562+
assertThat(result2).hasSize(1);
563+
}
550564
}

0 commit comments

Comments
 (0)