I am retrieving data from Cassandra and mapping it to a class using the build in object mapping API in the java driver. After I process the data I want to delete it. My clustering key is a timestamp and it is mapped to a Date object. When I try do delete a partition it does not get deleted. I suspect that it is because of the mapping to the Date object and that some data is lost there? Have you encountered a similar problem?
The Accessor:
@Query("SELECT * FROM my_table WHERE id = ? AND event_time < ?")
Result<MyObject> getAllObjectsByTime(UUID id, Date eventToTime);
The retrieval of the objects:
MappingManager manager = new MappingManager (_cassandraDatabaseManager.getSession());
CassandraAccessor cassandraAccessor = manager.createAccessor(CassandraAccessor.class);
Result<MyObject> myObjectResult = cassandraAccessor.getAllObjectsByTime(id, eventToTime);
MyObject:
@Table(keyspace = "myKeyspace", name = "my_table ")
public class MyObject
{
@PartitionKey
@Column(name = "id")
private UUID id;
@Column(name = "event_time")
private Date eventTime;
}
The delete logic:
PreparedStatement statement = session
.prepare("DELETE FROM my_table WHERE id = ? AND event_time = ?;");
BatchStatement batch = new BatchStatement();
for (MyObject myObject: myObjects)
{
batch.add(statement.bind(myObject.getStoreId(), myObject.getEventTime()));
}
session.execute(batch);
EDIT
After a lot of debugging I figured, that maybe the Date is not the problem. It appears that the delete is working, but not for all of the partitions. When I debug the Java application I get the following CQL
statement:
DELETE FROM my_table WHERE id=86a2f31d-5e6e-448b-b16c-052fe92a87c9 AND event_time=1442491082128;
When it is executed trough the Cassandra Java Driver
the partition is not deleted. If I execute it in the CQLSH
console the partition is deleted. I have no idea what is happening. I am starting to suspect that there is a problem with the Cassandra Java Driver
. Any ideas?
Edit 2
This is the table:
CREATE TABLE my_table(
id uuid,
event_time timestamp,
event_data text,
PRIMARY KEY (id, event_time)
) WITH CLUSTERING ORDER BY (event_time DESC)