Adding a view

To avoid confusion, let's recreate the user_follows table with a different name:

    CREATE TABLE "user_follows_base" (      "followed_username" text,      "follower_username" text,      PRIMARY KEY ("followed_username", "follower_username")    );

Primarily, the preceding table lets us query the list of followers of a person. To query a list of persons someone is following, we created a secondary index earlier. Let's create a materialized view for the same:

  CREATE MATERIALIZED VIEW "user_follows_view"   AS SELECT followed_username, follower_username     FROM "user_follows_base"   WHERE follower_username IS NOT NULL AND followed_username IS NOT NULL     PRIMARY KEY (follower_username, followed_username);

This CREATE MATERIALIZED VIEW statement has several ...

Get Learning Apache Cassandra - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.