sqoop导入空字符串

iqih9akk  于 2021-06-02  发布在  Hadoop
关注(0)|答案(3)|浏览(604)

这个 Null 查询配置单元外部表时,值显示为“\n”。
下面是sqoop导入脚本:
sqoop import-libjars/usr/lib/sqoop/lib/tdgssconfig.jar,/usr/lib/sqoop/lib/terajdbc4.jar-dmapred.job.queue.name=--connectjdbc:teradata://.xx..xx/database=$db,logmech=ldap--连接管理器org.apache.sqoop.teradata.teradata连接管理器--用户名$user--密码$pwd--查询“
从$db.中选择col1、col2、col3
其中$conditions“--null string”\n“--null non string”\n“--fields terminated by“\t”--num mappers 6 --split by job \u number --delete target dir --target dir$hdfs \u loc
请说明应该对脚本做什么更改,以便在查询外部配置单元表时将空值显示为空值。

xsuvu9jc

xsuvu9jc1#

在你提到的sqoop脚本中 --null-string '\N' --null-non-string '\N 也就是说,

--null-string '\N'  = The string to be written for a null value for string columns 

--null-non-string '\N' = The string to be written for a null value for non-string columns
k5ifujac

k5ifujac2#

如果表中的任何值为null,并且我们希望sqoop该表,那么sqoop将把null值作为字符串导入 null 在hdfs中。所以,在使用hive的查询中使用null条件会产生问题
例如:–将空值插入mysql表“cities”。

mysql> insert into cities values(6,7,NULL);

默认情况下,sqoop将空值作为字符串导入 null 在hdfs中。
让我们来看看会发生什么:

sqoop import –connect jdbc:mysql://localhost:3306/sqoop –username sqoop -P –table cities –hive-import –hive-overwrite –hive-table vikas.cities -m 1

http://deltafrog.com/how-to-handle-null-value-during-sqoop-import-export/

doinxwow

doinxwow3#

下面是我经过多次试验后的发现
如果在sqoop导入过程中不包括(null string)属性,则null在hdfs中存储为[blank for integer columns]和[blank for string columns]。2.如果查询hdfs顶部的配置单元表,我们将看到[null表示整数列]和[blank表示字符串列]
如果 (--null-string '\N') 属性,然后将空值存储为['\n'表示整数列和字符串列]。
如果查询hdfs顶部的配置单元表,我们将看到[null表示整数和字符串列,而不是'\n']

相关问题