累積型快照事實表 訂單表

2022-03-28 01:57:52 字數 2868 閱讀 3020

concat函式在連線字串的時候,只要其中乙個是null,那麼將返回null

hive> select concat('a','b');

abhive> select concat('a','b',null);

null

concat_ws函式在連線字串的時候,只要有乙個字串不是null,就不會返回null。

concat_ws函式需要指定分隔符。

hive> select concat_ws('-','a','b');

a-bhive> select concat_ws('-','a','b',null);

a-bhive> select concat_ws('','a','b',null);

ab

str_to_map(varchar text, varchar listdelimiter, varchar keyvaluedelimiter)

使用listdelimiter將text分隔成k-v對,

然後使用keyvaluedelimiter分隔每個k-v對,組裝成map返回。

預設listdelimiter為( ,)keyvaluedelimiter為(=)

str_to_map('1001=2020-03-10,1002=2020-03-10',  ','  ,  '=')

輸出

第一步:

hive> select order_id, concat(order_status,'

=', operate_time) from order_status_log where dt='

2020-03-10';

3210

1001=2020-03-10

00:00:00.0

3211

1001=2020-03-10

00:00:00.0

3212

1001=2020-03-10

00:00:00.0

3210

1002=2020-03-10

00:00:00.0

3211

1002=2020-03-10

00:00:00.0

3212

1002=2020-03-10

00:00:00.0

3210

1005=2020-03-10

00:00:00.0

3211

1004=2020-03-10

00:00:00.0

3212

1004=2020-03-10

00:00:00.0

第二步:

hive > select order_id, collect_set(concat(order_status,'

=',operate_time)) from order_status_log where dt='

2020-03-10

'group by order_id;

3210 ["

1001=2020-03-10 00:00:00.0

","1002=2020-03-10 00:00:00.0

","1005=2020-03-10 00:00:00.0"]

3211 ["

1001=2020-03-10 00:00:00.0

","1002=2020-03-10 00:00:00.0

","1004=2020-03-10 00:00:00.0"]

3212 ["

1001=2020-03-10 00:00:00.0

","1002=2020-03-10 00:00:00.0

","1004=2020-03-10 00:00:00.0

"]

第三步:

hive> 

select order_id, concat_ws('

,', collect_set(concat(order_status,'

=',operate_time))) from order_status_log where dt='

2020-03-10

'group by order_id;

3210

1001=2020-03-10

00:00:00.0,1002=2020-03-10

00:00:00.0,1005=2020-03-10

00:00:00.0

3211

1001=2020-03-10

00:00:00.0,1002=2020-03-10

00:00:00.0,1004=2020-03-10

00:00:00.0

3212

1001=2020-03-10

00:00:00.0,1002=2020-03-10

00:00:00.0,1004=2020-03-10

00:00:00.0

第四步:

hive >

select order_id, str_to_map(concat_ws('

,',collect_set(concat(order_status,'

=',operate_time))), '

,' , '

=') tms from order_status_log where dt='

2020-03-10

'group by order_id;

3210

3211

3212

第五步:取值

交易事實表 週期快照事實表和累積快照事實表

在資料倉儲領域有乙個概念叫transaction fact table,中文一般翻譯為 事務事實表 事務事實表是維度建模的資料倉儲中三種基本型別事實表中的一種,另外兩種分別是週期快照事實表和累積快照事實表。事務事實表與週期快照事實表 累積快照事實表使用相同的一致性維度,但是它們在描述業務事實方面是有...

交易事實表 週期快照事實表和累積快照事實表

在資料倉儲領域有乙個概念叫transaction fact table,中文一般翻譯為 事務事實表 事務事實表是維度建模的資料倉儲中三種基本型別事實表中的一種,另外兩種分別是週期快照事實表和累積快照事實表。事務事實表與週期快照事實表 累積快照事實表使用相同的一致性維度,但是它們在描述業務事實方面是有...

累積型快照事實表聚合操作案例

insert overwrite table dwd fact order info partition dt select 新老交替,如果新表有就取新表的,否則取old nvl new.id,old.id id,nvl new.order status,old.order status order...