Solution for Hive:
set hivevar:start_date=2010-01-01; --replace with your start_date
set hivevar:end_date=current_date; --replace with your end_date
with date_range as
(--this query generates date range
select date_add ('${hivevar:start_date}',s.i) as dt
from ( select posexplode(split(space(datediff(${hivevar:end_date},'${hivevar:start_date}')),' ')) as (i,x) ) s
),
holiday as (
select stack(5, --add more
'01-01', 'New Year',
'01-21', 'Martin Luther King Day',
'02-18', 'Presidents Day',
'05-27', 'Memorial Day',
'07-04', 'Independence Day'
) as ( mtdt,holiday_name)
)
select d.dt as date,
date_format(current_date,'u') as dayofweek,
day(dt) as dayofmonth,
date_format(current_date,'D') as dayofyear,
date_format(current_date,'W') as weekofmonth,
weekofyear(dt) as weekofyear,
case when h.mtdt is not null then 'Y' else 'N' end as Holiday,
h.holiday_name
from date_range d
left join holiday h on substr(d.dt,6)= h.mtdt
;
Add more holidays.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…