一、目的
經(jīng)過6個(gè)月的奮斗,項(xiàng)目的離線數(shù)倉部分終于可以上線了,因此整理一下離線數(shù)倉的整個(gè)流程,既是大家提供一個(gè)案例經(jīng)驗(yàn),也是對(duì)自己近半年的工作進(jìn)行一個(gè)總結(jié)。
二、數(shù)倉實(shí)施步驟
(五)步驟五、在Hive的DWS層建動(dòng)態(tài)分區(qū)表并動(dòng)態(tài)加載數(shù)據(jù)
1、Hive的DWS層建庫建表語句
--如果不存在則創(chuàng)建hurys_dc_dws數(shù)據(jù)庫
create database if not exists hurys_dc_dws;
--使用hurys_dc_dws數(shù)據(jù)庫
use hurys_dc_dws;
--1.1、轉(zhuǎn)向比數(shù)據(jù)內(nèi)部表——?jiǎng)討B(tài)分區(qū)——轉(zhuǎn)向流量——5分鐘周期 ?dws_turnratio_volume_5min
create ?table ?if not exists dws_turnratio_volume_5min(
? ? device_no ? ? ? string ? ? ? comment '設(shè)備編號(hào)',
? ? create_time ? ? timestamp ? ?comment '創(chuàng)建時(shí)間',
? ? start_time ? ? ?timestamp ? ?comment '開始時(shí)間',
? ? name ? ? ? ? ? ?string ? ? ? comment '場景',
? ? direction ? ? ? string ? ? ? comment '雷達(dá)朝向',
? ? volume_sum ? ? ?int ? ? ? ? ?comment '指定時(shí)間段內(nèi)通過路口的車輛總數(shù)',
? ? volume_left ? ? int ? ? ? ? ?comment '指定時(shí)間段內(nèi)通過路口的左轉(zhuǎn)車輛總數(shù)',
? ? volume_straight int ? ? ? ? ?comment '指定時(shí)間段內(nèi)通過路口的直行車輛總數(shù)',
? ? volume_right ? ?int ? ? ? ? ?comment '指定時(shí)間段內(nèi)通過路口的右轉(zhuǎn)車輛總數(shù)',
? ? volume_turn ? ? int ? ? ? ? ?comment '指定時(shí)間段內(nèi)通過路口的掉頭車輛總數(shù)'
)
comment '轉(zhuǎn)向比數(shù)據(jù)表——?jiǎng)討B(tài)分區(qū)——5分鐘周期'
partitioned by (day string) ? --分區(qū)字段不能是表中已經(jīng)存在的數(shù)據(jù),可以將分區(qū)字段看作表的偽列。
stored as orc ? ? ? ? ? ? ? ?--表存儲(chǔ)數(shù)據(jù)格式為orc
;
2、海豚執(zhí)行DWS層建表語句工作流
對(duì)于剛部署的服務(wù)器,由于Hive沒有建庫建表、而且手動(dòng)建表效率低,因此通過海豚調(diào)度器直接執(zhí)行建庫建表的.sql文件
(1)海豚的資源中心加建庫建表的SQL文件
(2)海豚配置DWS層建表語句的工作流(不需要定時(shí),一次就行)
3、海豚配置DWS層每日動(dòng)態(tài)加載數(shù)據(jù)的工作流(指定分區(qū)名)
(1)海豚配置DWS層每日動(dòng)態(tài)加載數(shù)據(jù)的工作流(需要定時(shí),每日一次)
#! /bin/bash
source /etc/profile
nowdate=`date --date='0 days ago' "+%Y%m%d"`
yesdate=`date -d yesterday +%Y-%m-%d`
hive -e "
use hurys_dc_dws;
set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;
set hive.exec.max.dynamic.partitions.pernode=1000;
set hive.exec.max.dynamic.partitions=1500;
insert ?overwrite ?table ?dws_evaluation_1hour ?partition(day='$yesdate')
select
? ? ? ?dwd_ev.device_no,
? ? ? ?lane_no,
? ? ? ?cycle,
? ? ? ?create_time,
? ? ? ?concat(substr(create_time, 1, 14), '00:00') start_time,
? ? ? ?dwd_te.name,
? ? ? ?dwd_rc.direction,
? ? ? ?dwd_rl.lane_direction,
? ? ? ?dwd_ev.volume,
? ? ? ?queue_len_max,
? ? ? ?sample_num,
? ? ? ?stop_avg,
? ? ? ?delay_avg,
? ? ? ?stop_rate,
? ? ? ?travel_dist,
? ? ? ?travel_time_avg
from hurys_dc_dwd.dwd_evaluation as dwd_ev
? ? right join hurys_dc_dwd.dwd_radar_lane as dwd_rl
? ? ? ? ? ? ? on dwd_rl.device_no=dwd_ev.device_no and dwd_rl.lane_num=dwd_ev.lane_no
? ? right join hurys_dc_dwd.dwd_device_team as dwd_dt
? ? ? ? ? ? ? on dwd_dt.device_no=dwd_ev.device_no
? ? right join hurys_dc_dwd.dwd_team as dwd_te
? ? ? ? ? ? ? on dwd_te.id = dwd_dt.team_id
? ? right join hurys_dc_dwd.dwd_radar_config as dwd_rc
? ? ? ? ? ? ?on dwd_rc.device_no=dwd_ev.device_no
where dwd_ev.create_time is not null ?and day= '$yesdate'
group by dwd_ev.device_no, lane_no, cycle, create_time, dwd_te.name, dwd_rc.direction, dwd_rl.lane_direction, dwd_ev.volume, queue_len_max, sample_num, stop_avg, delay_avg, stop_rate, travel_dist, travel_time_avg
"
(2)工作流定時(shí)任務(wù)設(shè)置(注意與其他工作流的時(shí)間間隔)
文章來源:http://www.zghlxwxcb.cn/news/detail-731252.html
(3)注意點(diǎn)
3.3.1 動(dòng)態(tài)加載數(shù)據(jù)的SQL需要指定分區(qū)名day='$yesdate',只加載前一天的數(shù)據(jù)
剩余數(shù)倉部分,待續(xù)!文章來源地址http://www.zghlxwxcb.cn/news/detail-731252.html
到了這里,關(guān)于一百八十六、大數(shù)據(jù)離線數(shù)倉完整流程——步驟五、在Hive的DWS層建動(dòng)態(tài)分區(qū)表并動(dòng)態(tài)加載數(shù)據(jù)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!