ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

sqoop导入hive数据时对换行等特殊字符处理

2021-01-21 19:32:28  阅读:414  来源: 互联网

标签:-- sqoop hive Hive mysql .-- 特殊字符 delims


使用场景:

 公司大数据平台ETL操作中,在使用sqoop将mysql中的数据抽取到hive中时,由于mysql库中默写字段中会有换行符,导致数据存入hive后,条数增多(每个换行符会多出带有null值得一条数据),导致统计数据不准确。

 

解决办法:

利用一下两个参数可以实现对换行等特殊字符的替换或者删除

  • --hive-delims-replacement
  • --hive-drop-import-delims

参考官方文档

Table 8. Hive arguments:

ArgumentDescription
--hive-home <dir>Override $HIVE_HOME
--hive-importImport tables into Hive (Uses Hive’s default delimiters if none are set.)
--hive-overwriteOverwrite existing data in the Hive table.
--create-hive-tableIf set, then the job will fail if the target hive
 table exits. By default this property is false.
--hive-table <table-name>Sets the table name to use when importing to Hive.
--hive-drop-import-delimsDrops \n\r, and \01 from string fields when importing to Hive.
--hive-delims-replacementReplace \n\r, and \01 from string fields with user defined string when importing to Hive.
--hive-partition-keyName of a hive field to partition are sharded on
--hive-partition-value <v>String-value that serves as partition key for this imported into hive in this job.
--map-column-hive <map>Override default mapping from SQL type to Hive type for configured columns.

 

使用方法,

1、在原有sqoop语句中添加 --hive-delims-replacement “ ” 可以将如mysql中取到的\n\r, and \01等特殊字符替换为自定义的字符,此处用了空格

2、在原有sqoop语句中添加 --hive-drop-import-delims 可以将如mysql中取到的\n\r, and \01等特殊字符丢弃

标签:--,sqoop,hive,Hive,mysql,.--,特殊字符,delims
来源: https://blog.csdn.net/zhangli_li520/article/details/112970079

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有