1. 程式人生 > >Hive 建立外部分割槽表並載入資料以及如何分桶

Hive 建立外部分割槽表並載入資料以及如何分桶

第一  建立資料庫並自定義路徑 如 /sogou/500w

         hive> create  database  sogou location '/sogou/500w' ;

              進入改表中建立表

        hive> use sogou;

第二步 建立外部分割槽表 如 sogou_partition

        hive> create external   table sogou_partition (ts string,uid string,keyword string,rank int ,order int,ulr string)    partitioned by (year string,month string,day stirng,hour string) row Format delimited fields  terminated by '\t' location '/sogou';

       標準格式 (注意關鍵字要大寫)

       hive> CREATE EXTERNAL TABLE sogou_partition(ts STRING,uid STRING,keyword STRING,rank INT, order INT, url STRING) PARTITIONED BY (year STRING,month STRING,day STRING,hour STRING) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' LOCATION '/sogou_3/500w';

       名詞解釋:  

       row  行 

       format  格式化

       delimited    劃定界限的

       fields  區域

       terminated 終止

第三步 載入資料

       hive> load   data  local  inpath  '/home/zkpk/resource/sogou-data/500w/ sogou.500w.utf8'  into   table  sogou_partition_3  partition (year='2011',month='12',day='30',hour='10');

第四步查詢資料(前100行)

       hive> select * from  sogou_partition_3 limit 100;