-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_mavenfuzzyfactory.sql
112 lines (98 loc) · 2.81 KB
/
create_mavenfuzzyfactory.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
CREATE OR REPLACE DATABASE advanced_sql_course;
CREATE OR REPLACE SCHEMA mavenfuzzyfactory;
CREATE STORAGE INTEGRATION S3_INTEGRATION
TYPE = EXTERNAL_STAGE
ENABLED = TRUE
STORAGE_ALLOWED_LOCATIONS = ('s3://<s3_bucket_name>')
STORAGE_PROVIDER = S3
STORAGE_AWS_ROLE_ARN = '<IAM_role_ARN>';
CREATE TABLE website_sessions (
website_session_id INT NOT NULL,
created_at TIMESTAMP NOT NULL,
user_id INT NOT NULL,
is_repeat_session INT NOT NULL,
utm_source VARCHAR(12),
utm_campaign VARCHAR(20),
utm_content VARCHAR(15),
device_type VARCHAR(15),
http_referer VARCHAR(30)
);
CREATE TABLE website_pageviews (
website_pageview_id INT NOT NULL,
created_at TIMESTAMP NOT NULL,
website_session_id INT NOT NULL,
pageview_url VARCHAR(50) NOT NULL
);
CREATE TABLE products (
product_id INT NOT NULL,
created_at TIMESTAMP NOT NULL,
product_name VARCHAR(50) NOT NULL
);
CREATE TABLE orders (
order_id INT NOT NULL,
created_at TIMESTAMP NOT NULL,
website_session_id INT NOT NULL,
user_id INT NOT NULL,
primary_product_id INT NOT NULL,
items_purchased INT NOT NULL,
price_usd DECIMAL(6,2) NOT NULL,
cogs_usd DECIMAL(6,2) NOT NULL
);
CREATE TABLE order_items (
order_item_id INT NOT NULL,
created_at TIMESTAMP NOT NULL,
order_id INT NOT NULL,
product_id INT NOT NULL,
is_primary_item INT NOT NULL,
price_usd DECIMAL(6,2) NOT NULL,
cogs_usd DECIMAL(6,2) NOT NULL
);
CREATE TABLE order_item_refunds (
order_item_refund_id INT NOT NULL,
created_at TIMESTAMP NOT NULL,
order_item_id INT NOT NULL,
order_id INT NOT NULL,
refund_amount_usd DECIMAL(6,2) NOT NULL
);
COPY INTO website_sessions
FROM
's3://<s3_bucket_name>/website_sessions.csv'
STORAGE_INTEGRATION = S3_INTEGRATION
FILE_FORMAT = ( TYPE = CSV FIELD_OPTIONALLY_ENCLOSED_BY = "'")
--VALIDATION_MODE = RETURN_ERRORS
;
COPY INTO website_pageviews
FROM
's3://<s3_bucket_name>/website_pageviews.csv'
STORAGE_INTEGRATION = S3_INTEGRATION
FILE_FORMAT = ( TYPE = CSV FIELD_OPTIONALLY_ENCLOSED_BY = "'")
--VALIDATION_MODE = RETURN_ERRORS
;
COPY INTO products
FROM
's3://<s3_bucket_name>/products.csv'
STORAGE_INTEGRATION = S3_INTEGRATION
FILE_FORMAT = ( TYPE = CSV FIELD_OPTIONALLY_ENCLOSED_BY = "'")
--VALIDATION_MODE = RETURN_ERRORS
;
COPY INTO orders
FROM
's3://<s3_bucket_name>/orders.csv'
STORAGE_INTEGRATION = S3_INTEGRATION
FILE_FORMAT = ( TYPE = CSV FIELD_OPTIONALLY_ENCLOSED_BY = "'")
--VALIDATION_MODE = RETURN_ERRORS
;
COPY INTO order_items
FROM
's3://<s3_bucket_name>/order_items.csv'
STORAGE_INTEGRATION = S3_INTEGRATION
FILE_FORMAT = ( TYPE = CSV FIELD_OPTIONALLY_ENCLOSED_BY = "'")
--VALIDATION_MODE = RETURN_ERRORS
;
COPY INTO order_item_refunds
FROM
's3://<s3_bucket_name>/order_item_refunds.csv'
STORAGE_INTEGRATION = S3_INTEGRATION
FILE_FORMAT = ( TYPE = CSV FIELD_OPTIONALLY_ENCLOSED_BY = "'")
--VALIDATION_MODE = RETURN_ERRORS
;