Hive 分桶的操作

2021-09-19 05:18:22 字數 1858 閱讀 4920

先建立表:

create table t_stu(

sno int,

sname string,

*** string,

sage int,

sdept string

)row format delimited

fields terminated by ','

stored as textfile

;

分桶查詢

select * from t_stu;

select * from t_stu cluster by (sno);

set mapreduce.job.reduces=4;

select * from t_stu cluster by (sno); 負責分割槽還負責排序,排序字段就是分割槽字段

select * from t_stu distribute by (sno) sort by (sage desc);

指定分割槽欄位和排序字段,排序欄位可和分割槽欄位不一致,排序規則還可以指定

建立分桶表並載入資料

create table if not exists buc1(

sno int,

sname string,

*** string,

sage int,

sdept string

)clustered by (sno) sorted by (sage desc) into 4 buckets

row format delimited

fields terminated by ','

stored as textfile

;

使用load的方式進行載入資料(load方式載入資料不能體現分桶的結果)

load data local inpath '/data/students.txt' into table buc1;
**************************

第一步:要在hive中建立乙個臨時表,將資料匯入臨時表中

第二步:通過對臨時表查詢的方式完成資料匯入,分桶的實現就是對分桶的字段做了hash然後存放到對應的檔案中,也就是說向分通表中插入資料的時候

必然要執行一次mr,這也就是為什麼分桶表的資料基本上只能通過從結果集的查詢插入方式匯入

**************************

先建立表:

create table if not exists buc2(

sno int,

sname string,

*** string,

sage int,

sdept string

)clustered by (sno) sorted by (sage desc) into 4 buckets

row format delimited

fields terminated by ','

stored as textfile

;

載入資料

(要注意reduce數量的設定與分桶數量一致) 

hive 修改分桶數 分桶表 Hive中的分桶

對於每乙個表 table 或者分割槽,hive可以進一步組織成桶,也就是說桶是更為細粒度的資料範圍劃分。hive也是針對某一列進行桶的組織。hive採用對列值雜湊,然後除以桶的個數求餘的方式決定該條記錄存放在哪個桶當中。把錶 或者分割槽 組織成桶 bucket 有兩個理由 1 獲得更高的查詢處理效率...

hive分桶 hive學習筆記之五 分桶

分割槽欄位的每個值都會建立乙個資料夾,值越多資料夾越多 不合理的分割槽會導致有的資料夾下資料過多,有的過少 set hive.enforce.bucketing true 如果不執行上述設定,您需要自行設定mapred.reduce.tasks引數,以控制reducers數量,本文咱們配置為hive...

Hive分桶筆記

分桶表與其他表的區別 分桶表是從別的表查詢的資料在insert到分桶表中 而其他表是load clustered by id into 4 buckets 通過id hash雜湊 建立分桶表 create table stu buck sno int,sname string,string,sage...