Learning Apache Cassandra - Second Edition by Sandeep Yarabarla

Learning Apache Cassandra - Second Edition by Sandeep Yarabarla

Author:Sandeep Yarabarla [Yarabarla, Sandeep]
Language: eng
Format: azw3
Tags: COM021000 - COMPUTERS / Databases / General, COM018000 - COMPUTERS / Data Processing, COM021030 - COMPUTERS / Databases / Data Mining
Publisher: Packt Publishing
Published: 2017-04-25T04:00:00+00:00


The problem with concurrent updates

Let's add a new feature to our MyStatus application: the user's ability to star their friend's status updates to indicate their approval. For each status update, we'll store a list of the users who have starred that status update so that we can display the usernames to the author of the update.

Serializing the collection

One approach is to simply store the list of users in a text column in some serialized form. JSON is a versatile serialization format for such scenarios, so we'll use that. First, we'll add the column to the user_status_updates table, recalling the technique from the Adding columns to tables section in Chapter 7, Expanding Your Data Model:

ALTER TABLE "user_status_updates"

ADD "starred_by_users" text;

Simple enough. Now let's suppose that bob wants to star one of the status updates of alice. From the application's standpoint, this means appending bob to the list of users who have starred alice's update. First, we'll read the existing list:

SELECT "starred_by_users"

FROM "user_status_updates"

WHERE "username" = 'alice'

AND "id" = 76e7a4d0-e796-11e3-90ce-5f98e903bf02;

We see that there's currently no value in the starred_by_users column, which we can just interpret as an empty list:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.