Skip to content

Commit 41991c8

Browse files
authored
JAVA-3083: Doc updates for new features in 4.17.0 (#1677)
1 parent dfc1164 commit 41991c8

File tree

3 files changed

+120
-51
lines changed

3 files changed

+120
-51
lines changed

manual/core/README.md

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -231,34 +231,35 @@ See [AccessibleByName] for an explanation of the conversion rules.
231231

232232
##### CQL to Java type mapping
233233

234-
| CQL3 data type | Getter name | Java type | See also |
235-
|---------------------|----------------|----------------------|-------------------------------------|
236-
| ascii | getString | java.lang.String | |
237-
| bigint | getLong | long | |
238-
| blob | getByteBuffer | java.nio.ByteBuffer | |
239-
| boolean | getBoolean | boolean | |
240-
| counter | getLong | long | |
241-
| date | getLocalDate | java.time.LocalDate | [Temporal types](temporal_types/) |
242-
| decimal | getBigDecimal | java.math.BigDecimal | |
243-
| double | getDouble | double | |
244-
| duration | getCqlDuration | [CqlDuration] | [Temporal types](temporal_types/) |
245-
| float | getFloat | float | |
246-
| inet | getInetAddress | java.net.InetAddress | |
247-
| int | getInt | int | |
248-
| list | getList | java.util.List<T> | |
249-
| map | getMap | java.util.Map<K, V> | |
250-
| set | getSet | java.util.Set<T> | |
251-
| smallint | getShort | short | |
252-
| text | getString | java.lang.String | |
253-
| time | getLocalTime | java.time.LocalTime | [Temporal types](temporal_types/) |
254-
| timestamp | getInstant | java.time.Instant | [Temporal types](temporal_types/) |
255-
| timeuuid | getUuid | java.util.UUID | |
256-
| tinyint | getByte | byte | |
257-
| tuple | getTupleValue | [TupleValue] | [Tuples](tuples/) |
258-
| user-defined types | getUDTValue | [UDTValue] | [User-defined types](udts/) |
259-
| uuid | getUuid | java.util.UUID | |
260-
| varchar | getString | java.lang.String | |
261-
| varint | getBigInteger | java.math.BigInteger | |
234+
| CQL3 data type | Getter name | Java type | See also |
235+
|--------------------|----------------|----------------------|-----------------------------------|
236+
| ascii | getString | java.lang.String | |
237+
| bigint | getLong | long | |
238+
| blob | getByteBuffer | java.nio.ByteBuffer | |
239+
| boolean | getBoolean | boolean | |
240+
| counter | getLong | long | |
241+
| date | getLocalDate | java.time.LocalDate | [Temporal types](temporal_types/) |
242+
| decimal | getBigDecimal | java.math.BigDecimal | |
243+
| double | getDouble | double | |
244+
| duration | getCqlDuration | [CqlDuration] | [Temporal types](temporal_types/) |
245+
| float | getFloat | float | |
246+
| inet | getInetAddress | java.net.InetAddress | |
247+
| int | getInt | int | |
248+
| list | getList | java.util.List<T> | |
249+
| map | getMap | java.util.Map<K, V> | |
250+
| set | getSet | java.util.Set<T> | |
251+
| smallint | getShort | short | |
252+
| text | getString | java.lang.String | |
253+
| time | getLocalTime | java.time.LocalTime | [Temporal types](temporal_types/) |
254+
| timestamp | getInstant | java.time.Instant | [Temporal types](temporal_types/) |
255+
| timeuuid | getUuid | java.util.UUID | |
256+
| tinyint | getByte | byte | |
257+
| tuple | getTupleValue | [TupleValue] | [Tuples](tuples/) |
258+
| user-defined types | getUDTValue | [UDTValue] | [User-defined types](udts/) |
259+
| uuid | getUuid | java.util.UUID | |
260+
| varchar | getString | java.lang.String | |
261+
| varint | getBigInteger | java.math.BigInteger | |
262+
| vector | getVector | [CqlVector] | [Custom Codecs](custom_codecs/) |
262263

263264
Sometimes the driver has to infer a CQL type from a Java type (for example when handling the values
264265
of [simple statements](statements/simple/)); for those that have multiple CQL equivalents, it makes
@@ -322,6 +323,7 @@ for (ColumnDefinitions.Definition definition : row.getColumnDefinitions()) {
322323
[AccessibleByName]: https://docs.datastax.com/en/drivers/java/4.14/com/datastax/oss/driver/api/core/data/AccessibleByName.html
323324
[GenericType]: https://docs.datastax.com/en/drivers/java/4.14/com/datastax/oss/driver/api/core/type/reflect/GenericType.html
324325
[CqlDuration]: https://docs.datastax.com/en/drivers/java/4.14/com/datastax/oss/driver/api/core/data/CqlDuration.html
326+
[CqlVector]: https://docs.datastax.com/en/drivers/java/4.14/com/datastax/oss/driver/api/core/data/CqlVector.html
325327
[TupleValue]: https://docs.datastax.com/en/drivers/java/4.14/com/datastax/oss/driver/api/core/data/TupleValue.html
326328
[UdtValue]: https://docs.datastax.com/en/drivers/java/4.14/com/datastax/oss/driver/api/core/data/UdtValue.html
327329
[SessionBuilder.addContactPoint()]: https://docs.datastax.com/en/drivers/java/4.14/com/datastax/oss/driver/api/core/session/SessionBuilder.html#addContactPoint-java.net.InetSocketAddress-

manual/core/custom_codecs/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,17 @@ that maps instances of that class to Json strings, using a newly-allocated, defa
256256
It is also possible to pass a custom `ObjectMapper` instance using [ExtraTypeCodecs.json(Class,
257257
ObjectMapper)] instead.
258258

259+
#### Mapping CQL vectors to Java array
260+
261+
By default, the driver maps CQL `vector` to the [CqlVector] value type. If you prefer to deal with
262+
arrays, the driver offers the following codec:
263+
264+
| Codec | CQL type | Java type |
265+
|-------------------------------------------|-----------------|-----------|
266+
| [ExtraTypeCodecs.floatVectorToArray(int)] | `vector<float>` | `float[]` |
267+
268+
This release only provides a codec for vectors containing float values.
269+
259270
### Writing codecs
260271

261272
If none of the driver built-in codecs above suits you, it is also possible to roll your own.
@@ -707,6 +718,7 @@ private static String formatRow(Row row) {
707718
[ExtraTypeCodecs.enumOrdinalsOf(Class)]: https://docs.datastax.com/en/drivers/java/4.14/com/datastax/oss/driver/api/core/type/codec/ExtraTypeCodecs.html#enumOrdinalsOf-java.lang.Class-
708719
[ExtraTypeCodecs.json(Class)]: https://docs.datastax.com/en/drivers/java/4.14/com/datastax/oss/driver/api/core/type/codec/ExtraTypeCodecs.html#json-java.lang.Class-
709720
[ExtraTypeCodecs.json(Class, ObjectMapper)]: https://docs.datastax.com/en/drivers/java/4.14/com/datastax/oss/driver/api/core/type/codec/ExtraTypeCodecs.html#json-java.lang.Class-com.fasterxml.jackson.databind.ObjectMapper-
721+
[ExtraTypeCodecs.floatVectorToArray(int)]: https://docs.datastax.com/en/drivers/java/4.14/com/datastax/oss/driver/api/core/type/codec/ExtraTypeCodecs.html#floatVectorToArray-int-
710722

711723
[TypeCodecs.BLOB]: https://docs.datastax.com/en/drivers/java/4.14/com/datastax/oss/driver/api/core/type/codec/TypeCodecs.html#BLOB
712724
[TypeCodecs.TIMESTAMP]: https://docs.datastax.com/en/drivers/java/4.14/com/datastax/oss/driver/api/core/type/codec/TypeCodecs.html#TIMESTAMP

upgrade_guide/README.md

Lines changed: 78 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,60 @@
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
1772
try {
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
2782
try {
28-
doSomethingWithDriver();
83+
doSomethingWithDriver();
2984
} catch(CodecNotFoundException e) {
3085
} catch(DriverException e) {
3186
}
@@ -35,7 +90,7 @@ Or catch only `DriverException`:
3590

3691
```java
3792
try {
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
230285
public 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;
531586
import com.datastax.driver.core.SimpleStatement;
532587

533588
SimpleStatement statement =
534-
new SimpleStatement("SELECT release_version FROM system.local");
589+
new SimpleStatement("SELECT release_version FROM system.local");
535590
ResultSet resultSet = session.execute(statement);
536591
Row row = resultSet.one();
537592
System.out.println(row.getString("release_version"));
@@ -543,7 +598,7 @@ import com.datastax.oss.driver.api.core.cql.Row;
543598
import com.datastax.oss.driver.api.core.cql.SimpleStatement;
544599

545600
SimpleStatement statement =
546-
SimpleStatement.newInstance("SELECT release_version FROM system.local");
601+
SimpleStatement.newInstance("SELECT release_version FROM system.local");
547602
ResultSet resultSet = session.execute(statement);
548603
Row row = resultSet.one();
549604
System.out.println(row.getString("release_version"));
@@ -606,9 +661,9 @@ datastax-java-driver {
606661

607662
// Application code:
608663
SimpleStatement statement1 =
609-
SimpleStatement.newInstance("...").setExecutionProfileName("profile1");
664+
SimpleStatement.newInstance("...").setExecutionProfileName("profile1");
610665
SimpleStatement statement2 =
611-
SimpleStatement.newInstance("...").setExecutionProfileName("profile2");
666+
SimpleStatement.newInstance("...").setExecutionProfileName("profile2");
612667
```
613668

614669
The configuration can be reloaded periodically at runtime:
@@ -727,13 +782,13 @@ propagating its own consistency level to its bound statements:
727782

728783
```java
729784
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));
733788
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));
737792

738793
assert ps1 != ps2;
739794

@@ -834,8 +889,8 @@ Optional<KeyspaceMetadata> ks = metadata.getKeyspace("test");
834889
assert !ks.isPresent();
835890

836891
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}");
839894

840895
// This is still the same metadata from before the CREATE
841896
ks = metadata.getKeyspace("test");

0 commit comments

Comments
 (0)