如何在hive中从结构数组中获取值?FAILED: ParseException line 6:20 cannot recognize input near '.' 'district' 'district' in table source

yqyhoc1h  于 2021-04-09  发布在  Hive
关注(0)|答案(1)|浏览(673)

表结构

CREATE EXTERNAL TABLE IF NOT EXISTS LocationTable
(
USER_ID BIGINT,
NAME STRING,
STATE STRUCT < DISTRICT ARRAY < ID:BIGINT, NAME:STRING > >
)

我的查询是:

SELECT user_id, name,
district.pos as district_pos,
district.name as district_name,
FROM
locationtable,
locationtable.state.district district
WHERE user_id = '58'

它抛出以下错误。

Error while compiling statement: FAILED: ParseException line 6:20 cannot recognize input near '.' 'district' 'district' in table source

我哪里做错了?

2izufjch

2izufjch1#

使用explode

select 
     user_id,
     name,
     state.district.ID as district_pos,
     state.district.NAME as district_name
from
   locationtable 
   lateral view explode(STATE) exploded_table as state;

相关问题