標籤:方式 rop row location 查詢 form 記錄 sorted by 處理
一,DDL操作
1,建立表
建立內部表
create table if not exists mytable(sid int, sname string )row format delimited fields terminated by ‘,‘ stored as textfile;
建立內部表
create external table if not exists pageview(pageid int, page_url string )
row format delimited fields terminated by ‘,‘
location ‘hdfs://192.168.184.131:9000/user/hive/warehouse/‘;
建立分區表 分表就是在加入資料前,對錶進行相應需求的分開儲存。
1 create table if exists invites (id int , name string )2 partitioned by (ds string)3 row format delimited fields terminated by ‘,‘ lines terminated by ‘\n‘ stored as textfile;
建立分桶表 分桶就是在輸入資料後,把表按照屬性的一致性進行整合。
1 //開啟分桶2 set hive.enforce.bucketing = true;
對於每一個表或者是分區,Hive可以進一步組織成桶,也就是說桶是更為細粒度的資料範圍劃分。Hive是針對某一列進行分桶。Hive採用對列值雜湊,然後除以桶的個數求餘的方式決定該條記錄存放在哪個桶中。分桶的好處是可以獲得更高的查詢處理效率。使取樣更高效。
當從桶表中進行查詢時,hive會根據分桶的欄位進行計算分析出資料存放的桶中,然後直接到對應的桶中去取資料,這樣做就很好的提高了效率。
1 create table student (id int , name string )
2 clustered by (id) sorted by(name) into 4 buckets
3 row format delimited fields terminated by ‘,‘;
2,修改表
添加分區
1 alter table student_p add partition(part=‘a‘) partition (part=‘b‘);
刪除分區
alter table student_p drop partition(part=‘a‘);
重新命名表
alter table table_name rename to new_table_name;
增加列
alter table student add columns (sex string);
更新列
Hive基本操作