Skip to content

Commit ae4784e

Browse files
NODEJS-666: Extend driver vector support to arbitrary subtypes and fix handling of variable length types (OSS C* 5.0) (#427)
1 parent 804e0bb commit ae4784e

File tree

14 files changed

+1432
-449
lines changed

14 files changed

+1432
-449
lines changed

doc/features/datatypes/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ tuple|[Tuple](tuples)
2929
uuid|[Uuid](uuids)
3030
varchar|String
3131
varint|[Integer](numerical)
32-
vector|[Float32Array](collections)
32+
vector|[Vector](collections)
3333

3434
## Encoding data
3535

doc/features/datatypes/collections/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ client.execute('SELECT map_val FROM tbl')
7373

7474
### Vector
7575

76-
As of version 4.7.0 the driver also includes support for the vector type available in Cassandra 5.0. Vectors are represented as instances of
77-
the [Float32Array] class. For example, to create and write to a vector with three dimensions you can do the following:
76+
The driver supports vectors of arbitrary subtypes available in Apache Cassandra 5.0. Vectors are represented as instances of `cassandra.types.Vector` class. For example, to create and write to a vector with three dimensions you can do the following:
7877

7978
```javascript
8079
await c.connect()
@@ -84,8 +83,10 @@ await c.connect()
8483
.then(() => c.execute("create custom index ann_index on test.foo(j) using 'StorageAttachedIndex'"))
8584

8685
// Base inserts using simple and prepared statements
87-
.then(() => c.execute(`insert into test.foo (i, j) values (?, ?)`, [cassandra.types.Integer.fromInt(1), new Float32Array([8, 2.3, 58])]))
88-
.then(() => c.execute(`insert into test.foo (i, j) values (?, ?)`, [cassandra.types.Integer.fromInt(5), new Float32Array([23, 18, 3.9])], {prepare: true}));
86+
.then(() => c.execute(`insert into test.foo (i, j) values (?, ?)`, [cassandra.types.Integer.fromInt(1), new cassandra.types.Vector([8, 2.3, 58], 'float')]))
87+
.then(() => c.execute(`insert into test.foo (i, j) values (?, ?)`, [cassandra.types.Integer.fromInt(5), new cassandra.types.Vector([23, 18, 3.9])], {prepare: true}));
8988
```
9089

90+
In driver versions 4.7.0 - 4.7.2, the vector of floats was represented as a [Float32Array]. This is still supported for backward compatibility, but it is deprecated, and it is recommended to use the `cassandra.types.Vector` class instead.
91+
9192
[Float32Array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array

index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,10 @@ export namespace errors {
349349
constructor(address: string, maxRequestsPerConnection: number, connectionLength: number);
350350
}
351351

352+
class VIntOutOfRangeException extends DriverError {
353+
constructor(long: Long);
354+
}
355+
352356
abstract class DriverError extends Error {
353357
info: string;
354358

0 commit comments

Comments
 (0)