May a Cassandra (CQL 3) map
hold null values? I thought null values were permitted, but failure of my program suggests otherwise. Or is there a bug in the driver I am using?
The official documentation for CQL map
s says:
A map is a typed set of key-value pairs, where keys are unique. Furthermore, note that the map are internally sorted by their keys and will thus always be returned in that order.
So the keys may not be null (otherwise sorting would be impossible), but there is no mention of a requirement that map values are not null.
I have a field that is a map<timestamp,uuid>
, which I am trying to write to using values in a Java Map< Date, UUID >
. One of the map values (UUID
s) is null. This seems to cause a NPE in the Cassandra client code (Cassandra version 1.2.6, called from DataStax Java driver 1.0.1) when marshalling the UUID of the map:
java.lang.NullPointerException
at org.apache.cassandra.utils.UUIDGen.decompose(UUIDGen.java:82)
at org.apache.cassandra.cql.jdbc.JdbcUUID.decompose(JdbcUUID.java:55)
at org.apache.cassandra.db.marshal.UUIDType.decompose(UUIDType.java:187)
at org.apache.cassandra.db.marshal.UUIDType.decompose(UUIDType.java:43)
at org.apache.cassandra.db.marshal.MapType.decompose(MapType.java:122)
at org.apache.cassandra.db.marshal.MapType.decompose(MapType.java:29)
at com.datastax.driver.core.BoundStatement.bind(BoundStatement.java:188)
at [my method]
The UUIDGen.decompose(UUID)
method has no special handling of a null UUID
, hence the NPE. Contrast with JdbcBoolean.decompose(Boolean)
, which decomposes a null Boolean
to an empty byte-buffer. Similarly, JdbcDate.decompose(Date)
decomposes a null Date
to an empty byte-buffer.
I can produce a similar problem if I have a map holding null integers (using a Java Map< Date, Integer >
with a null value, for a Cassandra map<timestamp,int>
), so this problem is not restricted to uuid
values.