til.duyet.net
Search…
AWS Athena - Add Partition
1
ALTER TABLE table_name ADD
2
PARTITION (dt = '2020-01-01')
3
LOCATION 's3://mystorage/path/to/2020/01/01/'
Copied!
​
Python script:
python
output
1
for year in range(2017, 2020):
2
for month in range(1, 13):
3
for day in range(1, 32):
4
print(
5
"""ADD PARTITION (date_index='{year}-{month}-{day}')
6
location "s3://data/dw/year={year}/month={month}/day={day}"
7
""".format(**{
8
'year': str(year).zfill(4),
9
'month': str(month).zfill(2),
10
'day': str(day).zfill(2)
11
}))
Copied!
1
ADD PARTITION (date_index='2019-01-01') location "s3://data/dw/year=2019/month=01/day=01"
2
ADD PARTITION (date_index='2019-01-02') location "s3://data/dw/year=2019/month=01/day=02"
3
ADD PARTITION (date_index='2019-01-03') location "s3://data/dw/year=2019/month=01/day=03"
4
ADD PARTITION (date_index='2019-01-04') location "s3://data/dw/year=2019/month=01/day=04"
5
....
Copied!
​
​
Copy link
Edit on GitHub