SQL (Hive) 中的动态聚合

Dynamic aggregation in SQL (Hive)

我有两张桌子。 Table 包含 3 列的 A:用户 ID、开始日期和结束日期。 Table B 带有事件和日期时间戳。我想根据 Table A 将 Table B 汇总到开始日期和结束日期之间的日期时间。所以像...

select a.userid, count(distinct b.eventid) as events
from table a
inner join table b
on a.userid=b.userid
and b.datetime between a.starttime and b.endtime
group by a.userid

但 Hive 不喜欢那样...我正在使用 Hadoop HortonWorks。非常感谢任何指导!

between 条件移至 where,因为在版本 2.2.0 之前仅支持 join 中的相等条件。

From Hive documentation

Complex expressions in ON clause are supported, starting with Hive 2.2.0 (see HIVE-15211, HIVE-15251). Prior to that, Hive did not support join conditions that are not equality conditions.