【问题标题】:how to eliminate the \N in hive file at hdfs?如何消除hdfs hive文件中的\ N?
【发布时间】:2017-07-19 02:16:00
【问题描述】:

我在 hive 表中加载数据,一些列是空的,而我在 hive 中查看表时显示为空。 当我在路径 /apps/hive/warehouse/dbname/file-name 中下载 HDFS 中的数据时。 在那个下载的文件中有 \N 值而不是空值。 如何在我的文件中用空来消除 \N 值。 而且我想以 XLSX 格式保存我的文件

【问题讨论】:

  • 你能显示代码吗?
  • 我回答了你的第一个问题,请为第二个问题打开一个新帖子。 (虽然我怀疑你的意思是分隔格式,例如 CSV、TSV 等)
  • 我在@dudu Markovitz 的新帖子中提出了一个新问题

标签: hive hdfs hiveql


【解决方案1】:
tblproperties ('serialization.null.format' = '')

演示

hive> create table t1 (i int,j int,k int);
hive> insert into t1 values (1,null,2);
hive> select * from t1;

+------+------+------+
| t1.i | t1.j | t1.k |
+------+------+------+
|    1 | NULL |    2 |
+------+------+------+

$ hdfs dfs -cat /user/hive/warehouse/t1/* | od -Anone -tacd1x1

    1  soh    \    N  soh    2   nl     # a  = named characters         
    1  001    \    N  001    2   \n     # c  = ASCII characters or backslash escapes
   49    1   92   78    1   50   10     # d1 = decimal     (1-byte)
   31   01   5c   4e   01   32   0a     # x1 = hexadecimal (1-byte)

hive> create table t2 (i int,j int,k int) tblproperties ('serialization.null.format' = '');
hive> insert into t2 values (1,null,2);
hive> select * from t2;

+------+------+------+
| t2.i | t2.j | t2.k |
+------+------+------+
|    1 | NULL |    2 |
+------+------+------+

$ hdfs dfs -cat /user/hive/warehouse/t2/* | od -Anone -tacd1x1

    1  soh  soh    2   nl       # a  = named characters
    1  001  001    2   \n       # c  = ASCII characters or backslash escapes
   49    1    1   50   10       # d1 = decimal     (1-byte)
   31   01   01   32   0a       # x1 = hexadecimal (1-byte)

【讨论】:

    猜你喜欢
    • 2017-09-24
    • 2023-03-29
    • 2017-08-29
    • 2017-10-08
    • 2016-03-12
    • 1970-01-01
    • 2014-04-19
    • 1970-01-01
    • 2013-09-23
    相关资源
    最近更新 更多