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

bx-index.sql 1.1 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
  1. --- #dep bx-ratings
  2. --- #dep cluster
  3. --- #step Index ratings
  4. CREATE INDEX IF NOT EXISTS bx_rating_user_idx ON bx.raw_ratings (user_id);
  5. CREATE INDEX IF NOT EXISTS bx_rating_isbn_idx ON bx.raw_ratings (isbn);
  6. ANALYZE bx.raw_ratings;
  7. --- #step Extract ISBNs
  8. INSERT INTO isbn_id (isbn)
  9. SELECT DISTINCT isbn
  10. FROM bx.raw_ratings WHERE isbn NOT IN (SELECT isbn FROM isbn_id);
  11. ANALYZE isbn_id;
  12. --- #step Set up rating views
  13. DROP VIEW IF EXISTS bx.rating;
  14. CREATE VIEW bx.rating
  15. AS SELECT user_id, COALESCE(cluster, bc_of_isbn(isbn_id)) AS book_id,
  16. MEDIAN(rating) AS rating, COUNT(rating) AS nratings
  17. FROM bx.raw_ratings
  18. JOIN isbn_id USING (isbn)
  19. LEFT JOIN isbn_cluster USING (isbn_id)
  20. WHERE rating > 0
  21. GROUP BY user_id, book_id;
  22. DROP VIEW IF EXISTS bx.add_action;
  23. CREATE VIEW bx.add_action
  24. AS SELECT user_id, COALESCE(cluster, bc_of_isbn(isbn_id)) AS book_id,
  25. COUNT(rating) AS nactions
  26. FROM bx.raw_ratings
  27. JOIN isbn_id USING (isbn)
  28. LEFT JOIN isbn_cluster USING (isbn_id)
  29. GROUP BY user_id, book_id;
Tip!

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

Comments

Loading...