前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >hive sql生成数仓分钟维表

hive sql生成数仓分钟维表

作者头像
chimchim
发布2022-11-28 13:05:33
4310
发布2022-11-28 13:05:33
举报

目录

一、建表ddl

二、加工格式说明

三、加工sql 

四、示例结果数据


一、建表ddl

代码语言:javascript
复制
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
;

二、加工格式说明

代码语言:javascript
复制
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 

代码语言:javascript
复制
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
;

四、示例结果数据

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-11-22,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、建表ddl
  • 二、加工格式说明
  • 三、加工sql 
  • 四、示例结果数据
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档