Skip to content

Commit 88675ba

Browse files
committed
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 7ce9397 commit 88675ba

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,20 +146,26 @@ public static Selection wildcard(TableMetadata table, boolean isJson, boolean re
146146

147147
public static Selection wildcard(TableMetadata table, Set<ColumnMetadata> orderingColumns, boolean isJson, boolean returnStaticContentOnPartitionWithNoRows)
148148
{
149+
// Add all table columns, but skip orderingColumns:
149150
List<ColumnMetadata> all = new ArrayList<>(table.columns().size());
150151
Iterators.addAll(all, table.allColumnsInSelectOrder());
151-
return new SimpleSelection(table, all, orderingColumns, true, isJson, returnStaticContentOnPartitionWithNoRows);
152+
153+
Set<ColumnMetadata> newOrderingColumns = new HashSet<>(orderingColumns);
154+
all.forEach(newOrderingColumns::remove);
155+
156+
return new SimpleSelection(table, all, newOrderingColumns, true, isJson, returnStaticContentOnPartitionWithNoRows);
152157
}
153158

154159
public static Selection wildcardWithGroupBy(TableMetadata table,
155160
VariableSpecifications boundNames,
161+
Set<ColumnMetadata> orderingColumns,
156162
boolean isJson,
157163
boolean returnStaticContentOnPartitionWithNoRows)
158164
{
159165
return fromSelectors(table,
160166
Lists.newArrayList(table.allColumnsInSelectOrder()),
161167
boundNames,
162-
Collections.emptySet(),
168+
orderingColumns,
163169
Collections.emptySet(),
164170
true,
165171
isJson,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,8 +1304,8 @@ private Selection prepareSelection(TableMetadata table,
13041304
if (selectables.isEmpty()) // wildcard query
13051305
{
13061306
return hasGroupBy
1307-
? Selection.wildcardWithGroupBy(table, boundNames, parameters.isJson, restrictions.returnStaticContentOnPartitionWithNoRows())
1308-
: Selection.wildcard(table, parameters.isJson, restrictions.returnStaticContentOnPartitionWithNoRows());
1307+
? Selection.wildcardWithGroupBy(table, boundNames, resultSetOrderingColumns, parameters.isJson, restrictions.returnStaticContentOnPartitionWithNoRows())
1308+
: Selection.wildcard(table, resultSetOrderingColumns, parameters.isJson, restrictions.returnStaticContentOnPartitionWithNoRows());
13091309
}
13101310

13111311
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)