Skip to content

Commit 6cf075f

Browse files
authored
JAVA-3061 Remove CqlVector, represent CQL vector types as Lists (#1656)
1 parent 2fa0faf commit 6cf075f

File tree

20 files changed

+290
-223
lines changed

20 files changed

+290
-223
lines changed

core/revapi.json

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6824,7 +6824,70 @@
68246824
"new": "class com.datastax.oss.driver.api.core.type.codec.CodecNotFoundException",
68256825
"superClass": "com.datastax.oss.driver.api.core.DriverException",
68266826
"justification": "Make CodecNotFoundException to extend DriverException as all other driver exceptions do"
6827-
}
6827+
},
6828+
{
6829+
"code": "java.class.removed",
6830+
"old": "class com.datastax.oss.driver.api.core.data.CqlVector<T>",
6831+
"justification": "Refactoring in JAVA-3061"
6832+
},
6833+
{
6834+
"code": "java.method.removed",
6835+
"old": "method com.datastax.oss.driver.api.core.data.CqlVector<?> com.datastax.oss.driver.api.core.data.GettableById::getCqlVector(com.datastax.oss.driver.api.core.CqlIdentifier)",
6836+
"justification": "Refactoring in JAVA-3061"
6837+
},
6838+
{
6839+
"code": "java.method.removed",
6840+
"old": "method com.datastax.oss.driver.api.core.data.CqlVector<?> com.datastax.oss.driver.api.core.data.GettableByIndex::getCqlVector(int)",
6841+
"justification": "Refactoring in JAVA-3061"
6842+
},
6843+
{
6844+
"code": "java.method.removed",
6845+
"old": "method com.datastax.oss.driver.api.core.data.CqlVector<?> com.datastax.oss.driver.api.core.data.GettableByName::getCqlVector(java.lang.String)",
6846+
"justification": "Refactoring in JAVA-3061"
6847+
},
6848+
{
6849+
"code": "java.method.removed",
6850+
"old": "method SelfT com.datastax.oss.driver.api.core.data.SettableById<SelfT extends com.datastax.oss.driver.api.core.data.SettableById<SelfT>>::setCqlVector(com.datastax.oss.driver.api.core.CqlIdentifier, com.datastax.oss.driver.api.core.data.CqlVector<?>)",
6851+
"justification": "Refactoring in JAVA-3061"
6852+
},
6853+
{
6854+
"code": "java.method.removed",
6855+
"old": "method SelfT com.datastax.oss.driver.api.core.data.SettableByIndex<SelfT extends com.datastax.oss.driver.api.core.data.SettableByIndex<SelfT>>::setCqlVector(int, com.datastax.oss.driver.api.core.data.CqlVector<?>)",
6856+
"justification": "Refactoring in JAVA-3061"
6857+
},
6858+
{
6859+
"code": "java.method.removed",
6860+
"old": "method SelfT com.datastax.oss.driver.api.core.data.SettableByName<SelfT extends com.datastax.oss.driver.api.core.data.SettableByName<SelfT>>::setCqlVector(java.lang.String, com.datastax.oss.driver.api.core.data.CqlVector<?>)",
6861+
"justification": "Refactoring in JAVA-3061"
6862+
},
6863+
{
6864+
"code": "java.class.removed",
6865+
"old": "class com.datastax.oss.driver.api.core.type.CqlVectorType",
6866+
"justification": "Refactoring in JAVA-3061"
6867+
},
6868+
{
6869+
"code": "java.method.returnTypeChanged",
6870+
"old": "method com.datastax.oss.driver.api.core.type.CqlVectorType com.datastax.oss.driver.api.core.type.DataTypes::vectorOf(com.datastax.oss.driver.api.core.type.DataType, int)",
6871+
"new": "method com.datastax.oss.driver.api.core.type.VectorType com.datastax.oss.driver.api.core.type.DataTypes::vectorOf(com.datastax.oss.driver.api.core.type.DataType, int)",
6872+
"justification": "Refactoring in JAVA-3061"
6873+
},
6874+
{
6875+
"code": "java.method.parameterTypeChanged",
6876+
"old": "parameter <SubtypeT> com.datastax.oss.driver.api.core.type.codec.TypeCodec<com.datastax.oss.driver.api.core.data.CqlVector<SubtypeT>> com.datastax.oss.driver.api.core.type.codec.TypeCodecs::vectorOf(===com.datastax.oss.driver.api.core.type.CqlVectorType===, com.datastax.oss.driver.api.core.type.codec.TypeCodec<SubtypeT>)",
6877+
"new": "parameter <SubtypeT> com.datastax.oss.driver.api.core.type.codec.TypeCodec<java.util.List<SubtypeT>> com.datastax.oss.driver.api.core.type.codec.TypeCodecs::vectorOf(===com.datastax.oss.driver.api.core.type.VectorType===, com.datastax.oss.driver.api.core.type.codec.TypeCodec<SubtypeT>)",
6878+
"justification": "Refactoring in JAVA-3061"
6879+
},
6880+
{
6881+
"code": "java.method.returnTypeTypeParametersChanged",
6882+
"old": "method <SubtypeT> com.datastax.oss.driver.api.core.type.codec.TypeCodec<com.datastax.oss.driver.api.core.data.CqlVector<SubtypeT>> com.datastax.oss.driver.api.core.type.codec.TypeCodecs::vectorOf(com.datastax.oss.driver.api.core.type.CqlVectorType, com.datastax.oss.driver.api.core.type.codec.TypeCodec<SubtypeT>)",
6883+
"new": "method <SubtypeT> com.datastax.oss.driver.api.core.type.codec.TypeCodec<java.util.List<SubtypeT>> com.datastax.oss.driver.api.core.type.codec.TypeCodecs::vectorOf(com.datastax.oss.driver.api.core.type.VectorType, com.datastax.oss.driver.api.core.type.codec.TypeCodec<SubtypeT>)",
6884+
"justification": "Refactoring in JAVA-3061"
6885+
},
6886+
{
6887+
"code": "java.method.removed",
6888+
"old": "method <T> com.datastax.oss.driver.api.core.type.reflect.GenericType<com.datastax.oss.driver.api.core.data.CqlVector<T>> com.datastax.oss.driver.api.core.type.reflect.GenericType<T>::vectorOf(com.datastax.oss.driver.api.core.type.reflect.GenericType<T>)",
6889+
"justification": "Refactoring in JAVA-3061"
6890+
}
68286891
]
68296892
}
68306893
}

