Skip to content

Commit d741d7f

Browse files
nikagraclaude
andcommitted
fix: keep ANN ordering on an empty orderByIds map
The ordering-clause rework made orderByIds(emptyMap) replace an ANN ordering with nothing; 4.19.2.x kept it. Document the map overloads' replace behaviour and fix a typo in CqlPrepareAsyncProcessor. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent e839d4e commit d741d7f

4 files changed

Lines changed: 20 additions & 3 deletions

File tree

‎core/src/main/java/com/datastax/oss/driver/internal/core/cql/CqlPrepareAsyncProcessor.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public CqlPrepareAsyncProcessor() {
6363
}
6464

6565
public CqlPrepareAsyncProcessor(@NonNull Optional<? extends DefaultDriverContext> context) {
66-
// Use weakValues to evict prepared statements from the cache as soon are they are
66+
// Use weakValues to evict prepared statements from the cache as soon as they are
6767
// no longer referenced elsewhere.
6868
this(context, CacheBuilder::weakValues);
6969
}

‎query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/select/Select.java‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,17 @@ default Select groupBy(@NonNull String columnName) {
117117
*
118118
* <p>They will be appended in the iteration order of the provided map. If an ordering was already
119119
* defined for a given identifier, it will be removed and the new ordering will appear in its
120-
* position in the provided map.
120+
* position in the provided map. If the query currently orders by {@code ANN OF}, that ordering is
121+
* replaced. An empty map leaves the query unchanged.
121122
*/
122123
@NonNull
123124
Select orderByIds(@NonNull Map<CqlIdentifier, ClusteringOrder> orderings);
124125

125126
/**
126127
* Shortcut for {@link #orderByIds(Map)} with the columns specified as case-insensitive names.
127-
* They will be wrapped with {@link CqlIdentifier#fromCql(String)}.
128+
* They will be wrapped with {@link CqlIdentifier#fromCql(String)}. As with {@link
129+
* #orderByIds(Map)}, an {@code ANN OF} ordering is replaced, and an empty map leaves the query
130+
* unchanged.
128131
*
129132
* <p>Note that it's possible for two different case-insensitive names to resolve to the same
130133
* identifier, for example "foo" and "Foo"; if this happens, a runtime exception will be thrown.

‎query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultSelect.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,9 @@ public Select orderByAnnOf(@NonNull CqlIdentifier columnId, @NonNull CqlVector<?
322322
@NonNull
323323
@Override
324324
public Select orderByIds(@NonNull Map<CqlIdentifier, ClusteringOrder> newOrderings) {
325+
if (newOrderings.isEmpty()) {
326+
return this;
327+
}
325328
ColumnsOrderingClause coc = getColumnOrderingClause();
326329
return withOrderingClause(coc.add(newOrderings));
327330
}

‎query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/select/SelectOrderingTest.java‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,15 @@ public void should_replace_ann_ordering_with_columns() {
107107
.orderBy("c2", ASC))
108108
.hasCql("SELECT * FROM foo WHERE k=1 ORDER BY c2 ASC");
109109
}
110+
111+
@Test
112+
public void should_keep_ann_ordering_when_map_is_empty() {
113+
assertThat(
114+
selectFrom("foo")
115+
.all()
116+
.where(Relation.column("k").isEqualTo(literal(1)))
117+
.orderByAnnOf("c1", CqlVector.newInstance(0.1, 0.2, 0.3))
118+
.orderBy(ImmutableMap.of()))
119+
.hasCql("SELECT * FROM foo WHERE k=1 ORDER BY c1 ANN OF [0.1, 0.2, 0.3]");
120+
}
110121
}

0 commit comments

Comments
 (0)