Skip to content

Commit ecc9e3d

Browse files
committed
partition Data and query Partitioned Table (location-temp dataset)
1 parent cb79987 commit ecc9e3d

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Advanced SQL for Data Science - Time Series/02.01.Modeling Time Series Data - Partitioning Data.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,12 @@ CREATE TABLE time_series.location_temp_p12 PARTITION OF time_series.location_tem
7979
CREATE INDEX idx_loc_temp_p12 ON time_series.location_temp_p12(event_time);
8080

8181

82+
--------- Copy original data to newly created Partitioned Table ------------
83+
INSERT INTO time_series.location_temp_p(
84+
event_time, event_hour, temp_celcius, location_id
85+
)
86+
(
87+
SELECT event_time, EXTRACT(HOUR FROM event_time), temp_celcius, location_id
88+
FROM time_series.location_temp
89+
);
90+

Advanced SQL for Data Science - Time Series/02.02.Modeling Time Series Data - Querying Partitioned Table.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ WHERE event_time BETWEEN '2019-03-05' AND '2019-03-06'
99
GROUP BY location_id;
1010

1111

12-
-- 2) partitioned version on new table: cost 166.23
12+
-- 2) partitioned version on new table: cost 37964.20
1313
EXPLAIN SELECT location_id, AVG(temp_celcius)
1414
FROM time_series.location_temp_p
1515
WHERE event_time BETWEEN '2019-03-05' AND '2019-03-06'
1616
GROUP BY location_id;
1717

18-
-- 3) partitioned version on new table using event hour: cost 78.52
18+
-- 3) partitioned version on new table using event hour: cost 14,449.74
1919
EXPLAIN SELECT location_id, AVG(temp_celcius)
2020
FROM time_series.location_temp_p
2121
WHERE event_hour BETWEEN 0 AND 4

0 commit comments

Comments
 (0)