Is there a way to use short and byte values in CQL? I've defined a table with int fields and can store and read short and byte values from there, but if I try to bind a value in a prepared statement, I get an error. I also tried varint, but still no luck. That's the exception I get:
Invalid type for value 1 of CQL type varint, expecting class java.math.BigInteger but class java.lang.Byte provided
Here's the table definition:
CREATE TABLE "Timeline" (
"BucketID" varchar,
"CreationTime" timestamp,
"Attr01" varint,
"Attr02" bigint,
"Attr03" varint,
"Attr04" varint,
"Attr05" uuid,
"Message" text,
PRIMARY KEY (("BucketID", "Attr01"), "CreationTime", "Attr02", "Attr03", "Attr04", "Attr05")
) WITH COMPACT STORAGE AND CLUSTERING ORDER BY ("CreationTime" DESC);
Is there a way to use shorts/bytes, instead of always casting/creating integers?
Here is a link to the CQL3 data types to Java types chart.
I also tried varint, but still no luck.
I would have thought that varint
should have worked, too. But I can see (in the link referenced above) that varint
maps to BigInteger
, so no luck there. In any case, it would appear that a mapping between a short
and a CQL3 integer-based type does not exist.
However, if you want to store bytes you can use the blob
CQL3 type.
EDIT 20180727
It looks like smallint
in CQL now maps to java.lang.Short
.