第9章 模式設計
1、按天劃分的表建議使用分區表
2、HDFS namenode會将所有的檔案系統的中繼資料資訊加載到記憶體中
3、hive沒有主鍵或基于序列秘鑰生成的自增鍵的概念
4、為了避免分區中資料不均的問題,可以用另一種資料分管的技術:分桶
create table weblog(user_id int, url string, source_id string)
partitioned by (dt string)
clustered by (user_id) into 96 buckets;
但是,要将資料正确的插入到表的過程完全取決于使用者自己!!!
5、怎麼使用分桶插入資料?
(1)、為分桶設定正确的reducer個數
set hive.enforce.bucketing = true;
(2)、插入資料
from raw_logs
insert overwrite table weblog
partition (dt='2009-02-25')
select user_id,url,source_ip where dt='2009-02-25';
6、分桶的優點:
(1)、因為桶數量是固定的,是以他沒有資料波動;
(2)、桶對抽樣非常适合;
(3)、分桶有利于執行高效的map-side join
7、為表增加字段,例子:
alter table weblogs add columns (user_id string);
8、hive通常使用行式存儲,不過hive也提供了一個列式SerDe來以混合列式格式存儲資訊。某些資料集使用列式存儲是最優的,如某些列重複資料特别多時,使用列式存儲會加快查詢速度。
9、在大多數情況下,都應該使用資料壓縮
*****************************
微信公衆号:IT人成長關注
大資料技術QQ群:485681776