在使用sqoop将数据从oracle导入hive时,对数据进行验证,发现hive中的数据比oracle的多,然后发现多出来的数据严重错位,大量字段为null
怀疑是某些字段含有了hive默认的分隔符,如“\n”,“\r”,“\01”
解决办法是增加参数--hive-drop-import-delims来解决
以下是http://archive.cloudera.com/cdh/3/sqoop/SqoopUserGuide.html中摘抄的内容,很好的解释了该参数
Hive will have problems using Sqoop-imported data if your database’s rows contain string fields that have Hive’s default row delimiters (\n
and \r
characters) or column delimiters (\01
characters) present in them. You can use the --hive-drop-import-delims
option to drop those characters on import to give Hive-compatible text data. Alternatively, you can use the --hive-delims-replacement
option to replace those characters with a user-defined string on import to give Hive-compatible text data. These options should only be used if you use Hive’s default delimiters and should not be used if different delimiters are specified.
可以从中看出,“\n”、“\r”是hive默认的行分隔符,而“\01”则是hive默认的列分隔符,如果数据中含有这些分隔符,在不处理的情况下,hive就会对数据进行错误的分割,造成数据错位以及数据增多的问题,解决办法就是
第一种,使用--hive-drop-import-delims 来去除这些字符
第二种,使用--hive-delims-replacement来替换这些字符