使用hive制作一张日历表
生活随笔
收集整理的這篇文章主要介紹了
使用hive制作一张日历表
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
如何做一張能支持標注中國節假日的日歷表呢,話不多說見Code~
with festival as (select f.`date` as festival_date,f.name as festival_name,if(f.not_work == 'yes', True, False) as not_workfrom (select array(named_struct('date', '2019-01-01', 'name', '元旦', 'not_work', 'yes'),named_struct('date', '2019-02-02', 'name', '元旦', 'not_work', 'no'),named_struct('date', '2019-02-03', 'name', '春節', 'not_work', 'no'),named_struct('date', '2019-02-04', 'name', '春節', 'not_work', 'yes'),named_struct('date', '2019-02-05', 'name', '春節', 'not_work', 'yes'),named_struct('date', '2019-02-06', 'name', '春節', 'not_work', 'yes'),named_struct('date', '2019-02-07', 'name', '春節', 'not_work', 'yes'),named_struct('date', '2019-02-08', 'name', '春節', 'not_work', 'yes'),named_struct('date', '2019-02-09', 'name', '春節', 'not_work', 'yes'),named_struct('date', '2019-02-10', 'name', '春節', 'not_work', 'yes'),named_struct('date', '2019-04-05', 'name', '清明節', 'not_work', 'yes'),named_struct('date', '2019-04-06', 'name', '清明節', 'not_work', 'yes'),named_struct('date', '2019-04-07', 'name', '清明節', 'not_work', 'yes'),named_struct('date', '2019-04-27', 'name', '勞動節', 'not_work', 'no'),named_struct('date', '2019-04-28', 'name', '勞動節', 'not_work', 'no'),named_struct('date', '2019-04-29', 'name', '勞動節', 'not_work', 'yes'),named_struct('date', '2019-04-30', 'name', '勞動節', 'not_work', 'yes'),named_struct('date', '2019-05-01', 'name', '勞動節', 'not_work', 'yes'),named_struct('date', '2019-06-07', 'name', '端午節', 'not_work', 'yes'),named_struct('date', '2019-06-08', 'name', '端午節', 'not_work', 'yes'),named_struct('date', '2019-06-09', 'name', '端午節', 'not_work', 'yes'),named_struct('date', '2019-09-13', 'name', '中秋節', 'not_work', 'yes'),named_struct('date', '2019-09-14', 'name', '中秋節', 'not_work', 'yes'),named_struct('date', '2019-09-15', 'name', '中秋節', 'not_work', 'yes'),named_struct('date', '2019-09-29', 'name', '國慶節', 'not_work', 'no'),named_struct('date', '2019-10-01', 'name', '國慶節', 'not_work', 'yes'),named_struct('date', '2019-10-02', 'name', '國慶節', 'not_work', 'yes'),named_struct('date', '2019-10-03', 'name', '國慶節', 'not_work', 'yes'),named_struct('date', '2019-10-04', 'name', '國慶節', 'not_work', 'yes'),named_struct('date', '2019-10-05', 'name', '國慶節', 'not_work', 'yes'),named_struct('date', '2019-10-06', 'name', '國慶節', 'not_work', 'yes'),named_struct('date', '2019-10-07', 'name', '國慶節', 'not_work', 'yes'),named_struct('date', '2019-10-12', 'name', '國慶節', 'not_work', 'no')) as arr)alateral view explode(arr) t as f ) select`date`,month,quarter,year,day,day_of_week,date_format(`date`, 'EEE') as day_of_week_s, date_format(`date`, 'D') as day_of_year, datediff(`date`, "1970-01-01") as day_of_epoch,date_format(`date`, 'W') as week_of_month, date_format(`date`, 'w') as week_of_year, date_add(`date`, 1 - cast(day_of_week as int)) as week_start_date,date_add(`date`, 7 - cast(day_of_week as int)) as week_end_date,datediff(concat(next_month_str, '-01'), concat(month_str, '-01')) as month_size,date_add(concat(next_month_str, '-01'), -1) as month_end_date,date_add(concat(month_str, '-01'), -1) as last_month_end_date,if(day_of_week in ('6','7'), true, false) as is_weekend,if(f.festival_date is not null and f.not_work, true, false) as is_festival_holiday,if(f.festival_date is not null and f.not_work = false, true, false) as is_festival_workday from (select `date`,day(`date`) as day,date_format(`date`, 'u') as day_of_week,month(`date`) as month,cast(month(`date`)/4 + 1 AS BIGINT) as quarter,year(`date`) as year,substr(`date`, 0, 7) as month_str,substr(date_add(concat(substr(`date`,0,8), '01'), 40), 0, 7) as next_month_strfrom (SELECT date_add('2019-01-01', t.pos) as `date`from(select posexplode(split(repeat(',', 365), ','))) t)aa )a left join festival as f on a.`date` = f.festival_date SORT BY date總結
以上是生活随笔為你收集整理的使用hive制作一张日历表的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 比天空还远的季节
- 下一篇: android的多渠道打包,Androi