从Hive表中删除NULL

时间:2018-04-30 15:53:45

标签: hive hiveql

我有一个表,在某些列中有'NULL'值,我的下游程序不接受NULL值,我可以编写一个switch case语句用空格''替换空值但我正在寻找一种更有效的方法改变表属性以显示空白而不是null。

1 个答案:

答案 0 :(得分:0)

您可以使用此查询来解释' NULL'在基础数据中作为空字符串。

SELECT TRANSLATE(column1,'NULL','') FROM MyTable;

<强>插图:

-- This is the Hive table

> desc hive_tbl;

col_name                data_type
h1                      string
h2                      string
h3                      string
h4                      string

-- This is the query that interprets h2 having 'NULL' as another character. 
-- In this case, 'X' is used instead of '' so that it prints in the display.

> SELECT h1, h2, h3, h4, TRANSLATE(h2,'NULL','X') h2_updated FROM hive_tbl;

h1  h2      h3  h4                                                h2_updated
1   foo     100 entry-foo                                         foo
2   NULL    200 The data is absent for second column              NULL
3   NULL    300 The value in second column is the string NULL     X