Book Image

Learning Apache Cassandra

By : Matthew Brown
4 (1)
Book Image

Learning Apache Cassandra

4 (1)
By: Matthew Brown

Overview of this book

Table of Contents (19 chapters)
Learning Apache Cassandra
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Retrieving status updates for a specific time range


Having explored the limits of the WHERE keyword in CQL, let's return to the user_status_updates table. Suppose we'd like to build an "archive" feature for MyStatus that displays all of the user's status updates for a requested month. In CQL terms, we want to select a range of clustering columns; for instance, let's get back all of alice's status updates created in May 2014:

SELECT "id", DATEOF("id"), "body"
FROM "user_status_updates"
WHERE "username" = 'alice'
AND "id" >= MINTIMEUUID('2014-05-01')
AND "id" <= MAXTIMEUUID('2014-05-31');

Before diving into the mechanics of this query, we can confirm that the only status update is the one with a UUID that was provided in the previous chapter, and was generated on May 29:

Creating time UUID ranges

In the preceding query, we encounter two new CQL functions: MINTIMEUUID and MAXTIMEUUID. These functions form perhaps the most powerful components of Cassandra's toolkit for working with timestamp...