1. 程式人生 > >hive 從Excel中匯入資料

hive 從Excel中匯入資料

  1. 拿到Excel表後將資料保留,其他的亂七八糟都刪掉,然後另存為txt格式的文字,用nodepad++將文字轉換為UTF-8編碼,此處命名為cityprovince.txt
  2. 將cityprovince.txt傳入操作的Linux環境中
  3. hive建表,注意欄位型別要相同
drop table tmp.cityprovince;
create table tmp.cityprovince (province String,city String,county String,station String) 
row format delimited fields terminated by
'\t' STORED AS TEXTFILE;

    此處txt文字中以空格分開,所以此處以 '/t' 進行分割,否則會將整個資料全放在第一列中

  4.在hive環境中執行指令

load data local inpath '/home/chengwu_1/cityprovince.txt' into table tmp.cityprovince;

  5.在上一步顯示ok後,可通過select * from tmp.cityprovince;進行驗證。

    注意:需要轉換為utf-8,否則tmp.citryprovince會顯示亂碼

 

  將欄位相同的表合併可用union all實現:

select * from tableA union all select * from tableB

 

insert into tmp.applogresult select a.* from (select * from tmp.name1 union all select * from tmp.name2 union all select * from tmp.name7 union all select * from tmp.name12 union
all select * from tmp.name17 ) a;