1. Sqoop import 任务里把原来NULL的转化成字符串‘null’了。
解决方法:
先: alter table ${table_name} SET SERDEPROPERTIES('serialization.null.format' = '\N');
再: sqoop代码最后面加上 --null-string '\N' --null-non-string '\N'
2. sqoop 如果hive to mysql 的时候,会因为hive数据条为0导致任务失败
其实本身任务是没问题的。
方法:直接再后面打印一行就是如,echo `date +%Y%m%d-%H:%M:%S` "cs_live_interaction end"
然后就会跳过前面的失败,却执行成功
但是同时,如果你这个任务真的同步失败的话,调度状态看不出来
3. sqoop import 和 export 样例
import
#!/bin/bash
set -v
echo `date +%Y%m%d-%H:%M:%S` "table_xxx begin"
sqoop import -D mapred.job.queue.name=root.offline
--mapreduce-job-name sqoop_table_xxx
--hive-drop-import-delims
--connect "${datasource_connect}"
--username ${datasource_username}
--password '${datasource_password}'
--split-by id
--boundary-query 'select min(id),max(id) from table_xxx'
--hive-overwrite
--hive-import
--hive-table db_xxx.table_xxx
--query 'select id,column1_xxx,column2_xxx from table_xxx where $CONDITIONS'
--target-dir /tmp/sqoop_table_xxx_`date +%s`
--fields-terminated-by ' '
export
#删除mysql数据
mysql -u${datasource_username} -p'${datasource_password}' -h${datasource_host} -P${datasource_port} db_xxx -e "truncate table table_xxx";
sqoop export -D mapred.job.queue.name=root.offline
--mapreduce-job-name sqoop_table_xxx
--connect "${datasource_connect}"
--driver "${datasource_driver}"
--username ${datasource_username}
--password '${datasource_password}'
--table table_xxx
--columns column1_xxx,column2_xxx
--export-dir /user/hive/warehouse/db_xxx.db/table_xxx
--mapreduce-job-name table_xxx
--input-fields-terminated-by ' '
--input-null-string '\N'
--input-null-non-string '\N'