将数组列查询为 Impala 中的行的解决方法

Workaround to query array column as rows in Impala

在 Hive 中,我可以使用 explode 函数,但如何在 Impala 中使用?

我读了这篇文章,但仍然没有头绪:

Is there a function equivalent to Hive's 'explode' function in Apache Impala?

这就是我在 Hive 中创建 table 的方式:

create table tb (arr_col array<string>)

insert into tb select array ('A','B') from (select 'temp') x

我的查询会报错:

select tb.arr_col from tb

..in select list returns a complex type 'ARRAY<STRING>'.
Only scalar types are allowed in the select list.

select tb.arr_col.item from tb

ERROR: AnalysisException: Illegal column/field reference 'arr_col.item' with intermediate collection 'item' of type 'ARRAY<STRING>'

请指教最好的方法。 谢谢

这就是您在 Impala 中查询数组的方式,它可能等同于 explode

select arr_col, m.item from tb , tb.arr_col m ;

默认情况下impala使用名称“item”来访问原始数组的元素。对于结构数组,您需要更改要访问的字段的“项目”。