首页 > 解决方案 > 在 Impala 中将数组列查询为行的解决方法

问题描述

在 Hive 中,我可以使用explode函数,但如何在 Impala 中做到这一点?

我读了这个,但仍然不知道:

Apache Impala 中是否有与 Hive 的“爆炸”功能等效的功能?

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

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>'

请告知最好的方法。谢谢

标签: sqlhadoophiveimpalasql-function

解决方案


这就是您在 Impala 中查询数组的方式,这可能相当于爆炸

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

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


推荐阅读