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

Recording aggregate analytics observations


When we explore precomputed aggregate data storage, let's focus on the first question posed above: how many total views did status updates receive on each day of September?

More generally, we want to store the daily overall view counts in a structure that allows us to easily retrieve the counts for a given range of time. We don't need to store discrete information about every view event that happened; simply knowing how many views occurred per day is sufficient.

Let's create a new daily_status_update_views table that aggregates our analytics observations at just the right granularity:

CREATE TABLE "daily_status_update_views" (
  "year" int,
  "date" timestamp,
  "total_views" counter,
  "web_views" counter,
  "mobile_views" counter,
  "api_views" counter,
  PRIMARY KEY (("year"), "date")
);

Of course, the most striking thing about this table definition is the introduction of the counter column type; we'll dive into this a little later in this chapter...