Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JAVA-3061 Remove CqlVector, represent CQL vector types as Lists #1656

Merged
merged 14 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 64 additions & 1 deletion core/revapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -6824,7 +6824,70 @@
"new": "class com.datastax.oss.driver.api.core.type.codec.CodecNotFoundException",
"superClass": "com.datastax.oss.driver.api.core.DriverException",
"justification": "Make CodecNotFoundException to extend DriverException as all other driver exceptions do"
}
},
{
"code": "java.class.removed",
"old": "class com.datastax.oss.driver.api.core.data.CqlVector<T>",
"justification": "Refactoring in JAVA-3061"
},
{
"code": "java.method.removed",
"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)",
"justification": "Refactoring in JAVA-3061"
},
{
"code": "java.method.removed",
"old": "method com.datastax.oss.driver.api.core.data.CqlVector<?> com.datastax.oss.driver.api.core.data.GettableByIndex::getCqlVector(int)",
"justification": "Refactoring in JAVA-3061"
},
{
"code": "java.method.removed",
"old": "method com.datastax.oss.driver.api.core.data.CqlVector<?> com.datastax.oss.driver.api.core.data.GettableByName::getCqlVector(java.lang.String)",
"justification": "Refactoring in JAVA-3061"
},
{
"code": "java.method.removed",
"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<?>)",
"justification": "Refactoring in JAVA-3061"
},
{
"code": "java.method.removed",
"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<?>)",
"justification": "Refactoring in JAVA-3061"
},
{
"code": "java.method.removed",
"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<?>)",
"justification": "Refactoring in JAVA-3061"
},
{
"code": "java.class.removed",
"old": "class com.datastax.oss.driver.api.core.type.CqlVectorType",
"justification": "Refactoring in JAVA-3061"
},
{
"code": "java.method.returnTypeChanged",
"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)",
"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)",
"justification": "Refactoring in JAVA-3061"
},
{
"code": "java.method.parameterTypeChanged",
"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>)",
"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>)",
"justification": "Refactoring in JAVA-3061"
},
{
"code": "java.method.returnTypeTypeParametersChanged",
"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>)",
"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>)",
"justification": "Refactoring in JAVA-3061"
},
{
"code": "java.method.removed",
"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>)",
"justification": "Refactoring in JAVA-3061"
}
]
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,9 @@ default CqlDuration getCqlDuration(@NonNull CqlIdentifier id) {
* @throws IllegalArgumentException if the id is invalid.
*/
@Nullable
default CqlVector<?> getCqlVector(@NonNull CqlIdentifier id) {
return getCqlVector(firstIndexOf(id));
default <ElementT> List<ElementT> getVector(
@NonNull CqlIdentifier id, @NonNull Class<ElementT> elementsClass) {
return getVector(firstIndexOf(id), elementsClass);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,8 @@ default CqlDuration getCqlDuration(int i) {
* @throws IndexOutOfBoundsException if the index is invalid.
*/
@Nullable
default CqlVector<?> getCqlVector(int i) {
return get(i, CqlVector.class);
default <ElementT> List<ElementT> getVector(int i, @NonNull Class<ElementT> elementsClass) {
return get(i, GenericType.listOf(elementsClass));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,9 @@ default CqlDuration getCqlDuration(@NonNull String name) {
* @throws IllegalArgumentException if the name is invalid.
*/
@Nullable
default CqlVector<?> getCqlVector(@NonNull String name) {
return getCqlVector(firstIndexOf(name));
default <ElementT> List<ElementT> getVector(
@NonNull String name, @NonNull Class<ElementT> elementsClass) {
return getList(firstIndexOf(name), elementsClass);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ default SelfT setCqlDuration(@NonNull CqlIdentifier id, @Nullable CqlDuration v)
}

/**
* Sets the value for all occurrences of {@code id} to the provided duration.
* Sets the value for all occurrences of {@code id} to the provided {@code vector}.
*
* <p>By default, this works with CQL type {@code vector}.
*
Expand All @@ -571,10 +571,13 @@ default SelfT setCqlDuration(@NonNull CqlIdentifier id, @Nullable CqlDuration v)
*/
@NonNull
@CheckReturnValue
default SelfT setCqlVector(@NonNull CqlIdentifier id, @Nullable CqlVector<?> v) {
default <ElementT> SelfT setVector(
@NonNull CqlIdentifier id,
@Nullable List<ElementT> v,
@NonNull Class<ElementT> elementsClass) {
SelfT result = null;
for (Integer i : allIndicesOf(id)) {
result = (result == null ? this : result).setCqlVector(i, v);
result = (result == null ? this : result).setVector(i, v, elementsClass);
}
assert result != null; // allIndices throws if there are no results
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,16 +415,17 @@ default SelfT setCqlDuration(int i, @Nullable CqlDuration v) {
}

/**
* Sets the {@code i}th value to the provided duration.
* Sets the {@code i}th value to the provided vector.
*
* <p>By default, this works with CQL type {@code vector}.
*
* @throws IndexOutOfBoundsException if the index is invalid.
*/
@NonNull
@CheckReturnValue
default SelfT setCqlVector(int i, @Nullable CqlVector<?> v) {
return set(i, v, CqlVector.class);
default <ElementT> SelfT setVector(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* Sets the {@code i}th value to the provided duration.

Should this be vector?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should indeed... good catch @hhughes!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

int i, @Nullable List<ElementT> v, @NonNull Class<ElementT> elementsClass) {
return set(i, v, GenericType.listOf(elementsClass));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ default SelfT setCqlDuration(@NonNull String name, @Nullable CqlDuration v) {
}

/**
* Sets the value for all occurrences of {@code name} to the provided duration.
* Sets the value for all occurrences of {@code name} to the provided vector.
*
* <p>By default, this works with CQL type {@code vector}.
*
Expand All @@ -570,10 +570,11 @@ default SelfT setCqlDuration(@NonNull String name, @Nullable CqlDuration v) {
*/
@NonNull
@CheckReturnValue
default SelfT setCqlVector(@NonNull String name, @Nullable CqlVector<?> v) {
default <ElementT> SelfT setVector(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace duration with vector in the javadoc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, this one too!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@NonNull String name, @Nullable List<ElementT> v, @NonNull Class<ElementT> elementsClass) {
SelfT result = null;
for (Integer i : allIndicesOf(name)) {
result = (result == null ? this : result).setCqlVector(i, v);
result = (result == null ? this : result).setVector(i, v, elementsClass);
}
assert result != null; // allIndices throws if there are no results
return result;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright DataStax, Inc.
*
* Licensed 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.core.type;

import edu.umd.cs.findbugs.annotations.NonNull;

/**
* Representation of a type which "contains" some other type. This might be a collection type or it
* could be some other kind of container; the term is deliberately left somewhat vague.
*/
public interface ContainerType {

@NonNull
DataType getElementType();
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.datastax.oss.driver.internal.core.type.DefaultMapType;
import com.datastax.oss.driver.internal.core.type.DefaultSetType;
import com.datastax.oss.driver.internal.core.type.DefaultTupleType;
import com.datastax.oss.driver.internal.core.type.DefaultVectorType;
import com.datastax.oss.driver.internal.core.type.PrimitiveType;
import com.datastax.oss.driver.shaded.guava.common.base.Splitter;
import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableList;
Expand Down Expand Up @@ -65,14 +66,19 @@ public static DataType custom(@NonNull String className) {
if (className.equals("org.apache.cassandra.db.marshal.DurationType")) return DURATION;

/* Vector support is currently implemented as a custom type but is also parameterized */
if (className.startsWith(CqlVectorType.CQLVECTOR_CLASS_NAME)) {
if (className.startsWith(DefaultVectorType.VECTOR_CLASS_NAME)) {
List<String> params =
paramSplitter.splitToList(
className.substring(
CqlVectorType.CQLVECTOR_CLASS_NAME.length() + 1, className.length() - 1));
DefaultVectorType.VECTOR_CLASS_NAME.length() + 1, className.length() - 1));
DataType subType = classNameParser.parse(params.get(0), AttachmentPoint.NONE);
int dimensions = Integer.parseInt(params.get(1));
return new CqlVectorType(subType, dimensions);
if (dimensions <= 0) {
throw new IllegalArgumentException(
String.format(
"Request to create vector of size %d, size must be positive", dimensions));
}
return new DefaultVectorType(subType, dimensions);
}
return new DefaultCustomType(className);
}
Expand Down Expand Up @@ -135,7 +141,7 @@ public static TupleType tupleOf(@NonNull DataType... componentTypes) {
return new DefaultTupleType(ImmutableList.copyOf(Arrays.asList(componentTypes)));
}

public static CqlVectorType vectorOf(DataType subtype, int dimensions) {
return new CqlVectorType(subtype, dimensions);
public static VectorType vectorOf(DataType subtype, int dimensions) {
return new DefaultVectorType(subtype, dimensions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
import com.datastax.oss.protocol.internal.ProtocolConstants;
import edu.umd.cs.findbugs.annotations.NonNull;

public interface ListType extends DataType {

@NonNull
DataType getElementType();
public interface ListType extends DataType, ContainerType {

boolean isFrozen();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
import com.datastax.oss.protocol.internal.ProtocolConstants;
import edu.umd.cs.findbugs.annotations.NonNull;

public interface SetType extends DataType {

@NonNull
DataType getElementType();
public interface SetType extends DataType, ContainerType {

boolean isFrozen();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright DataStax, Inc.
*
* Licensed 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.core.type;

/**
* Type representing a Cassandra vector type as described in CEP-30. At the moment this is
* implemented as a custom type so we include the CustomType interface as well.
*/
public interface VectorType extends CustomType, ContainerType {

int getDimensions();
}
Loading