利用sqoop指定列指定条件的方式将数据从mysql中增量导入hive表中

========1、sqoop增量(指定列指定条件的方式增量导入hive表中)导入hive脚本=======
#!/bin/bash
#Set the RDBMS connection params
rdbms_ip=$1
rdbms_connect="jdbc:mysql://${rdbms_ip}:**/*******?useUnicode=true&characterEncoding=UTF-8"
rdbms_username="****"
rdbms_password="*****"
#Set the source table in RDBMS
rdbms_table="*****"
rdbms_columns="**,**,**,**,**,**"
#Set the hive tables
hive_full_table="******"
hive_database="*****"
cast_column="content"
yesterday_param1=$2
nowday_param2=$3
sqoop-import --connect ${rdbms_connect} --driver com.mysql.jdbc.Driver --username ${rdbms_username} --password ${rdbms_password} --table ${rdbms_table} --columns ${rdbms_columns} --where "createTime >=${yesterday_param1} and createTime <${nowday_param2}" -m 4 --hive-import --hive-database ${hive_database} --hive-table ${hive_full_table} --fields-terminated-by "\001" --lines-terminated-by "\n" --hive-drop-import-delims --map-column-java ${cast_column}=String --delete-target-dir
 
注释:--hive-drop-import-delims 删掉字段中的\n \t \r\n等字符 不删掉的话,若字段中存在\n \t等这种字符,容易导致hive表中的数据位置错乱,我就遇到了这个问题

猜你喜欢

转载自www.cnblogs.com/wtb0810/p/10026578.html