Skip to content

Instantly share code, notes, and snippets.

@davidlzs
Created March 19, 2021 17:51
Show Gist options
  • Select an option

  • Save davidlzs/0435e74c970b3634388c84514d989690 to your computer and use it in GitHub Desktop.

Select an option

Save davidlzs/0435e74c970b3634388c84514d989690 to your computer and use it in GitHub Desktop.
Cassandra UDF textToTimestamp
CREATE OR REPLACE FUNCTION akka_projection.textToTimestamp (
input TEXT
)
CALLED ON NULL INPUT
RETURNS Timestamp
LANGUAGE java AS
$$
final long NUM_100NS_INTERVALS_SINCE_UUID_EPOCH = 0x01b21dd213814000L;
UUID uuid = UUID.fromString(input);
long time = (uuid.timestamp() - NUM_100NS_INTERVALS_SINCE_UUID_EPOCH) / 10000;
Date date = new Date(time);
return date;
$$
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment