hive 分割槽表 Hive的DDL分割槽表建立

2021-10-12 05:13:22 字數 2992 閱讀 4924

1. 單分割槽表

#建立表t_user,指定分割槽hive (xiaoliu)> create table t_user(id int,name string)              > partitioned by (country string)              > row format delimited              > fields terminated by ',';[xiaokang@hadoop hive_data]$ vi 5.txt1,allen2,bob3,tom    #5.txt傳入表t_user,並指定分割槽         hive (xiaoliu)> load data local inpath '/home/xiaokang/hive_data/5.txt' into table t_user partition(country='us');hive (xiaoliu)> select * from t_user;t_user.id  t_user.name  t_user.country1  allen  us2  bob  us3  tom  us              [xiaokang@hadoop hive_data]$ vi 6.txt6,kongzi7,mozi8,laozihive (xiaoliu)> load data local inpath '/home/xiaokang/hive_data/6.txt' into table t_user partition(country='china');hive (xiaoliu)> select * from t_user;okt_user.id  t_user.name  t_user.country6  kongzi  china7  mozi  china8  laozi  china1  allen  us2  bob  us3  tom  us

注意:①分割槽表字段不能再表的屬性中已經存在,如果已存在會報錯

hive (xiaoliu)> create table t_user2(id int,name string) partitioned by (name string)              > row format delimited              > fields terminated by ',';failed: semanticexception [error 10035]: column repeated in partitioning columns
②分割槽欄位是乙個虛擬字段,不存放任何資料。分割槽欄位的資料來自於裝載分割槽表資料的時候指定的。分割槽欄位可用作查詢條件。

hive (xiaoliu)> select * from t_user where country='china';okt_user.id  t_user.name  t_user.country6  kongzi  china7  mozi  china8  laozi  china
分割槽建表分為兩種,一種是單分割槽,也就是說在表資料夾目錄下只有一級資料夾。另一種是多分割槽,表資料夾下出現多資料夾巢狀模式。

2. 雙分割槽表

總結:分割槽表字段 在hdfs上的效果就是 在建立表的資料夾下面又建立了子資料夾,這樣資料的劃分更加細緻,減少了查詢時候全表掃瞄的成本,只需要按照指定的分割槽掃瞄資料並顯示結果即可

hive 分割槽表

partitioned by create table tb name name string partitioned by age int row format delimited fields terminated by t load data local inpath file path in...

hive分割槽表

partition對應於資料庫的 partition 列的密集索引 在 hive 中,表中的乙個 partition 對應於表下的乙個目錄,所有的 partition 的資料都儲存在對應的目錄中 例如 test表中包含 date 和 city 兩個 partition 則對應於date 201302...

hive 分割槽表

建立分割槽表的原因 單錶資料量隨著時間越來越大。為了避免全表掃瞄,引入分割槽。hive分割槽和mysql分割槽表的區別?hive分割槽使用表外字段,mysql使用表內字段。hive分割槽表細節?1.hive分割槽的字段是乙個偽欄位,它不會在表中真實存在,可以用來過濾查詢等 2.乙個表或者乙個分割槽可...