【问题标题】:Sqoop import Null stringSqoop 导入 Null 字符串
【发布时间】:2017-03-10 11:29:21
【问题描述】:

查询 Hive 外部表时,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 "

从 $db.xxx 中选择 col1,col2,col3

在哪里 \$CONDITIONS" \ --null-string '\N' --null-non-string '\N' \ --fields-terminated-by '\t' --num-mappers 6 \ --按作业编号拆分\ --删除目标目录\ --target-dir $hdfs_loc

请告知应该对脚本进行哪些更改,以便在查询外部配置单元表时将空值显示为空值。

【问题讨论】:

    标签: hadoop null hive teradata sqoop


    【解决方案1】:

    Sathiyan- 以下是我经过多次试验后的发现

    1. 如果在 sqoop 导入期间不包含(空字符串)属性,则在 HDFS 中将 NULL 存储为 [blank for integer columns] 和 [blank for string columns] . 2.如果查询HDFS之上的HIVE表,我们会看到[NULL for integer column]和[blank for String columns]
    2. 如果在 sqoop 导入期间包含 (--null-string '\N') 属性,则 NULL 将存储为 ['\N' 用于整数和字符串列]。
    3. 如果查询 HDFS 顶部的 HIVE 表,我们将看到 [NULL 用于整数和字符串列而不是 '\N']

    【讨论】:

    • 对我来说 --null-string '\N' 的 null-non-string 值在 HDFS 中被写为“null”,但您的指南使它工作:) 它们被正确读取为 null 值。
    • 对我来说,没有--null-string 属性会导致值写为“null”,就像文档sqoop.apache.org/docs/1.4.6/SqoopUserGuide.html 中所述。
    【解决方案2】:

    在你的 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
    

    【讨论】:

    • 是的。这就是将空值存储在 HDFS 中的方式。但是,当查询 hive 表时,null 应该显示为实际的 null,而不是 '\\N'
    • 不,您在此处提供的任何字符串都将存储在 HDFS 中,因此存储在 HDFS 中的内容将反映在 hive 查询中。
    【解决方案3】:

    如果表中的任何值为NULL,并且我们想对该表进行sqoop,那么sqoop会将NULL值导入HDFS中的字符串null。因此,在使用 hive 的查询中使用 Null 条件会产生问题

    例如:- 让 NULL 值插入 mysql 表“城市”。

    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/

    【讨论】:

      【解决方案4】:

      在 sqoop 导入命令中删除 --null-string 和 --null-non-string '\N' 选项。 默认情况下,系统将为字符串和非字符串值分配 null。

      我尝试了 --null-string '\N' 和 --null-string '' 和其他选项,但得到空白和不同的问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-07-01
        • 1970-01-01
        • 2013-06-25
        • 2016-10-08
        • 1970-01-01
        • 1970-01-01
        • 2017-06-13
        • 1970-01-01
        相关资源
        最近更新 更多