tecles_192911 avatar image
tecles_192911 asked Erick Ramirez commented

Isn't the table name video_ratings_by_user in the week 2 workshop misleading?


In Week-2 notebook Cassandra Developer Workshop #4 - Data Modelling, there's a table called video_ratings_by_user with the following structure:

// Video ratings by user (to try and mitigate voting multiple times)
CREATE TABLE IF NOT EXISTS video_ratings_by_user (
    videoid uuid,
    userid uuid,
    rating int,
    PRIMARY KEY (videoid, userid)

Well, since this is a data modelling practice, isn't that table name misleading?

With the partitioning key videoid, this table doesn't seem to be of much help in retrieving video ratings by user. Have I missed something?

10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

smadhavan avatar image
smadhavan answered

@tecles_192911, thanks you for the feedback. Based on the schema you’ve posted above, yeah, the name is not intuitive enough as it is fetching data from that table based on “videoid” and not by “userid”. I shall check and forward that feedback.

10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Erick Ramirez avatar image
Erick Ramirez answered Erick Ramirez commented

I can see where you're coming from, but table names are arbitrary and don't have to follow a particular formula.

If we step back for a second, the table contains video ratings by users. Another way of saying it is that it contains ratings by users of videos.

As you stated, you already know that the table is partitioned by the video ID. It's interesting that you used these words: retrieving video ratings by user.

If it's not to retrieve the video ratings by a user, what else would you be retrieving from the table? For me at least, the natural query is to retrieve the rating that a user gave for a video like this:

SELECT rating FROM video_ratings_by_user WHERE videoid = ? AND userid = ?

For the record, we really appreciate the feedback. And I would be interested in hearing what name you would give the table. Cheers!

[UPDATE] I've thought about this a bit more. As much as video_ratings_by_user is a very natural name (at least to me personally), if we are being technical for the purposes of this discussion (as we are now) then I would probably concede that a more technical name like user_ratings_by_video would probably be more what you're looking for.

If I may add though, I work with lots of organisations on a daily basis and I almost always don't care about the table. In fact, I almost never care about the whole table schema. In most cases, I only ask for the PRIMARY KEY of the table because that tells me everything I need when I'm helping someone. Because as someone else pointed out, you can name a table anything you like but PRIMARY KEY is what matters. :)

3 comments Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

tecles_192911 avatar image tecles_192911 commented ·

Ok, I see what you mean and your observations have helped. Thank you.

I just pointed out the case to be sure I understood that table. It's all clear now.

Names are elusive creatures, aren't they? And, yes, we see them all, of all sorts. And once a table is created, the name is not going to change.

Right, table names need not follow a pattern; tables can have any name, but, in a data modelling practice, that is not a strong argument.

My confusion came from the emphasis data modelling was given throughout the workshop sessions and the course materials; I was led to believe it's good pratice with Cassandra to have table names reflect their organizations. I thought names like xxxx_by_something meant "xxxx organized by something". So, I got stuck with that table. Naming conventions have been in use for a long time, so, maybe it's just force of habit from my part.


0 Likes 0 ·
tecles_192911 avatar image tecles_192911 commented ·


Now, if you really would like to know my suggestion, let's go back to the table video_ratings_by_user. In the killrvideo app, if we imagine a conceptual model, a "video rating" is a relationship between user and video, or, more plainly, the result of a user rating a video. So, a name like video_ratings would be fine, but ratings_by_video or user_ratings_by_video seem even better.

Thank you for taking the time to answer. I do appreciate that.

0 Likes 0 ·
Erick Ramirez avatar image Erick Ramirez ♦♦ tecles_192911 commented ·

Not a problem. Cheers!

0 Likes 0 ·