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.3 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
  1. CREATE INDEX IF NOT EXISTS bx_rating_user_idx ON bx_ratings (user_id);
  2. CREATE INDEX IF NOT EXISTS bx_rating_isbn_idx ON bx_ratings (isbn);
  3. ANALYZE bx_ratings;
  4. INSERT INTO isbn_info (isbn, book_id)
  5. SELECT isbn, nextval('synthetic_book_id_seq') * 3
  6. FROM bx_ratings
  7. LEFT JOIN isbn_info USING (isbn)
  8. WHERE book_id IS NULL;
  9. REFRESH MATERIALIZED VIEW isbn_book_id;
  10. ANALYZE isbn_info;
  11. ANALYZE isbn_book_id;
  12. REFRESH MATERIALIZED VIEW ol_book_first_author;
  13. ANALYZE ol_book_first_author;
  14. DROP VIEW IF EXISTS bx_book_info;
  15. CREATE VIEW bx_book_info
  16. AS SELECT DISTINCT ib.book_id AS book_id, isbn, author_id, author_name, author_gender
  17. FROM bx_ratings JOIN isbn_book_id ib USING (isbn)
  18. LEFT OUTER JOIN ol_book_first_author USING (book_id)
  19. LEFT OUTER JOIN ol_author USING (author_id)
  20. LEFT OUTER JOIN author_resolution USING (author_id);
  21. DROP VIEW IF EXISTS bx_explicit_ratings;
  22. CREATE VIEW bx_explicit_ratings
  23. AS SELECT user_id, book_id, MEDIAN(rating) AS rating, COUNT(rating) AS nratings
  24. FROM bx_ratings
  25. JOIN isbn_book_id USING (isbn)
  26. WHERE rating > 0
  27. GROUP BY user_id, book_id;
  28. DROP VIEW IF EXISTS bx_all_ratings;
  29. CREATE VIEW bx_all_ratings
  30. AS SELECT user_id, book_id, MEDIAN(rating) AS rating, COUNT(rating) AS nratings
  31. FROM bx_ratings
  32. JOIN isbn_book_id USING (isbn)
  33. 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...