使用sqoop从mysql往hive中增量导数据shell脚本

一:sqoop增量导入的两种方式

Incremental import arguments:

ArgumentDescription
--check-column (col)Specifies the column to be examined when determining which rows to import. (the column should not be of type CHAR/NCHAR/VARCHAR/VARNCHAR/ LONGVARCHAR/LONGNVARCHAR)
--incremental (mode)Specifies how Sqoop determines which rows are new. Legal values for mode include append and lastmodified.
--last-value (value)Specifies the maximum value of the check column from the previous import.

此处采用的--increamental append方式,这种方式需注意主键或split-colunm是递增,否则建议在关系表中增加一个createTime字段,采用lastmodified方式。

 

二:shell脚本

    

 1 #!/bin/sh
 2 export SQOOP_HOME=/usr/share/sqoop-1.4.4
 3 hostname="192.168.1.199"
 4 user="root"
 5 password="root"
 6 database="test"
 7 table="tags"
 8 curr_max=0
 9 
10 function db_to_hive(){
11 
12     ${SQOOP_HOME}/bin/sqoop import --connect jdbc:mysql://${hostname}/${database} --username ${user} --password ${password}  --table ${table}   --split-by docid --hive-import --hive-table lan.ding  
13  --fields-terminated-by '\t' --incremental  append  --check-column docid --last-value ${curr_max}   
14     result=`mysql -h${hostname} -u${user} -p${password} ${database}<<EOF 
15 select max(docid) from ${table};
16 EOF`
17 curr_max=`echo $result |awk '{print $2}'`
18 }
19 
20 if [ $# -eq 0 ];then
21     while true
22     do
23       db_to_hive
24       sleep 120
25     done
26     exit
27 fi

每隔2分钟,就往hive中增量导入数据。

转载于:https://www.cnblogs.com/weiqiang-liu/p/3799927.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值