-
Notifications
You must be signed in to change notification settings - Fork 62
/
init_s3_sources.sql
111 lines (107 loc) · 4.47 KB
/
init_s3_sources.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
{% macro init_s3_sources() -%}
{% set sources = [
'DROP TABLE IF EXISTS src_customer'
, 'CREATE TABLE IF NOT EXISTS src_customer
(
C_CUSTKEY UInt32,
C_NAME String,
C_ADDRESS String,
C_NATIONKEY UInt32,
C_PHONE String,
C_ACCTBAL Decimal(15,2),
C_MKTSEGMENT LowCardinality(String),
C_COMMENT String
)
ENGINE = S3(\'https://storage.yandexcloud.net/otus-dwh/tpch-dbgen-1g/customer.tbl\', \'CustomSeparated\')
SETTINGS
format_custom_field_delimiter=\'|\'
,format_custom_escaping_rule=\'CSV\'
,format_custom_row_after_delimiter=\'|\n\'
'
, 'DROP TABLE IF EXISTS src_orders'
, 'CREATE TABLE src_orders
(
O_ORDERKEY UInt32,
O_CUSTKEY UInt32,
O_ORDERSTATUS LowCardinality(String),
O_TOTALPRICE Decimal(15,2),
O_ORDERDATE Date,
O_ORDERPRIORITY LowCardinality(String),
O_CLERK String,
O_SHIPPRIORITY UInt8,
O_COMMENT String
)
ENGINE = S3(\'https://storage.yandexcloud.net/otus-dwh/tpch-dbgen-1g/orders.tbl\', \'CustomSeparated\')
SETTINGS
format_custom_field_delimiter=\'|\'
,format_custom_escaping_rule=\'CSV\'
,format_custom_row_after_delimiter=\'|\n\'
'
, 'DROP TABLE IF EXISTS src_lineitem'
, 'CREATE TABLE src_lineitem
(
L_ORDERKEY UInt32,
L_PARTKEY UInt32,
L_SUPPKEY UInt32,
L_LINENUMBER UInt8,
L_QUANTITY Decimal(15,2),
L_EXTENDEDPRICE Decimal(15,2),
L_DISCOUNT Decimal(15,2),
L_TAX Decimal(15,2),
L_RETURNFLAG LowCardinality(String),
L_LINESTATUS LowCardinality(String),
L_SHIPDATE Date,
L_COMMITDATE Date,
L_RECEIPTDATE Date,
L_SHIPINSTRUCT String,
L_SHIPMODE LowCardinality(String),
L_COMMENT String
)
ENGINE = S3(\'https://storage.yandexcloud.net/otus-dwh/tpch-dbgen-1g/lineitem.tbl\', \'CustomSeparated\')
SETTINGS
format_custom_field_delimiter=\'|\'
,format_custom_escaping_rule=\'CSV\'
,format_custom_row_after_delimiter=\'|\n\'
'
, 'DROP TABLE IF EXISTS src_part'
, 'CREATE TABLE src_part
(
P_PARTKEY UInt32,
P_NAME String,
P_MFGR LowCardinality(String),
P_BRAND LowCardinality(String),
P_TYPE LowCardinality(String),
P_SIZE UInt8,
P_CONTAINER LowCardinality(String),
P_RETAILPRICE Decimal(15,2),
P_COMMENT String
)
ENGINE = S3(\'https://storage.yandexcloud.net/otus-dwh/tpch-dbgen-1g/part.tbl\', \'CustomSeparated\')
SETTINGS
format_custom_field_delimiter=\'|\'
,format_custom_escaping_rule=\'CSV\'
,format_custom_row_after_delimiter=\'|\n\'
'
, 'DROP TABLE IF EXISTS src_supplier'
, 'CREATE TABLE src_supplier
(
S_SUPPKEY UInt32,
S_NAME String,
S_ADDRESS String,
S_NATIONKEY UInt32,
S_PHONE String,
S_ACCTBAL Decimal(15,2),
S_COMMENT String
)
ENGINE = S3(\'https://storage.yandexcloud.net/otus-dwh/tpch-dbgen-1g/supplier.tbl\', \'CustomSeparated\')
SETTINGS
format_custom_field_delimiter=\'|\'
,format_custom_escaping_rule=\'CSV\'
,format_custom_row_after_delimiter=\'|\n\'
'
] %}
{% for src in sources %}
{% set statement = run_query(src) %}
{% endfor %}
{{ print('Initialized source tables – TPCH (S3)') }}
{%- endmacro %}