sqoop从关系库导出数据到hive

[Author]: kwu 

sqoop从关系库导出数据到hive,sqoop支持条件查询关系库中的数到hive数据仓库中,并且字段无须与hive表中的字段一致。


具体实现的脚本:

[plain]  view plain copy
  1. #!/bin/sh    
  2. # upload logs to hdfs    
  3.   
  4. today=`date --date='0 days ago' +%Y-%m-%d`  
  5.   
  6. 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-  
  7. drop-import-delims --hive-table stage.sh_comp_index -m 1  
  8.   
  9. year=`date +%Y`    
  10.     
  11. hive -e "    
  12. insert overwrite table ods.sh_comp_index partition(year='${year}')  
  13. select distinct  
  14. trans_date ,             
  15. open_price ,  
  16. ceil_price  ,  
  17. close_price ,  
  18. bottom_price ,  
  19. volume_of_business ,  
  20. trans_amount  
  21. from  
  22. stage.sh_comp_index  
  23. where year(trans_date)=${year};    
  24. "  

说明:

1、条件语句,需要加上双引号: "" ,如下:

[html]  view plain copy
  1. --where "V1='${today}'"  

2、注意,sqoop的语句需要写成一行执行。


3、-m 1说明是一个map执行。

你可能感兴趣的:(sqoop)