2017-02-16 64 views
0

請幫助建議。僅加載4個字段的2個字段 - Pig to Hive表

場景:使用Pig將數據從HDFS存儲到Hive。

我有從mySQL中挖出的文件,它有4個字段Ord_Id, Cust_Id, Cust_name, Ord_date。我喜歡將僅2個字段Ord_Id和Cust_Id存儲到Hive。我怎麼能這樣做?請建議。

下面的代碼不能執行:

pig -useHCatalog 
orders = LOAD '<HDFS_file_path>' USAGE PigStorage(',') AS (Ord_Id:Int, Cust_Id:Int, Cust_name:chararray, Ord_date:chararray); 
STORE orders INTO 'pig_demo.orders' USAGE org.apache.hive.hcatalog.pig.HCatStorer(); 

感謝。

回答

0

首先,您的表格應該已經存在於配置單元中,並且您想從豬存儲相同的列名稱。

orders = LOAD '<HDFS_file_path>' USAGE PigStorage(',') AS 
(Ord_Id:Int, Cust_Id:Int, Cust_name:chararray, Ord_date:chararray); 

select_columns = FOREACH orders GENERATE Ord_Id AS ord_id, Cust_Id AS cust_id; 

STORE select_columns INTO 'pig_demo.orders' USING org.apache.hive.hcatalog.pig.HCatStorer(); 

還提到HCatalog LoadStore

0

如果目的是隻是有一個表在蜂巢只是兩列,那麼你可以只用SQOOP的--columns說法在特定的這兩個coulmns與--hive-import選項,並避免使用附加PIG腳本一起執行。

像 -

sqoop import \ 
--connect jdbc:mysql://cloudera.quickstart:3306/retail_db \ 
--table orders \ 
--columns Ord_Id, Cust_Id \ 
--hive-import \ 
--direct