1. 程式人生 > >hive學習筆記以及一些linux命令

hive學習筆記以及一些linux命令


 
  去雙引號:
 
 
  
  
sed -i "s/"//g" textName
working:
perl -p -i -e "s/ /,/g" ./wuhan_feiy_end_result.csv
出現 分組無效情況
select patient_sn,year,sex,cast(year as int)-cast(birth_date as int) from tableName  limit 10;
select trim(patient_sn) as patient_sn,trim(visit_type) as visit_type,trim(year) as year,trim(sex) as sex,trim(age) as age,sum(fee_sum) from tableName  group by
trim(visit_type) ,trim(patient_sn), trim
(year),trim(sex),trim(age) order by patient_sn,year,sex,age,visit_type ;
--結論:可能是 分組資料存在空格導致分組無效,使用trim()函式解決

建表語句, 載入csv檔案:
create table tableName (JZJLH string,SDYWH string)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.OpenCSVSerde'
 WITH SERDEPROPERTIES (
 "separatorChar" = ",", 
 "quoteChar" = "\"", 
 "escapeChar" = "\\" 
 ) 
--建表語句模板:
create table tableName(JZJLH string,SDYWH string)
row format delimited
fields terminated by '","'
lines terminated by '\n'
stored as textfile;
載入資料到表中:
OVERWRITE INTO TABLE tableName; load本地新檔案到hive:utf-8
load data local INPATH path

OVERWRITE INTO TABLE tableName;
查詢結果只 生成一個檔案:(部分欄位)匯出到本地
hive -e "SELECT concat(jzjlh,',',fldmmc,',',zje) FROM zhangheng.tableName;">/opt/textName
查詢到資料插入本地檔案
INSERT OVERWRITE LOCAL DIRECTORY '/opt/zhangheng'
row format delimited fields terminated by ","
SELECT jzjlh, fyrq, fldm,sum(cast( zje as double)),fldmmc FROM 
tableName group by jzjlh, fyrq, fldm ,fldmmc ORDER BY  jzjlh desc,  fldm desc,  fyrq desc ;
查詢結果插入hive表:
insert overwrite table tableName
SELECT jzjlh, fyrq, fldm,sum(zje),fldmmc,count(zje) FROM 
tableName group by jzjlh, fyrq, fldm ,fldmmc ORDER BY  jzjlh desc,  fldm desc,  fyrq desc ;