How to convert Cassandra TimeUUID stored in the TEXT field to a TimeStamp in cql?
The Akka Projection library stores TimeUUID values as TEXT in the offset_store
table. When you query the offset
from the offset_store
table, it shows the UUID string. It would be nice if it could be converted to a human-readable timestamp. Unfortunately, after hours of fruitless googling, I decided to create my own UDF (User-Defined Function) in Cassandra to make the conversation possible.
First, let’s look at the schema of the Akka Projection offset storage table in Cassandra;
The column we are interested in is offset
.
Second, let’s create the UDF in Cassandra;
- By default, Cassandra disables user defined functions. You can enable it by editing
cassandra.yaml
. Remember to restart your Cassandra;
- Now we are ready to create our own function:
textToTimestamp
Finally, we are ready to use the UDF that was just created in a cql SELECT statement;
Here you go, you can easily see the timestamp of the offset
column.
If you know any other way of converting TimeUUID stored in the TEXT column to a human-readable format in cql, please comment below.