Sqoop 导入空字符串
Sqoop import Null string
当查询外部配置单元 table 时,Null
值显示为 '\N'。
下面是 sqoop 导入脚本:
sqoop import -libjars /usr/lib/sqoop/lib/tdgssconfig.jar,/usr/lib/sqoop/lib/terajdbc4.jar -Dmapred.job.queue.name=xxxxxx \
--connect jdbc:teradata://xxx.xx.xxx.xx/DATABASE=$db,LOGMECH=LDAP --connection-manager org.apache.sqoop.teradata.TeradataConnManager \
--username $user --password $pwd --query "
select col1,col2,col3 from $db.xxx
where $CONDITIONS" \
--null-string '\N' --null-non-string '\N' \
--fields-terminated-by '\t' --num-mappers 6 \
--split-by job_number \
--delete-target-dir \
--target-dir $hdfs_loc
请告知应该对脚本进行哪些更改,以便在查询外部配置单元 table 时将空值显示为空值。
在您的 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
Sathiyan- 以下是我经过多次试验后的发现
- 如果在 sqoop 导入期间不包含(空字符串)属性,则 NULL 将存储为 [blank 用于整数列] 和 [ blank for string columns] 在 HDFS 中。
2.If 查询 HDFS 顶部的 HIVE table,我们会看到 [NULL for integer column] 和 [blank 对于字符串列]
- 如果在 sqoop 导入期间包含
(--null-string '\N')
属性,则整数和字符串列的 NULL 存储为 ['\N'] .
- 如果查询 HDFS 顶部的 HIVE table,我们将看到整数和字符串列的 [NULL 而不是 '\N ']
如果 table 中的任何值为 NULL 并且我们想要对 table 进行 sqoop,那么 sqoop 将在 HDFS 中将 NULL 值作为字符串 null
导入。因此,这将在我们使用 hive
的查询中使用 Null 条件时产生问题
例如:– 让我们将 NULL 值插入 mysql table “cities”。
mysql> insert into cities values(6,7,NULL);
默认情况下,Sqoop 会将 NULL 值作为字符串 null
导入 HDFS。
让 sqoop 看看会发生什么:–
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/
在 sqoop 导入命令中删除 --null-string 和 --null-non-string '\N' 选项。
默认情况下,系统将为字符串和非字符串值分配 null。
我尝试了 --null-string '\N' 和 --null-string '' 以及其他选项,但出现空白和不同的问题。
当查询外部配置单元 table 时,Null
值显示为 '\N'。
下面是 sqoop 导入脚本:
sqoop import -libjars /usr/lib/sqoop/lib/tdgssconfig.jar,/usr/lib/sqoop/lib/terajdbc4.jar -Dmapred.job.queue.name=xxxxxx \ --connect jdbc:teradata://xxx.xx.xxx.xx/DATABASE=$db,LOGMECH=LDAP --connection-manager org.apache.sqoop.teradata.TeradataConnManager \ --username $user --password $pwd --query "
select col1,col2,col3 from $db.xxx
where $CONDITIONS" \ --null-string '\N' --null-non-string '\N' \ --fields-terminated-by '\t' --num-mappers 6 \ --split-by job_number \ --delete-target-dir \ --target-dir $hdfs_loc
请告知应该对脚本进行哪些更改,以便在查询外部配置单元 table 时将空值显示为空值。
在您的 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
Sathiyan- 以下是我经过多次试验后的发现
- 如果在 sqoop 导入期间不包含(空字符串)属性,则 NULL 将存储为 [blank 用于整数列] 和 [ blank for string columns] 在 HDFS 中。 2.If 查询 HDFS 顶部的 HIVE table,我们会看到 [NULL for integer column] 和 [blank 对于字符串列]
- 如果在 sqoop 导入期间包含
(--null-string '\N')
属性,则整数和字符串列的 NULL 存储为 ['\N'] . - 如果查询 HDFS 顶部的 HIVE table,我们将看到整数和字符串列的 [NULL 而不是 '\N ']
如果 table 中的任何值为 NULL 并且我们想要对 table 进行 sqoop,那么 sqoop 将在 HDFS 中将 NULL 值作为字符串 null
导入。因此,这将在我们使用 hive
例如:– 让我们将 NULL 值插入 mysql table “cities”。
mysql> insert into cities values(6,7,NULL);
默认情况下,Sqoop 会将 NULL 值作为字符串 null
导入 HDFS。
让 sqoop 看看会发生什么:–
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/
在 sqoop 导入命令中删除 --null-string 和 --null-non-string '\N' 选项。 默认情况下,系统将为字符串和非字符串值分配 null。
我尝试了 --null-string '\N' 和 --null-string '' 以及其他选项,但出现空白和不同的问题。