forked from pmcfadin/killrvideo-sample-schema
-
Notifications
You must be signed in to change notification settings - Fork 1
/
killrvideo-sample-queries.cql
123 lines (102 loc) · 3.83 KB
/
killrvideo-sample-queries.cql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Sample queries for Apache Cassandra 2.1 version of schema
use killrvideo;
//User select statements
// Select all users. Will be limited to 1000 rows. Rows returned in a random order.
SELECT *
FROM users;
// Select on a specific user. Result set will contain first and last name
SELECT firstname, lastname
FROM users
WHERE userid = d0f60aa8-54a9-4840-b70c-fe562b68842b;
// Video select statements.
// Select everything from a specific video based on ID. Note the format for UUID and it is not quoted.
SELECT *
FROM videos
WHERE videoId = 06049cbb-dfed-421f-b889-5f649a0de1ed;
// Select set collection. Only the entire set can be returned.
SELECT tags
FROM videos
WHERE videoid = 06049cbb-dfed-421f-b889-5f649a0de1ed;
// Select map collection. Individual elements can be returned.
SELECT location
FROM videos
WHERE videoid = 06049cbb-dfed-421f-b889-5f649a0de1ed;
// Username->video index. With more fields in the PRIMARY KEY declaration,
// we can do a variety of interesting queries.
// Lookup video by username
SELECT name,videoID,added_date
FROM user_videos
WHERE userid = 9761d3d7-7fbd-4269-9988-6cfd4e188678;
// Lookup video but ORDER BY the upload date
SELECT name,videoID,added_date
FROM user_videos
WHERE userid = 9761d3d7-7fbd-4269-9988-6cfd4e188678
ORDER BY added_date;
// Lookup video and reverse sort upload date but ORDER BY
SELECT name,videoID,added_date
FROM user_videos
WHERE userid = 9761d3d7-7fbd-4269-9988-6cfd4e188678
ORDER BY added_date DESC;
// Lookup last video uploaded by reverse sorting upload date and limiting results;
SELECT name,videoID,added_date
FROM user_videos
WHERE userid = 9761d3d7-7fbd-4269-9988-6cfd4e188678
ORDER BY added_date DESC
LIMIT 1;
// Lookup video by username and upload date greater than June 6, 2013
SELECT name,videoID,added_date
FROM user_videos
WHERE userid = 9761d3d7-7fbd-4269-9988-6cfd4e188678
AND added_date > '2013-06-01';
// Lookup video by username and upload date between May 15, 2013 and July 1, 2013
SELECT name,videoID,added_date
FROM user_videos
WHERE userid = 9761d3d7-7fbd-4269-9988-6cfd4e188678
AND added_date > '2013-05-15'
AND added_date < '2013-07-01';
// Lookup video by username and upload date between May 15, 2013 and July 1, 2013 and order results
SELECT name,videoID,added_date
FROM user_videos
WHERE userid = 9761d3d7-7fbd-4269-9988-6cfd4e188678
AND added_date > '2013-05-15'
AND added_date < '2013-07-01'
ORDER BY added_date;
// Video rating selects
// Select counter fields. Divide rating_total by rating_counter to get average rating.
SELECT rating_counter, rating_total
FROM video_rating
WHERE videoId = 99051fe9-6a9c-46c2-b949-38ef78858dd0;
// Tag index
// Find a list of videos by tag
SELECT videoID, tagged_date
FROM videos_by_tag
WHERE tag = 'lol';
// Video comments. We have stored this many-to-many in two different fields.
// We will query on either table based on which view we want.
// From the side of comments by video
// All comments for a video
SELECT userid, comment, dateOf(commentid)
FROM comments_by_video
WHERE videoid = 99051fe9-6a9c-46c2-b949-38ef78858dd0;
// Last comment made on a video
SELECT userid, comment, dateOf(commentid)
FROM comments_by_user
WHERE userid = d0f60aa8-54a9-4840-b70c-fe562b68842b
LIMIT 1;
// From the side of comments by userid
// Specific comments for a video by one user
SELECT userid, comment, dateOf(commentid)
FROM comments_by_user
WHERE userid = d0f60aa8-54a9-4840-b70c-fe562b68842b;
// Video event. Time series
// Select all events for a particular video and user combination
SELECT dateOf(event_timestamp), event, video_timestamp
FROM video_event
WHERE videoID = 99051fe9-6a9c-46c2-b949-38ef78858dd0
AND userid= d0f60aa8-54a9-4840-b70c-fe562b68842b;
// Get the last 5 video events
SELECT dateOf(event_timestamp), event, video_timestamp
FROM video_event
WHERE videoID = 99051fe9-6a9c-46c2-b949-38ef78858dd0
AND userid= d0f60aa8-54a9-4840-b70c-fe562b68842b
limit 5;