Frage

I understand that Cassandra stores timestamps as seconds (or microseconds) since epoch. So if I care about the time zone where the particular event took place do I need to store it in a separate column? Is there any best practice or suggestions for how to store that? Integer offset from GMT?

War es hilfreich?

Lösung

We store millions of timestamps and their timezones in our Cassandra cluster per day.

Our recommended practice is to store timestamps as two values:

  1. Store the timestamp itself as a timestamp type or bigint and always align it to UTC (we use .NET datetimes, which start from year zero and not the UNIX epoch, so we have to use bigint.)
  2. Store the UTC offset as a bigint, in microseconds

That way all of our timestamps are, by default, using the same timezone across the board. However, whenever we need to do something in local time we can just fetch the UTC offset column and subtract it from the timestamp in order to get local time.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top