Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/java/org/apache/cassandra/cql3/selection/Selection.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,26 @@ public static Selection wildcard(TableMetadata table, boolean isJson, boolean re

public static Selection wildcard(TableMetadata table, Set<ColumnMetadata> orderingColumns, boolean isJson, boolean returnStaticContentOnPartitionWithNoRows)
{
// Add all table columns, but skip orderingColumns:
List<ColumnMetadata> all = new ArrayList<>(table.columns().size());
Iterators.addAll(all, table.allColumnsInSelectOrder());
return new SimpleSelection(table, all, orderingColumns, true, isJson, returnStaticContentOnPartitionWithNoRows);

Set<ColumnMetadata> newOrderingColumns = new HashSet<>(orderingColumns);
all.forEach(newOrderingColumns::remove);

return new SimpleSelection(table, all, newOrderingColumns, true, isJson, returnStaticContentOnPartitionWithNoRows);
}

public static Selection wildcardWithGroupBy(TableMetadata table,
VariableSpecifications boundNames,
Set<ColumnMetadata> orderingColumns,
boolean isJson,
boolean returnStaticContentOnPartitionWithNoRows)
{
return fromSelectors(table,
Lists.newArrayList(table.allColumnsInSelectOrder()),
boundNames,
Collections.emptySet(),
orderingColumns,
Collections.emptySet(),
true,
isJson,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1304,8 +1304,8 @@ private Selection prepareSelection(TableMetadata table,
if (selectables.isEmpty()) // wildcard query
{
return hasGroupBy
? Selection.wildcardWithGroupBy(table, boundNames, parameters.isJson, restrictions.returnStaticContentOnPartitionWithNoRows())
: Selection.wildcard(table, parameters.isJson, restrictions.returnStaticContentOnPartitionWithNoRows());
? Selection.wildcardWithGroupBy(table, boundNames, resultSetOrderingColumns, parameters.isJson, restrictions.returnStaticContentOnPartitionWithNoRows())
: Selection.wildcard(table, resultSetOrderingColumns, parameters.isJson, restrictions.returnStaticContentOnPartitionWithNoRows());
}

return Selection.fromSelectors(table,
Expand Down
14 changes: 14 additions & 0 deletions test/unit/org/apache/cassandra/index/sai/cql/BM25Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -547,4 +547,18 @@ public void testBM25RaceConditionConcurrentQueriesInInvertedIndexSearcher() thro
// Shutdown executor
assertEquals(0, executor.shutdownNow().size());
}

@Test
public void testWildcardSelection()
{
createTable("CREATE TABLE %s (k int, c int, v text, PRIMARY KEY (k, c))");
analyzeIndex();
execute("INSERT INTO %s (k, c, v) VALUES (1, 1, 'apple')");

var result = execute("SELECT * FROM %s ORDER BY v BM25 OF 'apple' LIMIT 3");
assertThat(result).hasSize(1);

var result2 = execute("SELECT * FROM %s GROUP BY k, c ORDER BY v BM25 OF 'apple' LIMIT 3");
assertThat(result2).hasSize(1);
}
}