-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHiveQL Codes.sql
73 lines (48 loc) · 1.55 KB
/
HiveQL Codes.sql
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
--HiveQL codes
--Table for Objective 1,3,4
CREATE TABLE IF NOT EXISTS ratings1 (movieid int,rating int, title string, budget float)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n';
LOAD DATA LOCAL INPATH '/home/hadoop/Assignment/ratings.csv' INTO TABLE ratings1;
--OBJECTIVE 1
SELECT movieid, CAST(budget as decimal(11,2)), AVG(rating) as avgrating
FROM ratings1
GROUP by movieid, budget
ORDER BY budget DESC limit 20;
--OBJECTIVE 2
--2017
CREATE TABLE IF NOT EXISTS ratings2_1 (movieid int,rating int)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n';
LOAD DATA LOCAL INPATH'/home/hadoop/Assignment/obj1.csv' INTO TABLE ratings2_1;
SELECT rating, COUNT(rating)
FROM ratings2_1
GROUP BY rating
ORDER BY rating DESC;
--2019
CREATE TABLE IF NOT EXISTS ratings2_2 (movieid int,rating int)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n';
LOAD DATA LOCAL INPATH'/home/hadoop/Assignment/obj2.csv' INTO TABLE ratings2_2;
SELECT rating, COUNT(rating)
FROM ratings2_2
GROUP BY rating
ORDER BY rating DESC;
--OBJECTIVE 3
--Average ratings a movie has in descending order (Top 10)
SELECT title, AVG(rating) AS ratingavg
FROM ratings1
GROUP BY title
ORDER BY ratingavg DESC limit 10;
--Average ratings a movie has in no order and no limit
SELECT title, AVG(rating) AS ratingavg
FROM ratings1
GROUP BY title;
--OBJECTIVE 4
SELECT title, COUNT(rating) AS ratingcount
FROM ratings1
GROUP BY title
ORDER BY ratingcount DESC limit 20;