The https://github/adejanovski/cassandra-jdbc-wrapper is great but more than a bit outdated. E.g., it has a target of Java 1.6, it's using version 3.0.0 of a key library (datastax) where the final version was 3.8.0 (and the current version is 4.4), etc. It can connect to Cassandra 3.x but is missing some of the latest features.
We've been able to fork the project and update the datastax library to 3.8.0 but I'm stuck at adding the 'duration' data type. There's a table that (seems to) map the wire protocol's protocolId
for data types to the wrapper's class that implements it. I've searched both datastax code (which supports this data type) and the cassandra code and been totally stumped finding the correct value since everything uses the enum (yay!) instead of the much more opaque protocolId... but I haven't been able to find where the association is made on the Cassadra server's side.
So two questions. First is there already a fork of this project that adds support for the 'duration' type? (I wish it was possible to do a code search over both a project and its forks.)
Second, what is the protocol id / where is it defined?
At this point I'm almost ready to just add some instrumentation so the "unknown codec" message adds more details. It would work but could be fragile.
Note on JDBC vs CQL: our current code was written several years ago by someone reusing our extensive JDBC infrastructure. It was "good enough" but requires maintained JDBC drivers. It's now clear that we should refactor the code to use CQL but that will take time to write and test and a customer wants a solution now. We found a commercial solution but it's incompatible with our system since we load our jars from a mongo store instead of the filesystem. (Don't ask.) Forking this driver gives us some breathing room.
If it helps this is the table in com.github.adejanovski.cassandra.jdbc
:
public enum DataTypeEnum {
ASCII (1, String.class, DataType.Name.ASCII),
BIGINT (2, Long.class, DataType.Name.BIGINT),
BLOB (3, ByteBuffer.class, DataType.Name.BLOB),
BOOLEAN (4, Boolean.class, DataType.Name.BOOLEAN),
COUNTER (5, Long.class, DataType.Name.COUNTER),
DECIMAL (6, BigDecimal.class, DataType.Name.DECIMAL),
DOUBLE (7, Double.class, DataType.Name.DOUBLE),
FLOAT (8, Float.class, DataType.Name.FLOAT),
INET (16, InetAddress.class, DataType.Name.INET),
INT (9, Integer.class, DataType.Name.INT),
TEXT (10, String.class, DataType.Name.TEXT),
TIMESTAMP (11, Date.class, DataType.Name.TIMESTAMP),
UUID (12, UUID.class, DataType.Name.UUID),
VARCHAR (13, String.class, DataType.Name.VARCHAR),
VARINT (14, BigInteger.class, DataType.Name.VARINT),
TIMEUUID (15, UUID.class, DataType.Name.TIMEUUID),
LIST (32, List.class, DataType.Name.LIST),
SET (34, Set.class, DataType.Name.SET),
MAP (33, Map.class, DataType.Name.MAP),
UDT (48, UDTValue.class, DataType.Name.UDT),
TUPLE (49, TupleValue.class, DataType.Name.TUPLE),
CUSTOM (0, ByteBuffer.class, DataType.Name.CUSTOM),
SMALLINT (19, Integer.class, DataType.Name.SMALLINT),
TINYINT (20, Integer.class, DataType.Name.TINYINT),
DATE (17, Date.class, DataType.Name.DATE),
TIME (18, Date.class, DataType.Name.TIME),
DURATION (???, Duration.class, DataType.Name.DURATION);
final int protocolId;
final Class<?> javaType;
final Name cqlType;
private static final DataTypeEnum[] nameToIds;
private static final Map<DataType.Name, DataTypeEnum> cqlDataTypeToDataType;
Codes for types, together with their encoding information are defined in CQL protocol specification - Duration type is in the version 5 - this type has identifier 0x15 (21). You can also find all codes in the source code of the Java driver.