Last active
January 19, 2017 13:32
-
-
Save bepcyc/615b6fcd35f6ff10f14e26eb5bfcc2f6 to your computer and use it in GitHub Desktop.
When you need the partitions.. for CONCATENATE in Hive or other operations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
today = datetime.datetime.today() | |
# redefine parameters | |
days_delta = 365 | |
month_partiton = 'month' | |
day_partition = 'day' | |
date_range = [today - datetime.timedelta(days=x) for x in range(0, days_delta)] | |
# pairs of ('YYYYMM', 'DD') | |
partitions = [(str(d.year*100+d.month), str(100+d.day)[1:]) for d in date_range ] | |
for m, d in partitions: | |
print 'month={0}/day={1}'.format(m, d) | |
# print "PARTITION (month='{0}', day='{1}')".format(m, d) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment