从配置单元表中删除null

c3frrgcw  于 2021-06-26  发布在  Hive
关注(0)|答案(1)|浏览(325)

我有一个表,其中某些列有“null”值,我的下游程序不接受null值,我可以编写一个switch case语句,将null替换为空“”,但我正在寻找一种更有效的方法,例如更改表属性以显示blank而不是null。

unguejic

unguejic1#

可以使用此查询将基础数据中的“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

相关问题