-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hadoop Code
334 lines (98 loc) · 5.84 KB
/
Hadoop Code
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
Uploading Files to Server
Scp instagram_locations.csv ggonza156@144.24.14.145:/home/ggonza156
Uploading to HDFS
Hdfs dfs –mkdir instagram_locations
Hdfs dfs –put instagram_locations.csv instagram_locations
Creating Tables
CREATE EXTERNAL TABLE IF NOT EXISTS instagram_locations (
sid STRING, id STRING, name STRING, street STRING, zip STRING, city STRING, region STRING, cd STRING, phone STRING, exact_city STRING, exact_country STRING, blurb STRING, city_id INT, city_name STRING, city_tag STRING, country_id STRING, country STRING, lat STRING, lng STRING, bool_flag STRING, slug STRING, website STRING, cts TIMESTAMP
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'
LOCATION '/user/ggonza156/instagram_locations'
TBLPROPERTIES ('skip.header.line.count'='1');
CREATE EXTERNAL TABLE IF NOT EXISTS instagram_profiles (
sid STRING, id STRING, profile_name STRING, firstname_lastname STRING, description STRING, insta_following INT, followers INT, n_posts INT, url STRING, cts TIMESTAMP, is_business_account STRING
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'
LOCATION '/user/ggonza156/instagram_profiles'
TBLPROPERTIES ('skip.header.line.count'='1');
CREATE EXTERNAL TABLE IF NOT EXISTS instagram_posts (
Sid INT, sid_profile STRING, post_id STRING, profile_id STRING, location_id STRING, cts TIMESTAMP, post_type INT, description STRING, number_likes INT, number_comments INT
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'
LOCATION '/user/ggonza156/instagram_posts'
TBLPROPERTIES ('skip.header.line.count'='1');
Select * from instagram_locations LIMIT 2;
Select * from instagram_locs_copy LIMIT 2;
Select * from instagram_prof_copy where insta_following != NULL;
Data Analysis
DID NOT WORK
CREATE TABLE instagram_locs_copy AS select sid, id, name, exact_city, exact_country, lat, lng from instagram_locations;
CREATE TABLE instagram_prof_copy AS select sid, id, profile_name, insta_following, followers, n_posts, cts from instagram_profiles;
SELECT c.sid, c.exact_city, c.exact_country, c.lat, c.lng, o.profile_name, o.insta_following, o.followers, o.n_posts FROM instagram_locs_copy c LEFT OUTER JOIN instagram_prof_copy o ON(c.sid=o.sid);
CREATE TABLE posts_clean AS select sid, profile_id, post_type, number_likes, number_comments from instagram_posts;
show tables;
describe instagram_profiles;
describe instagram_prof_copy
SELECT * FROM instagram_profiles ORDER BY followers LIMIT 6;
SELECT profile_name, followers, is_business_account FROM instagram_profiles ORDER BY followers LIMIT 6;
SELECT * FROM instagram_prof_copy ORDER BY followers DESC LIMIT 6;
SELECT profile_name, followers FROM instagram_prof_copy ORDER BY followers DESC LIMIT 6;
SELECT * FROM instagram_prof_copy ORDER BY insta_following DESC LIMIT 5;
SELECT profile_name, insta_following FROM instagram_prof_copy ORDER BY insta_following DESC LIMIT 5;
SELECT * FROM instagram_prof_copy ORDER BY n_posts DESC LIMIT 6;
SELECT profile_name, n_posts FROM instagram_prof_copy ORDER BY n_posts DESC LIMIT 6;
SELECT * FROM instagram_posts ORDER BY number_likes DESC LIMIT 6;
SELECT * FROM posts_clean ORDER BY number_likes DESC LIMIT 6;
SELECT profile_name, n_posts FROM instagram_prof_copy ORDER BY n_posts DESC LIMIT 6;
SELECT profile_name, n_posts FROM instagram_prof_copy ORDER BY n_posts DESC LIMIT 6;
SELECT c.sid, c.post_type, c.number_likes, c.number_comments, o.profile_name, o.insta_following, o.followers, o.n_posts
FROM posts_clean c
LEFT OUTER JOIN instagram_prof_copy o ON(c.sid=o.sid)
ORDER BY c.number_likes DESC LIMIT 6;
SELECT c.sid, c.post_type, c.number_likes, c.number_comments, o.profile_name, o.insta_following, o.followers, o.n_posts
FROM posts_clean c
LEFT OUTER JOIN instagram_prof_copy o ON(c.sid=o.sid)
ORDER BY c.number_comments DESC LIMIT 6;
DID NOT WORK
SELECT c.profile_name, c.insta_following, c.followers, c.n_posts, o.sid, o.post_type, o.number_likes
FROM instagram_prof_copy c
LEFT OUTER JOIN posts_clean o ON(c.sid=o.sid)
ORDER BY o.number_likes DESC LIMIT 6;
DID NOT WORK
SELECT c.sid, c.post_type, c.number_likes, c.number_comments, o.profile_name, o.insta_following, o.followers, o.n_posts
FROM instagram_prof_copy o
LEFT OUTER JOIN posts_clean c ON(c.sid=o.sid)
ORDER BY c.number_likes DESC LIMIT 6;
SELECT c.sid, c.post_type, c.number_likes, c.number_comments, o.profile_name
FROM posts_clean c
LEFT OUTER JOIN instagram_prof_copy o ON(c.sid=o.sid)
ORDER BY c.number_likes DESC LIMIT 6;
SELECT * FROM instagram_prof_copy WHERE sid=34909573;
SELECT profile_id, post_type, description, number_likes, number_comments
FROM instagram_posts
ORDER BY number_likes DESC LIMIT 6;
SELECT profile_id, post_type, description, number_likes, number_comments
FROM instagram_posts
ORDER BY number_comments DESC LIMIT 6;
SELECT profile_id, post_type, number_likes, number_comments
FROM instagram_posts
ORDER BY number_likes DESC LIMIT 6;
SELECT profile_id, post_type, number_likes, number_comments
FROM instagram_posts
ORDER BY number_comments DESC LIMIT 6;
SELECT c.post_id, c.profile_id, c.post_type, c.number_likes, c.number_comments, o.profile_name
FROM instagram_posts c
LEFT OUTER JOIN instagram_profiles o ON(c.sid=o.sid)
ORDER BY c.number_likes DESC LIMIT 6;
SELECT c.post_id, c.profile_id, c.post_type, c.number_likes, c.number_comments, o.profile_name
FROM instagram_posts c
LEFT OUTER JOIN instagram_profiles o ON(c.sid=o.sid)
ORDER BY c.number_comments DESC LIMIT 6;
EXPORT DATA
INSERT OVERWRITE DIRECTORY '/user/ggonza156'
ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
SELECT * FROM instagram_prof_copy;