1
1
## Upgrade guide
2
2
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
+
3
58
### 4.15.0
4
59
5
60
#### CodecNotFoundException now extends DriverException
@@ -15,7 +70,7 @@ a logic such as below, it won't compile anymore:
15
70
16
71
``` java
17
72
try {
18
- doSomethingWithDriver();
73
+ doSomethingWithDriver();
19
74
} catch (DriverException e) {
20
75
} catch (CodecNotFoundException e) {
21
76
}
@@ -25,7 +80,7 @@ You need to either reverse the catch order and catch `CodecNotFoundException` fi
25
80
26
81
``` java
27
82
try {
28
- doSomethingWithDriver();
83
+ doSomethingWithDriver();
29
84
} catch (CodecNotFoundException e) {
30
85
} catch (DriverException e) {
31
86
}
@@ -35,7 +90,7 @@ Or catch only `DriverException`:
35
90
36
91
``` java
37
92
try {
38
- doSomethingWithDriver();
93
+ doSomethingWithDriver();
39
94
} catch (DriverException e) {
40
95
}
41
96
```
@@ -229,16 +284,16 @@ The above can also be achieved by an adapter class as shown below:
229
284
``` java
230
285
public class NodeFilterToDistanceEvaluatorAdapter implements NodeDistanceEvaluator {
231
286
232
- private final Predicate<Node > nodeFilter;
287
+ private final Predicate<Node > nodeFilter;
233
288
234
- public NodeFilterToDistanceEvaluatorAdapter (@NonNull Predicate<Node > nodeFilter ) {
235
- this . nodeFilter = nodeFilter;
236
- }
289
+ public NodeFilterToDistanceEvaluatorAdapter (@NonNull Predicate<Node > nodeFilter ) {
290
+ this . nodeFilter = nodeFilter;
291
+ }
237
292
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
+ }
242
297
}
243
298
```
244
299
@@ -531,7 +586,7 @@ import com.datastax.driver.core.Row;
531
586
import com.datastax.driver.core.SimpleStatement;
532
587
533
588
SimpleStatement statement =
534
- new SimpleStatement("SELECT release_version FROM system.local");
589
+ new SimpleStatement("SELECT release_version FROM system.local");
535
590
ResultSet resultSet = session.execute(statement);
536
591
Row row = resultSet.one();
537
592
System.out.println(row.getString("release_version"));
@@ -543,7 +598,7 @@ import com.datastax.oss.driver.api.core.cql.Row;
543
598
import com.datastax.oss.driver.api.core.cql.SimpleStatement;
544
599
545
600
SimpleStatement statement =
546
- SimpleStatement.newInstance("SELECT release_version FROM system.local");
601
+ SimpleStatement.newInstance("SELECT release_version FROM system.local");
547
602
ResultSet resultSet = session.execute(statement);
548
603
Row row = resultSet.one();
549
604
System.out.println(row.getString("release_version"));
@@ -606,9 +661,9 @@ datastax-java-driver {
606
661
607
662
// Application code:
608
663
SimpleStatement statement1 =
609
- SimpleStatement . newInstance(" ..." ). setExecutionProfileName(" profile1" );
664
+ SimpleStatement . newInstance(" ..." ). setExecutionProfileName(" profile1" );
610
665
SimpleStatement statement2 =
611
- SimpleStatement . newInstance(" ..." ). setExecutionProfileName(" profile2" );
666
+ SimpleStatement . newInstance(" ..." ). setExecutionProfileName(" profile2" );
612
667
```
613
668
614
669
The configuration can be reloaded periodically at runtime:
@@ -727,13 +782,13 @@ propagating its own consistency level to its bound statements:
727
782
728
783
``` java
729
784
PreparedStatement 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 ));
733
788
PreparedStatement 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 ));
737
792
738
793
assert ps1 != ps2;
739
794
@@ -834,8 +889,8 @@ Optional<KeyspaceMetadata> ks = metadata.getKeyspace("test");
834
889
assert ! ks. isPresent();
835
890
836
891
session. 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}" );
839
894
840
895
// This is still the same metadata from before the CREATE
841
896
ks = metadata. getKeyspace(" test" );
0 commit comments