sqoop从关系库导出数据到hive

[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执行。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值