Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

cql_queries.py 2.5 KB

You have to be logged in to leave a comment. Sign In
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
  1. # For table song_features, the itemInSession was used as a partition key because the queries will
  2. # filter by this column. The sessionId were used as clustering column to help make up a unique key.
  3. #
  4. # For table artist_song_by_user, the userId and sessionId was used as a composite partition key
  5. # because the queries will filter by these columns. The itemInSession were used as clustering column
  6. # to help make up a unique key.
  7. #
  8. # For table user_name, the song was used as a partition key because the queries will filter by
  9. # this column. The userId were used as clustering column to help make up a unique key.
  10. # ========
  11. # Tables
  12. # ========
  13. song_features = """CREATE TABLE IF NOT EXISTS song_features (itemInSession int,
  14. sessionId int, artist text, song text,
  15. length float, PRIMARY KEY(itemInSession, sessionId) )"""
  16. artist_song_by_user = """CREATE TABLE IF NOT EXISTS artist_song_by_user (userId int, sessionId int, itemInSession int,
  17. artist text, song text, firstName text,
  18. lastName text, PRIMARY KEY ((userId, sessionId), itemInSession))"""
  19. user_name = """CREATE TABLE IF NOT EXISTS user_name (song text, userId int,
  20. firstName text, lastName text,
  21. PRIMARY KEY (song, userId))"""
  22. # =========
  23. # Inserts
  24. # =========
  25. insert_data_song_features = """INSERT INTO song_features (
  26. itemInSession, sessionId,
  27. artist, song, length) VALUES (%s, %s, %s, %s, %s)"""
  28. insert_data_artist_song_by_user = """INSERT INTO artist_song_by_user (
  29. userId, sessionId, itemInSession,
  30. artist, song, firstName, lastName)
  31. VALUES (%s, %s, %s, %s, %s, %s, %s)"""
  32. insert_data_user_name = """INSERT INTO user_name (song, userId,
  33. firstName, lastName) VALUES (%s, %s, %s, %s)"""
  34. # =========
  35. # Queries
  36. # =========
  37. query_1 = """SELECT artist, song, length
  38. FROM song_features
  39. WHERE itemInSession = %s AND sessionId = %s"""
  40. query_2 = """SELECT artist, song, firstName, lastName
  41. FROM artist_song_by_user
  42. WHERE userId = %s AND sessionId = %s"""
  43. query_3 = """SELECT firstName, lastName
  44. FROM user_name
  45. WHERE song = %s"""
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...