forked from OvertureMaps/data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
athena_setup_queries.sql
239 lines (209 loc) · 8.24 KB
/
athena_setup_queries.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
------------------------------------------------------------------------
-- Set up the Overture Maps data tables in Amazon Athena on AWS
------------------------------------------------------------------------
-- The below Athena SQL queries will create tables in your AWS account's
-- data catalog pointing directly to data hosted on Overture's S3
-- bucket. You can then query Overture data directly from Athena without
-- needing to copy it.
--
-- 💡 TIP: Athena only allows one SQL statement to be run at a time, so
-- highlight and run each SQL query separately.
-- 💡 TIP: Overture's S3 bucket is located in the us-west-2 AWS region,
-- so use Athena in us-west-2 for best performance.
------------------------------------------------------------------------
-- Themes distributed since the October 2023 release are described using
-- compatible schemas and may be viewed as part of a unified table,
-- partitioned by `theme` and `type`.
CREATE EXTERNAL TABLE `overture` (
`id` string,
`geometry` binary,
`bbox` struct<minx:double,maxx:double,miny:double,maxy:double>,
`subtype` string,
`locality_type` string,
`names` struct<primary:string,common:map<string,string>,rules:array<struct<variant:string,language:string,value:string,at:array<double>,side:string>>>,
`context_id` string,
`admin_level` int,
`iso_country_code_alpha_2` string,
`iso_sub_country_code` string,
`default_language` string,
`driving_side` string,
`version` int,
`update_time` string,
`sources` array<struct<property:string,dataset:string,record_id:string,confidence:double>>,
`is_maritime` boolean,
`geopol_display` string,
`locality_id` string,
`class` string,
`source_tags` map<string,string>,
`wikidata` string,
`surface` string,
`elevation` int,
`is_salt` boolean,
`is_intermittent` boolean,
`has_parts` boolean,
`height` double,
`num_floors` int,
`facade_color` string,
`facade_material` string,
`roof_material` string,
`roof_shape` string,
`roof_direction` double,
`roof_orientation` string,
`roof_color` string,
`eave_height` double,
`level` int,
`min_height` double,
`building_id` string,
`categories` struct<main:string,alternate:array<string>>,
`confidence` double,
`websites` array<string>,
`socials` array<string>,
`emails` array<string>,
`phones` array<string>,
`brand` struct<names:struct<common:array<struct<value:string,language:string>>,official:array<struct<value:string,language:string>>,alternate:array<struct<value:string,language:string>>,short:array<struct<value:string,language:string>>>,wikidata:string>,
`addresses` array<struct<freeform:string,locality:string,postcode:string,region:string,country:string>>,
`connectors` array<string>,
`road` string)
PARTITIONED BY (
`theme` string,
`type` string)
STORED AS PARQUET
LOCATION
's3://overturemaps-us-west-2/release/<release-version>/'
-- Load partitions
MSCK REPAIR TABLE `overture`;
-- =====================================================================
-- The below queries are for the July 2023 Data Release
-- Admins theme
-- =====================================================================
CREATE EXTERNAL TABLE `admins`(
`id` string,
`geometry` binary,
`bbox` struct<minx:double,maxx:double,miny:double,maxy:double>,
`subtype` string,
`localitytype` string,
`names` struct<common:array<struct<value:string,language:string>>,official:array<struct<value:string,language:string>>,alternate:array<struct<value:string,language:string>>,short:array<struct<value:string,language:string>>>,
`contextid` string,
`adminlevel` int,
`isocountrycodealpha2` string,
`isosubcountrycode` string,
`defaultlanguage` string,
`drivingside` string,
`version` int,
`updatetime` string,
`sources` array<struct<property:string,dataset:string,recordId:string,confidence:double>>,
`ismaritime` boolean,
`geopoldisplay` string,
`localityid` string)
PARTITIONED BY (
`type` string)
STORED AS PARQUET
LOCATION
's3://overturemaps-us-west-2/release/<release-version>/theme=admins'
-- Load partitions
MSCK REPAIR TABLE `admins`
-- =====================================================================
-- Base theme
-- =====================================================================
CREATE EXTERNAL TABLE `base`(
`id` string,
`geometry` binary,
`bbox` struct<minx:double,maxx:double,miny:double,maxy:double>,
`subtype` string,
`names` struct<common:array<struct<value:string,language:string>>,official:array<struct<value:string,language:string>>,alternate:array<struct<value:string,language:string>>,short:array<struct<value:string,language:string>>>,
`version` int,
`updatetime` string,
`sources` array<struct<property:string,dataset:string,recordId:string,confidence:double>>,
`class` string,
`sourcetags` map<string,string>,
`wikidata` string,
`surface` string,
`issalt` boolean,
`isintermittent` boolean)
PARTITIONED BY (
`type` string)
STORED AS PARQUET
LOCATION
's3://overturemaps-us-west-2/release/<release-version>/theme=base'
-- Load partitions
MSCK REPAIR TABLE `base`
-- =====================================================================
-- Buildings theme
-- =====================================================================
CREATE EXTERNAL TABLE `buildings`(
`id` string,
`geometry` binary,
`bbox` struct<minx:double,maxx:double,miny:double,maxy:double>,
`names` struct<common:array<struct<value:string,language:string>>,official:array<struct<value:string,language:string>>,alternate:array<struct<value:string,language:string>>,short:array<struct<value:string,language:string>>>,
`version` int,
`updatetime` string,
`sources` array<struct<property:string,dataset:string,recordId:string,confidence:double>>,
`class` string,
`hasparts` boolean,
`height` double,
`numfloors` int,
`facadecolor` string,
`facadematerial` string,
`roofmaterial` string,
`roofshape` string,
`roofdirection` double,
`rooforientation` string,
`roofcolor` string,
`eaveheight` double,
`level` int,
`minheight` double,
`buildingid` string)
PARTITIONED BY (
`type` string)
STORED AS PARQUET
LOCATION
's3://overturemaps-us-west-2/release/<release-version>/theme=buildings'
-- Load partitions
MSCK REPAIR TABLE `buildings`
-- =====================================================================
-- Places theme
-- =====================================================================
CREATE EXTERNAL TABLE `places`(
`id` string,
`geometry` binary,
`bbox` struct<minx:double,maxx:double,miny:double,maxy:double>,
`names` struct<common:array<struct<value:string,language:string>>,official:array<struct<value:string,language:string>>,alternate:array<struct<value:string,language:string>>,short:array<struct<value:string,language:string>>>,
`version` int,
`updatetime` string,
`sources` array<struct<property:string,dataset:string,recordId:string,confidence:double>>,
`categories` struct<main:string,alternate:array<string>>,
`confidence` double,
`websites` array<string>,
`socials` array<string>,
`emails` array<string>,
`phones` array<string>,
`brand` struct<names:struct<common:array<struct<value:string,language:string>>,official:array<struct<value:string,language:string>>,alternate:array<struct<value:string,language:string>>,short:array<struct<value:string,language:string>>>,wikidata:string>,
`addresses` array<struct<freeform:string,locality:string,postcode:string,region:string,country:string>>)
PARTITIONED BY (
`type` string)
STORED AS PARQUET
LOCATION
's3://overturemaps-us-west-2/release/<release-version>/theme=places'
-- Load partitions
MSCK REPAIR TABLE `places`
-- =====================================================================
-- Transportation theme
-- =====================================================================
CREATE EXTERNAL TABLE `transportation`(
`id` string,
`geometry` binary,
`bbox` struct<minx:double,maxx:double,miny:double,maxy:double>,
`subtype` string,
`version` int,
`updatetime` string,
`sources` array<struct<property:string,dataset:string,recordId:string,confidence:double>>,
`level` int,
`connectors` array<string>,
`road` string)
PARTITIONED BY (
`type` string)
STORED AS PARQUET
LOCATION
's3://overturemaps-us-west-2/release/<release-version>/theme=transportation'
-- Load partitions
MSCK REPAIR TABLE `transportation`