- Learning Apache Cassandra(Second Edition)
- Sandeep Yarabarla
- 192字
- 2021-07-03 00:19:33
Extracting timestamps
As we previously mentioned, Cassandra has special capabilities for the timeuuid type, which includes extracting the timestamp that's encoded in these UUIDs. We can see this in action using the DATEOF function:
SELECT "username", "id", "body", DATEOF("id")
FROM "user_status_updates";
The DATEOF function instructs Cassandra to return a result column containing the timestamp at which the given column's UUID value was created. We now have access to information encoded in the id column that was previously obscure:
If you're following along with your CQL shell, you'll notice that the dates do not tell you when the rows were created but when the UUIDs in the id column were generated. Since we're using UUIDs that I generated when writing this book, we'll see that the creation timestamp shows an older time.
While the DATEOF output is very readable, the timestamps only offer precision at the second level. For a more precise representation of the timestamp at which the UUIDs were generated, use the UNIXTIMESTAMPOF function instead:
SELECT "username", "id", "body", UNIXTIMESTAMPOF("id")
FROM "user_status_updates";
The UNIXTIMESTAMPOF function returns the timestamp represented as the number of milliseconds since January 1, 1970 at midnight UTC:
- 返璞歸真:UNIX技術(shù)內(nèi)幕
- 大數(shù)據(jù)挑戰(zhàn)與NoSQL數(shù)據(jù)庫技術(shù)
- 21天學(xué)通Java
- Windows游戲程序設(shè)計(jì)基礎(chǔ)
- Grome Terrain Modeling with Ogre3D,UDK,and Unity3D
- 傳感器原理及實(shí)用技術(shù)
- EJB JPA數(shù)據(jù)庫持久層開發(fā)實(shí)踐詳解
- 單片機(jī)C51應(yīng)用技術(shù)
- 網(wǎng)絡(luò)信息安全項(xiàng)目教程
- Python語言從入門到精通
- ARM體系結(jié)構(gòu)與編程
- PowerPoint 2003中文演示文稿5日通
- 深度學(xué)習(xí)之模型優(yōu)化:核心算法與案例實(shí)踐
- 從實(shí)踐中學(xué)嵌入式Linux操作系統(tǒng)
- 仿蛛機(jī)器人的設(shè)計(jì)與制作