Sqoop 报错 Can’t parse input data: ‘\N’
问题描述:
使用sqoop吧hive中的数据推到 oracle中,程序报错:Can’t parse input data: ‘\N’
导数时无法识别null值 。
造成这个异常问题的原因是因为,hive中表是分区表的时候,增加字段未使用cascade 如:
alter table app.suntest_user add columns(name string comment '姓名') cascade
当未使用cascade关键字时,hive并不会更新历史分区定义,导致传历史数据时,表中的列和目标表列有差异。
- 举例说明:
假表 suntest_user在8月时建立的分区 M08 ,在9月时新增 name列,并建立分区 M09 则,且在目标库(oracle)中的表定义也新增了name列。 通过sqoop脚本导出M09分区数据没什么问题,但是导出M08数据时就会报错: Can’t parse input data: ‘\N’
- 解决方法:
可以把8月份分区重建,或者建立一个表用来导数。 下面是建表语句。
----- 创建一个分区对应的表,临时导数使用
create table app.test_suntest_user as
select id,name from app.suntest_user where partition_month='M08'
----重建分区语句
--重命名分区
alter table app.suntest_user partition (partition_month='M08') rename to partition (partition_month='M08bak');
--新建分区
insert overwrite table app.suntest_user partition(partition_month='M08')
select id ,name from app.suntest_user where partition_month='M08bak';
- sqoop语句如下:
sqoop export --connect "jdbc:oracle:thin:@**********" \
--username "abc" \
--password "123" \
--input-null-string '\\N' --input-null-non-string '\\N' \
--table "SUNTEST_USER" \
--export-dir /user/hive/warehouse/app/test_suntest_user\
--input-fields-terminated-by '\001' \
版权声明:本文为weixin_38360072原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。