sqoop从oracle倒数时为null的问题

本文讨论了使用SQOOP将Oracle表数据导入HDFS时,遇到null值被自动转换为null字符串的问题,并提供了三种解决方案来避免赋值失效:在导入前对JavaBean字段进行预处理、修改Hive脚本条件判断、正确配置null值的处理方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

1 现象:

通过sqoop将oracle表数据导入hdfs,在oracle的数据为null下,sqoop自动将null变成null字符串存储到hdfs上

这样,在执行hive脚本:

 

case when a.begindate is not null and a.enddate >= '%current_date%' and instrfun(a.status,'无效')=0 then 'R商标'
   when a.begindate is not null and instrfun(a.status,'无效')>0 or instrfun(a.status,'注销')>0 then '过期商标'
   when a.enddate < '%current_date%' then '过期商标'
   when a.begindate is not null and (instrfun(a.status,'无效')>0 or instrfun(b.xiangmu_new,'无效')>0 or instrfun(b.xiangmu_new,'驳回')>0)  then '无效(被否)商标' 
  when a.begindate is null then 'TM商标'
   else '未知'
 end MARKTYPE_NEW

 

 

 

 

 

的时候, 因为begindate 已经是 'null'字符串了因此上述赋值失效,

 

处理这种方式如下:

 

1 sqoop导入数据前针对javabean的字段做预处理比如赋值为 ''

 

2 或者上述脚本修改为:

case when a.begindate <> 'null' and a.enddate >= '%current_date%' and instrfun(a.status,'无效')=0 then 'R商标'
   when a.begindate <> 'null' and instrfun(a.status,'无效')>0 or instrfun(a.status,'注销')>0 then '过期商标'
   when a.enddate < '%current_date%' then '过期商标'
   when a.begindate <> 'null' and (instrfun(a.status,'无效')>0 or instrfun(b.xiangmu_new,'无效')>0 or instrfun(b.xiangmu_new,'驳回')>0)  then '无效(被否)商标' 
  when a.begindate = 'null' then 'TM商标'
   else '未知'
 end MARKTYPE_NEW

 

 3 正规要在sqoop导入数据的时候 将oracle的null入hdfs也是null的写法如下:

 

Sqoop will by default import NULL values as string null. Hive is however using string \N to denote NULL values and therefore predicates dealing with NULL (like IS NULL) will not work correctly. You should append parameters --null-string and --null-non-string in case of import job or --input-null-string and --input-null-non-string in case of an export job if you wish to properly preserve NULL values. Because sqoop is using those parameters in generated code, you need to properly escape value \N to \\N:

$ sqoop import  ... --null-string '\\N' --null-non-string '\\N'

 

 

参考链接:

http://bbs.csdn.net/topics/390459433?page=1

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值