Skip to content

Commit 8b426da

Browse files
committed
parametrize pipeline
1 parent 19c3982 commit 8b426da

File tree

3 files changed

+48
-7
lines changed

3 files changed

+48
-7
lines changed

steps/01_setup_snowflake.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ CREATE OR ALTER DATABASE QUICKSTART_COMMON;
1313
-- API integration is needed for GitHub integration
1414
CREATE OR REPLACE API INTEGRATION git_api_integration
1515
API_PROVIDER = git_https_api
16-
API_ALLOWED_PREFIXES = ('https://github.com/<insert GitHub username>') -- INSERT YOUR GITHUB USERNAME HERE
16+
API_ALLOWED_PREFIXES = ('https://github.com/PowerAtlas') -- INSERT YOUR GITHUB USERNAME HERE
1717
ENABLED = TRUE;
1818

1919

2020
-- Git repository object is similar to external stage
2121
CREATE OR REPLACE GIT REPOSITORY quickstart_common.public.quickstart_repo
2222
API_INTEGRATION = git_api_integration
23-
ORIGIN = '<insert URL of forked GitHub repo>'; -- INSERT URL OF FORKED REPO HERE
23+
ORIGIN = 'https://github.com/PowerAtlas/sfguide-getting-started-with-snowflake-devops.git'; -- INSERT URL OF FORKED REPO HERE
2424

2525

2626
CREATE OR ALTER DATABASE QUICKSTART_PROD;

steps/03_harmonize_data.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,32 @@ def main(df):
245245
)
246246
for view in pipeline:
247247
silver_schema.views.create(view, mode=CreateMode.or_replace)
248+
249+
View(
250+
name="attractions",
251+
columns=[
252+
ViewColumn(name="geo_id"),
253+
ViewColumn(name="geo_name"),
254+
ViewColumn(name="aquarium_cnt"),
255+
ViewColumn(name="zoo_cnt"),
256+
ViewColumn(name="korean_restaurant_cnt"),
257+
],
258+
query="""
259+
select
260+
city.geo_id,
261+
city.geo_name,
262+
count(case when category_main = 'Aquarium' THEN 1 END) aquarium_cnt,
263+
count(case when category_main = 'Zoo' THEN 1 END) zoo_cnt,
264+
count(case when category_main = 'Korean Restaurant' THEN 1 END) korean_restaurant_cnt,
265+
from us_addresses__poi.cybersyn.point_of_interest_index poi
266+
join us_addresses__poi.cybersyn.point_of_interest_addresses_relationships poi_add
267+
on poi_add.poi_id = poi.poi_id
268+
join us_addresses__poi.cybersyn.us_addresses address
269+
on address.address_id = poi_add.address_id
270+
join major_us_cities city on city.geo_id = address.id_city
271+
where true
272+
and category_main in ('Aquarium', 'Zoo', 'Korean Restaurant')
273+
and id_country = 'country/USA'
274+
group by city.geo_id, city.geo_name
275+
""",
276+
),

steps/04_orchestrate_jobs.sql

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ create or alter table vacation_spots (
1313
, avg_cloud_cover_pct float
1414
, precipitation_probability_pct float
1515
-- STEP 5: INSERT CHANGES HERE
16+
, aquarium_cnt int
17+
, zoo_cnt int
18+
, korean_restaurant_cnt int
1619
) data_retention_time_in_days = 1;
1720

1821

@@ -26,6 +29,7 @@ create or alter task vacation_spots_update
2629
from silver.flights_from_home flight
2730
join silver.weather_joined_with_major_cities city on city.geo_name = flight.arrival_city
2831
-- STEP 5: INSERT CHANGES HERE
32+
join silver.attractions att on att.geo_name = city.geo_name
2933
) as harmonized_vacation_spots ON vacation_spots.city = harmonized_vacation_spots.arrival_city and vacation_spots.airport = harmonized_vacation_spots.arrival_airport
3034
WHEN MATCHED THEN
3135
UPDATE SET
@@ -36,6 +40,9 @@ create or alter task vacation_spots_update
3640
, vacation_spots.avg_cloud_cover_pct = harmonized_vacation_spots.avg_cloud_cover_pct
3741
, vacation_spots.precipitation_probability_pct = harmonized_vacation_spots.precipitation_probability_pct
3842
-- STEP 5: INSERT CHANGES HERE
43+
, vacation_spots.aquarium_cnt = harmonized_vacation_spots.aquarium_cnt
44+
, vacation_spots.zoo_cnt = harmonized_vacation_spots.zoo_cnt
45+
, vacation_spots.korean_restaurant_cnt = harmonized_vacation_spots.korean_restaurant_cnt
3946
WHEN NOT MATCHED THEN
4047
INSERT VALUES (
4148
harmonized_vacation_spots.arrival_city
@@ -47,6 +54,9 @@ create or alter task vacation_spots_update
4754
, harmonized_vacation_spots.avg_cloud_cover_pct
4855
, harmonized_vacation_spots.precipitation_probability_pct
4956
-- STEP 5: INSERT CHANGES HERE
57+
, harmonized_vacation_spots.aquarium_cnt
58+
, harmonized_vacation_spots.zoo_cnt
59+
, harmonized_vacation_spots.korean_restaurant_cnt
5060
);
5161

5262

@@ -64,13 +74,15 @@ create or alter task email_notification
6474
and punctual_pct >= 50
6575
and avg_temperature_air_f >= 70
6676
-- STEP 5: INSERT CHANGES HERE
77+
and korean_restaurant_cnt > 0
78+
and (zoo_cnt > 0 or aquarium_cnt > 0)
6779
limit 10);
6880

6981

7082
if (:options = '[]') then
7183
CALL SYSTEM$SEND_EMAIL(
7284
'email_integration',
73-
'<insert your email here>', -- INSERT YOUR EMAIL HERE
85+
'[email protected]', -- INSERT YOUR EMAIL HERE
7486
'New data successfully processed: No suitable vacation spots found.',
7587
'The query did not return any results. Consider adjusting your filters.');
7688
end if;
@@ -83,14 +95,14 @@ create or alter task email_notification
8395

8496
CALL SYSTEM$SEND_EMAIL(
8597
'email_integration',
86-
'<insert your email here>', -- INSERT YOUR EMAIL HERE
98+
'[email protected]', -- INSERT YOUR EMAIL HERE
8799
'New data successfully processed: The perfect place for your summer vacation has been found.',
88100
:response);
89101
exception
90102
when EXPRESSION_ERROR then
91103
CALL SYSTEM$SEND_EMAIL(
92104
'email_integration',
93-
'<insert your email here>', -- INSERT YOUR EMAIL HERE
105+
'[email protected]', -- INSERT YOUR EMAIL HERE
94106
'New data successfully processed: Cortex LLM function inaccessible.',
95107
'It appears that the Cortex LLM functions are not available in your region');
96108
end;
@@ -105,7 +117,7 @@ alter task email_notification resume;
105117
execute task vacation_spots_update;
106118

107119

108-
/*
120+
109121
-- SQL commands to monitor the progress of tasks
110122

111123
-- Get a list of tasks
@@ -127,4 +139,4 @@ SELECT
127139
FROM TABLE(INFORMATION_SCHEMA.TASK_HISTORY())
128140
WHERE STATE = 'SCHEDULED'
129141
ORDER BY COMPLETED_TIME DESC;
130-
*/
142+

0 commit comments

Comments
 (0)