Professional Documents
Culture Documents
Snowflake Mini Project
Snowflake Mini Project
Project Activities –
1:Warehouse Creation:
Create a warehouse of name SFTRNG. Document the parameters with which the WH is created and the
reasons behind the WH options used.
Solution:
Warehouse: Warehouses are required for queries, as well as all DML operations, including loading
data into tables. A warehouse is defined by its size, as well as the other properties that can be set to
help control and automate warehouse activity.
In this picture we create a Warehouse (SFTRNG) with the help of Snowflake tool, where we
configure with different parameters like size, clusters and scalling policy.
2:Resource Monitor:
Create a Resource Monitor of name TRNG_TRACK to track the WH SFTRNG. Document the parameters
with which the Resource Monitor is created and the reasons behind the WH options used.
Solution :
Resource monitors can be used to monitor credit usage by user-managed virtual warehouses and
virtual warehouses used by cloud services. A resource monitor can suspend user-managed
warehouses based on credit usage thresholds.
3:Unloading data:
Solution:
""SNOWFLAKE_SAMPLE_DATA"SELECT * FROM
"SNOWFLAKE_SAMPLE_DATA"."TPCH_SF10"."LINEITEM"
type = 'CSV'
field_delimiter = '|'
COMPRESSION = NONE;
"SNOWFLAKE_SAMPLE_DATA"."TPCH_SF10"
file_format = my_unload_format;
remove @my_unload_stage2
--SINGLE = FALSE
MAX_FILE_SIZE=16777216;
"SNOWFLAKE_SAMPLE_DATA"
"SNOWFLAKE_SAMPLE_DATA"."TPCH_SF10"
""SNOWFLAKE_SAMPLE_DATA"."TPCH_SF10""SNOWFLAKE_SAMPLE_DATA""SNOWFLAKE_
SAMPLE_DATA"SELECT * FROM "SNOWFLAKE_SAMPLE_DATA"."TPCH_SF10"."LINEITEM"
type = 'CSV'
field_delimiter = '|-|'
COMPRESSION = NONE;
"SNOWFLAKE_SAMPLE_DATA"."TPCH_SF10"
file_format = my_unload_format;
remove @my_unload_stage
--SINGLE = FALSE
MAX_FILE_SIZE=16777216;
"SNOWFLAKE_SAMPLE_DATA"
list @my_unload_stage ------ Unloading it as .gz file ------------
4) DB Objects creation:
Solution:
L_ORDERKEY NUMBER,
L_PARTKEY NUMBER,
L_SUPPKEY NUMBER,
L_LINENUMBER NUMBER,
L_QUANTITY NUMBER,
L_EXTENDEDPRICE NUMBER,
L_DISCOUNT NUMBER,
L_TAX NUMBER,
L_RETURNFLAG VARCHAR,
L_LINESTATUS VARCHAR,
L_SHIPDATEDATE,
L_COMMITDATE DATE,
L_RECEIPTDATE DATE,
L_SHIPINSTRUCT VARCHAR,
L_SHIPMODE VARCHAR,
L_COMMENT VARCHAR);
create or replace file format LINEITEM_Local
type = 'CSV'
field_delimiter = '|'
skip_header = 1;
file_format = LINEITEM_Local;
list @my_local_stage;
from @my_local_stage/contacts1.csv
--on_error = 'SKIP_FILE'
FORCE = TRUE
PURGE = TRUE;
from @my_local_stage
--pattern='.*contacts[1-5].csv.gz'
--on_error = 'skip_file'
--on_error = 'CONTINUE'
FORCE = TRUE
VALIDATION_MODE = 'RETURN_3_ROWS';
from @my_local_stage/contacts.csv;
1) COPY/CLONE:
Solution:
2) TimeTravel:
A) Drop the table ORDERS_BKUP and note the query id.
D) Restore the data into ORDERS_BKUP using time travel and note the query id and query
Solutoin:
Performance:
Write a query to find the number of orders each customer has made and total price of the orders
From the ORDERS_BKUP table.
Note the total micro partitions being used and micro partitions being scanned.
Solution: