Skip to content

Commit

Permalink
Prepare version 4.10.0
Browse files Browse the repository at this point in the history
- Add vectors similarity functions from CEP-30 into the numeric functions
listed into the DatabaseMetadata.
- Allow disabling DSE tests using Maven profile.
  • Loading branch information
maximevw committed Sep 30, 2023
1 parent 7b4c5b8 commit 20a2264
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 79 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [4.10.0] - Unreleased
## [4.10.0] - 2023-09-30
### Added
- Add support for new [`vector` CQL type](https://datastax-oss.atlassian.net/browse/JAVA-3060)
defined in [CEP-30](https://cwiki.apache.org/confluence/x/OQ40Dw).
defined in [CEP-30](https://cwiki.apache.org/confluence/x/OQ40Dw)
Also see PR [#27](https://github.com/ing-bank/cassandra-jdbc-wrapper/pull/27).
- Implement the method `getWarnings()` in `CassandraResultSet`.
- Implement the following methods of `CassandraDatabaseMetaData`:
`getBestRowIdentifier(String, String, String, int, boolean)` and `getAttributes(String, String, String, String)`.
Expand Down
33 changes: 26 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ To compile and run tests, execute the following Maven command:
```bash
mvn clean package
```

#### Some considerations about running tests

If for some reason the tests using DataStax Enterprise server (`*DseContainerTest`) fail in your local environment, you
might disable them using the Maven profile `disableDseTests`:
```bash
mvn clean package -PdisableDseTests
```

The test suite also includes integration tests with AstraDB (`DbaasAstraIntegrationTest`). These tests require an
AstraDB token configured in the environment variable `ASTRA_DB_APPLICATION_TOKEN`, otherwise they are skipped.

### Integration in Maven projects

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

### Connecting to DBaaS

In order to connect to the cloud [Cassandra-based DBaaS AstraDB](https://www.datastax.com/astra) cluster, one would
need to specify:
An alternative JDBC driver based on this one exists to ease the connection to the cloud
[Cassandra-based DBaaS AstraDB](https://www.datastax.com/astra) cluster:
[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.

It's still possible to connect to AstraDB using this JDBC wrapper, so one would need to specify:
* `secureconnectbundle`: the fully qualified path of the cloud secure connect bundle file
* `keyspace`: the keyspace to connect to
* `user`: the username
Expand Down Expand Up @@ -352,14 +366,16 @@ CREATE TABLE example_table (
varint_col varint,
string_set_col set<text>,
string_list_col list<text>,
string_map_col map<text, text>
string_map_col map<text, text>,
vector_col vector<float, 5>
);
```

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

```java
import com.datastax.oss.driver.api.core.data.CqlDuration;
import com.datastax.oss.driver.api.core.data.CqlVector;

import java.io.ByteArrayInputStream;
import java.sql.Date;
Expand All @@ -370,8 +386,8 @@ public class HelloCassandra {
final String insertCql = "INSERT INTO example_table (bigint_col, ascii_col, blob_col, boolean_col, decimal_col, "
+ "double_col, float_col, inet_col, int_col, smallint_col, text_col, timestamp_col, time_col, date_col, "
+ "tinyint_col, duration_col, uuid_col, timeuuid_col, varchar_col, varint_col, string_set_col, "
+ "string_list_col, string_map_col) "
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, now(), ?, ?, ?, ?, ?);";
+ "string_list_col, string_map_col, vector_col) "
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, now(), ?, ?, ?, ?, ?, ?);";
final PreparedStatement preparedStatement = connection.prepareStatement(insertCql);
preparedStatement.setObject(1, 1L); // bigint
preparedStatement.setObject(2, "test"); // ascii
Expand Down Expand Up @@ -401,14 +417,16 @@ public class HelloCassandra {
sampleSet.add("test1");
sampleSet.add("test2");
preparedStatement.setObject(20, sampleSet); // set
ArrayList<String> sampleList = new ArrayList<String>();
final ArrayList<String> sampleList = new ArrayList<String>();
sampleList.add("test1");
sampleList.add("test2");
preparedStatement.setObject(21, sampleList); // list
HashMap<String, String> sampleMap = new HashMap<String, String>();
final HashMap<String, String> sampleMap = new HashMap<String, String>();
sampleMap.put("1", "test1");
sampleMap.put("2", "test2");
preparedStatement.setObject(22, sampleMap); // map
final CqlVector<Float> sampleVector = CqlVector.newInstance(1.0f, 0.0f, 1.0f, 0.5f, 0.2f);
preparedStatement.setObject(23, sampleVector); // vector
// Execute the prepare statement.
preparedStatement.execute();
}
Expand Down Expand Up @@ -696,6 +714,7 @@ We use [SemVer](http://semver.org/) for versioning.
* Madhavan Sridharan - **[@msmygit](https://github.com/msmygit)**
* Marius Jokubauskas - **[@mjok](https://github.com/mjok)**
* Sualeh Fatehi - **[@sualeh](https://github.com/sualeh)**
* Cedrick Lunven - **[@clun](https://github.com/clun)**

And special thanks to the developer of the original project on which is based this one:
* Alexander Dejanovski - **[@adejanovski](https://github.com/adejanovski)**
Expand Down
29 changes: 24 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.ing.data</groupId>
<artifactId>cassandra-jdbc-wrapper</artifactId>
<version>4.9.1</version>
<version>4.10.0</version>
<packaging>jar</packaging>

<name>Cassandra JDBC Wrapper</name>
Expand Down Expand Up @@ -109,10 +109,10 @@
<hamcrest.version>2.2</hamcrest.version>
<junit5.version>5.10.0</junit5.version>
<junit-platform.version>1.10.0</junit-platform.version>
<lombok.version>1.18.28</lombok.version>
<lombok.version>1.18.30</lombok.version>
<mockito.version>3.12.4</mockito.version>
<slf4j.version>1.7.36</slf4j.version>
<testcontainers.version>1.18.3</testcontainers.version>
<testcontainers.version>1.19.0</testcontainers.version>
<astra-sdk.version>0.6.11</astra-sdk.version>
<!-- Versions for plugins -->
<maven-checkstyle-plugin.version>3.3.0</maven-checkstyle-plugin.version>
Expand Down Expand Up @@ -241,14 +241,14 @@
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<!-- Astra Test instances for integration tests -->
<!-- Astra SDK for integration tests with AstraDB -->
<dependency>
<groupId>com.datastax.astra</groupId>
<artifactId>astra-sdk-devops</artifactId>
<version>${astra-sdk.version}</version>
<scope>test</scope>
</dependency>
<!-- handy to build the Cql Queries -->
<!-- Handy to build the CQL queries -->
<dependency>
<groupId>com.datastax.oss</groupId>
<artifactId>java-driver-query-builder</artifactId>
Expand Down Expand Up @@ -461,5 +461,24 @@
</plugins>
</build>
</profile>

<!-- 'disableDseTests' excludes integration tests using DataStax Enterprise server. This can be handy if
these specific tests failed for some reason in a local environment. -->
<profile>
<id>disableDseTests</id>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<excludes>
<exclude>*DseContainerTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,9 @@ public int getMaxUserNameLength() {
@Override
public String getNumericFunctions() throws SQLException {
checkStatementClosed();
// Cassandra does not implement natively numeric functions.
return StringUtils.EMPTY;
// We consider here the vectors similarity functions introduced by CEP-30 as numeric functions (see
// https://issues.apache.org/jira/browse/CASSANDRA-18640).
return "similarity_cosine,similarity_euclidean,similarity_dot_product";
}

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ public CassandraMetadataResultSet buildPrimaryKeys(final String schema, final St
* </p>
*
* @param schema A schema name pattern. It must match the schema name as it is stored in the database; {@code ""}
* retrieves those without a schema and {@code null} means that the schema name should not be used to
* narrow the search. Using {@code ""} as the same effect as {@code null} because here the schema
* retrieves those without a schema and {@code null} means that the schema name should not be used
* to narrow the search. Using {@code ""} as the same effect as {@code null} because here the schema
* corresponds to the keyspace and Cassandra tables cannot be defined outside a keyspace.
* @param table A table name. It must match the table name as it is stored in the database.
* @param scope The scope of interest, using the same values as {@code SCOPE} in the result set.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ public enum DataTypeEnum {
*/
VECTOR(DataType.LIST, CqlVector.class, "Vector");

static final String VECTOR_CLASSNAME = "org.apache.cassandra.db.marshal.VectorType";

private static final Map<String, DataTypeEnum> CQL_DATATYPE_TO_DATATYPE;

/**
Expand All @@ -185,8 +187,6 @@ public enum DataTypeEnum {

final int protocolId;

static final String VECTOR_CLASSNAME = "org.apache.cassandra.db.marshal.VectorType";

static {
CQL_DATATYPE_TO_DATATYPE = new HashMap<>();
for (final DataTypeEnum dataType : DataTypeEnum.values()) {
Expand Down Expand Up @@ -220,6 +220,7 @@ public static DataTypeEnum fromCqlTypeName(final String cqlTypeName) {
if (cqlTypeName.startsWith(UDT.cqlType)) {
return UDT;
}
// Manage vector type
if (cqlTypeName.contains(VECTOR_CLASSNAME)) {
return VECTOR;
}
Expand Down Expand Up @@ -337,7 +338,10 @@ public String toString() {
*/
public static String cqlName(@Nonnull final com.datastax.oss.driver.api.core.type.DataType dataType) {
final String rawCql = dataType.asCql(false, false);
return rawCql.contains(VECTOR_CLASSNAME) ? VECTOR.cqlType : rawCql;
if (rawCql.contains(VECTOR_CLASSNAME)) {
return VECTOR.cqlType;
}
return rawCql;
}
}

Expand Down
Loading

0 comments on commit 20a2264

Please sign in to comment.