Skip to content

Commit 88e32df

Browse files
committed
fmt
1 parent 29ad892 commit 88e32df

File tree

6 files changed

+97
-65
lines changed

6 files changed

+97
-65
lines changed
Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
118
package com.datastax.oss.driver.api.querybuilder.select;
219

3-
import com.datastax.oss.driver.api.core.data.CqlVector;
420
import com.datastax.oss.driver.api.querybuilder.BuildableQuery;
521

6-
public interface Ann extends BuildableQuery {
7-
8-
}
22+
public interface Ann extends BuildableQuery {}
Lines changed: 60 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,73 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
118
package com.datastax.oss.driver.internal.querybuilder.select;
219

20+
import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.literal;
21+
322
import com.datastax.oss.driver.api.core.CqlIdentifier;
423
import com.datastax.oss.driver.api.core.cql.SimpleStatement;
524
import com.datastax.oss.driver.api.core.cql.SimpleStatementBuilder;
625
import com.datastax.oss.driver.api.core.data.CqlVector;
726
import com.datastax.oss.driver.api.querybuilder.select.Ann;
827
import edu.umd.cs.findbugs.annotations.NonNull;
9-
1028
import java.util.Map;
1129

12-
import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.literal;
13-
1430
public class DefaultAnn implements Ann {
15-
private final CqlIdentifier cqlIdentifier;
16-
private final CqlVector<Number> vector;
17-
18-
public DefaultAnn(@NonNull CqlIdentifier cqlIdentifier, @NonNull CqlVector<Number> vector) {
19-
this.cqlIdentifier = cqlIdentifier;
20-
this.vector = vector;
21-
}
22-
23-
@NonNull
24-
@Override
25-
public String asCql() {
26-
StringBuilder builder = new StringBuilder();
27-
builder.append("ORDER BY ");
28-
builder.append(this.cqlIdentifier.asCql(true));
29-
builder.append(" ANN OF ");
30-
literal(vector).appendTo(builder);
31-
return builder.toString();
32-
}
33-
34-
@NonNull
35-
@Override
36-
public SimpleStatement build() {
37-
return Ann.super.build();
38-
}
39-
40-
@NonNull
41-
@Override
42-
public SimpleStatement build(@NonNull Object... values) {
43-
return Ann.super.build(values);
44-
}
45-
46-
@NonNull
47-
@Override
48-
public SimpleStatement build(@NonNull Map<String, Object> namedValues) {
49-
return Ann.super.build(namedValues);
50-
}
51-
52-
@NonNull
53-
@Override
54-
public SimpleStatementBuilder builder() {
55-
return Ann.super.builder();
56-
}
31+
private final CqlIdentifier cqlIdentifier;
32+
private final CqlVector<Number> vector;
33+
34+
public DefaultAnn(@NonNull CqlIdentifier cqlIdentifier, @NonNull CqlVector<Number> vector) {
35+
this.cqlIdentifier = cqlIdentifier;
36+
this.vector = vector;
37+
}
38+
39+
@NonNull
40+
@Override
41+
public String asCql() {
42+
StringBuilder builder = new StringBuilder();
43+
builder.append("ORDER BY ");
44+
builder.append(this.cqlIdentifier.asCql(true));
45+
builder.append(" ANN OF ");
46+
literal(vector).appendTo(builder);
47+
return builder.toString();
48+
}
49+
50+
@NonNull
51+
@Override
52+
public SimpleStatement build() {
53+
return Ann.super.build();
54+
}
55+
56+
@NonNull
57+
@Override
58+
public SimpleStatement build(@NonNull Object... values) {
59+
return Ann.super.build(values);
60+
}
61+
62+
@NonNull
63+
@Override
64+
public SimpleStatement build(@NonNull Map<String, Object> namedValues) {
65+
return Ann.super.build(namedValues);
66+
}
5767

68+
@NonNull
69+
@Override
70+
public SimpleStatementBuilder builder() {
71+
return Ann.super.builder();
72+
}
5873
}

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ public DefaultSelect(@Nullable CqlIdentifier keyspace, @NonNull CqlIdentifier ta
7777
* @param selectors if it contains {@link AllSelector#INSTANCE}, that must be the only element.
7878
* This isn't re-checked because methods that call this constructor internally already do it,
7979
* make sure you do it yourself.
80-
* @param ann Approximate nearest neighbor. ANN ordering does not support secondary ordering or ASC order.
80+
* @param ann Approximate nearest neighbor. ANN ordering does not support secondary ordering or
81+
* ASC order.
8182
*/
8283
public DefaultSelect(
8384
@Nullable CqlIdentifier keyspace,
@@ -100,8 +101,7 @@ public DefaultSelect(
100101
|| limit instanceof BindMarker,
101102
"limit must be a strictly positive integer or a bind marker");
102103
Preconditions.checkArgument(
103-
orderings.isEmpty() || ann == null,
104-
"ANN ordering does not support secondary ordering");
104+
orderings.isEmpty() || ann == null, "ANN ordering does not support secondary ordering");
105105
this.ann = ann;
106106
this.keyspace = keyspace;
107107
this.table = table;
@@ -282,7 +282,7 @@ public Select orderByIds(@NonNull Map<CqlIdentifier, ClusteringOrder> newOrderin
282282

283283
@NonNull
284284
@Override
285-
public Select orderBy(@NonNull Ann ann){
285+
public Select orderBy(@NonNull Ann ann) {
286286
return withAnn(ann);
287287
}
288288

@@ -303,7 +303,8 @@ public Select withOrderings(@NonNull ImmutableMap<CqlIdentifier, ClusteringOrder
303303
allowsFiltering);
304304
}
305305

306-
@NonNull Select withAnn(@NonNull Ann ann){
306+
@NonNull
307+
Select withAnn(@NonNull Ann ann) {
307308
return new DefaultSelect(
308309
keyspace,
309310
table,
@@ -433,9 +434,9 @@ public String asCql() {
433434
CqlHelper.append(relations, builder, " WHERE ", " AND ", null);
434435
CqlHelper.append(groupByClauses, builder, " GROUP BY ", ",", null);
435436

436-
if (ann != null){
437+
if (ann != null) {
437438
builder.append(" ").append(this.ann.asCql());
438-
}else{
439+
} else {
439440
boolean first = true;
440441
for (Map.Entry<CqlIdentifier, ClusteringOrder> entry : orderings.entrySet()) {
441442
if (first) {

query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/delete/DeleteSelectorTest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222
import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.deleteFrom;
2323
import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.literal;
2424

25-
import org.junit.Test;
26-
2725
import java.util.Arrays;
26+
import org.junit.Test;
2827

2928
public class DeleteSelectorTest {
3029

@@ -38,7 +37,11 @@ public void should_generate_column_deletion() {
3837

3938
@Test
4039
public void should_generate_vector_deletion() {
41-
assertThat(deleteFrom("foo").column("v").whereColumn("k").isEqualTo(literal(Arrays.asList(0.1, 0.2))))
40+
assertThat(
41+
deleteFrom("foo")
42+
.column("v")
43+
.whereColumn("k")
44+
.isEqualTo(literal(Arrays.asList(0.1, 0.2))))
4245
.hasCql("DELETE v FROM foo WHERE k=[0.1,0.2]");
4346
}
4447

query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/insert/RegularInsertTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import com.datastax.oss.driver.api.querybuilder.term.Term;
2727
import com.datastax.oss.driver.internal.querybuilder.insert.DefaultInsert;
2828
import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap;
29-
3029
import java.util.Arrays;
3130
import java.util.Map;
3231
import org.junit.Test;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ public void should_generate_ann_clause() {
8888
}
8989

9090
@Test(expected = IllegalArgumentException.class)
91-
public void should_fail_when_provided_ann_with_other_orderings(){
91+
public void should_fail_when_provided_ann_with_other_orderings() {
9292
selectFrom("foo")
93-
.all()
94-
.where(Relation.column("k").isEqualTo(literal(1)))
95-
.orderBy("c1", ASC)
96-
.orderBy(annOf("c1", CqlVector.newInstance(0.1, 0.2, 0.3)));
93+
.all()
94+
.where(Relation.column("k").isEqualTo(literal(1)))
95+
.orderBy("c1", ASC)
96+
.orderBy(annOf("c1", CqlVector.newInstance(0.1, 0.2, 0.3)));
9797
}
9898
}

0 commit comments

Comments
 (0)