[Author]: kwu
sqoop从关系库导出数据到hive,sqoop支持条件查询关系库中的数到hive数据仓库中,并且字段无须与hive表中的字段一致。
具体实现的脚本:
#!/bin/sh
# upload logs to hdfs
today=`date --date='0 days ago' +%Y-%m-%d`
sqoop import --connect jdbc:mysql://10.130.2.6:3306/bdc_test --username lvwenjuan --password Abcd1234 --table sh_compsite_index --where "V1='${today}'" --columns "V1,V2,V3,V4,V5,V6,V7" --fields-terminated-by '\001' --hive-import --hive-
drop-import-delims --hive-table stage.sh_comp_index -m 1
year=`date +%Y`
hive -e "
insert overwrite table ods.sh_comp_index partition(year='${year}')
select distinct
trans_date ,
open_price ,
ceil_price ,
close_price ,
bottom_price ,
volume_of_business ,
trans_amount
from
stage.sh_comp_index
where year(trans_date)=${year};
"
说明:
1、条件语句,需要加上双引号: "" ,如下:
--where "V1='${today}'"
2、注意,sqoop的语句需要写成一行执行。
3、-m 1说明是一个map执行。