From 9e870339a3e587978f5d532534fa568c8676978f Mon Sep 17 00:00:00 2001 From: janehe Date: Thu, 2 May 2024 08:16:32 -0700 Subject: [PATCH 01/12] INSERT and DELETE working --- .../api/querybuilder/delete/DeleteSelectorTest.java | 8 ++++++++ .../driver/api/querybuilder/insert/RegularInsertTest.java | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/delete/DeleteSelectorTest.java b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/delete/DeleteSelectorTest.java index 23210971bc..d8a22a14c3 100644 --- a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/delete/DeleteSelectorTest.java +++ b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/delete/DeleteSelectorTest.java @@ -24,6 +24,8 @@ import org.junit.Test; +import java.util.Arrays; + public class DeleteSelectorTest { @Test @@ -34,6 +36,12 @@ public void should_generate_column_deletion() { .hasCql("DELETE v FROM ks.foo WHERE k=?"); } + @Test + public void should_generate_vector_deletion() { + assertThat(deleteFrom("foo").column("v").whereColumn("k").isEqualTo(literal(Arrays.asList(0.1, 0.2)))) + .hasCql("DELETE v FROM foo WHERE k=[0.1,0.2]"); + } + @Test public void should_generate_field_deletion() { assertThat( diff --git a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/insert/RegularInsertTest.java b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/insert/RegularInsertTest.java index 36133445b3..c22b87dd7e 100644 --- a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/insert/RegularInsertTest.java +++ b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/insert/RegularInsertTest.java @@ -26,6 +26,8 @@ import com.datastax.oss.driver.api.querybuilder.term.Term; import com.datastax.oss.driver.internal.querybuilder.insert.DefaultInsert; import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap; + +import java.util.Arrays; import java.util.Map; import org.junit.Test; @@ -41,6 +43,12 @@ public void should_generate_column_assignments() { .hasCql("INSERT INTO foo (a,b) VALUES (?,?)"); } + @Test + public void should_generate_vector_literals() { + assertThat(insertInto("foo").value("a", literal(Arrays.asList(0.1, 0.2, 0.3)))) + .hasCql("INSERT INTO foo (a) VALUES ([0.1,0.2,0.3])"); + } + @Test public void should_keep_last_assignment_if_column_listed_twice() { assertThat( From 9ea8689dd5ca8e3189dbb7d24ef2c160c88855dd Mon Sep 17 00:00:00 2001 From: janehe Date: Mon, 6 May 2024 12:10:48 -0700 Subject: [PATCH 02/12] orderBy(annOf("c1", CqlVector.newInstance(0.1, 0.2, 0.3)))) --- .../driver/api/querybuilder/QueryBuilder.java | 11 ++++ .../driver/api/querybuilder/select/Ann.java | 8 +++ .../api/querybuilder/select/Select.java | 2 + .../querybuilder/select/DefaultAnn.java | 58 +++++++++++++++++ .../querybuilder/select/DefaultSelect.java | 62 ++++++++++++++++--- .../select/SelectOrderingTest.java | 21 +++++++ 6 files changed, 154 insertions(+), 8 deletions(-) create mode 100644 query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/select/Ann.java create mode 100644 query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultAnn.java diff --git a/query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/QueryBuilder.java b/query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/QueryBuilder.java index 8df2b7efdd..ff5608e848 100644 --- a/query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/QueryBuilder.java +++ b/query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/QueryBuilder.java @@ -19,6 +19,7 @@ import com.datastax.oss.driver.api.core.CqlIdentifier; import com.datastax.oss.driver.api.core.context.DriverContext; +import com.datastax.oss.driver.api.core.data.CqlVector; import com.datastax.oss.driver.api.core.metadata.token.Token; import com.datastax.oss.driver.api.core.type.DataType; import com.datastax.oss.driver.api.core.type.DataTypes; @@ -29,6 +30,7 @@ import com.datastax.oss.driver.api.querybuilder.delete.DeleteSelection; import com.datastax.oss.driver.api.querybuilder.insert.InsertInto; import com.datastax.oss.driver.api.querybuilder.relation.Relation; +import com.datastax.oss.driver.api.querybuilder.select.Ann; import com.datastax.oss.driver.api.querybuilder.select.SelectFrom; import com.datastax.oss.driver.api.querybuilder.select.Selector; import com.datastax.oss.driver.api.querybuilder.term.Term; @@ -43,6 +45,7 @@ import com.datastax.oss.driver.internal.querybuilder.DefaultRaw; import com.datastax.oss.driver.internal.querybuilder.delete.DefaultDelete; import com.datastax.oss.driver.internal.querybuilder.insert.DefaultInsert; +import com.datastax.oss.driver.internal.querybuilder.select.DefaultAnn; import com.datastax.oss.driver.internal.querybuilder.select.DefaultBindMarker; import com.datastax.oss.driver.internal.querybuilder.select.DefaultSelect; import com.datastax.oss.driver.internal.querybuilder.term.BinaryArithmeticTerm; @@ -538,4 +541,12 @@ public static Truncate truncate(@Nullable String keyspace, @NonNull String table return truncate( keyspace == null ? null : CqlIdentifier.fromCql(keyspace), CqlIdentifier.fromCql(table)); } + + public static Ann annOf(@NonNull CqlIdentifier cqlIdentifier, @NonNull CqlVector vector) { + return new DefaultAnn(cqlIdentifier, vector); + } + + public static Ann annOf(@NonNull String cqlIdentifier, @NonNull CqlVector vector) { + return new DefaultAnn(CqlIdentifier.fromCql(cqlIdentifier), vector); + } } diff --git a/query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/select/Ann.java b/query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/select/Ann.java new file mode 100644 index 0000000000..0423d675fd --- /dev/null +++ b/query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/select/Ann.java @@ -0,0 +1,8 @@ +package com.datastax.oss.driver.api.querybuilder.select; + +import com.datastax.oss.driver.api.core.data.CqlVector; +import com.datastax.oss.driver.api.querybuilder.BuildableQuery; + +public interface Ann extends BuildableQuery { + +} diff --git a/query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/select/Select.java b/query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/select/Select.java index a22b45c35b..f0b5e74438 100644 --- a/query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/select/Select.java +++ b/query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/select/Select.java @@ -146,6 +146,8 @@ default Select orderBy(@NonNull String columnName, @NonNull ClusteringOrder orde return orderBy(CqlIdentifier.fromCql(columnName), order); } + @NonNull + Select orderBy(@NonNull Ann ann); /** * Adds a LIMIT clause to this query with a literal value. * diff --git a/query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultAnn.java b/query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultAnn.java new file mode 100644 index 0000000000..05ca97352e --- /dev/null +++ b/query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultAnn.java @@ -0,0 +1,58 @@ +package com.datastax.oss.driver.internal.querybuilder.select; + +import com.datastax.oss.driver.api.core.CqlIdentifier; +import com.datastax.oss.driver.api.core.cql.SimpleStatement; +import com.datastax.oss.driver.api.core.cql.SimpleStatementBuilder; +import com.datastax.oss.driver.api.core.data.CqlVector; +import com.datastax.oss.driver.api.querybuilder.select.Ann; +import edu.umd.cs.findbugs.annotations.NonNull; + +import java.util.Map; + +import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.literal; + +public class DefaultAnn implements Ann { + private final CqlIdentifier cqlIdentifier; + private final CqlVector vector; + + public DefaultAnn(@NonNull CqlIdentifier cqlIdentifier, @NonNull CqlVector vector) { + this.cqlIdentifier = cqlIdentifier; + this.vector = vector; + } + + @NonNull + @Override + public String asCql() { + StringBuilder builder = new StringBuilder(); + builder.append("ORDER BY "); + builder.append(this.cqlIdentifier.asCql(true)); + builder.append(" ANN OF "); + literal(vector).appendTo(builder); + return builder.toString(); + } + + @NonNull + @Override + public SimpleStatement build() { + return Ann.super.build(); + } + + @NonNull + @Override + public SimpleStatement build(@NonNull Object... values) { + return Ann.super.build(values); + } + + @NonNull + @Override + public SimpleStatement build(@NonNull Map namedValues) { + return Ann.super.build(namedValues); + } + + @NonNull + @Override + public SimpleStatementBuilder builder() { + return Ann.super.builder(); + } + +} diff --git a/query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultSelect.java b/query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultSelect.java index 86a2a07a3f..4519385a76 100644 --- a/query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultSelect.java +++ b/query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultSelect.java @@ -23,6 +23,7 @@ import com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder; import com.datastax.oss.driver.api.querybuilder.BindMarker; import com.datastax.oss.driver.api.querybuilder.relation.Relation; +import com.datastax.oss.driver.api.querybuilder.select.Ann; import com.datastax.oss.driver.api.querybuilder.select.Select; import com.datastax.oss.driver.api.querybuilder.select.SelectFrom; import com.datastax.oss.driver.api.querybuilder.select.Selector; @@ -49,6 +50,7 @@ public class DefaultSelect implements SelectFrom, Select { private final ImmutableList relations; private final ImmutableList groupByClauses; private final ImmutableMap orderings; + private final Ann ann; private final Object limit; private final Object perPartitionLimit; private final boolean allowsFiltering; @@ -65,6 +67,7 @@ public DefaultSelect(@Nullable CqlIdentifier keyspace, @NonNull CqlIdentifier ta ImmutableMap.of(), null, null, + null, false); } @@ -74,6 +77,7 @@ public DefaultSelect(@Nullable CqlIdentifier keyspace, @NonNull CqlIdentifier ta * @param selectors if it contains {@link AllSelector#INSTANCE}, that must be the only element. * This isn't re-checked because methods that call this constructor internally already do it, * make sure you do it yourself. + * @param ann Approximate nearest neighbor. ANN ordering does not support secondary ordering or ASC order. */ public DefaultSelect( @Nullable CqlIdentifier keyspace, @@ -84,6 +88,7 @@ public DefaultSelect( @NonNull ImmutableList relations, @NonNull ImmutableList groupByClauses, @NonNull ImmutableMap orderings, + @Nullable Ann ann, @Nullable Object limit, @Nullable Object perPartitionLimit, boolean allowsFiltering) { @@ -94,6 +99,10 @@ public DefaultSelect( || (limit instanceof Integer && (Integer) limit > 0) || limit instanceof BindMarker, "limit must be a strictly positive integer or a bind marker"); + Preconditions.checkArgument( + orderings.isEmpty() || ann == null, + "ANN ordering does not support secondary ordering"); + this.ann = ann; this.keyspace = keyspace; this.table = table; this.isJson = isJson; @@ -117,6 +126,7 @@ public SelectFrom json() { relations, groupByClauses, orderings, + null, limit, perPartitionLimit, allowsFiltering); @@ -134,6 +144,7 @@ public SelectFrom distinct() { relations, groupByClauses, orderings, + null, limit, perPartitionLimit, allowsFiltering); @@ -193,6 +204,7 @@ public Select withSelectors(@NonNull ImmutableList newSelectors) { relations, groupByClauses, orderings, + null, limit, perPartitionLimit, allowsFiltering); @@ -221,6 +233,7 @@ public Select withRelations(@NonNull ImmutableList newRelations) { newRelations, groupByClauses, orderings, + null, limit, perPartitionLimit, allowsFiltering); @@ -249,6 +262,7 @@ public Select withGroupByClauses(@NonNull ImmutableList newGroupByClau relations, newGroupByClauses, orderings, + null, limit, perPartitionLimit, allowsFiltering); @@ -266,6 +280,12 @@ public Select orderByIds(@NonNull Map newOrderin return withOrderings(ImmutableCollections.concat(orderings, newOrderings)); } + @NonNull + @Override + public Select orderBy(@NonNull Ann ann){ + return withAnn(ann); + } + @NonNull public Select withOrderings(@NonNull ImmutableMap newOrderings) { return new DefaultSelect( @@ -277,6 +297,23 @@ public Select withOrderings(@NonNull ImmutableMap entry : orderings.entrySet()) { - if (first) { - builder.append(" ORDER BY "); - first = false; - } else { - builder.append(","); + if (ann != null){ + builder.append(" ").append(this.ann.asCql()); + }else{ + boolean first = true; + for (Map.Entry entry : orderings.entrySet()) { + if (first) { + builder.append(" ORDER BY "); + first = false; + } else { + builder.append(","); + } + builder.append(entry.getKey().asCql(true)).append(" ").append(entry.getValue().name()); } - builder.append(entry.getKey().asCql(true)).append(" ").append(entry.getValue().name()); } if (limit != null) { diff --git a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/select/SelectOrderingTest.java b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/select/SelectOrderingTest.java index ff27fde4f8..437a705b62 100644 --- a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/select/SelectOrderingTest.java +++ b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/select/SelectOrderingTest.java @@ -20,9 +20,11 @@ import static com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder.ASC; import static com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder.DESC; import static com.datastax.oss.driver.api.querybuilder.Assertions.assertThat; +import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.annOf; import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.literal; import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.selectFrom; +import com.datastax.oss.driver.api.core.data.CqlVector; import com.datastax.oss.driver.api.querybuilder.relation.Relation; import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap; import org.junit.Test; @@ -74,4 +76,23 @@ public void should_replace_previous_ordering() { .orderBy(ImmutableMap.of("c1", DESC, "c2", ASC))) .hasCql("SELECT * FROM foo WHERE k=1 ORDER BY c3 ASC,c1 DESC,c2 ASC"); } + + @Test + public void should_generate_ann_clause() { + assertThat( + selectFrom("foo") + .all() + .where(Relation.column("k").isEqualTo(literal(1))) + .orderBy(annOf("c1", CqlVector.newInstance(0.1, 0.2, 0.3)))) + .hasCql("SELECT * FROM foo WHERE k=1 ORDER BY c1 ANN OF [0.1, 0.2, 0.3]"); + } + + @Test(expected = IllegalArgumentException.class) + public void should_fail_when_provided_ann_with_other_orderings(){ + selectFrom("foo") + .all() + .where(Relation.column("k").isEqualTo(literal(1))) + .orderBy("c1", ASC) + .orderBy(annOf("c1", CqlVector.newInstance(0.1, 0.2, 0.3))); + } } From b035763082f89a28fcd8c67b2fd18dcdfd6d5952 Mon Sep 17 00:00:00 2001 From: janehe Date: Mon, 6 May 2024 12:18:15 -0700 Subject: [PATCH 03/12] fmt --- .../driver/api/querybuilder/select/Ann.java | 22 +++- .../querybuilder/select/DefaultAnn.java | 105 ++++++++++-------- .../querybuilder/select/DefaultSelect.java | 15 +-- .../delete/DeleteSelectorTest.java | 9 +- .../insert/RegularInsertTest.java | 1 - .../select/SelectOrderingTest.java | 10 +- 6 files changed, 97 insertions(+), 65 deletions(-) diff --git a/query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/select/Ann.java b/query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/select/Ann.java index 0423d675fd..d287fc6e8f 100644 --- a/query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/select/Ann.java +++ b/query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/select/Ann.java @@ -1,8 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.datastax.oss.driver.api.querybuilder.select; -import com.datastax.oss.driver.api.core.data.CqlVector; import com.datastax.oss.driver.api.querybuilder.BuildableQuery; -public interface Ann extends BuildableQuery { - -} +public interface Ann extends BuildableQuery {} diff --git a/query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultAnn.java b/query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultAnn.java index 05ca97352e..6510f5dfbd 100644 --- a/query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultAnn.java +++ b/query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultAnn.java @@ -1,58 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.datastax.oss.driver.internal.querybuilder.select; +import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.literal; + import com.datastax.oss.driver.api.core.CqlIdentifier; import com.datastax.oss.driver.api.core.cql.SimpleStatement; import com.datastax.oss.driver.api.core.cql.SimpleStatementBuilder; import com.datastax.oss.driver.api.core.data.CqlVector; import com.datastax.oss.driver.api.querybuilder.select.Ann; import edu.umd.cs.findbugs.annotations.NonNull; - import java.util.Map; -import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.literal; - public class DefaultAnn implements Ann { - private final CqlIdentifier cqlIdentifier; - private final CqlVector vector; - - public DefaultAnn(@NonNull CqlIdentifier cqlIdentifier, @NonNull CqlVector vector) { - this.cqlIdentifier = cqlIdentifier; - this.vector = vector; - } - - @NonNull - @Override - public String asCql() { - StringBuilder builder = new StringBuilder(); - builder.append("ORDER BY "); - builder.append(this.cqlIdentifier.asCql(true)); - builder.append(" ANN OF "); - literal(vector).appendTo(builder); - return builder.toString(); - } - - @NonNull - @Override - public SimpleStatement build() { - return Ann.super.build(); - } - - @NonNull - @Override - public SimpleStatement build(@NonNull Object... values) { - return Ann.super.build(values); - } - - @NonNull - @Override - public SimpleStatement build(@NonNull Map namedValues) { - return Ann.super.build(namedValues); - } - - @NonNull - @Override - public SimpleStatementBuilder builder() { - return Ann.super.builder(); - } + private final CqlIdentifier cqlIdentifier; + private final CqlVector vector; + + public DefaultAnn(@NonNull CqlIdentifier cqlIdentifier, @NonNull CqlVector vector) { + this.cqlIdentifier = cqlIdentifier; + this.vector = vector; + } + + @NonNull + @Override + public String asCql() { + StringBuilder builder = new StringBuilder(); + builder.append("ORDER BY "); + builder.append(this.cqlIdentifier.asCql(true)); + builder.append(" ANN OF "); + literal(vector).appendTo(builder); + return builder.toString(); + } + + @NonNull + @Override + public SimpleStatement build() { + return Ann.super.build(); + } + + @NonNull + @Override + public SimpleStatement build(@NonNull Object... values) { + return Ann.super.build(values); + } + + @NonNull + @Override + public SimpleStatement build(@NonNull Map namedValues) { + return Ann.super.build(namedValues); + } + @NonNull + @Override + public SimpleStatementBuilder builder() { + return Ann.super.builder(); + } } diff --git a/query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultSelect.java b/query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultSelect.java index 4519385a76..a45a515a62 100644 --- a/query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultSelect.java +++ b/query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultSelect.java @@ -77,7 +77,8 @@ public DefaultSelect(@Nullable CqlIdentifier keyspace, @NonNull CqlIdentifier ta * @param selectors if it contains {@link AllSelector#INSTANCE}, that must be the only element. * This isn't re-checked because methods that call this constructor internally already do it, * make sure you do it yourself. - * @param ann Approximate nearest neighbor. ANN ordering does not support secondary ordering or ASC order. + * @param ann Approximate nearest neighbor. ANN ordering does not support secondary ordering or + * ASC order. */ public DefaultSelect( @Nullable CqlIdentifier keyspace, @@ -100,8 +101,7 @@ public DefaultSelect( || limit instanceof BindMarker, "limit must be a strictly positive integer or a bind marker"); Preconditions.checkArgument( - orderings.isEmpty() || ann == null, - "ANN ordering does not support secondary ordering"); + orderings.isEmpty() || ann == null, "ANN ordering does not support secondary ordering"); this.ann = ann; this.keyspace = keyspace; this.table = table; @@ -282,7 +282,7 @@ public Select orderByIds(@NonNull Map newOrderin @NonNull @Override - public Select orderBy(@NonNull Ann ann){ + public Select orderBy(@NonNull Ann ann) { return withAnn(ann); } @@ -303,7 +303,8 @@ public Select withOrderings(@NonNull ImmutableMap entry : orderings.entrySet()) { if (first) { diff --git a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/delete/DeleteSelectorTest.java b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/delete/DeleteSelectorTest.java index d8a22a14c3..77c2c543cf 100644 --- a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/delete/DeleteSelectorTest.java +++ b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/delete/DeleteSelectorTest.java @@ -22,9 +22,8 @@ import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.deleteFrom; import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.literal; -import org.junit.Test; - import java.util.Arrays; +import org.junit.Test; public class DeleteSelectorTest { @@ -38,7 +37,11 @@ public void should_generate_column_deletion() { @Test public void should_generate_vector_deletion() { - assertThat(deleteFrom("foo").column("v").whereColumn("k").isEqualTo(literal(Arrays.asList(0.1, 0.2)))) + assertThat( + deleteFrom("foo") + .column("v") + .whereColumn("k") + .isEqualTo(literal(Arrays.asList(0.1, 0.2)))) .hasCql("DELETE v FROM foo WHERE k=[0.1,0.2]"); } diff --git a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/insert/RegularInsertTest.java b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/insert/RegularInsertTest.java index c22b87dd7e..a277b037fc 100644 --- a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/insert/RegularInsertTest.java +++ b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/insert/RegularInsertTest.java @@ -26,7 +26,6 @@ import com.datastax.oss.driver.api.querybuilder.term.Term; import com.datastax.oss.driver.internal.querybuilder.insert.DefaultInsert; import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap; - import java.util.Arrays; import java.util.Map; import org.junit.Test; diff --git a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/select/SelectOrderingTest.java b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/select/SelectOrderingTest.java index 437a705b62..824f1c48c6 100644 --- a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/select/SelectOrderingTest.java +++ b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/select/SelectOrderingTest.java @@ -88,11 +88,11 @@ public void should_generate_ann_clause() { } @Test(expected = IllegalArgumentException.class) - public void should_fail_when_provided_ann_with_other_orderings(){ + public void should_fail_when_provided_ann_with_other_orderings() { selectFrom("foo") - .all() - .where(Relation.column("k").isEqualTo(literal(1))) - .orderBy("c1", ASC) - .orderBy(annOf("c1", CqlVector.newInstance(0.1, 0.2, 0.3))); + .all() + .where(Relation.column("k").isEqualTo(literal(1))) + .orderBy("c1", ASC) + .orderBy(annOf("c1", CqlVector.newInstance(0.1, 0.2, 0.3))); } } From 943e3f726183d3af45174618a6e4645d429965de Mon Sep 17 00:00:00 2001 From: janehe Date: Tue, 7 May 2024 13:14:45 -0700 Subject: [PATCH 04/12] DataTypes.custom("org.apache.cassandra.db.marshal.VectorType(org.apache.cassandra.db.marshal.FloatType,3)") --- .../oss/driver/internal/core/type/DefaultVectorType.java | 2 +- .../driver/api/querybuilder/schema/CreateTableTest.java | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/datastax/oss/driver/internal/core/type/DefaultVectorType.java b/core/src/main/java/com/datastax/oss/driver/internal/core/type/DefaultVectorType.java index 5915adc2fb..37647faebb 100644 --- a/core/src/main/java/com/datastax/oss/driver/internal/core/type/DefaultVectorType.java +++ b/core/src/main/java/com/datastax/oss/driver/internal/core/type/DefaultVectorType.java @@ -60,7 +60,7 @@ public String getClassName() { @NonNull @Override public String asCql(boolean includeFrozen, boolean pretty) { - return String.format("'%s(%d)'", getClassName(), getDimensions()); + return String.format("VECTOR<%s, %d>", this.subtype.asCql(includeFrozen, pretty).toUpperCase(), getDimensions()); } /* ============== General class implementation ============== */ diff --git a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/CreateTableTest.java b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/CreateTableTest.java index d32c66f629..0ebbf7ec3b 100644 --- a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/CreateTableTest.java +++ b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/CreateTableTest.java @@ -307,4 +307,13 @@ public void should_generate_create_table_time_window_compaction() { .hasCql( "CREATE TABLE bar (k int PRIMARY KEY,v text) WITH compaction={'class':'TimeWindowCompactionStrategy','compaction_window_size':10,'compaction_window_unit':'DAYS','timestamp_resolution':'MICROSECONDS','unsafe_aggressive_sstable_expiration':false}"); } + + @Test + public void should_generate_vector_column(){ + assertThat(createTable("foo") + .withPartitionKey("k", DataTypes.INT) + .withColumn("v", DataTypes.custom("org.apache.cassandra.db.marshal.VectorType(org.apache.cassandra.db.marshal.FloatType,3)") + )) + .hasCql("CREATE TABLE foo (k int PRIMARY KEY,v VECTOR)"); + } } From d176f09145adca730bd37bd912d554602b5ac787 Mon Sep 17 00:00:00 2001 From: janehe Date: Tue, 7 May 2024 14:54:07 -0700 Subject: [PATCH 05/12] SchemaBuilder add tests --- .../internal/core/type/DefaultVectorType.java | 4 ++-- .../api/querybuilder/schema/AlterTableTest.java | 11 +++++++++++ .../api/querybuilder/schema/AlterTypeTest.java | 7 +++++++ .../api/querybuilder/schema/CreateTableTest.java | 13 +++++++------ .../api/querybuilder/schema/CreateTypeTest.java | 10 ++++++++++ 5 files changed, 37 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/com/datastax/oss/driver/internal/core/type/DefaultVectorType.java b/core/src/main/java/com/datastax/oss/driver/internal/core/type/DefaultVectorType.java index 37647faebb..762fc931c6 100644 --- a/core/src/main/java/com/datastax/oss/driver/internal/core/type/DefaultVectorType.java +++ b/core/src/main/java/com/datastax/oss/driver/internal/core/type/DefaultVectorType.java @@ -33,7 +33,6 @@ public class DefaultVectorType implements VectorType { private final int dimensions; public DefaultVectorType(DataType subtype, int dimensions) { - this.dimensions = dimensions; this.subtype = subtype; } @@ -60,7 +59,8 @@ public String getClassName() { @NonNull @Override public String asCql(boolean includeFrozen, boolean pretty) { - return String.format("VECTOR<%s, %d>", this.subtype.asCql(includeFrozen, pretty).toUpperCase(), getDimensions()); + return String.format( + "VECTOR<%s, %d>", this.subtype.asCql(includeFrozen, pretty).toUpperCase(), getDimensions()); } /* ============== General class implementation ============== */ diff --git a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/AlterTableTest.java b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/AlterTableTest.java index 1567b0848c..499e2e0857 100644 --- a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/AlterTableTest.java +++ b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/AlterTableTest.java @@ -108,4 +108,15 @@ public void should_generate_alter_table_with_no_compression() { assertThat(alterTable("bar").withNoCompression()) .hasCql("ALTER TABLE bar WITH compression={'sstable_compression':''}"); } + + @Test + public void should_generate_alter_table_with_vector() { + assertThat( + alterTable("bar") + .alterColumn( + "v", + DataTypes.custom( + "org.apache.cassandra.db.marshal.VectorType(org.apache.cassandra.db.marshal.FloatType,3)"))) + .hasCql("ALTER TABLE bar ALTER v TYPE VECTOR"); + } } diff --git a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/AlterTypeTest.java b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/AlterTypeTest.java index 2becb9338f..570dc9e6d6 100644 --- a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/AlterTypeTest.java +++ b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/AlterTypeTest.java @@ -21,6 +21,7 @@ import static com.datastax.oss.driver.api.querybuilder.SchemaBuilder.alterType; import com.datastax.oss.driver.api.core.type.DataTypes; +import com.datastax.oss.driver.internal.core.type.DefaultVectorType; import org.junit.Test; public class AlterTypeTest { @@ -53,4 +54,10 @@ public void should_generate_alter_table_with_rename_three_columns() { assertThat(alterType("bar").renameField("x", "y").renameField("u", "v").renameField("b", "a")) .hasCql("ALTER TYPE bar RENAME x TO y AND u TO v AND b TO a"); } + + @Test + public void should_generate_alter_type_with_vector() { + assertThat(alterType("foo", "bar").alterField("vec", new DefaultVectorType(DataTypes.FLOAT, 3))) + .hasCql("ALTER TYPE foo.bar ALTER vec TYPE VECTOR"); + } } diff --git a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/CreateTableTest.java b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/CreateTableTest.java index 0ebbf7ec3b..6d8fd538e0 100644 --- a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/CreateTableTest.java +++ b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/CreateTableTest.java @@ -27,6 +27,7 @@ import com.datastax.oss.driver.api.querybuilder.SchemaBuilder.RowsPerPartition; import com.datastax.oss.driver.api.querybuilder.schema.compaction.TimeWindowCompactionStrategy.CompactionWindowUnit; import com.datastax.oss.driver.api.querybuilder.schema.compaction.TimeWindowCompactionStrategy.TimestampResolution; +import com.datastax.oss.driver.internal.core.type.DefaultVectorType; import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap; import org.junit.Test; @@ -309,11 +310,11 @@ public void should_generate_create_table_time_window_compaction() { } @Test - public void should_generate_vector_column(){ - assertThat(createTable("foo") - .withPartitionKey("k", DataTypes.INT) - .withColumn("v", DataTypes.custom("org.apache.cassandra.db.marshal.VectorType(org.apache.cassandra.db.marshal.FloatType,3)") - )) - .hasCql("CREATE TABLE foo (k int PRIMARY KEY,v VECTOR)"); + public void should_generate_vector_column() { + assertThat( + createTable("foo") + .withPartitionKey("k", DataTypes.INT) + .withColumn("v", new DefaultVectorType(DataTypes.FLOAT, 3))) + .hasCql("CREATE TABLE foo (k int PRIMARY KEY,v VECTOR)"); } } diff --git a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/CreateTypeTest.java b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/CreateTypeTest.java index d881a0500c..3c9897ef17 100644 --- a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/CreateTypeTest.java +++ b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/CreateTypeTest.java @@ -22,6 +22,7 @@ import static com.datastax.oss.driver.api.querybuilder.SchemaBuilder.udt; import com.datastax.oss.driver.api.core.type.DataTypes; +import com.datastax.oss.driver.internal.core.type.DefaultVectorType; import org.junit.Test; public class CreateTypeTest { @@ -83,4 +84,13 @@ public void should_create_type_with_collections() { .withField("map", DataTypes.mapOf(DataTypes.INT, DataTypes.TEXT))) .hasCql("CREATE TYPE ks1.type (map map)"); } + + @Test + public void should_create_type_with_vector() { + assertThat( + createType("ks1", "type") + .withField("c1", DataTypes.INT) + .withField("vec", new DefaultVectorType(DataTypes.FLOAT, 3))) + .hasCql("CREATE TYPE ks1.type (c1 int,vec VECTOR)"); + } } From 953fa47c5380eb91621dfa3c50cd09e7a5ef66a4 Mon Sep 17 00:00:00 2001 From: janehe Date: Tue, 7 May 2024 14:57:37 -0700 Subject: [PATCH 06/12] Add blank line --- .../oss/driver/internal/core/type/DefaultVectorType.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/main/java/com/datastax/oss/driver/internal/core/type/DefaultVectorType.java b/core/src/main/java/com/datastax/oss/driver/internal/core/type/DefaultVectorType.java index 762fc931c6..158ee88865 100644 --- a/core/src/main/java/com/datastax/oss/driver/internal/core/type/DefaultVectorType.java +++ b/core/src/main/java/com/datastax/oss/driver/internal/core/type/DefaultVectorType.java @@ -33,6 +33,7 @@ public class DefaultVectorType implements VectorType { private final int dimensions; public DefaultVectorType(DataType subtype, int dimensions) { + this.dimensions = dimensions; this.subtype = subtype; } From 009b6e6f993b5134913b11161fdad63ba233cec2 Mon Sep 17 00:00:00 2001 From: janehe Date: Wed, 2 Oct 2024 15:01:11 -0800 Subject: [PATCH 07/12] fix tests and fmt --- .../oss/driver/internal/core/type/DefaultVectorType.java | 2 +- .../api/querybuilder/delete/DeleteSelectorTest.java | 6 +++--- .../api/querybuilder/insert/RegularInsertTest.java | 6 +++--- .../driver/api/querybuilder/schema/AlterTableTest.java | 9 ++------- .../driver/api/querybuilder/schema/AlterTypeTest.java | 5 ++--- .../driver/api/querybuilder/schema/CreateTableTest.java | 5 ++--- .../driver/api/querybuilder/schema/CreateTypeTest.java | 5 ++--- 7 files changed, 15 insertions(+), 23 deletions(-) diff --git a/core/src/main/java/com/datastax/oss/driver/internal/core/type/DefaultVectorType.java b/core/src/main/java/com/datastax/oss/driver/internal/core/type/DefaultVectorType.java index 158ee88865..e6a413c6c2 100644 --- a/core/src/main/java/com/datastax/oss/driver/internal/core/type/DefaultVectorType.java +++ b/core/src/main/java/com/datastax/oss/driver/internal/core/type/DefaultVectorType.java @@ -61,7 +61,7 @@ public String getClassName() { @Override public String asCql(boolean includeFrozen, boolean pretty) { return String.format( - "VECTOR<%s, %d>", this.subtype.asCql(includeFrozen, pretty).toUpperCase(), getDimensions()); + "vector<%s, %d>", this.subtype.asCql(includeFrozen, pretty), getDimensions()); } /* ============== General class implementation ============== */ diff --git a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/delete/DeleteSelectorTest.java b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/delete/DeleteSelectorTest.java index 77c2c543cf..cce4cf51a1 100644 --- a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/delete/DeleteSelectorTest.java +++ b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/delete/DeleteSelectorTest.java @@ -22,7 +22,7 @@ import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.deleteFrom; import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.literal; -import java.util.Arrays; +import com.datastax.oss.driver.api.core.data.CqlVector; import org.junit.Test; public class DeleteSelectorTest { @@ -41,8 +41,8 @@ public void should_generate_vector_deletion() { deleteFrom("foo") .column("v") .whereColumn("k") - .isEqualTo(literal(Arrays.asList(0.1, 0.2)))) - .hasCql("DELETE v FROM foo WHERE k=[0.1,0.2]"); + .isEqualTo(literal(CqlVector.newInstance(0.1, 0.2)))) + .hasCql("DELETE v FROM foo WHERE k=[0.1, 0.2]"); } @Test diff --git a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/insert/RegularInsertTest.java b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/insert/RegularInsertTest.java index a277b037fc..89c833ff1c 100644 --- a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/insert/RegularInsertTest.java +++ b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/insert/RegularInsertTest.java @@ -23,10 +23,10 @@ import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.literal; import static org.assertj.core.api.Assertions.catchThrowable; +import com.datastax.oss.driver.api.core.data.CqlVector; import com.datastax.oss.driver.api.querybuilder.term.Term; import com.datastax.oss.driver.internal.querybuilder.insert.DefaultInsert; import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap; -import java.util.Arrays; import java.util.Map; import org.junit.Test; @@ -44,8 +44,8 @@ public void should_generate_column_assignments() { @Test public void should_generate_vector_literals() { - assertThat(insertInto("foo").value("a", literal(Arrays.asList(0.1, 0.2, 0.3)))) - .hasCql("INSERT INTO foo (a) VALUES ([0.1,0.2,0.3])"); + assertThat(insertInto("foo").value("a", literal(CqlVector.newInstance(0.1, 0.2, 0.3)))) + .hasCql("INSERT INTO foo (a) VALUES ([0.1, 0.2, 0.3])"); } @Test diff --git a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/AlterTableTest.java b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/AlterTableTest.java index 499e2e0857..2c99b154b3 100644 --- a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/AlterTableTest.java +++ b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/AlterTableTest.java @@ -111,12 +111,7 @@ public void should_generate_alter_table_with_no_compression() { @Test public void should_generate_alter_table_with_vector() { - assertThat( - alterTable("bar") - .alterColumn( - "v", - DataTypes.custom( - "org.apache.cassandra.db.marshal.VectorType(org.apache.cassandra.db.marshal.FloatType,3)"))) - .hasCql("ALTER TABLE bar ALTER v TYPE VECTOR"); + assertThat(alterTable("bar").alterColumn("v", DataTypes.vectorOf(DataTypes.FLOAT, 3))) + .hasCql("ALTER TABLE bar ALTER v TYPE vector"); } } diff --git a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/AlterTypeTest.java b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/AlterTypeTest.java index 570dc9e6d6..14bec0a6ce 100644 --- a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/AlterTypeTest.java +++ b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/AlterTypeTest.java @@ -21,7 +21,6 @@ import static com.datastax.oss.driver.api.querybuilder.SchemaBuilder.alterType; import com.datastax.oss.driver.api.core.type.DataTypes; -import com.datastax.oss.driver.internal.core.type.DefaultVectorType; import org.junit.Test; public class AlterTypeTest { @@ -57,7 +56,7 @@ public void should_generate_alter_table_with_rename_three_columns() { @Test public void should_generate_alter_type_with_vector() { - assertThat(alterType("foo", "bar").alterField("vec", new DefaultVectorType(DataTypes.FLOAT, 3))) - .hasCql("ALTER TYPE foo.bar ALTER vec TYPE VECTOR"); + assertThat(alterType("foo", "bar").alterField("vec", DataTypes.vectorOf(DataTypes.FLOAT, 3))) + .hasCql("ALTER TYPE foo.bar ALTER vec TYPE vector"); } } diff --git a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/CreateTableTest.java b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/CreateTableTest.java index 6d8fd538e0..72ff086b41 100644 --- a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/CreateTableTest.java +++ b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/CreateTableTest.java @@ -27,7 +27,6 @@ import com.datastax.oss.driver.api.querybuilder.SchemaBuilder.RowsPerPartition; import com.datastax.oss.driver.api.querybuilder.schema.compaction.TimeWindowCompactionStrategy.CompactionWindowUnit; import com.datastax.oss.driver.api.querybuilder.schema.compaction.TimeWindowCompactionStrategy.TimestampResolution; -import com.datastax.oss.driver.internal.core.type.DefaultVectorType; import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap; import org.junit.Test; @@ -314,7 +313,7 @@ public void should_generate_vector_column() { assertThat( createTable("foo") .withPartitionKey("k", DataTypes.INT) - .withColumn("v", new DefaultVectorType(DataTypes.FLOAT, 3))) - .hasCql("CREATE TABLE foo (k int PRIMARY KEY,v VECTOR)"); + .withColumn("v", DataTypes.vectorOf(DataTypes.FLOAT, 3))) + .hasCql("CREATE TABLE foo (k int PRIMARY KEY,v vector)"); } } diff --git a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/CreateTypeTest.java b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/CreateTypeTest.java index 3c9897ef17..f7c15788a0 100644 --- a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/CreateTypeTest.java +++ b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/schema/CreateTypeTest.java @@ -22,7 +22,6 @@ import static com.datastax.oss.driver.api.querybuilder.SchemaBuilder.udt; import com.datastax.oss.driver.api.core.type.DataTypes; -import com.datastax.oss.driver.internal.core.type.DefaultVectorType; import org.junit.Test; public class CreateTypeTest { @@ -90,7 +89,7 @@ public void should_create_type_with_vector() { assertThat( createType("ks1", "type") .withField("c1", DataTypes.INT) - .withField("vec", new DefaultVectorType(DataTypes.FLOAT, 3))) - .hasCql("CREATE TYPE ks1.type (c1 int,vec VECTOR)"); + .withField("vec", DataTypes.vectorOf(DataTypes.FLOAT, 3))) + .hasCql("CREATE TYPE ks1.type (c1 int,vec vector)"); } } From ae90a069c1375e51845217673cf44d3e428a3f76 Mon Sep 17 00:00:00 2001 From: janehe Date: Wed, 2 Oct 2024 15:45:07 -0800 Subject: [PATCH 08/12] refactor and pass tests --- .../driver/api/querybuilder/QueryBuilder.java | 11 --- .../driver/api/querybuilder/select/Ann.java | 22 ------ .../api/querybuilder/select/Select.java | 11 ++- .../querybuilder/select/DefaultAnn.java | 73 ------------------- .../querybuilder/select/DefaultSelect.java | 30 ++++++-- .../select/SelectOrderingTest.java | 5 +- 6 files changed, 36 insertions(+), 116 deletions(-) delete mode 100644 query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/select/Ann.java delete mode 100644 query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultAnn.java diff --git a/query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/QueryBuilder.java b/query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/QueryBuilder.java index ff5608e848..8df2b7efdd 100644 --- a/query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/QueryBuilder.java +++ b/query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/QueryBuilder.java @@ -19,7 +19,6 @@ import com.datastax.oss.driver.api.core.CqlIdentifier; import com.datastax.oss.driver.api.core.context.DriverContext; -import com.datastax.oss.driver.api.core.data.CqlVector; import com.datastax.oss.driver.api.core.metadata.token.Token; import com.datastax.oss.driver.api.core.type.DataType; import com.datastax.oss.driver.api.core.type.DataTypes; @@ -30,7 +29,6 @@ import com.datastax.oss.driver.api.querybuilder.delete.DeleteSelection; import com.datastax.oss.driver.api.querybuilder.insert.InsertInto; import com.datastax.oss.driver.api.querybuilder.relation.Relation; -import com.datastax.oss.driver.api.querybuilder.select.Ann; import com.datastax.oss.driver.api.querybuilder.select.SelectFrom; import com.datastax.oss.driver.api.querybuilder.select.Selector; import com.datastax.oss.driver.api.querybuilder.term.Term; @@ -45,7 +43,6 @@ import com.datastax.oss.driver.internal.querybuilder.DefaultRaw; import com.datastax.oss.driver.internal.querybuilder.delete.DefaultDelete; import com.datastax.oss.driver.internal.querybuilder.insert.DefaultInsert; -import com.datastax.oss.driver.internal.querybuilder.select.DefaultAnn; import com.datastax.oss.driver.internal.querybuilder.select.DefaultBindMarker; import com.datastax.oss.driver.internal.querybuilder.select.DefaultSelect; import com.datastax.oss.driver.internal.querybuilder.term.BinaryArithmeticTerm; @@ -541,12 +538,4 @@ public static Truncate truncate(@Nullable String keyspace, @NonNull String table return truncate( keyspace == null ? null : CqlIdentifier.fromCql(keyspace), CqlIdentifier.fromCql(table)); } - - public static Ann annOf(@NonNull CqlIdentifier cqlIdentifier, @NonNull CqlVector vector) { - return new DefaultAnn(cqlIdentifier, vector); - } - - public static Ann annOf(@NonNull String cqlIdentifier, @NonNull CqlVector vector) { - return new DefaultAnn(CqlIdentifier.fromCql(cqlIdentifier), vector); - } } diff --git a/query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/select/Ann.java b/query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/select/Ann.java deleted file mode 100644 index d287fc6e8f..0000000000 --- a/query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/select/Ann.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.datastax.oss.driver.api.querybuilder.select; - -import com.datastax.oss.driver.api.querybuilder.BuildableQuery; - -public interface Ann extends BuildableQuery {} diff --git a/query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/select/Select.java b/query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/select/Select.java index f0b5e74438..d2dd7bc444 100644 --- a/query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/select/Select.java +++ b/query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/select/Select.java @@ -18,6 +18,7 @@ package com.datastax.oss.driver.api.querybuilder.select; import com.datastax.oss.driver.api.core.CqlIdentifier; +import com.datastax.oss.driver.api.core.data.CqlVector; import com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder; import com.datastax.oss.driver.api.querybuilder.BindMarker; import com.datastax.oss.driver.api.querybuilder.BuildableQuery; @@ -146,8 +147,16 @@ default Select orderBy(@NonNull String columnName, @NonNull ClusteringOrder orde return orderBy(CqlIdentifier.fromCql(columnName), order); } + /** + * Shortcut for {@link #orderBy(CqlIdentifier, CqlVector)}, adding an ORDER BY ... ANN OF ... + * clause + */ + @NonNull + Select orderBy(@NonNull String columnName, @NonNull CqlVector ann); + + /** Adds the ORDER BY ... ANN OF ... clause */ @NonNull - Select orderBy(@NonNull Ann ann); + Select orderBy(@NonNull CqlIdentifier columnId, @NonNull CqlVector ann); /** * Adds a LIMIT clause to this query with a literal value. * diff --git a/query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultAnn.java b/query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultAnn.java deleted file mode 100644 index 6510f5dfbd..0000000000 --- a/query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultAnn.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.datastax.oss.driver.internal.querybuilder.select; - -import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.literal; - -import com.datastax.oss.driver.api.core.CqlIdentifier; -import com.datastax.oss.driver.api.core.cql.SimpleStatement; -import com.datastax.oss.driver.api.core.cql.SimpleStatementBuilder; -import com.datastax.oss.driver.api.core.data.CqlVector; -import com.datastax.oss.driver.api.querybuilder.select.Ann; -import edu.umd.cs.findbugs.annotations.NonNull; -import java.util.Map; - -public class DefaultAnn implements Ann { - private final CqlIdentifier cqlIdentifier; - private final CqlVector vector; - - public DefaultAnn(@NonNull CqlIdentifier cqlIdentifier, @NonNull CqlVector vector) { - this.cqlIdentifier = cqlIdentifier; - this.vector = vector; - } - - @NonNull - @Override - public String asCql() { - StringBuilder builder = new StringBuilder(); - builder.append("ORDER BY "); - builder.append(this.cqlIdentifier.asCql(true)); - builder.append(" ANN OF "); - literal(vector).appendTo(builder); - return builder.toString(); - } - - @NonNull - @Override - public SimpleStatement build() { - return Ann.super.build(); - } - - @NonNull - @Override - public SimpleStatement build(@NonNull Object... values) { - return Ann.super.build(values); - } - - @NonNull - @Override - public SimpleStatement build(@NonNull Map namedValues) { - return Ann.super.build(namedValues); - } - - @NonNull - @Override - public SimpleStatementBuilder builder() { - return Ann.super.builder(); - } -} diff --git a/query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultSelect.java b/query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultSelect.java index a45a515a62..29878b200e 100644 --- a/query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultSelect.java +++ b/query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultSelect.java @@ -20,10 +20,11 @@ import com.datastax.oss.driver.api.core.CqlIdentifier; import com.datastax.oss.driver.api.core.cql.SimpleStatement; import com.datastax.oss.driver.api.core.cql.SimpleStatementBuilder; +import com.datastax.oss.driver.api.core.data.CqlVector; import com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder; import com.datastax.oss.driver.api.querybuilder.BindMarker; +import com.datastax.oss.driver.api.querybuilder.QueryBuilder; import com.datastax.oss.driver.api.querybuilder.relation.Relation; -import com.datastax.oss.driver.api.querybuilder.select.Ann; import com.datastax.oss.driver.api.querybuilder.select.Select; import com.datastax.oss.driver.api.querybuilder.select.SelectFrom; import com.datastax.oss.driver.api.querybuilder.select.Selector; @@ -276,14 +277,20 @@ public Select orderBy(@NonNull CqlIdentifier columnId, @NonNull ClusteringOrder @NonNull @Override - public Select orderByIds(@NonNull Map newOrderings) { - return withOrderings(ImmutableCollections.concat(orderings, newOrderings)); + public Select orderBy(@NonNull String columnName, @NonNull CqlVector ann) { + return withAnn(new Ann(CqlIdentifier.fromCql(columnName), ann)); + } + + @NonNull + @Override + public Select orderBy(@NonNull CqlIdentifier columnId, @NonNull CqlVector ann) { + return withAnn(new Ann(columnId, ann)); } @NonNull @Override - public Select orderBy(@NonNull Ann ann) { - return withAnn(ann); + public Select orderByIds(@NonNull Map newOrderings) { + return withOrderings(ImmutableCollections.concat(orderings, newOrderings)); } @NonNull @@ -435,7 +442,8 @@ public String asCql() { CqlHelper.append(groupByClauses, builder, " GROUP BY ", ",", null); if (ann != null) { - builder.append(" ").append(this.ann.asCql()); + builder.append(" ORDER BY ").append(this.ann.columnId.asCql(true)).append(" ANN OF "); + QueryBuilder.literal(ann.vector).appendTo(builder); } else { boolean first = true; for (Map.Entry entry : orderings.entrySet()) { @@ -559,4 +567,14 @@ public boolean allowsFiltering() { public String toString() { return asCql(); } + + public static class Ann { + private final CqlVector vector; + private final CqlIdentifier columnId; + + private Ann(CqlIdentifier columnId, CqlVector vector) { + this.vector = vector; + this.columnId = columnId; + } + } } diff --git a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/select/SelectOrderingTest.java b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/select/SelectOrderingTest.java index 824f1c48c6..8d8a39575b 100644 --- a/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/select/SelectOrderingTest.java +++ b/query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/select/SelectOrderingTest.java @@ -20,7 +20,6 @@ import static com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder.ASC; import static com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder.DESC; import static com.datastax.oss.driver.api.querybuilder.Assertions.assertThat; -import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.annOf; import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.literal; import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.selectFrom; @@ -83,7 +82,7 @@ public void should_generate_ann_clause() { selectFrom("foo") .all() .where(Relation.column("k").isEqualTo(literal(1))) - .orderBy(annOf("c1", CqlVector.newInstance(0.1, 0.2, 0.3)))) + .orderBy("c1", CqlVector.newInstance(0.1, 0.2, 0.3))) .hasCql("SELECT * FROM foo WHERE k=1 ORDER BY c1 ANN OF [0.1, 0.2, 0.3]"); } @@ -93,6 +92,6 @@ public void should_fail_when_provided_ann_with_other_orderings() { .all() .where(Relation.column("k").isEqualTo(literal(1))) .orderBy("c1", ASC) - .orderBy(annOf("c1", CqlVector.newInstance(0.1, 0.2, 0.3))); + .orderBy("c2", CqlVector.newInstance(0.1, 0.2, 0.3)); } } From eb800ba997254499d5dd70d04daa3136e69b0fc0 Mon Sep 17 00:00:00 2001 From: janehe Date: Wed, 2 Oct 2024 17:13:05 -0800 Subject: [PATCH 09/12] revapi --- query-builder/revapi.json | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/query-builder/revapi.json b/query-builder/revapi.json index 9d0163b487..385e5b3694 100644 --- a/query-builder/revapi.json +++ b/query-builder/revapi.json @@ -2772,6 +2772,16 @@ "code": "java.method.addedToInterface", "new": "method com.datastax.oss.driver.api.querybuilder.update.UpdateStart com.datastax.oss.driver.api.querybuilder.update.UpdateStart::usingTtl(int)", "justification": "JAVA-2210: Add ability to set TTL for modification queries" + }, + { + "code": "java.method.addedToInterface", + "new": "method com.datastax.oss.driver.api.querybuilder.select.Select com.datastax.oss.driver.api.querybuilder.select.Select::orderBy(java.lang.String, com.datastax.oss.driver.api.core.data.CqlVector)", + "justification": "JAVA-3118: Add support for vector data type in Schema Builder, QueryBuilder" + }, + { + "code": "java.method.addedToInterface", + "new": "method com.datastax.oss.driver.api.querybuilder.select.Select com.datastax.oss.driver.api.querybuilder.select.Select::orderBy(com.datastax.oss.driver.api.core.CqlIdentifier, com.datastax.oss.driver.api.core.data.CqlVector)", + "justification": "JAVA-3118: Add support for vector data type in Schema Builder, QueryBuilder" } ] } From 19148d5cb9e2e2975a4d503358e9fae8737e0fcc Mon Sep 17 00:00:00 2001 From: janehe Date: Wed, 2 Oct 2024 17:45:45 -0800 Subject: [PATCH 10/12] add test of similarity functions --- query-builder/revapi.json | 4 +- .../api/querybuilder/select/Select.java | 6 +-- .../querybuilder/select/DefaultSelect.java | 27 ++++++------ .../select/SelectOrderingTest.java | 4 +- .../select/SelectSelectorTest.java | 43 +++++++++++++++++++ 5 files changed, 64 insertions(+), 20 deletions(-) diff --git a/query-builder/revapi.json b/query-builder/revapi.json index 385e5b3694..44c285d084 100644 --- a/query-builder/revapi.json +++ b/query-builder/revapi.json @@ -2775,12 +2775,12 @@ }, { "code": "java.method.addedToInterface", - "new": "method com.datastax.oss.driver.api.querybuilder.select.Select com.datastax.oss.driver.api.querybuilder.select.Select::orderBy(java.lang.String, com.datastax.oss.driver.api.core.data.CqlVector)", + "new": "method com.datastax.oss.driver.api.querybuilder.select.Select com.datastax.oss.driver.api.querybuilder.select.Select::orderByAnnOf(java.lang.String, com.datastax.oss.driver.api.core.data.CqlVector)", "justification": "JAVA-3118: Add support for vector data type in Schema Builder, QueryBuilder" }, { "code": "java.method.addedToInterface", - "new": "method com.datastax.oss.driver.api.querybuilder.select.Select com.datastax.oss.driver.api.querybuilder.select.Select::orderBy(com.datastax.oss.driver.api.core.CqlIdentifier, com.datastax.oss.driver.api.core.data.CqlVector)", + "new": "method com.datastax.oss.driver.api.querybuilder.select.Select com.datastax.oss.driver.api.querybuilder.select.Select::orderByAnnOf(com.datastax.oss.driver.api.core.CqlIdentifier, com.datastax.oss.driver.api.core.data.CqlVector)", "justification": "JAVA-3118: Add support for vector data type in Schema Builder, QueryBuilder" } ] diff --git a/query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/select/Select.java b/query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/select/Select.java index d2dd7bc444..291cb88bea 100644 --- a/query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/select/Select.java +++ b/query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/select/Select.java @@ -148,15 +148,15 @@ default Select orderBy(@NonNull String columnName, @NonNull ClusteringOrder orde } /** - * Shortcut for {@link #orderBy(CqlIdentifier, CqlVector)}, adding an ORDER BY ... ANN OF ... + * Shortcut for {@link #orderByAnnOf(CqlIdentifier, CqlVector)}, adding an ORDER BY ... ANN OF ... * clause */ @NonNull - Select orderBy(@NonNull String columnName, @NonNull CqlVector ann); + Select orderByAnnOf(@NonNull String columnName, @NonNull CqlVector ann); /** Adds the ORDER BY ... ANN OF ... clause */ @NonNull - Select orderBy(@NonNull CqlIdentifier columnId, @NonNull CqlVector ann); + Select orderByAnnOf(@NonNull CqlIdentifier columnId, @NonNull CqlVector ann); /** * Adds a LIMIT clause to this query with a literal value. * diff --git a/query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultSelect.java b/query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultSelect.java index 29878b200e..c60376a5ed 100644 --- a/query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultSelect.java +++ b/query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultSelect.java @@ -127,7 +127,7 @@ public SelectFrom json() { relations, groupByClauses, orderings, - null, + ann, limit, perPartitionLimit, allowsFiltering); @@ -145,7 +145,7 @@ public SelectFrom distinct() { relations, groupByClauses, orderings, - null, + ann, limit, perPartitionLimit, allowsFiltering); @@ -205,7 +205,7 @@ public Select withSelectors(@NonNull ImmutableList newSelectors) { relations, groupByClauses, orderings, - null, + ann, limit, perPartitionLimit, allowsFiltering); @@ -234,7 +234,7 @@ public Select withRelations(@NonNull ImmutableList newRelations) { newRelations, groupByClauses, orderings, - null, + ann, limit, perPartitionLimit, allowsFiltering); @@ -263,7 +263,7 @@ public Select withGroupByClauses(@NonNull ImmutableList newGroupByClau relations, newGroupByClauses, orderings, - null, + ann, limit, perPartitionLimit, allowsFiltering); @@ -277,13 +277,14 @@ public Select orderBy(@NonNull CqlIdentifier columnId, @NonNull ClusteringOrder @NonNull @Override - public Select orderBy(@NonNull String columnName, @NonNull CqlVector ann) { + public Select orderByAnnOf(@NonNull String columnName, @NonNull CqlVector ann) { return withAnn(new Ann(CqlIdentifier.fromCql(columnName), ann)); } @NonNull @Override - public Select orderBy(@NonNull CqlIdentifier columnId, @NonNull CqlVector ann) { + public Select orderByAnnOf( + @NonNull CqlIdentifier columnId, @NonNull CqlVector ann) { return withAnn(new Ann(columnId, ann)); } @@ -304,7 +305,7 @@ public Select withOrderings(@NonNull ImmutableMap Date: Wed, 9 Oct 2024 22:06:49 -0400 Subject: [PATCH 11/12] CqlVector --- query-builder/revapi.json | 4 ++-- .../oss/driver/api/querybuilder/select/Select.java | 4 ++-- .../driver/internal/querybuilder/select/DefaultSelect.java | 7 +++---- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/query-builder/revapi.json b/query-builder/revapi.json index 44c285d084..c4d8aa2721 100644 --- a/query-builder/revapi.json +++ b/query-builder/revapi.json @@ -2775,12 +2775,12 @@ }, { "code": "java.method.addedToInterface", - "new": "method com.datastax.oss.driver.api.querybuilder.select.Select com.datastax.oss.driver.api.querybuilder.select.Select::orderByAnnOf(java.lang.String, com.datastax.oss.driver.api.core.data.CqlVector)", + "new": "method com.datastax.oss.driver.api.querybuilder.select.Select com.datastax.oss.driver.api.querybuilder.select.Select::orderByAnnOf(java.lang.String, com.datastax.oss.driver.api.core.data.CqlVector)", "justification": "JAVA-3118: Add support for vector data type in Schema Builder, QueryBuilder" }, { "code": "java.method.addedToInterface", - "new": "method com.datastax.oss.driver.api.querybuilder.select.Select com.datastax.oss.driver.api.querybuilder.select.Select::orderByAnnOf(com.datastax.oss.driver.api.core.CqlIdentifier, com.datastax.oss.driver.api.core.data.CqlVector)", + "new": "method com.datastax.oss.driver.api.querybuilder.select.Select com.datastax.oss.driver.api.querybuilder.select.Select::orderByAnnOf(com.datastax.oss.driver.api.core.CqlIdentifier, com.datastax.oss.driver.api.core.data.CqlVector)", "justification": "JAVA-3118: Add support for vector data type in Schema Builder, QueryBuilder" } ] diff --git a/query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/select/Select.java b/query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/select/Select.java index 291cb88bea..680a307fa0 100644 --- a/query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/select/Select.java +++ b/query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/select/Select.java @@ -152,11 +152,11 @@ default Select orderBy(@NonNull String columnName, @NonNull ClusteringOrder orde * clause */ @NonNull - Select orderByAnnOf(@NonNull String columnName, @NonNull CqlVector ann); + Select orderByAnnOf(@NonNull String columnName, @NonNull CqlVector ann); /** Adds the ORDER BY ... ANN OF ... clause */ @NonNull - Select orderByAnnOf(@NonNull CqlIdentifier columnId, @NonNull CqlVector ann); + Select orderByAnnOf(@NonNull CqlIdentifier columnId, @NonNull CqlVector ann); /** * Adds a LIMIT clause to this query with a literal value. * diff --git a/query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultSelect.java b/query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultSelect.java index c60376a5ed..dfa5ca02f8 100644 --- a/query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultSelect.java +++ b/query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultSelect.java @@ -277,14 +277,13 @@ public Select orderBy(@NonNull CqlIdentifier columnId, @NonNull ClusteringOrder @NonNull @Override - public Select orderByAnnOf(@NonNull String columnName, @NonNull CqlVector ann) { + public Select orderByAnnOf(@NonNull String columnName, @NonNull CqlVector ann) { return withAnn(new Ann(CqlIdentifier.fromCql(columnName), ann)); } @NonNull @Override - public Select orderByAnnOf( - @NonNull CqlIdentifier columnId, @NonNull CqlVector ann) { + public Select orderByAnnOf(@NonNull CqlIdentifier columnId, @NonNull CqlVector ann) { return withAnn(new Ann(columnId, ann)); } @@ -570,7 +569,7 @@ public String toString() { } public static class Ann { - private final CqlVector vector; + private final CqlVector vector; private final CqlIdentifier columnId; private Ann(CqlIdentifier columnId, CqlVector vector) { From 0a36ff0694a3f2cd51dfaccc14f8ad013adfb363 Mon Sep 17 00:00:00 2001 From: janehe Date: Wed, 9 Oct 2024 22:20:14 -0400 Subject: [PATCH 12/12] add getAnn() --- .../driver/internal/querybuilder/select/DefaultSelect.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultSelect.java b/query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultSelect.java index dfa5ca02f8..d56413f597 100644 --- a/query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultSelect.java +++ b/query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultSelect.java @@ -554,6 +554,11 @@ public Object getLimit() { return limit; } + @Nullable + public Ann getAnn() { + return ann; + } + @Nullable public Object getPerPartitionLimit() { return perPartitionLimit;