Skip to content

Commit 1b08b8d

Browse files
committed
airflow_data_pipeline plugin helpers
1 parent 3dfddef commit 1b08b8d

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from helpers.sql_queries import SQLQueries
2+
3+
__all__ = [
4+
"SqlQueries",
5+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
class SQLQueries:
2+
songplay_table_insert = ("""
3+
INSERT INTO songplays (playid, start_time, userid, songid, artistid,
4+
sessionid, location, user_agent)
5+
SELECT
6+
md5(events.sessionid || events.start_time) songplayid,
7+
events.start_time,
8+
events.userid,
9+
events.level,
10+
songs.song_id,
11+
songs.artist_id,
12+
events.sessionid,
13+
events.location,
14+
events.useragent
15+
FROM (SELECT TIMESTAMP 'epoch' + ts/100 * interval '1 second' AS start_time, *
16+
FROM staging_events
17+
WHERE page="NextSong') events
18+
LEFT JOIN staging_songs songs
19+
ON events.song = songs.title
20+
AND events.artist = songs.artist_name
21+
AND events.length = songs.duration
22+
""")
23+
24+
user_table_insert = ("""
25+
INSERT INTO users (userid, first_name, last_name, gender, level)
26+
SELECT distinct userid, firstname, lastname, gender, level
27+
FROM staging_events
28+
WHERE page = 'NextSong')
29+
""")
30+
31+
sort_table_insert = ("""
32+
INSERT INTO songs (songid, title, artistid, year, duration)
33+
SELECT distinct song_id, title, artist_id, year, duration
34+
FROM staging_songs
35+
""")
36+
37+
artist_table_insert = ("""
38+
INSERT INTO artists (artistid, name, location, latitude, longitude)
39+
SELECT distinct artist_id, artist_name, artist_location,
40+
artist_latitude, artist_longitude
41+
FROM staging_songs
42+
""")
43+
44+
time_table_insert = ("""
45+
INSERT INTO time (start_time, hour, day, week, month, year, dayofweek)
46+
SELECT start_time, extract(hour from start_time),
47+
extract(day from start_time), extract(wek from start_time),
48+
extract(dayofweek from start_time)
49+
FROM songplays
50+
""")

0 commit comments

Comments
 (0)