Closed mpashka closed 1 year ago
I'm not quite sure what you're asking for. If you provide a different data type to either Cassandra or the prepared statement, then your query will fail. Codecs are a matter of the Cassandra driver, Spring Data only uses the driver and the codecs.
A more lenient approach of the driver, by accepting Integer
for BIGINT
would be neat. However, please reach out to the Cassandra driver team for such requests.
Еhe collective mind from stackoverflow gives an advice to remove @CassandraType annotations. That didn't help in my case. Probably column type update in cassandra can help.
For now I don't see possibility to update nested (udt) field value in cassandra through spring data query API:
Updating separate field results in Undefined column name:
cql.update(Query.query(
Criteria.where(Attachment.Key.MESSAGE_ID).is(5),
Criteria.where(Attachment.Key.ATTACHMENT_ID).is(6)
), Update.update(Attachment.DATA + '.' + Attachment.AttachmentData.DT_STATUS, "Hello5"), Attachment.class);
org.springframework.data.cassandra.CassandraInvalidQueryException: Query; CQL [UPDATE attachment SET status=? WHERE message_id=? AND attachment_id=?]; Unknown identifier status; nested exception is com.datastax.oss.driver.api.core.servererrors.InvalidQueryException: Unknown identifier status
...
Caused by: com.datastax.oss.driver.api.core.servererrors.InvalidQueryException: Unknown identifier status
while I'm using 'data.status' for column name. And I didn't find an option to fix that.
Updating whole object:
cql.update(Query.query(
Criteria.where(Attachment.Key.MESSAGE_ID).is(5),
Criteria.where(Attachment.Key.ATTACHMENT_ID).is(6)
), Update.update(Attachment.DATA, Attachment.AttachmentData.builder()
.status("Hello4")
.build()
), Attachment.class);
reports com.datastax.oss.driver.api.core.type.codec.CodecNotFoundException: Codec not found for requested operation: [BIGINT <-> java.lang.Integer]
I suppose that is a defect, but probably I'm wrong and that's ok.
If you change .is(5)
to .is(5L)
(using long values), then the issue goes away. Same for the attachment Id.
I'm trying to update cassandra udf field using CassandraOperations update API.
And that results in error:
After adding appropriate codec manually (long <-> BIGINT with java.lang.Integer java type exposed) that code works fine:
where
BigintIntegerCodec
is copy-paste fromcom.datastax.oss.driver.internal.core.type.codec.BigIntCodec
class withjava.lang.Integer
instead ofjava.lang.Long
java type exposed.Cassandra schema:
Here is junit test