11## Upgrade guide
22
3+ ### 4.17.0
4+
5+ #### Beta support for Java17
6+
7+ With the completion of [ JAVA-3042] ( https://datastax-oss.atlassian.net/browse/JAVA-3042 ) the driver now passes our automated test matrix for Java driver releases.
8+ While all features function normally when run with Java 17 tests, we do not offer full support for this
9+ platform until we've received feedback from other users in the ecosystem.
10+
11+ If you discover an issue with the Java driver running on Java 17, please let us know. We will triage and address Java 17 issues.
12+
13+ #### Updated API for vector search
14+
15+ The 4.16.0 release introduced support for the CQL ` vector ` datatype. This release modifies the ` CqlVector `
16+ value type used to represent a CQL vector to make it easier to use. ` CqlVector ` now implements the Iterable interface
17+ as well as several methods modelled on the JDK's List interface. For more, see
18+ [ JAVA-3060] ( https://datastax-oss.atlassian.net/browse/JAVA-3060 ) .
19+
20+ The builder interface was replaced with factory methods that resemble similar methods on ` CqlDuration ` .
21+ For example, the following code will create a keyspace and table, populate that table with some data, and then execute
22+ a query that will return a ` vector ` type. This data is retrieved directly via ` Row.getVector() ` and the resulting
23+ ` CqlVector ` value object can be interrogated directly.
24+
25+ ``` java
26+ try (CqlSession session = new CqlSessionBuilder (). withLocalDatacenter(" datacenter1" ). build()) {
27+
28+ session. execute(" DROP KEYSPACE IF EXISTS test" );
29+ session. execute(" CREATE KEYSPACE test WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}" );
30+ session. execute(" CREATE TABLE test.foo(i int primary key, j vector<float, 3>)" );
31+ session. execute(" CREAT CUSTOM INDEX ann_index ON test.foo(j) USING 'StorageAttachedIndex'" );
32+ session. execute(" INSERT INTO test.foo (i, j) VALUES (1, [8, 2.3, 58])" );
33+ session. execute(" INSERT INTO test.foo (i, j) VALUES (2, [1.2, 3.4, 5.6])" );
34+ session. execute(" INSERT INTO test.foo (i, j) VALUES (5, [23, 18, 3.9])" );
35+ ResultSet rs= session. execute(" SELECT j FROM test.foo WHERE j ann of [3.4, 7.8, 9.1] limit 1" );
36+ for (Row row : rs){
37+ CqlVector<Float > v = row. getVector(0 , Float . class);
38+ System . out. println(v);
39+ if (Iterables . size(v) != 3 ) {
40+ throw new RuntimeException (" Expected vector with three dimensions" );
41+ }
42+ }
43+ }
44+ ```
45+
46+ You can also use the ` CqlVector ` type with prepared statements:
47+
48+ ``` java
49+ PreparedStatement preparedInsert = session. prepare(" INSERT INTO test.foo (i, j) VALUES (?,?)" );
50+ CqlVector<Float > vector = CqlVector . newInstance(1.4f , 2.5f , 3.6f );
51+ session. execute(preparedInsert. bind(3 , vector));
52+ ```
53+
54+ In some cases, it makes sense to access the vector directly as an array of some numerical type. This version
55+ supports such use cases by providing a codec which translates a CQL vector to and from a primitive array. Only float arrays are supported.
56+ You can find more information about this codec in the manual documentation on [ custom codecs] ( ../manual/core/custom_codecs/ )
57+
358### 4.15.0
459
560#### CodecNotFoundException now extends DriverException
@@ -15,7 +70,7 @@ a logic such as below, it won't compile anymore:
1570
1671``` java
1772try {
18- doSomethingWithDriver();
73+ doSomethingWithDriver();
1974} catch (DriverException e) {
2075} catch (CodecNotFoundException e) {
2176}
@@ -25,7 +80,7 @@ You need to either reverse the catch order and catch `CodecNotFoundException` fi
2580
2681``` java
2782try {
28- doSomethingWithDriver();
83+ doSomethingWithDriver();
2984} catch (CodecNotFoundException e) {
3085} catch (DriverException e) {
3186}
@@ -35,7 +90,7 @@ Or catch only `DriverException`:
3590
3691``` java
3792try {
38- doSomethingWithDriver();
93+ doSomethingWithDriver();
3994} catch (DriverException e) {
4095}
4196```
@@ -229,16 +284,16 @@ The above can also be achieved by an adapter class as shown below:
229284``` java
230285public class NodeFilterToDistanceEvaluatorAdapter implements NodeDistanceEvaluator {
231286
232- private final Predicate<Node > nodeFilter;
287+ private final Predicate<Node > nodeFilter;
233288
234- public NodeFilterToDistanceEvaluatorAdapter (@NonNull Predicate<Node > nodeFilter ) {
235- this . nodeFilter = nodeFilter;
236- }
289+ public NodeFilterToDistanceEvaluatorAdapter (@NonNull Predicate<Node > nodeFilter ) {
290+ this . nodeFilter = nodeFilter;
291+ }
237292
238- @Nullable @Override
239- public NodeDistance evaluateDistance (@NonNull Node node , @Nullable String localDc ) {
240- return nodeFilter. test(node) ? null : NodeDistance . IGNORED ;
241- }
293+ @Nullable @Override
294+ public NodeDistance evaluateDistance (@NonNull Node node , @Nullable String localDc ) {
295+ return nodeFilter. test(node) ? null : NodeDistance . IGNORED ;
296+ }
242297}
243298```
244299
@@ -531,7 +586,7 @@ import com.datastax.driver.core.Row;
531586import com.datastax.driver.core.SimpleStatement;
532587
533588SimpleStatement statement =
534- new SimpleStatement("SELECT release_version FROM system.local");
589+ new SimpleStatement("SELECT release_version FROM system.local");
535590ResultSet resultSet = session.execute(statement);
536591Row row = resultSet.one();
537592System.out.println(row.getString("release_version"));
@@ -543,7 +598,7 @@ import com.datastax.oss.driver.api.core.cql.Row;
543598import com.datastax.oss.driver.api.core.cql.SimpleStatement;
544599
545600SimpleStatement statement =
546- SimpleStatement.newInstance("SELECT release_version FROM system.local");
601+ SimpleStatement.newInstance("SELECT release_version FROM system.local");
547602ResultSet resultSet = session.execute(statement);
548603Row row = resultSet.one();
549604System.out.println(row.getString("release_version"));
@@ -606,9 +661,9 @@ datastax-java-driver {
606661
607662// Application code:
608663SimpleStatement statement1 =
609- SimpleStatement . newInstance(" ..." ). setExecutionProfileName(" profile1" );
664+ SimpleStatement . newInstance(" ..." ). setExecutionProfileName(" profile1" );
610665SimpleStatement statement2 =
611- SimpleStatement . newInstance(" ..." ). setExecutionProfileName(" profile2" );
666+ SimpleStatement . newInstance(" ..." ). setExecutionProfileName(" profile2" );
612667```
613668
614669The configuration can be reloaded periodically at runtime:
@@ -727,13 +782,13 @@ propagating its own consistency level to its bound statements:
727782
728783``` java
729784PreparedStatement ps1 =
730- session. prepare(
731- SimpleStatement . newInstance(" SELECT * FROM product WHERE sku = ?" )
732- .setConsistencyLevel(DefaultConsistencyLevel . ONE ));
785+ session. prepare(
786+ SimpleStatement . newInstance(" SELECT * FROM product WHERE sku = ?" )
787+ .setConsistencyLevel(DefaultConsistencyLevel . ONE ));
733788PreparedStatement ps2 =
734- session. prepare(
735- SimpleStatement . newInstance(" SELECT * FROM product WHERE sku = ?" )
736- .setConsistencyLevel(DefaultConsistencyLevel . TWO ));
789+ session. prepare(
790+ SimpleStatement . newInstance(" SELECT * FROM product WHERE sku = ?" )
791+ .setConsistencyLevel(DefaultConsistencyLevel . TWO ));
737792
738793assert ps1 != ps2;
739794
@@ -834,8 +889,8 @@ Optional<KeyspaceMetadata> ks = metadata.getKeyspace("test");
834889assert ! ks. isPresent();
835890
836891session. execute(
837- " CREATE KEYSPACE IF NOT EXISTS test "
838- + " WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}" );
892+ " CREATE KEYSPACE IF NOT EXISTS test "
893+ + " WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}" );
839894
840895// This is still the same metadata from before the CREATE
841896ks = metadata. getKeyspace(" test" );
0 commit comments