-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SQL deployment scripts for Snowflake object hierarchy
- Loading branch information
1 parent
73e1bb9
commit 902ea04
Showing
10 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
The current maximum allowed execution depth of EXECUTE IMMEDIATE FROM | ||
statements is 5. Unfortunately, that makes a call stack which looks like: | ||
depth | ||
0 deploy.sql => | ||
1 databases/deploy.sql => | ||
2 databases/recover/deploy.sql => | ||
3 databases/recover/schemas/deploy.sql => | ||
4 databases/recover/schemas/parquet/deploy.sql => | ||
5 databases/recover/schemas/parquet/tables/deploy.sql => | ||
6 databases/recover/schemas/parquet/tables/enrolled_participants.sql | ||
not possible. To circumvent this issue, we omit the highest level of | ||
abstraction (databases/deploy.sql) and instead EXECUTE IMMEDIATE FROM | ||
database deployments individually in the primary deployment script (deploy.sql) | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
Create a recover database (if it doesn't yet exist) for an environment and | ||
deploy all child objects. | ||
*/ | ||
CREATE DATABASE IF NOT EXISTS recover_{{ environment }}; | ||
USE DATABASE recover_{{ environment }}; | ||
|
||
EXECUTE IMMEDIATE | ||
FROM './schemas/deploy.sql' | ||
USING (environment => '{{ environment }}'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* | ||
Deploy schemas and their child objects. | ||
*/ | ||
EXECUTE IMMEDIATE | ||
FROM './parquet/deploy.sql' | ||
USING (environment => '{{ environment }}'); |
26 changes: 26 additions & 0 deletions
26
snowflake/objects/databases/recover/schemas/parquet/deploy.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
Create a parquet schema (if it doesn't yet exist) and deploy all child objects. | ||
*/ | ||
CREATE SCHEMA IF NOT EXISTS parquet; | ||
USE SCHEMA parquet; | ||
|
||
SET parquet_file_format_name = 'parquet_format'; | ||
SET parquet_stage_name = 'parquet_s3'; | ||
|
||
EXECUTE IMMEDIATE | ||
FROM './file_format/deploy.sql' | ||
USING ( | ||
parquet_file_format_name => $parquet_file_format_name | ||
); | ||
EXECUTE IMMEDIATE | ||
FROM './stages/deploy.sql' | ||
USING ( | ||
environment => '{{ environment }}', | ||
parquet_stage_name => $parquet_stage_name | ||
); | ||
EXECUTE IMMEDIATE | ||
FROM './tables/deploy.sql' | ||
USING ( | ||
parquet_file_format_name => $parquet_file_format_name, | ||
parquet_stage_name => $parquet_stage_name | ||
); |
8 changes: 8 additions & 0 deletions
8
snowflake/objects/databases/recover/schemas/parquet/file_format/deploy.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
Deploy all file formats | ||
*/ | ||
EXECUTE IMMEDIATE | ||
FROM './parquet_format.sql' | ||
USING ( | ||
parquet_file_format_name => '{{ parquet_file_format_name }}' | ||
); |
7 changes: 7 additions & 0 deletions
7
snowflake/objects/databases/recover/schemas/parquet/file_format/parquet_format.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
Create the Parquet file format | ||
*/ | ||
CREATE OR REPLACE FILE FORMAT {{ parquet_file_format_name }} | ||
TYPE = PARQUET | ||
COMPRESSION = AUTO | ||
USE_VECTORIZED_SCANNER = TRUE; |
9 changes: 9 additions & 0 deletions
9
snowflake/objects/databases/recover/schemas/parquet/stages/deploy.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
Deploy all stages under the `parquet` schema. | ||
*/ | ||
EXECUTE IMMEDIATE | ||
FROM './parquet_s3.sql' | ||
USING ( | ||
environment => '{{ environment }}', | ||
parquet_stage_name => '{{ parquet_stage_name }}' | ||
); |
6 changes: 6 additions & 0 deletions
6
snowflake/objects/databases/recover/schemas/parquet/stages/parquet_s3.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* | ||
Create an external stage over the Parquet data in S3 | ||
*/ | ||
CREATE OR REPLACE STAGE parquet_s3 | ||
URL = 's3://recover-processed-data/{{ environment }}/parquet/' | ||
STORAGE_INTEGRATION = recover_prod_s3; |
14 changes: 14 additions & 0 deletions
14
snowflake/objects/databases/recover/schemas/parquet/tables/deploy.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
CREATE OR ALTER all tables | ||
*/ | ||
CREATE OR ALTER TABLE enrolledparticipants | ||
USING TEMPLATE ( | ||
SELECT ARRAY_AGG(OBJECT_CONSTRUCT(*)) | ||
WITHIN GROUP(ORDER BY order_id) | ||
FROM TABLE( | ||
INFER_SCHEMA( | ||
LOCATION => '@{{ parquet_stage_name }}/dataset_enrolledparticipants', | ||
FILE_FORMAT => '{{ parquet_file_format_name }}' | ||
) | ||
) | ||
); |
2 changes: 1 addition & 1 deletion
2
snowflake/objects/databases/recover/schemas/parquet/tables/enrolled_participants.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters