Hive基本操作

來源:互聯網
上載者:User

標籤:方式   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基本操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.