从 Hive QL 中的数组中获取正确的值



我有一个包装数组,并且只想在使用横向视图爆炸查询时获取相应的值结构

样品结构:

列名:数组

WrappedArray([null,theVal,valTags,[123,null,null,null,null,null],false], [null,theVar,varTags,[abc,null,null,null,null,null],false])

架构为

array<struct<id:string,name:string,type:string,value:struct<member0:string,member1:bigint,member2:int,member3:double,member4:float,member5:boolean>,shouldIndex:boolean>>

我的查询:

SELECT DISTINCT theName, allValues
FROM table 
LATERAL VIEW EXPLODE(column.name) theTab1 AS theName
LATERAL VIEW EXPLODE(column.value.member0) theTab2 AS allValues
WHERE theName = 'theVal'

我的结果:

___________________________
|**theName**|**allValues**|
___________________________
|theVal     |     123     |
___________________________
| theVal    |     abc     |
___________________________

我需要:

___________________________
|**theName**|**allValues**|
___________________________
|theVal     |     123     |
___________________________

如何修复我的查询以获得上述结果?

不需要在结构顶部进行额外的爆炸。你应该能够像这样执行它

SELECT DISTINCT theName, column.value.member0
FROM table 
LATERAL VIEW EXPLODE(column.name) theTab1 AS theName
WHERE theName = 'theVal'

最新更新