我正在使用Apache Hive 0.13(支持子查询),我正在尝试运行一个查询,其子查询使用LATERAL VIEW和explode()。我一直在接受NPE:
FAILED:NullPointerException null
我已经单独尝试了子查询&独立,它工作正常。在Hive documentation
中使用LATERAL VIEW进行子查询时,我也找不到任何限制所以我想知道我的查询是什么问题。您可以在下面看到查询:
select u.name, u.employment
from users u
where u.id IN (
SELECT distinct su.id
FROM users su LATERAL VIEW explode(su.employment) empTable AS emp
where su.frCount >= 10
and su.frCount < 20
and emp.endDate is NULL
);
我正在使用带有JSON数据的Hive。这是表格的DDL:
CREATE TABLE users(
id BIGINT,
name string,
frCount INT,
employment array<struct<
organization_name : string,
start_date: BIGINT,
end_date: BIGINT>>
) ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe' STORED AS TEXTFILE;
答案 0 :(得分:2)
你可以使用Hive左半连接。
select u.name, u.employment
from users u left semi join
(SELECT distinct su.id
FROM users su LATERAL VIEW explode(su.employment) empTable AS emp
where su.frCount >= 10
and su.frCount < 20
and emp.endDate is NULL) t on u.id = t.id