We have a schema where the partition key will be a date (yyyy-MM-dd) and we are thinking about choosing the data type between text and date for this partition key.
Does one data type provide benefits over the other and how would they differ in querying/storage?
Here is an example schema.
CREATE TABLE test.user_sessions (
sess_date date (or text),
sess_starttime timestamp,
event_type text,
total_req int,
ended_at timestamp
PRIMARY KEY (sess_date, sess_starttime)
);
Cassandra Date Type :
Value is a date with no corresponding time value; Cassandra encodes date as a 32-bit integer representing days since epoch (January 1, 1970)
Cassandra Text Type :
UTF-8 encoded string; 16 bit for each character
If you store date (yyyy-MM-dd) as date data type each entry will only take 32-bit. On the other hand if you store the date as text it will take 10*16 = 160 bit storage.
As per your comments, if you need maximum portability simply store the information as a timestamp (that is a 64-bit number) corresponding to the something like yyyy-MM-dd 00:00:00 (a truncated time stamp). You can't go wrong with an "universal" number...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With