如何在 HIVE 中合并具有不同模式的表?

How to union tables with different schema in HIVE?

我在 HIVE 中有两个 table:

tableA 和 B 都包含列 "C"。

我想像这样合并它们:

select g.* from 

(select N, C from A
union all
select null as N, C from B
) g;

但这会在 HIVE 中引发错误:

FAILED:...Schema of both sides of union should match: Column N is of type array<string> on first table and type void on second table.

因此,我尝试转换数据类型:

select g.* from 

(select N, C from A
union all
select cast(null as array) as N, C from B
) g;

失败 "cannot recognize input near 'array' ')' 'as' in primitive type specification.

我该如何解决这个问题?感谢

嗯。可能有更简单的方法,但我不确定如何在 Hive 中表达 NULL 数组常量。您可以为此使用 SQL:

select g.*
from (select N, C from A
      union all
      select A.N, C
      from B join
           A 
           on 1 = 0
     ) g;

换句话说,我可能不知道如何表达我头脑中的常数。但是,我可以安排从 A 中获取它——通过匹配行失败。