hive sql生成数仓分钟维表
Posted chimchim66
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hive sql生成数仓分钟维表相关的知识,希望对你有一定的参考价值。
目录
一、建表ddl
create table dim_pub_minute(
date_timestamp bigint comment '时间戳',
date_str string comment '时间-日期时分秒',
day_str string comment '日期',
time_str string comment '时分秒',
hour_str string comment '小时',
minute_str string comment '分钟'
) comment '分钟维表'
row format delimited fields terminated by '\\t'
stored as textfile
;
二、加工格式说明
select
from_unixtime(unix_timestamp('开始日期-时分秒') + a.pos*60) as date_str
from(
select posexplode(split(repeat("o", cast((UNIX_TIMESTAMP('结束日期-时分秒')-UNIX_TIMESTAMP('开始日期-时分秒'))/60 as int)), "o"))
) a
;
三、加工sql
with dim_pub_minute as (
select
unix_timestamp('2022-11-21 00:01:00') + a.pos*60 as date_timestamp
,from_unixtime(unix_timestamp('2022-11-21 00:01:00') + a.pos*60) as date_str
from (select posexplode(split(repeat("o", cast((unix_timestamp('2022-11-21 00:10:00')-unix_timestamp('2022-11-21 00:01:00'))/60 as int)), "o"))) a
)
insert overwrite table dim_pub_minute
select
date_timestamp
,date_str
,substr(date_str,1,10) as day_str
,substr(date_str,12) as time_str
,substr(date_str,12,2) as hour_str
,substr(date_str,15,2) as minute_str
from dim_pub_minute
;
四、示例结果数据
以上是关于hive sql生成数仓分钟维表的主要内容,如果未能解决你的问题,请参考以下文章