core/src/main/java/com/datastax/oss/driver/api/core/data/CqlVector.java

Lines changed: 0 additions & 91 deletions
This file was deleted.

core/src/main/java/com/datastax/oss/driver/api/core/data/GettableById.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,9 @@ default CqlDuration getCqlDuration(@NonNull CqlIdentifier id) {
529529
* @throws IllegalArgumentException if the id is invalid.
530530
*/
531531
@Nullable
532-
default CqlVector<?> getCqlVector(@NonNull CqlIdentifier id) {
533-
return getCqlVector(firstIndexOf(id));
532+
default <ElementT> List<ElementT> getVector(
533+
@NonNull CqlIdentifier id, @NonNull Class<ElementT> elementsClass) {
534+
return getVector(firstIndexOf(id), elementsClass);
534535
}
535536

536537
/**

core/src/main/java/com/datastax/oss/driver/api/core/data/GettableByIndex.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,8 @@ default CqlDuration getCqlDuration(int i) {
444444
* @throws IndexOutOfBoundsException if the index is invalid.
445445
*/
446446
@Nullable
447-
default CqlVector<?> getCqlVector(int i) {
448-
return get(i, CqlVector.class);
447+
default <ElementT> List<ElementT> getVector(int i, @NonNull Class<ElementT> elementsClass) {
448+
return get(i, GenericType.listOf(elementsClass));
449449
}
450450

451451
/**

core/src/main/java/com/datastax/oss/driver/api/core/data/GettableByName.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,9 @@ default CqlDuration getCqlDuration(@NonNull String name) {
525525
* @throws IllegalArgumentException if the name is invalid.
526526
*/
527527
@Nullable
528-
default CqlVector<?> getCqlVector(@NonNull String name) {
529-
return getCqlVector(firstIndexOf(name));
528+
default <ElementT> List<ElementT> getVector(
529+
@NonNull String name, @NonNull Class<ElementT> elementsClass) {
530+
return getList(firstIndexOf(name), elementsClass);
530531
}
531532

532533
/**

core/src/main/java/com/datastax/oss/driver/api/core/data/SettableById.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ default SelfT setCqlDuration(@NonNull CqlIdentifier id, @Nullable CqlDuration v)
560560
}
561561

562562
/**
563-
* Sets the value for all occurrences of {@code id} to the provided duration.
563+
* Sets the value for all occurrences of {@code id} to the provided {@code vector}.
564564
*
565565
* <p>By default, this works with CQL type {@code vector}.
566566
*
@@ -571,10 +571,13 @@ default SelfT setCqlDuration(@NonNull CqlIdentifier id, @Nullable CqlDuration v)
571571
*/
572572
@NonNull
573573
@CheckReturnValue
574-
default SelfT setCqlVector(@NonNull CqlIdentifier id, @Nullable CqlVector<?> v) {
574+
default <ElementT> SelfT setVector(
575+
@NonNull CqlIdentifier id,
576+
@Nullable List<ElementT> v,
577+
@NonNull Class<ElementT> elementsClass) {
575578
SelfT result = null;
576579
for (Integer i : allIndicesOf(id)) {
577-
result = (result == null ? this : result).setCqlVector(i, v);
580+
result = (result == null ? this : result).setVector(i, v, elementsClass);
578581
}
579582
assert result != null; // allIndices throws if there are no results
580583
return result;

core/src/main/java/com/datastax/oss/driver/api/core/data/SettableByIndex.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,16 +415,17 @@ default SelfT setCqlDuration(int i, @Nullable CqlDuration v) {
415415
}
416416

417417
/**
418-
* Sets the {@code i}th value to the provided duration.
418+
* Sets the {@code i}th value to the provided vector.
419419
*
420420
* <p>By default, this works with CQL type {@code vector}.
421421
*
422422
* @throws IndexOutOfBoundsException if the index is invalid.
423423
*/
424424
@NonNull
425425
@CheckReturnValue
426-
default SelfT setCqlVector(int i, @Nullable CqlVector<?> v) {
427-
return set(i, v, CqlVector.class);
426+
default <ElementT> SelfT setVector(
427+
int i, @Nullable List<ElementT> v, @NonNull Class<ElementT> elementsClass) {
428+
return set(i, v, GenericType.listOf(elementsClass));
428429
}
429430

430431
/**

core/src/main/java/com/datastax/oss/driver/api/core/data/SettableByName.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ default SelfT setCqlDuration(@NonNull String name, @Nullable CqlDuration v) {
559559
}
560560

561561
/**
562-
* Sets the value for all occurrences of {@code name} to the provided duration.
562+
* Sets the value for all occurrences of {@code name} to the provided vector.
563563
*
564564
* <p>By default, this works with CQL type {@code vector}.
565565
*
@@ -570,10 +570,11 @@ default SelfT setCqlDuration(@NonNull String name, @Nullable CqlDuration v) {
570570
*/
571571
@NonNull
572572
@CheckReturnValue
573-
default SelfT setCqlVector(@NonNull String name, @Nullable CqlVector<?> v) {
573+
default <ElementT> SelfT setVector(
574+
@NonNull String name, @Nullable List<ElementT> v, @NonNull Class<ElementT> elementsClass) {
574575
SelfT result = null;
575576
for (Integer i : allIndicesOf(name)) {
576-
result = (result == null ? this : result).setCqlVector(i, v);
577+
result = (result == null ? this : result).setVector(i, v, elementsClass);
577578
}
578579
assert result != null; // allIndices throws if there are no results
579580
return result;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright DataStax, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.datastax.oss.driver.api.core.type;
17+
18+
import edu.umd.cs.findbugs.annotations.NonNull;
19+
20+
/**
21+
* Representation of a type which "contains" some other type. This might be a collection type or it
22+
* could be some other kind of container; the term is deliberately left somewhat vague.
23+
*/
24+
public interface ContainerType {
25+
26+
@NonNull
27+
DataType getElementType();
28+
}

core/src/main/java/com/datastax/oss/driver/api/core/type/DataTypes.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.datastax.oss.driver.internal.core.type.DefaultMapType;
2424
import com.datastax.oss.driver.internal.core.type.DefaultSetType;
2525
import com.datastax.oss.driver.internal.core.type.DefaultTupleType;
26+
import com.datastax.oss.driver.internal.core.type.DefaultVectorType;
2627
import com.datastax.oss.driver.internal.core.type.PrimitiveType;
2728
import com.datastax.oss.driver.shaded.guava.common.base.Splitter;
2829
import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableList;
@@ -65,14 +66,19 @@ public static DataType custom(@NonNull String className) {
6566
if (className.equals("org.apache.cassandra.db.marshal.DurationType")) return DURATION;
6667

6768
/* Vector support is currently implemented as a custom type but is also parameterized */
68-
if (className.startsWith(CqlVectorType.CQLVECTOR_CLASS_NAME)) {
69+
if (className.startsWith(DefaultVectorType.VECTOR_CLASS_NAME)) {
6970
List<String> params =
7071
paramSplitter.splitToList(
7172
className.substring(
72-
CqlVectorType.CQLVECTOR_CLASS_NAME.length() + 1, className.length() - 1));
73+
DefaultVectorType.VECTOR_CLASS_NAME.length() + 1, className.length() - 1));
7374
DataType subType = classNameParser.parse(params.get(0), AttachmentPoint.NONE);
7475
int dimensions = Integer.parseInt(params.get(1));
75-
return new CqlVectorType(subType, dimensions);
76+
if (dimensions <= 0) {
77+
throw new IllegalArgumentException(
78+
String.format(
79+
"Request to create vector of size %d, size must be positive", dimensions));
80+
}
81+
return new DefaultVectorType(subType, dimensions);
7682
}
7783
return new DefaultCustomType(className);
7884
}
@@ -135,7 +141,7 @@ public static TupleType tupleOf(@NonNull DataType... componentTypes) {
135141
return new DefaultTupleType(ImmutableList.copyOf(Arrays.asList(componentTypes)));
136142
}
137143

138-
public static CqlVectorType vectorOf(DataType subtype, int dimensions) {
139-
return new CqlVectorType(subtype, dimensions);
144+
public static VectorType vectorOf(DataType subtype, int dimensions) {
145+
return new DefaultVectorType(subtype, dimensions);
140146
}
141147
}

0 commit comments

Comments
 (0)