Skip to content

Commit 20a2264

Browse files
committed
Prepare version 4.10.0
- Add vectors similarity functions from CEP-30 into the numeric functions listed into the DatabaseMetadata. - Allow disabling DSE tests using Maven profile.
1 parent 7b4c5b8 commit 20a2264

File tree

10 files changed

+123
-79
lines changed

10 files changed

+123
-79
lines changed

Diff for: CHANGELOG.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to
55
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
## [4.10.0] - Unreleased
7+
## [4.10.0] - 2023-09-30
88
### Added
99
- Add support for new [`vector` CQL type](https://datastax-oss.atlassian.net/browse/JAVA-3060)
10-
defined in [CEP-30](https://cwiki.apache.org/confluence/x/OQ40Dw).
10+
defined in [CEP-30](https://cwiki.apache.org/confluence/x/OQ40Dw)
11+
Also see PR [#27](https://github.com/ing-bank/cassandra-jdbc-wrapper/pull/27).
1112
- Implement the method `getWarnings()` in `CassandraResultSet`.
1213
- Implement the following methods of `CassandraDatabaseMetaData`:
1314
`getBestRowIdentifier(String, String, String, int, boolean)` and `getAttributes(String, String, String, String)`.

Diff for: README.md

+26-7
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ To compile and run tests, execute the following Maven command:
4949
```bash
5050
mvn clean package
5151
```
52+
53+
#### Some considerations about running tests
54+
55+
If for some reason the tests using DataStax Enterprise server (`*DseContainerTest`) fail in your local environment, you
56+
might disable them using the Maven profile `disableDseTests`:
57+
```bash
58+
mvn clean package -PdisableDseTests
59+
```
60+
61+
The test suite also includes integration tests with AstraDB (`DbaasAstraIntegrationTest`). These tests require an
62+
AstraDB token configured in the environment variable `ASTRA_DB_APPLICATION_TOKEN`, otherwise they are skipped.
5263

5364
### Integration in Maven projects
5465

@@ -265,8 +276,11 @@ For further information about custom implementations of `SslEngineFactory`, see
265276

266277
### Connecting to DBaaS
267278

268-
In order to connect to the cloud [Cassandra-based DBaaS AstraDB](https://www.datastax.com/astra) cluster, one would
269-
need to specify:
279+
An alternative JDBC driver based on this one exists to ease the connection to the cloud
280+
[Cassandra-based DBaaS AstraDB](https://www.datastax.com/astra) cluster:
281+
[Astra JDBC driver](https://github.com/DataStax-Examples/astra-jdbc-connector/tree/main). Do not hesitate to use it if you are in this specific situation.
282+
283+
It's still possible to connect to AstraDB using this JDBC wrapper, so one would need to specify:
270284
* `secureconnectbundle`: the fully qualified path of the cloud secure connect bundle file
271285
* `keyspace`: the keyspace to connect to
272286
* `user`: the username
@@ -352,14 +366,16 @@ CREATE TABLE example_table (
352366
varint_col varint,
353367
string_set_col set<text>,
354368
string_list_col list<text>,
355-
string_map_col map<text, text>
369+
string_map_col map<text, text>,
370+
vector_col vector<float, 5>
356371
);
357372
```
358373

359374
To insert a record into `example_table` using a prepared statement:
360375

361376
```java
362377
import com.datastax.oss.driver.api.core.data.CqlDuration;
378+
import com.datastax.oss.driver.api.core.data.CqlVector;
363379

364380
import java.io.ByteArrayInputStream;
365381
import java.sql.Date;
@@ -370,8 +386,8 @@ public class HelloCassandra {
370386
final String insertCql = "INSERT INTO example_table (bigint_col, ascii_col, blob_col, boolean_col, decimal_col, "
371387
+ "double_col, float_col, inet_col, int_col, smallint_col, text_col, timestamp_col, time_col, date_col, "
372388
+ "tinyint_col, duration_col, uuid_col, timeuuid_col, varchar_col, varint_col, string_set_col, "
373-
+ "string_list_col, string_map_col) "
374-
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, now(), ?, ?, ?, ?, ?);";
389+
+ "string_list_col, string_map_col, vector_col) "
390+
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, now(), ?, ?, ?, ?, ?, ?);";
375391
final PreparedStatement preparedStatement = connection.prepareStatement(insertCql);
376392
preparedStatement.setObject(1, 1L); // bigint
377393
preparedStatement.setObject(2, "test"); // ascii
@@ -401,14 +417,16 @@ public class HelloCassandra {
401417
sampleSet.add("test1");
402418
sampleSet.add("test2");
403419
preparedStatement.setObject(20, sampleSet); // set
404-
ArrayList<String> sampleList = new ArrayList<String>();
420+
final ArrayList<String> sampleList = new ArrayList<String>();
405421
sampleList.add("test1");
406422
sampleList.add("test2");
407423
preparedStatement.setObject(21, sampleList); // list
408-
HashMap<String, String> sampleMap = new HashMap<String, String>();
424+
final HashMap<String, String> sampleMap = new HashMap<String, String>();
409425
sampleMap.put("1", "test1");
410426
sampleMap.put("2", "test2");
411427
preparedStatement.setObject(22, sampleMap); // map
428+
final CqlVector<Float> sampleVector = CqlVector.newInstance(1.0f, 0.0f, 1.0f, 0.5f, 0.2f);
429+
preparedStatement.setObject(23, sampleVector); // vector
412430
// Execute the prepare statement.
413431
preparedStatement.execute();
414432
}
@@ -696,6 +714,7 @@ We use [SemVer](http://semver.org/) for versioning.
696714
* Madhavan Sridharan - **[@msmygit](https://github.com/msmygit)**
697715
* Marius Jokubauskas - **[@mjok](https://github.com/mjok)**
698716
* Sualeh Fatehi - **[@sualeh](https://github.com/sualeh)**
717+
* Cedrick Lunven - **[@clun](https://github.com/clun)**
699718

700719
And special thanks to the developer of the original project on which is based this one:
701720
* Alexander Dejanovski - **[@adejanovski](https://github.com/adejanovski)**

Diff for: pom.xml

+24-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.ing.data</groupId>
77
<artifactId>cassandra-jdbc-wrapper</artifactId>
8-
<version>4.9.1</version>
8+
<version>4.10.0</version>
99
<packaging>jar</packaging>
1010

1111
<name>Cassandra JDBC Wrapper</name>
@@ -109,10 +109,10 @@
109109
<hamcrest.version>2.2</hamcrest.version>
110110
<junit5.version>5.10.0</junit5.version>
111111
<junit-platform.version>1.10.0</junit-platform.version>
112-
<lombok.version>1.18.28</lombok.version>
112+
<lombok.version>1.18.30</lombok.version>
113113
<mockito.version>3.12.4</mockito.version>
114114
<slf4j.version>1.7.36</slf4j.version>
115-
<testcontainers.version>1.18.3</testcontainers.version>
115+
<testcontainers.version>1.19.0</testcontainers.version>
116116
<astra-sdk.version>0.6.11</astra-sdk.version>
117117
<!-- Versions for plugins -->
118118
<maven-checkstyle-plugin.version>3.3.0</maven-checkstyle-plugin.version>
@@ -241,14 +241,14 @@
241241
<version>${testcontainers.version}</version>
242242
<scope>test</scope>
243243
</dependency>
244-
<!-- Astra Test instances for integration tests -->
244+
<!-- Astra SDK for integration tests with AstraDB -->
245245
<dependency>
246246
<groupId>com.datastax.astra</groupId>
247247
<artifactId>astra-sdk-devops</artifactId>
248248
<version>${astra-sdk.version}</version>
249249
<scope>test</scope>
250250
</dependency>
251-
<!-- handy to build the Cql Queries -->
251+
<!-- Handy to build the CQL queries -->
252252
<dependency>
253253
<groupId>com.datastax.oss</groupId>
254254
<artifactId>java-driver-query-builder</artifactId>
@@ -461,5 +461,24 @@
461461
</plugins>
462462
</build>
463463
</profile>
464+
465+
<!-- 'disableDseTests' excludes integration tests using DataStax Enterprise server. This can be handy if
466+
these specific tests failed for some reason in a local environment. -->
467+
<profile>
468+
<id>disableDseTests</id>
469+
<build>
470+
<plugins>
471+
<plugin>
472+
<artifactId>maven-surefire-plugin</artifactId>
473+
<version>${maven-surefire-plugin.version}</version>
474+
<configuration>
475+
<excludes>
476+
<exclude>*DseContainerTest.java</exclude>
477+
</excludes>
478+
</configuration>
479+
</plugin>
480+
</plugins>
481+
</build>
482+
</profile>
464483
</profiles>
465484
</project>

Diff for: src/main/java/com/ing/data/cassandra/jdbc/CassandraDatabaseMetaData.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,9 @@ public int getMaxUserNameLength() {
511511
@Override
512512
public String getNumericFunctions() throws SQLException {
513513
checkStatementClosed();
514-
// Cassandra does not implement natively numeric functions.
515-
return StringUtils.EMPTY;
514+
// We consider here the vectors similarity functions introduced by CEP-30 as numeric functions (see
515+
// https://issues.apache.org/jira/browse/CASSANDRA-18640).
516+
return "similarity_cosine,similarity_euclidean,similarity_dot_product";
516517
}
517518

518519
@Override
@@ -779,7 +780,7 @@ public String getTimeDateFunctions() throws SQLException {
779780
checkStatementClosed();
780781
// See: https://cassandra.apache.org/doc/latest/cassandra/cql/functions.html
781782
return "dateOf,now,minTimeuuid,maxTimeuuid,unixTimestampOf,toDate,toTimestamp,toUnixTimestamp,currentTimestamp,"
782-
+ "currentDate,currentTime,currentTimeUUID,";
783+
+ "currentDate,currentTime,currentTimeUUID";
783784
}
784785

785786
@Override

Diff for: src/main/java/com/ing/data/cassandra/jdbc/metadata/TableMetadataResultSetBuilder.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ public CassandraMetadataResultSet buildPrimaryKeys(final String schema, final St
330330
* </p>
331331
*
332332
* @param schema A schema name pattern. It must match the schema name as it is stored in the database; {@code ""}
333-
* retrieves those without a schema and {@code null} means that the schema name should not be used to
334-
* narrow the search. Using {@code ""} as the same effect as {@code null} because here the schema
333+
* retrieves those without a schema and {@code null} means that the schema name should not be used
334+
* to narrow the search. Using {@code ""} as the same effect as {@code null} because here the schema
335335
* corresponds to the keyspace and Cassandra tables cannot be defined outside a keyspace.
336336
* @param table A table name. It must match the table name as it is stored in the database.
337337
* @param scope The scope of interest, using the same values as {@code SCOPE} in the result set.

Diff for: src/main/java/com/ing/data/cassandra/jdbc/types/DataTypeEnum.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ public enum DataTypeEnum {
172172
*/
173173
VECTOR(DataType.LIST, CqlVector.class, "Vector");
174174

175+
static final String VECTOR_CLASSNAME = "org.apache.cassandra.db.marshal.VectorType";
176+
175177
private static final Map<String, DataTypeEnum> CQL_DATATYPE_TO_DATATYPE;
176178

177179
/**
@@ -185,8 +187,6 @@ public enum DataTypeEnum {
185187

186188
final int protocolId;
187189

188-
static final String VECTOR_CLASSNAME = "org.apache.cassandra.db.marshal.VectorType";
189-
190190
static {
191191
CQL_DATATYPE_TO_DATATYPE = new HashMap<>();
192192
for (final DataTypeEnum dataType : DataTypeEnum.values()) {
@@ -220,6 +220,7 @@ public static DataTypeEnum fromCqlTypeName(final String cqlTypeName) {
220220
if (cqlTypeName.startsWith(UDT.cqlType)) {
221221
return UDT;
222222
}
223+
// Manage vector type
223224
if (cqlTypeName.contains(VECTOR_CLASSNAME)) {
224225
return VECTOR;
225226
}
@@ -337,7 +338,10 @@ public String toString() {
337338
*/
338339
public static String cqlName(@Nonnull final com.datastax.oss.driver.api.core.type.DataType dataType) {
339340
final String rawCql = dataType.asCql(false, false);
340-
return rawCql.contains(VECTOR_CLASSNAME) ? VECTOR.cqlType : rawCql;
341+
if (rawCql.contains(VECTOR_CLASSNAME)) {
342+
return VECTOR.cqlType;
343+
}
344+
return rawCql;
341345
}
342346
}
343347

0 commit comments

Comments
 (0)