sql - 在 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>'
请告知最好的方法。谢谢
解决方案
这就是您在 Impala 中查询数组的方式,这可能相当于爆炸
select arr_col, m.item from tb , tb.arr_col m ;
默认情况下,impala 使用名称“item”来访问原始数组的元素。在结构数组的情况下,您需要更改要访问的字段的“项目”。
推荐阅读
- amazon-web-services - 关于验证 Secrets Manager 的凭证轮换 Lambda 函数是否成功的问题
- angular - 如何从指令中访问某种类型的所有子组件?
- php - 删除一年中的月份
- java - Long 和 Double 比较 (==) 的行为不同
- python - 如何从没有numpy的多维数组中提取一行?
- javascript - 将 $_POST 变量传递给新 URL,然后返回到以前的 URL - 最佳实践?
- unit-testing - Kafka Streams 测试:java.util.NoSuchElementException:未初始化的主题:“output_topic_name”
- acumatica - 如何在屏幕和导入场景中避免 Acumatica 网格中的重复条目
- android - 如何对 LiveData 转换进行单元测试
- python-3.x - Python/Tkinter:ModuleNotFoundError:没有名为“_tkinter”的模块