溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

hive 中的拉鏈表 2

發(fā)布時間:2020-07-16 20:24:00 來源:網(wǎng)絡(luò) 閱讀:1450 作者:jackwxh 欄目:大數(shù)據(jù)

本例以hive為例,只考慮到實現(xiàn),與性能無關(guān)

首先創(chuàng)建表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
CREATE TABLE orders (
orderid INT,
createtime STRING,
modifiedtime STRING,
status STRING
) row format delimited fields terminated by '\t'
 
 
CREATE TABLE ods_orders_inc (
orderid INT,
createtime STRING,
modifiedtime STRING,
status STRING
) PARTITIONED BY (day STRING)
row format delimited fields terminated by '\t'
 
 
CREATE TABLE dw_orders_his (
orderid INT,
createtime STRING,
modifiedtime STRING,
status STRING,
dw_start_date STRING,
dw_end_date STRING
) row format delimited fields terminated by '\t' ;

首先全量更新,我們先到2016-08-20為止的數(shù)據(jù)。

初始化,先把2016-08-20的數(shù)據(jù)初始化進去

1
2
3
4
INSERT overwrite TABLE ods_orders_inc PARTITION (day '2016-08-20')
SELECT orderid,createtime,modifiedtime,status
FROM orders
WHERE createtime < '2016-08-21' and modifiedtime <'2016-08-21';

刷到dw中

1
2
3
4
5
6
INSERT overwrite TABLE dw_orders_his
SELECT orderid,createtime,modifiedtime,status,
createtime AS dw_start_date,
'9999-12-31' AS dw_end_date
FROM ods_orders_inc
WHERE day '2016-08-20';

如下結(jié)果

1
2
3
4
5
select from dw_orders_his;
OK
1  2016-08-20  2016-08-20  創(chuàng)建 2016-08-20  9999-12-31
2  2016-08-20  2016-08-20  創(chuàng)建 2016-08-20  9999-12-31
3  2016-08-20  2016-08-20  創(chuàng)建 2016-08-20  9999-12-31

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI